add ENUMERATED and OBJECT IDENTIFIER

git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@10741 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
Assar Westerlund
2001-09-25 13:39:27 +00:00
parent 680399419e
commit 2bcae56ac3
18 changed files with 323 additions and 26 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997 - 2000 Kungliga Tekniska H<>gskolan
* Copyright (c) 1997 - 2001 Kungliga Tekniska H<>gskolan
* (Royal Institute of Technology, Stockholm, Sweden).
* All rights reserved.
*
@@ -138,6 +138,38 @@ der_get_octet_string (const unsigned char *p, size_t len,
return 0;
}
int
der_get_oid (const unsigned char *p, size_t len,
oid *data, size_t *size)
{
int n;
if (len < 1)
return ASN1_OVERRUN;
data->components = malloc(len * sizeof(*data->components));
if (data->components == NULL && len != 0)
return ENOMEM;
data->components[0] = (*p) / 40;
data->components[1] = (*p) % 40;
--len;
++p;
for (n = 2; len > 0; ++n) {
unsigned u = 0;
do {
--len;
u = u * 128 + (*p % 128);
} while (len > 0 && p[-1] & 0x80);
data->components[n] = u;
}
if (p[-1] & 0x80) {
free_oid (data);
return ASN1_OVERRUN;
}
return 0;
}
int
der_get_tag (const unsigned char *p, size_t len,
Der_class *class, Der_type *type,
@@ -251,6 +283,33 @@ decode_unsigned (const unsigned char *p, size_t len,
return 0;
}
int
decode_enumerated (const unsigned char *p, size_t len,
unsigned *num, size_t *size)
{
size_t ret = 0;
size_t l, reallen;
int e;
e = der_match_tag (p, len, UNIV, PRIM, UT_Enumerated, &l);
if (e) return e;
p += l;
len -= l;
ret += l;
e = der_get_length (p, len, &reallen, &l);
if (e) return e;
p += l;
len -= l;
ret += l;
e = der_get_int (p, reallen, num, &l);
if (e) return e;
p += l;
len -= l;
ret += l;
if(size) *size = ret;
return 0;
}
int
decode_general_string (const unsigned char *p, size_t len,
general_string *str, size_t *size)