aboutsummaryrefslogtreecommitdiffstats
path: root/agent/protect.c
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2002-03-04 10:34:51 +0000
committerWerner Koch <[email protected]>2002-03-04 10:34:51 +0000
commit9301f1cf6971e8850f316665470b38574b4e5abb (patch)
tree733ad5ba52bfcb10a80989477a64a21a1194918a /agent/protect.c
parentAdded more code fragments. (diff)
downloadgnupg-9301f1cf6971e8850f316665470b38574b4e5abb.tar.gz
gnupg-9301f1cf6971e8850f316665470b38574b4e5abb.zip
* pksign.c (agent_pksign): Detect whether a Smartcard is to be
used and divert the operation in this case. * pkdecrypt.c (agent_pkdecrypt): Likewise * findkey.c (agent_key_from_file): Add optional arg shadow_info and have it return information about a shadowed key. * protect.c (agent_get_shadow_info): New. * protect.c (snext,sskip,smatch): Moved to * sexp-parse.h: new file. * divert-scd.c: New.
Diffstat (limited to 'agent/protect.c')
-rw-r--r--agent/protect.c76
1 files changed, 2 insertions, 74 deletions
diff --git a/agent/protect.c b/agent/protect.c
index ea8e30496..08f322bac 100644
--- a/agent/protect.c
+++ b/agent/protect.c
@@ -30,6 +30,8 @@
#include "agent.h"
+#include "sexp-parse.h"
+
#define PROT_CIPHER GCRY_CIPHER_AES
#define PROT_CIPHER_STRING "aes"
#define PROT_CIPHER_KEYLEN (128/8)
@@ -54,80 +56,6 @@ hash_passphrase (const char *passphrase, int hashalgo,
unsigned char *key, size_t keylen);
-
-/* Return the length of the next S-Exp part and update the pointer to
- the first data byte. 0 is return on error */
-static size_t
-snext (unsigned char const **buf)
-{
- const unsigned char *s;
- int n;
-
- s = *buf;
- for (n=0; *s && *s != ':' && digitp (s); s++)
- n = n*10 + atoi_1 (s);
- if (!n || *s != ':')
- return 0; /* we don't allow empty lengths */
- *buf = s+1;
- return n;
-}
-
-/* Skip over the S-Expression BUF points to and update BUF to point to
- the chacter right behind. DEPTH gives the initial number of open
- lists and may be passed as a positive number to skip over the
- remainder of an S-Expression if the current position is somewhere
- in an S-Expression. The function may return an error code if it
- encounters an impossible conditions */
-static int
-sskip (unsigned char const **buf, int *depth)
-{
- const unsigned char *s = *buf;
- size_t n;
- int d = *depth;
-
- while (d > 0)
- {
- if (*s == '(')
- {
- d++;
- s++;
- }
- else if (*s == ')')
- {
- d--;
- s++;
- }
- else
- {
- if (!d)
- return GNUPG_Invalid_Sexp;
- n = snext (&s);
- if (!n)
- return GNUPG_Invalid_Sexp;
- s += n;
- }
- }
- *buf = s;
- *depth = d;
- return 0;
-}
-
-
-/* Check whether the the string at the address BUF points to matches
- the token. Return true on match and update BUF to point behind the
- token. */
-static int
-smatch (unsigned char const **buf, size_t buflen, const char *token)
-{
- size_t toklen = strlen (token);
-
- if (buflen != toklen || memcmp (*buf, token, toklen))
- return 0;
- *buf += toklen;
- return 1;
-}
-
-
/* Calculate the MIC for a private key S-Exp. SHA1HASH should pint to
a 20 byte buffer. This function is suitable for any algorithms. */