Skip to content

Commit

Permalink
clean-up; removed unnecessary field from type descriptor
Browse files Browse the repository at this point in the history
  • Loading branch information
vlm committed Sep 26, 2004
1 parent 9821098 commit 8e8078a
Show file tree
Hide file tree
Showing 52 changed files with 251 additions and 415 deletions.
5 changes: 2 additions & 3 deletions skeletons/ANY.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ asn1_TYPE_descriptor_t asn1_DEF_ANY = {
ANY_encode_xer,
0, /* Use generic outmost tag fetcher */
0, 0, 0, 0,
-1, /* Both ways are fine (primitive and constructed) */
0, 0, /* No members */
(void *)1 /* Special indicator that this is an ANY type */
(void *)2 /* Special indicator that this is an ANY type */
};


Expand Down Expand Up @@ -139,7 +138,7 @@ static int ANY__consume_bytes(const void *buffer, size_t size, void *key) {
size_t nsize = (arg->size ? arg->size << 2 : 16) + size;
void *p = REALLOC(arg->buffer, nsize);
if(!p) return -1;
(void *)arg->buffer = p;
arg->buffer = (uint8_t *)p;
arg->size = nsize;
}

Expand Down
22 changes: 9 additions & 13 deletions skeletons/BIT_STRING.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/
#include <asn_internal.h>
#include <BIT_STRING.h>
#include <asn_internal.h>

/*
* BIT STRING basic type description.
Expand All @@ -27,9 +28,8 @@ asn1_TYPE_descriptor_t asn1_DEF_BIT_STRING = {
asn1_DEF_BIT_STRING_tags, /* Same as above */
sizeof(asn1_DEF_BIT_STRING_tags)
/ sizeof(asn1_DEF_BIT_STRING_tags[0]),
-1, /* Both ways are fine */
0, 0, /* No members */
(void *)-1 /* Special indicator that this is a BIT STRING */
(void *)1 /* Special indicator that this is a BIT STRING */
};

/*
Expand Down Expand Up @@ -144,9 +144,10 @@ BIT_STRING_print(asn1_TYPE_descriptor_t *td, const void *sptr, int ilevel,

(void)td; /* Unused argument */

if(!st || !st->buf) return cb("<absent>", 8, app_key);
if(!st || !st->buf)
return (cb("<absent>", 8, app_key) < 0) ? -1 : 0;

ilevel += 4;
ilevel++;
buf = st->buf;
end = buf + st->size;

Expand All @@ -156,12 +157,9 @@ BIT_STRING_print(asn1_TYPE_descriptor_t *td, const void *sptr, int ilevel,
for(buf++; buf < end; buf++) {
if(((buf - st->buf) - 1) % 16 == 0 && (st->size > 17)
&& buf != st->buf+1) {
int i;
/* Indentation */
if(cb("\n", 1, app_key)) return -1;
for(i = 0; i < ilevel; i++) cb(" ", 1, app_key);
_i_INDENT(1);
/* Dump the string */
if(cb(scratch, p - scratch, app_key)) return -1;
if(cb(scratch, p - scratch, app_key) < 0) return -1;
p = scratch;
}
*p++ = h2c[*buf >> 4];
Expand All @@ -173,13 +171,11 @@ BIT_STRING_print(asn1_TYPE_descriptor_t *td, const void *sptr, int ilevel,
p--; /* Eat the tailing space */

if((st->size > 17)) {
int i;
if(cb("\n", 1, app_key)) return -1;
for(i = 0; i < ilevel; i++) cb(" ", 1, app_key);
_i_INDENT(1);
}

/* Dump the incomplete 16-bytes row */
if(cb(scratch, p - scratch, app_key))
if(cb(scratch, p - scratch, app_key) < 0)
return -1;
}

Expand Down
4 changes: 2 additions & 2 deletions skeletons/BMPString.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ asn1_TYPE_descriptor_t asn1_DEF_BMPString = {
asn1_DEF_BMPString_tags,
sizeof(asn1_DEF_BMPString_tags)
/ sizeof(asn1_DEF_BMPString_tags[0]),
-1, /* Both ways are fine */
0, 0, /* No members */
0 /* No specifics */
};
Expand Down Expand Up @@ -101,7 +100,8 @@ BMPString_print(asn1_TYPE_descriptor_t *td, const void *sptr, int ilevel,
(void)td; /* Unused argument */
(void)ilevel; /* Unused argument */

if(!st || !st->buf) return cb("<absent>", 8, app_key);
if(!st || !st->buf)
return (cb("<absent>", 8, app_key) < 0) ? -1 : 0;

if(BMPString__dump(st, cb, app_key) < 0)
return -1;
Expand Down
32 changes: 19 additions & 13 deletions skeletons/BOOLEAN.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ asn1_TYPE_descriptor_t asn1_DEF_BOOLEAN = {
sizeof(asn1_DEF_BOOLEAN_tags) / sizeof(asn1_DEF_BOOLEAN_tags[0]),
asn1_DEF_BOOLEAN_tags, /* Same as above */
sizeof(asn1_DEF_BOOLEAN_tags) / sizeof(asn1_DEF_BOOLEAN_tags[0]),
0, /* Always in primitive form */
0, 0, /* No members */
0 /* No specifics */
};
Expand All @@ -43,7 +42,7 @@ BOOLEAN_decode_ber(asn1_TYPE_descriptor_t *td,
ber_tlv_len_t lidx;

if(st == NULL) {
(void *)st = *bool_value = CALLOC(1, sizeof(*st));
st = (BOOLEAN_t *)(*bool_value = CALLOC(1, sizeof(*st)));
if(st == NULL) {
rval.code = RC_FAIL;
rval.consumed = 0;
Expand All @@ -57,7 +56,7 @@ BOOLEAN_decode_ber(asn1_TYPE_descriptor_t *td,
/*
* Check tags.
*/
rval = ber_check_tags(td, 0, buf_ptr, size, tag_mode, &length, 0);
rval = ber_check_tags(td, 0, buf_ptr, size, tag_mode, 0, &length, 0);
if(rval.code != RC_OK)
return rval;

Expand Down Expand Up @@ -101,7 +100,7 @@ BOOLEAN_encode_der(asn1_TYPE_descriptor_t *td, void *sptr,
asn_enc_rval_t erval;
BOOLEAN_t *st = (BOOLEAN_t *)sptr;

erval.encoded = der_write_tags(td, 1, tag_mode, tag, cb, app_key);
erval.encoded = der_write_tags(td, 1, tag_mode, 0, tag, cb, app_key);
if(erval.encoded == -1) {
erval.failed_type = td;
erval.structure_ptr = sptr;
Expand All @@ -110,11 +109,10 @@ BOOLEAN_encode_der(asn1_TYPE_descriptor_t *td, void *sptr,

if(cb) {
uint8_t bool_value;
ssize_t ret;

bool_value = *st?0xff:0; /* 0xff mandated by DER */
ret = cb(&bool_value, 1, app_key);
if(ret == -1) {
bool_value = *st ? 0xff : 0; /* 0xff mandated by DER */

if(cb(&bool_value, 1, app_key) < 0) {
erval.encoded = -1;
erval.failed_type = td;
erval.structure_ptr = sptr;
Expand Down Expand Up @@ -154,18 +152,26 @@ int
BOOLEAN_print(asn1_TYPE_descriptor_t *td, const void *sptr, int ilevel,
asn_app_consume_bytes_f *cb, void *app_key) {
const BOOLEAN_t *st = (const BOOLEAN_t *)sptr;
const char *buf;
size_t buflen;

(void)td; /* Unused argument */
(void)ilevel; /* Unused argument */

if(st) {
if(*st)
return cb("TRUE", 4, app_key);
else
return cb("FALSE", 5, app_key);
if(*st) {
buf = "TRUE";
buflen = 4;
} else {
buf = "FALSE";
buflen = 5;
}
} else {
return cb("<absent>", 8, app_key);
buf = "<absent>";
buflen = 8;
}

return (cb(buf, buflen, app_key) < 0) ? -1 : 0;
}

void
Expand Down
6 changes: 3 additions & 3 deletions skeletons/ENUMERATED.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/
#include <asn_internal.h>
#include <ENUMERATED.h>
#include <ber_codec_prim.h>

/*
* ENUMERATED basic type description.
Expand All @@ -13,10 +14,10 @@ static ber_tlv_tag_t asn1_DEF_ENUMERATED_tags[] = {
};
asn1_TYPE_descriptor_t asn1_DEF_ENUMERATED = {
"ENUMERATED",
INTEGER_free, /* Implemented in terms of INTEGER */
ASN__PRIMITIVE_TYPE_free,
INTEGER_print, /* Implemented in terms of INTEGER */
asn_generic_no_constraint,
INTEGER_decode_ber, /* Implemented in terms of INTEGER */
ber_decode_primitive,
INTEGER_encode_der, /* Implemented in terms of INTEGER */
0, /* Not implemented yet */
INTEGER_encode_xer, /* Implemented in terms of INTEGER */
Expand All @@ -25,7 +26,6 @@ asn1_TYPE_descriptor_t asn1_DEF_ENUMERATED = {
sizeof(asn1_DEF_ENUMERATED_tags) / sizeof(asn1_DEF_ENUMERATED_tags[0]),
asn1_DEF_ENUMERATED_tags, /* Same as above */
sizeof(asn1_DEF_ENUMERATED_tags) / sizeof(asn1_DEF_ENUMERATED_tags[0]),
0, /* Primitive */
0, 0, /* No members */
0 /* No specifics */
};
Expand Down
1 change: 0 additions & 1 deletion skeletons/GeneralString.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ asn1_TYPE_descriptor_t asn1_DEF_GeneralString = {
asn1_DEF_GeneralString_tags,
sizeof(asn1_DEF_GeneralString_tags)
/ sizeof(asn1_DEF_GeneralString_tags[0]),
-1, /* Both ways are fine */
0, 0, /* No members */
0 /* No specifics */
};
Expand Down
19 changes: 10 additions & 9 deletions skeletons/GeneralizedTime.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ static time_t timegm(struct tm *tm) {
* GeneralizedTime basic type description.
*/
static ber_tlv_tag_t asn1_DEF_GeneralizedTime_tags[] = {
(ASN_TAG_CLASS_UNIVERSAL | (24 << 2))
(ASN_TAG_CLASS_UNIVERSAL | (24 << 2)), /* [UNIVERSAL 24] IMPLICIT ...*/
(ASN_TAG_CLASS_UNIVERSAL | (26 << 2)), /* [UNIVERSAL 26] IMPLICIT ...*/
(ASN_TAG_CLASS_UNIVERSAL | (4 << 2)) /* ... OCTET STRING */
};
asn1_TYPE_descriptor_t asn1_DEF_GeneralizedTime = {
"GeneralizedTime",
Expand All @@ -124,11 +126,10 @@ asn1_TYPE_descriptor_t asn1_DEF_GeneralizedTime = {
0, /* Use generic outmost tag fetcher */
asn1_DEF_GeneralizedTime_tags,
sizeof(asn1_DEF_GeneralizedTime_tags)
/ sizeof(asn1_DEF_GeneralizedTime_tags[0]),
asn1_DEF_GeneralizedTime_tags, /* Same as above */
/ sizeof(asn1_DEF_GeneralizedTime_tags[0]) - 2,
asn1_DEF_GeneralizedTime_tags,
sizeof(asn1_DEF_GeneralizedTime_tags)
/ sizeof(asn1_DEF_GeneralizedTime_tags[0]),
-1, /* Both ways are fine */
0, 0, /* No members */
0 /* No specifics */
};
Expand Down Expand Up @@ -242,16 +243,16 @@ GeneralizedTime_print(asn1_TYPE_descriptor_t *td, const void *sptr, int ilevel,

errno = EPERM;
if(asn_GT2time(st, &tm, 1) == -1 && errno != EPERM)
return cb("<bad-value>", 11, app_key);
return (cb("<bad-value>", 11, app_key) < 0) ? -1 : 0;

ret = snprintf(buf, sizeof(buf),
"%04d-%02d-%02d %02d:%02d%02d (GMT)",
tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
tm.tm_hour, tm.tm_min, tm.tm_sec);
assert(ret > 0 && ret < (int)sizeof(buf));
return cb(buf, ret, app_key);
return (cb(buf, ret, app_key) < 0) ? -1 : 0;
} else {
return cb("<absent>", 8, app_key);
return (cb("<absent>", 8, app_key) < 0) ? -1 : 0;
}
}

Expand Down Expand Up @@ -493,7 +494,7 @@ asn_time2GT(GeneralizedTime_t *opt_gt, const struct tm *tm, int force_gmt) {
}

/* Pre-allocate a buffer of sufficient yet small length */
(void *)buf = MALLOC(buf_size);
buf = (char *)MALLOC(buf_size);
if(!buf) return 0;

gmtoff = GMTOFF(*tm);
Expand Down Expand Up @@ -536,7 +537,7 @@ asn_time2GT(GeneralizedTime_t *opt_gt, const struct tm *tm, int force_gmt) {
if(opt_gt->buf)
FREEMEM(opt_gt->buf);
} else {
(void *)opt_gt = CALLOC(1, sizeof *opt_gt);
opt_gt = (GeneralizedTime_t *)CALLOC(1, sizeof *opt_gt);
if(!opt_gt) { free(buf); return 0; }
}

Expand Down
1 change: 0 additions & 1 deletion skeletons/GraphicString.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ asn1_TYPE_descriptor_t asn1_DEF_GraphicString = {
asn1_DEF_GraphicString_tags,
sizeof(asn1_DEF_GraphicString_tags)
/ sizeof(asn1_DEF_GraphicString_tags[0]),
-1, /* Both ways are fine */
0, 0, /* No members */
0 /* No specifics */
};
Expand Down
1 change: 0 additions & 1 deletion skeletons/IA5String.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ asn1_TYPE_descriptor_t asn1_DEF_IA5String = {
asn1_DEF_IA5String_tags,
sizeof(asn1_DEF_IA5String_tags)
/ sizeof(asn1_DEF_IA5String_tags[0]),
-1, /* Both ways are fine */
0, 0, /* No members */
0 /* No specifics */
};
Expand Down
Loading

0 comments on commit 8e8078a

Please sign in to comment.