diff options
-rw-r--r-- | skeletons/ANY.c | 23 | ||||
-rw-r--r-- | skeletons/ANY.h | 32 | ||||
-rw-r--r-- | skeletons/OCTET_STRING.c | 22 | ||||
-rw-r--r-- | skeletons/OCTET_STRING.h | 4 | ||||
-rw-r--r-- | skeletons/file-dependencies | 3 |
5 files changed, 73 insertions, 11 deletions
diff --git a/skeletons/ANY.c b/skeletons/ANY.c new file mode 100644 index 00000000..20571209 --- /dev/null +++ b/skeletons/ANY.c @@ -0,0 +1,23 @@ +/*- + * Copyright (c) 2004 Lev Walkin <vlm@lionet.info>. All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#include <ANY.h> +#include <assert.h> +#include <errno.h> + +asn1_TYPE_descriptor_t asn1_DEF_ANY = { + "ANY", + asn_generic_no_constraint, + OCTET_STRING_decode_ber, + OCTET_STRING_encode_der, + OCTET_STRING_print, + OCTET_STRING_free, + 0, /* Use generic outmost tag fetcher */ + 0, + 0, + 0, /* No tags may be overridden */ + -1, /* Both ways are fine (primitive and constructed) */ + 0, 0, /* No members */ + (void *)1 /* Special indicator that this is an ANY type */ +}; diff --git a/skeletons/ANY.h b/skeletons/ANY.h new file mode 100644 index 00000000..0f10e101 --- /dev/null +++ b/skeletons/ANY.h @@ -0,0 +1,32 @@ +/*- + * Copyright (c) 2004 Lev Walkin <vlm@lionet.info>. All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#ifndef ASN_TYPE_ANY_H +#define ASN_TYPE_ANY_H + +#include <constr_TYPE.h> +#include <OCTET_STRING.h> /* Implemented via OCTET SRING type */ + +typedef struct ANY { + uint8_t *buf; /* BER-encoded ANY contents */ + int size; /* Size of the above buffer */ + + ber_dec_ctx_t _ber_dec_ctx; /* Parsing across buffer boundaries */ +} ANY_t; + +extern asn1_TYPE_descriptor_t asn1_DEF_ANY; + +ber_type_decoder_f ANY_decode_ber; +der_type_encoder_f ANY_encode_der; +asn_struct_print_f ANY_print; +asn_struct_free_f ANY_free; + +/****************************** + * Handy conversion routines. * + ******************************/ + +#define ANY_fromBuf(s, buf, size) OCTET_STRING_fromBuf((s), (buf), (size)) +#define ANY_new_fromBuf(buf, size) OCTET_STRING_new_fromBuf((buf), (size)) + +#endif /* ASN_TYPE_ANY_H */ diff --git a/skeletons/OCTET_STRING.c b/skeletons/OCTET_STRING.c index 6e0e426d..147dae70 100644 --- a/skeletons/OCTET_STRING.c +++ b/skeletons/OCTET_STRING.c @@ -150,7 +150,7 @@ OCTET_STRING_decode_ber(asn1_TYPE_descriptor_t *td, * This is a some sort of a hack. * The OCTET STRING decoder is being used in BIT STRING mode. */ - int is_bit_str = td->specifics?1:0; + int is_bit_str = (td->specifics==(void *)-1)?1:0; ASN_DEBUG("Decoding %s as %s (%ld)", td->name, @@ -395,6 +395,8 @@ OCTET_STRING_encode_der(asn1_TYPE_descriptor_t *sd, void *ptr, der_enc_rval_t erval; OCTET_STRING_t *st = (OCTET_STRING_t *)ptr; int add_byte = 0; + int is_bit_str = (td->specifics == (void *)-1); + int is_ANY_type = (td->specifics == (void *)1; ASN_DEBUG("%s %s as OCTET STRING", cb?"Estimating":"Encoding", sd->name); @@ -402,7 +404,7 @@ OCTET_STRING_encode_der(asn1_TYPE_descriptor_t *sd, void *ptr, /* * Canonicalize BIT STRING. */ - if(sd->specifics && st->buf) { + if(is_bit_str && st->buf) { switch(st->size) { case 0: add_byte = 1; break; case 1: st->buf[0] = 0; break; @@ -412,12 +414,16 @@ OCTET_STRING_encode_der(asn1_TYPE_descriptor_t *sd, void *ptr, } } - erval.encoded = der_write_tags(sd, st->size + add_byte, tag_mode, tag, - cb, app_key); - if(erval.encoded == -1) { - erval.failed_type = sd; - erval.structure_ptr = ptr; - return erval; + if(is_ANY_type) { + erval.encoded = 0; + } else { + erval.encoded = der_write_tags(sd, st->size + add_byte, + tag_mode, tag, cb, app_key); + if(erval.encoded == -1) { + erval.failed_type = sd; + erval.structure_ptr = ptr; + return erval; + } } if(cb) { diff --git a/skeletons/OCTET_STRING.h b/skeletons/OCTET_STRING.h index 223e1da5..df6ff4f2 100644 --- a/skeletons/OCTET_STRING.h +++ b/skeletons/OCTET_STRING.h @@ -28,8 +28,8 @@ asn_struct_free_f OCTET_STRING_free; /* * This function clears the previous value of the OCTET STRING (if any) - * and then allocates a new memory and makes s point to the newly allocated - * memory. If size = -1, the size of the original string will be determined + * and then allocates a new memory and returns a pointer to it. + * If size = -1, the size of the original string will be determined * using strlen(str). * If str equals to NULL, the function will silently clear the * current contents of the OCTET STRING. diff --git a/skeletons/file-dependencies b/skeletons/file-dependencies index 4c19c7a5..3dd94e92 100644 --- a/skeletons/file-dependencies +++ b/skeletons/file-dependencies @@ -6,6 +6,7 @@ # $Id$ # +ANY.h ANY.h BIT_STRING.h BIT_STRING.c BMPString.h BMPString.c BOOLEAN.h BOOLEAN.c @@ -25,7 +26,7 @@ ObjectDescriptor.h ObjectDescriptor.c GraphicString.h PrintableString.h PrintableString.c RELATIVE-OID.h RELATIVE-OID.c OBJECT-IDENTIFIER.h T61String.h T61String.c -TeletexString.h TeletexString.c +TeletexString.h TeletexString.c UTCTime.h UTCTime.c GeneralizedTime.h UTF8String.h UTF8String.c UniversalString.h UniversalString.c |