diff options
Diffstat (limited to '')
-rw-r--r-- | common/ChangeLog | 9 | ||||
-rw-r--r-- | common/Makefile.am | 1 | ||||
-rw-r--r-- | common/gettime.c | 6 | ||||
-rw-r--r-- | common/tlv.c (renamed from scd/tlv.c) | 36 | ||||
-rw-r--r-- | common/tlv.h (renamed from scd/tlv.h) | 20 | ||||
-rw-r--r-- | common/util.h | 2 |
6 files changed, 45 insertions, 29 deletions
diff --git a/common/ChangeLog b/common/ChangeLog index d3f55066d..f963e5282 100644 --- a/common/ChangeLog +++ b/common/ChangeLog @@ -1,3 +1,10 @@ +2007-08-07 Werner Koch <[email protected]> + + * tlv.c, tlv.h: Move from ../scd/. + * tlv.c (parse_sexp, parse_ber_header): Add ERRSOURCE arg and prefix + name with a _. + * tlv.h: Use macro to convey ERRSOURCE. + 2007-08-02 Werner Koch <[email protected]> * gc-opt-flags.h: New. @@ -29,7 +36,7 @@ 2007-07-04 Werner Koch <[email protected]> - * estream.c (es_init_do): Do not throw an error if pth as already + * estream.c (es_init_do): Do not throw an error if pth has already been initialized. 2007-06-26 Werner Koch <[email protected]> diff --git a/common/Makefile.am b/common/Makefile.am index 0ce11f188..fc0c357d9 100644 --- a/common/Makefile.am +++ b/common/Makefile.am @@ -36,6 +36,7 @@ common_sources = \ gc-opt-flags.h \ keyserver.h \ sexp-parse.h \ + tlv.c tlv.h \ init.c init.h \ sexputil.c \ sysutils.c sysutils.h \ diff --git a/common/gettime.c b/common/gettime.c index 56ff40eec..1814826c0 100644 --- a/common/gettime.c +++ b/common/gettime.c @@ -72,10 +72,10 @@ gnupg_get_isotime (gnupg_isotime_t timebuf) } -/* set the time to NEWTIME so that gnupg_get_time returns a time +/* Set the time to NEWTIME so that gnupg_get_time returns a time starting with this one. With FREEZE set to 1 the returned time will never change. Just for completeness, a value of (time_t)-1 - for NEWTIME gets you back to rality. Note that this is obviously + for NEWTIME gets you back to reality. Note that this is obviously not thread-safe but this is not required. */ void gnupg_set_time (time_t newtime, int freeze) @@ -165,7 +165,7 @@ scan_isodatestr( const char *string ) return stamp; } -/* Scan am ISO timestamp and return a epoch based timestamp. The only +/* Scan am ISO timestamp and return an Epoch based timestamp. The only supported format is "yyyymmddThhmmss" delimited by white space, nul, a colon or a comma. Returns (time_t)(-1) for an invalid string. */ time_t diff --git a/scd/tlv.c b/common/tlv.c index e665f9087..c68756406 100644 --- a/scd/tlv.c +++ b/common/tlv.c @@ -29,7 +29,7 @@ #define GPG_ERR_BAD_BER (1) /*G10ERR_GENERAL*/ #define GPG_ERR_INV_SEXP (45) /*G10ERR_INV_ARG*/ typedef int gpg_error_t; -#define gpg_error(n) (n) +#define gpg_make_err(x,n) (n) #else #include <gpg-error.h> #endif @@ -151,10 +151,11 @@ find_tlv_unchecked (const unsigned char *buffer, size_t length, and the length part from the TLV triplet. Update BUFFER and SIZE on success. */ gpg_error_t -parse_ber_header (unsigned char const **buffer, size_t *size, - int *r_class, int *r_tag, - int *r_constructed, int *r_ndef, - size_t *r_length, size_t *r_nhdr) +_parse_ber_header (unsigned char const **buffer, size_t *size, + int *r_class, int *r_tag, + int *r_constructed, int *r_ndef, + size_t *r_length, size_t *r_nhdr, + gpg_err_source_t errsource) { int c; unsigned long tag; @@ -167,7 +168,7 @@ parse_ber_header (unsigned char const **buffer, size_t *size, /* Get the tag. */ if (!length) - return gpg_error (GPG_ERR_EOF); + return gpg_err_make (errsource, GPG_ERR_EOF); c = *buf++; length--; ++*r_nhdr; *r_class = (c & 0xc0) >> 6; @@ -181,7 +182,7 @@ parse_ber_header (unsigned char const **buffer, size_t *size, { tag <<= 7; if (!length) - return gpg_error (GPG_ERR_EOF); + return gpg_err_make (errsource, GPG_ERR_EOF); c = *buf++; length--; ++*r_nhdr; tag |= c & 0x7f; @@ -192,7 +193,7 @@ parse_ber_header (unsigned char const **buffer, size_t *size, /* Get the length. */ if (!length) - return gpg_error (GPG_ERR_EOF); + return gpg_err_make (errsource, GPG_ERR_EOF); c = *buf++; length--; ++*r_nhdr; if ( !(c & 0x80) ) @@ -200,20 +201,20 @@ parse_ber_header (unsigned char const **buffer, size_t *size, else if (c == 0x80) *r_ndef = 1; else if (c == 0xff) - return gpg_error (GPG_ERR_BAD_BER); + return gpg_err_make (errsource, GPG_ERR_BAD_BER); else { unsigned long len = 0; int count = c & 0x7f; if (count > sizeof (len) || count > sizeof (size_t)) - return gpg_error (GPG_ERR_BAD_BER); + return gpg_err_make (errsource, GPG_ERR_BAD_BER); for (; count; count--) { len <<= 8; if (!length) - return gpg_error (GPG_ERR_EOF); + return gpg_err_make (errsource, GPG_ERR_EOF); c = *buf++; length--; ++*r_nhdr; len |= c & 0xff; } @@ -254,8 +255,9 @@ parse_ber_header (unsigned char const **buffer, size_t *size, handle_error (); */ gpg_error_t -parse_sexp (unsigned char const **buf, size_t *buflen, - int *depth, unsigned char const **tok, size_t *toklen) +_parse_sexp (unsigned char const **buf, size_t *buflen, + int *depth, unsigned char const **tok, size_t *toklen, + gpg_err_source_t errsource) { const unsigned char *s; size_t n, vlen; @@ -265,7 +267,7 @@ parse_sexp (unsigned char const **buf, size_t *buflen, *tok = NULL; *toklen = 0; if (!n) - return *depth ? gpg_error (GPG_ERR_INV_SEXP) : 0; + return *depth ? gpg_err_make (errsource, GPG_ERR_INV_SEXP) : 0; if (*s == '(') { s++; n--; @@ -277,7 +279,7 @@ parse_sexp (unsigned char const **buf, size_t *buflen, if (*s == ')') { if (!*depth) - return gpg_error (GPG_ERR_INV_SEXP); + return gpg_err_make (errsource, GPG_ERR_INV_SEXP); *toklen = 1; s++; n--; (*depth)--; @@ -288,10 +290,10 @@ parse_sexp (unsigned char const **buf, size_t *buflen, for (vlen=0; n && *s && *s != ':' && (*s >= '0' && *s <= '9'); s++, n--) vlen = vlen*10 + (*s - '0'); if (!n || *s != ':') - return gpg_error (GPG_ERR_INV_SEXP); + return gpg_err_make (errsource, GPG_ERR_INV_SEXP); s++; n--; if (vlen > n) - return gpg_error (GPG_ERR_INV_SEXP); + return gpg_err_make (errsource, GPG_ERR_INV_SEXP); *tok = s; *toklen = vlen; s += vlen; diff --git a/scd/tlv.h b/common/tlv.h index 66ea871bc..a04af93ad 100644 --- a/scd/tlv.h +++ b/common/tlv.h @@ -80,11 +80,14 @@ const unsigned char *find_tlv_unchecked (const unsigned char *buffer, /* ASN.1 BER parser: Parse BUFFER of length SIZE and return the tag and the length part from the TLV triplet. Update BUFFER and SIZE on success. */ -gpg_error_t parse_ber_header (unsigned char const **buffer, size_t *size, - int *r_class, int *r_tag, - int *r_constructed, - int *r_ndef, size_t *r_length, size_t *r_nhdr); - +gpg_error_t _parse_ber_header (unsigned char const **buffer, size_t *size, + int *r_class, int *r_tag, + int *r_constructed, + int *r_ndef, size_t *r_length, size_t *r_nhdr, + gpg_err_source_t errsource); +#define parse_ber_header(a,b,c,d,e,f,g,h) \ + _parse_ber_header ((a),(b),(c),(d),(e),(f),(g),(h),\ + GPG_ERR_SOURCE_DEFAULT) /* Return the next token of an canconical encoded S-expression. BUF @@ -99,8 +102,11 @@ gpg_error_t parse_ber_header (unsigned char const **buffer, size_t *size, reflect on return the actual depth of the tree. To detect the end of the S-expression it is advisable to check DEPTH after a successful return. */ -gpg_error_t parse_sexp (unsigned char const **buf, size_t *buflen, - int *depth, unsigned char const **tok, size_t *toklen); +gpg_error_t _parse_sexp (unsigned char const **buf, size_t *buflen, + int *depth, unsigned char const **tok, size_t *toklen, + gpg_err_source_t errsource); +#define parse_sexp(a,b,c,d,e) \ + _parse_sexp ((a),(b),(c),(d),(e), GPG_ERR_SOURCE_DEFAULT) diff --git a/common/util.h b/common/util.h index 3ec5200bf..9821d6ab6 100644 --- a/common/util.h +++ b/common/util.h @@ -112,7 +112,7 @@ const char *isotimestamp (u32 stamp); /* GMT */ const char *asctimestamp (u32 stamp); /* localized */ -/* Copy one iso ddate to another, this is inline so that we can do a +/* Copy one ISO date to another, this is inline so that we can do a sanity check. */ static inline void gnupg_copy_time (gnupg_isotime_t d, const gnupg_isotime_t s) |