aboutsummaryrefslogtreecommitdiffstats
path: root/common/tlv.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--common/tlv.c (renamed from scd/tlv.c)36
1 files changed, 19 insertions, 17 deletions
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;