Author: Pekka Riikonen <priikone@silcnet.org>
- Copyright (C) 2003 - 2006 Pekka Riikonen
+ Copyright (C) 2003 - 2007 Pekka Riikonen
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
SilcList types;
SilcAsn1Tag type;
SilcBuffer *retb;
- SilcUInt32 *retc;
- SilcAsn1Tag rtag;
+ SilcUInt32 *retc, rtag;
const unsigned char *rdata;
SilcUInt32 rdata_len, len = 0;
SilcBool found = FALSE, rindef;
assert(type == SILC_ASN1_END);
/* Decode the SEQUENCE or SET */
- ret = silc_ber_decode(src, NULL, NULL, (SilcUInt32 *)&rtag, &rdata,
+ ret = silc_ber_decode(src, NULL, NULL, &rtag, &rdata,
&rdata_len, &rindef, &len);
if (!ret) {
SILC_LOG_DEBUG(("Error parsing BER block, malformed ASN.1 data"));
while (silc_buffer_len(src)) {
/* Decode the BER data. */
- ret = silc_ber_decode(src, NULL, NULL, (SilcUInt32 *)&rtag, &rdata,
+ ret = silc_ber_decode(src, NULL, NULL, &rtag, &rdata,
&rdata_len, &rindef, &len);
if (!ret) {
SILC_LOG_DEBUG(("Error parsing BER block, malformed ASN.1 data"));
ret = FALSE; \
goto fail; \
} \
- *s = silc_smalloc_ua(stack1, *s_len + 1); \
+ *s = silc_smalloc(stack1, *s_len + 1); \
if (*s) { \
silc_utf8_encode(rdata, rdata_len, (enc), *s, *s_len); \
(*s)[*s_len] = '\0'; \
SilcBool primitive)
{
unsigned char *ptr = src->data;
- SilcAsn1Tag rtype, rtag;
+ SilcAsn1Tag rtype;
SilcAsn1Options ropts;
SilcBerClass rclass;
SilcBerEncoding renc;
- SilcUInt32 len = 0;
+ SilcUInt32 len = 0, rtag;
SilcBool ret, indef, rindef, found = FALSE, choice = FALSE;
const unsigned char *rdata;
SilcUInt32 rdata_len;
}
}
+ /* Short integer is actually big integer in the BER data, so handle
+ it correctly */
+ if (type == SILC_ASN1_TAG_SHORT_INTEGER && type == tag)
+ tag = SILC_ASN1_TAG_INTEGER;
+
/* Now decode a BER encoded block from the source buffer. It must be
exactly the same user is expecting. */
- ret = silc_ber_decode(src, &rclass, &renc, (SilcUInt32 *)&rtag, &rdata,
+ ret = silc_ber_decode(src, &rclass, &renc, &rtag, &rdata,
&rdata_len, &rindef, &len);
if (!ret) {
SILC_LOG_DEBUG(("Error parsing BER block, malformed ASN.1 data"));
break;
}
+ case SILC_ASN1_TAG_SHORT_INTEGER:
+ {
+ /* Short Integer */
+ SilcMPInt z;
+ SILC_ASN1_VAD(asn1, opts, SilcUInt32, intval);
+
+ if (rdata_len < 1) {
+ SILC_LOG_DEBUG(("Malformed integer value"));
+ SILC_ASN1_VA_FREE(opts, intval);
+ ret = FALSE;
+ goto fail;
+ }
+
+ silc_stack_push(asn1->stack1, NULL);
+ silc_mp_sinit(asn1->stack1, &z);
+ silc_mp_bin2mp((unsigned char *)rdata, rdata_len, &z);
+ *(*intval) = silc_mp_get_ui(&z);
+ silc_mp_uninit(&z);
+ silc_stack_pop(asn1->stack1);
+ break;
+ }
+
case SILC_ASN1_TAG_OID:
{
/* Object identifier */
if (rdata_len < 1) {
SILC_LOG_DEBUG(("Malformed object identifier value"));
+ SILC_ASN1_VA_FREE(opts, oidstr);
ret = FALSE;
goto fail;
}
/* Set two OID values */
memset(&tmpb, 0, sizeof(tmpb));
memset(tmpstr, 0, sizeof(tmpstr));
- snprintf(tmpstr, sizeof(tmpstr) - 1, "%lu.%lu",
+ silc_snprintf(tmpstr, sizeof(tmpstr) - 1, "%lu.%lu",
(unsigned long)(rdata[0] & 0xff) / 40,
(unsigned long)(rdata[0] & 0xff) % 40);
silc_buffer_sstrformat(asn1->stack1, &tmpb, tmpstr, SILC_STR_END);
oid |= rdata[i];
memset(tmpstr, 0, sizeof(tmpstr));
- snprintf(tmpstr, sizeof(tmpstr) - 1, ".%lu", (unsigned long)oid);
+ silc_snprintf(tmpstr, sizeof(tmpstr) - 1, ".%lu", (unsigned long)oid);
silc_buffer_sstrformat(asn1->stack1, &tmpb, tmpstr, SILC_STR_END);
}
*oidstr = tmpb.head;
if (rdata_len < 2) {
SILC_LOG_DEBUG(("Malformed bit string value"));
+ SILC_ASN1_VA_FREE(opts, d);
ret = FALSE;
goto fail;
}
if (rdata_len < 1) {
SILC_LOG_DEBUG(("Malformed UTC time value"));
+ SILC_ASN1_VA_FREE(opts, t);
ret = FALSE;
goto fail;
}
if (rdata_len < 1) {
SILC_LOG_DEBUG(("Malformed generalized time value"));
+ SILC_ASN1_VA_FREE(opts, t);
ret = FALSE;
goto fail;
}
/* Parse the time string */
if (!silc_time_generalized(rdata, *t)) {
SILC_LOG_DEBUG(("Malformed generalized time value"));
+ SILC_ASN1_VA_FREE(opts, t);
ret = FALSE;
goto fail;
}
if (!silc_utf8_valid(rdata, rdata_len)) {
SILC_LOG_DEBUG(("Malformed UTF-8 string value"));
+ SILC_ASN1_VA_FREE(opts, s);
ret = FALSE;
goto fail;
}
case SILC_ASN1_TAG_OCTET_STRING:
{
- /* Octet string. We take it as 8-bit ASCII */
+ /* Octet string. Take data as is. */
SILC_ASN1_VAD_UCHAR(asn1, opts, unsigned char, s, s_len);
- SILC_ASN1_DECODE_STRING(SILC_STRING_ASCII, s, s_len);
+ *s = silc_smemdup(stack1, rdata, rdata_len);
+ *s_len = rdata_len;
break;
}
SILC_ASN1_ARGS(asn1, type, tag, ber_class, opts);
if (!type) {
va_end(asn1->ap);
- asn1->ap = NULL;
return FALSE;
}
}
va_end(asn1->ap);
- asn1->ap = NULL;
return ret;
}