Commit a737f3b4 authored by Lev Walkin's avatar Lev Walkin

preliminary ANY support

parent cec43b58
/*-
* 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 */
};
/*-
* 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 */
...@@ -150,7 +150,7 @@ OCTET_STRING_decode_ber(asn1_TYPE_descriptor_t *td, ...@@ -150,7 +150,7 @@ OCTET_STRING_decode_ber(asn1_TYPE_descriptor_t *td,
* This is a some sort of a hack. * This is a some sort of a hack.
* The OCTET STRING decoder is being used in BIT STRING mode. * 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)", ASN_DEBUG("Decoding %s as %s (%ld)",
td->name, td->name,
...@@ -395,6 +395,8 @@ OCTET_STRING_encode_der(asn1_TYPE_descriptor_t *sd, void *ptr, ...@@ -395,6 +395,8 @@ OCTET_STRING_encode_der(asn1_TYPE_descriptor_t *sd, void *ptr,
der_enc_rval_t erval; der_enc_rval_t erval;
OCTET_STRING_t *st = (OCTET_STRING_t *)ptr; OCTET_STRING_t *st = (OCTET_STRING_t *)ptr;
int add_byte = 0; 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", ASN_DEBUG("%s %s as OCTET STRING",
cb?"Estimating":"Encoding", sd->name); cb?"Estimating":"Encoding", sd->name);
...@@ -402,7 +404,7 @@ OCTET_STRING_encode_der(asn1_TYPE_descriptor_t *sd, void *ptr, ...@@ -402,7 +404,7 @@ OCTET_STRING_encode_der(asn1_TYPE_descriptor_t *sd, void *ptr,
/* /*
* Canonicalize BIT STRING. * Canonicalize BIT STRING.
*/ */
if(sd->specifics && st->buf) { if(is_bit_str && st->buf) {
switch(st->size) { switch(st->size) {
case 0: add_byte = 1; break; case 0: add_byte = 1; break;
case 1: st->buf[0] = 0; break; case 1: st->buf[0] = 0; break;
...@@ -412,13 +414,17 @@ OCTET_STRING_encode_der(asn1_TYPE_descriptor_t *sd, void *ptr, ...@@ -412,13 +414,17 @@ OCTET_STRING_encode_der(asn1_TYPE_descriptor_t *sd, void *ptr,
} }
} }
erval.encoded = der_write_tags(sd, st->size + add_byte, tag_mode, tag, if(is_ANY_type) {
cb, app_key); erval.encoded = 0;
} else {
erval.encoded = der_write_tags(sd, st->size + add_byte,
tag_mode, tag, cb, app_key);
if(erval.encoded == -1) { if(erval.encoded == -1) {
erval.failed_type = sd; erval.failed_type = sd;
erval.structure_ptr = ptr; erval.structure_ptr = ptr;
return erval; return erval;
} }
}
if(cb) { if(cb) {
uint8_t zero; uint8_t zero;
......
...@@ -28,8 +28,8 @@ asn_struct_free_f OCTET_STRING_free; ...@@ -28,8 +28,8 @@ asn_struct_free_f OCTET_STRING_free;
/* /*
* This function clears the previous value of the OCTET STRING (if any) * 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 * and then allocates a new memory and returns a pointer to it.
* memory. If size = -1, the size of the original string will be determined * If size = -1, the size of the original string will be determined
* using strlen(str). * using strlen(str).
* If str equals to NULL, the function will silently clear the * If str equals to NULL, the function will silently clear the
* current contents of the OCTET STRING. * current contents of the OCTET STRING.
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
# $Id$ # $Id$
# #
ANY.h ANY.h
BIT_STRING.h BIT_STRING.c BIT_STRING.h BIT_STRING.c
BMPString.h BMPString.c BMPString.h BMPString.c
BOOLEAN.h BOOLEAN.c BOOLEAN.h BOOLEAN.c
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment