Skip to content

Commit

Permalink
per support
Browse files Browse the repository at this point in the history
  • Loading branch information
vlm committed Aug 18, 2006
1 parent 1dc8529 commit 523de9e
Show file tree
Hide file tree
Showing 52 changed files with 1,043 additions and 63 deletions.
2 changes: 1 addition & 1 deletion skeletons/ANY.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ asn_TYPE_descriptor_t asn_DEF_ANY = {
OCTET_STRING_encode_der,
OCTET_STRING_decode_xer_hex,
ANY_encode_xer,
0,
0, 0,
0, /* Use generic outmost tag fetcher */
0, 0, 0, 0,
0, /* No PER visible constraints */
Expand Down
1 change: 1 addition & 0 deletions skeletons/BIT_STRING.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ asn_TYPE_descriptor_t asn_DEF_BIT_STRING = {
OCTET_STRING_decode_xer_binary,
BIT_STRING_encode_xer,
OCTET_STRING_decode_uper, /* Unaligned PER decoder */
OCTET_STRING_encode_uper, /* Unaligned PER encoder */
0, /* Use generic outmost tag fetcher */
asn_DEF_BIT_STRING_tags,
sizeof(asn_DEF_BIT_STRING_tags)
Expand Down
2 changes: 1 addition & 1 deletion skeletons/BMPString.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ asn_TYPE_descriptor_t asn_DEF_BMPString = {
OCTET_STRING_encode_der,
BMPString_decode_xer, /* Convert from UTF-8 */
BMPString_encode_xer, /* Convert to UTF-8 */
0,
0, 0,
0, /* Use generic outmost tag fetcher */
asn_DEF_BMPString_tags,
sizeof(asn_DEF_BMPString_tags)
Expand Down
16 changes: 16 additions & 0 deletions skeletons/BOOLEAN.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ asn_TYPE_descriptor_t asn_DEF_BOOLEAN = {
BOOLEAN_decode_xer,
BOOLEAN_encode_xer,
BOOLEAN_decode_uper, /* Unaligned PER decoder */
BOOLEAN_encode_uper, /* Unaligned PER encoder */
0, /* Use generic outmost tag fetcher */
asn_DEF_BOOLEAN_tags,
sizeof(asn_DEF_BOOLEAN_tags) / sizeof(asn_DEF_BOOLEAN_tags[0]),
Expand Down Expand Up @@ -266,3 +267,18 @@ BOOLEAN_decode_uper(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td,
return rv;
}


asn_enc_rval_t
BOOLEAN_encode_uper(asn_TYPE_descriptor_t *td,
asn_per_constraints_t *constraints, void *sptr, asn_per_outp_t *po) {
const BOOLEAN_t *st = (const BOOLEAN_t *)sptr;
asn_enc_rval_t er;

(void)constraints;

if(!st) _ASN_ENCODE_FAILED;

per_put_few_bits(po, *st ? 1 : 0, 1);

_ASN_ENCODED_OK(er);
}
1 change: 1 addition & 0 deletions skeletons/BOOLEAN.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ der_type_encoder_f BOOLEAN_encode_der;
xer_type_decoder_f BOOLEAN_decode_xer;
xer_type_encoder_f BOOLEAN_encode_xer;
per_type_decoder_f BOOLEAN_decode_uper;
per_type_encoder_f BOOLEAN_encode_uper;

#ifdef __cplusplus
}
Expand Down
17 changes: 16 additions & 1 deletion skeletons/ENUMERATED.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*-
* Copyright (c) 2003, 2005 Lev Walkin <[email protected]>. All rights reserved.
* Copyright (c) 2003, 2005, 2006 Lev Walkin <[email protected]>.
* All rights reserved.
* Redistribution and modifications are permitted subject to BSD license.
*/
#include <asn_internal.h>
Expand All @@ -24,6 +25,7 @@ asn_TYPE_descriptor_t asn_DEF_ENUMERATED = {
INTEGER_decode_xer, /* This is temporary! */
INTEGER_encode_xer,
ENUMERATED_decode_uper, /* Unaligned PER decoder */
ENUMERATED_encode_uper, /* Unaligned PER encoder */
0, /* Use generic outmost tag fetcher */
asn_DEF_ENUMERATED_tags,
sizeof(asn_DEF_ENUMERATED_tags) / sizeof(asn_DEF_ENUMERATED_tags[0]),
Expand Down Expand Up @@ -54,3 +56,16 @@ ENUMERATED_decode_uper(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td
rval.code = RC_FAIL;
return rval;
}

asn_enc_rval_t
ENUMERATED_encode_uper(asn_TYPE_descriptor_t *td,
asn_per_constraints_t *constraints, void *sptr, asn_per_outp_t *po) {
ENUMERATED_t *st = (ENUMERATED_t *)sptr;
long value;

if(asn_INTEGER2long(st, &value))
_ASN_ENCODE_FAILED;

return NativeEnumerated_encode_uper(td, constraints, &value, po);
}

1 change: 1 addition & 0 deletions skeletons/ENUMERATED.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ typedef INTEGER_t ENUMERATED_t; /* Implemented via INTEGER */
extern asn_TYPE_descriptor_t asn_DEF_ENUMERATED;

per_type_decoder_f ENUMERATED_decode_uper;
per_type_encoder_f ENUMERATED_encode_uper;

#ifdef __cplusplus
}
Expand Down
2 changes: 1 addition & 1 deletion skeletons/GeneralString.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ asn_TYPE_descriptor_t asn_DEF_GeneralString = {
OCTET_STRING_encode_der,
OCTET_STRING_decode_xer_hex,
OCTET_STRING_encode_xer,
0,
0, 0,
0, /* Use generic outmost tag fetcher */
asn_DEF_GeneralString_tags,
sizeof(asn_DEF_GeneralString_tags)
Expand Down
2 changes: 1 addition & 1 deletion skeletons/GeneralizedTime.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ asn_TYPE_descriptor_t asn_DEF_GeneralizedTime = {
GeneralizedTime_encode_der,
OCTET_STRING_decode_xer_utf8,
GeneralizedTime_encode_xer,
0,
0, 0,
0, /* Use generic outmost tag fetcher */
asn_DEF_GeneralizedTime_tags,
sizeof(asn_DEF_GeneralizedTime_tags)
Expand Down
2 changes: 1 addition & 1 deletion skeletons/GraphicString.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ asn_TYPE_descriptor_t asn_DEF_GraphicString = {
OCTET_STRING_encode_der,
OCTET_STRING_decode_xer_hex,
OCTET_STRING_encode_xer, /* Can't expect it to be ASCII/UTF8 */
0,
0, 0,
0, /* Use generic outmost tag fetcher */
asn_DEF_GraphicString_tags,
sizeof(asn_DEF_GraphicString_tags)
Expand Down
2 changes: 1 addition & 1 deletion skeletons/IA5String.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ asn_TYPE_descriptor_t asn_DEF_IA5String = {
OCTET_STRING_encode_der,
OCTET_STRING_decode_xer_utf8,
OCTET_STRING_encode_xer_utf8,
0,
0, 0,
0, /* Use generic outmost tag fetcher */
asn_DEF_IA5String_tags,
sizeof(asn_DEF_IA5String_tags)
Expand Down
75 changes: 74 additions & 1 deletion skeletons/INTEGER.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*-
* Copyright (c) 2003, 2004, 2005 Lev Walkin <[email protected]>.
* Copyright (c) 2003, 2004, 2005, 2006 Lev Walkin <[email protected]>.
* All rights reserved.
* Redistribution and modifications are permitted subject to BSD license.
*/
Expand All @@ -25,6 +25,7 @@ asn_TYPE_descriptor_t asn_DEF_INTEGER = {
INTEGER_decode_xer,
INTEGER_encode_xer,
INTEGER_decode_uper, /* Unaligned PER decoder */
INTEGER_encode_uper, /* Unaligned PER encoder */
0, /* Use generic outmost tag fetcher */
asn_DEF_INTEGER_tags,
sizeof(asn_DEF_INTEGER_tags) / sizeof(asn_DEF_INTEGER_tags[0]),
Expand Down Expand Up @@ -530,6 +531,78 @@ INTEGER_decode_uper(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td,
return rval;
}

asn_enc_rval_t
INTEGER_encode_uper(asn_TYPE_descriptor_t *td,
asn_per_constraints_t *constraints, void *sptr, asn_per_outp_t *po) {
asn_enc_rval_t er;
INTEGER_t *st = (INTEGER_t *)sptr;
const uint8_t *buf;
const uint8_t *end;
asn_per_constraint_t *ct;
long value = 0;

if(!st || st->size == 0) _ASN_ENCODE_FAILED;

if(!constraints) constraints = td->per_constraints;
ct = constraints ? &constraints->value : 0;

er.encoded = 0;

if(ct) {
int inext = 0;
if(asn_INTEGER2long(st, &value))
_ASN_ENCODE_FAILED;
/* Check proper range */
if(ct->flags & APC_SEMI_CONSTRAINED) {
if(value < ct->lower_bound)
inext = 1;
} else if(ct->range_bits >= 0) {
if(value < ct->lower_bound
|| value > ct->upper_bound)
inext = 1;
}
ASN_DEBUG("Value %ld (%02x/%d) lb %ld ub %ld %s",
value, st->buf[0], st->size,
ct->lower_bound, ct->upper_bound,
inext ? "ext" : "fix");
if(ct->flags & APC_EXTENSIBLE) {
if(per_put_few_bits(po, inext, 1))
_ASN_ENCODE_FAILED;
if(inext) ct = 0;
} else if(inext) {
_ASN_ENCODE_FAILED;
}
}


/* X.691, #12.2.2 */
if(ct && ct->range_bits >= 0) {
/* #10.5.6 */
ASN_DEBUG("Encoding integer with range %d bits",
ct->range_bits);
if(per_put_few_bits(po, value - ct->lower_bound,
ct->range_bits))
_ASN_ENCODE_FAILED;
_ASN_ENCODED_OK(er);
}

if(ct && ct->lower_bound) {
ASN_DEBUG("Adjust lower bound to %ld", ct->lower_bound);
/* TODO: adjust lower bound */
_ASN_ENCODE_FAILED;
}

for(buf = st->buf, end = st->buf + st->size; buf < end;) {
ssize_t mayEncode = uper_put_length(po, end - buf);
if(mayEncode < 0)
_ASN_ENCODE_FAILED;
if(per_put_many_bits(po, buf, 8 * mayEncode))
_ASN_ENCODE_FAILED;
}

_ASN_ENCODED_OK(er);
}

int
asn_INTEGER2long(const INTEGER_t *iptr, long *lptr) {
uint8_t *b, *end;
Expand Down
1 change: 1 addition & 0 deletions skeletons/INTEGER.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ der_type_encoder_f INTEGER_encode_der;
xer_type_decoder_f INTEGER_decode_xer;
xer_type_encoder_f INTEGER_encode_xer;
per_type_decoder_f INTEGER_decode_uper;
per_type_encoder_f INTEGER_encode_uper;

/***********************************
* Some handy conversion routines. *
Expand Down
2 changes: 1 addition & 1 deletion skeletons/ISO646String.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ asn_TYPE_descriptor_t asn_DEF_ISO646String = {
OCTET_STRING_encode_der,
OCTET_STRING_decode_xer_utf8,
OCTET_STRING_encode_xer_utf8,
0,
0, 0,
0, /* Use generic outmost tag fetcher */
asn_DEF_ISO646String_tags,
sizeof(asn_DEF_ISO646String_tags)
Expand Down
15 changes: 15 additions & 0 deletions skeletons/NULL.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ asn_TYPE_descriptor_t asn_DEF_NULL = {
NULL_decode_xer,
NULL_encode_xer,
NULL_decode_uper, /* Unaligned PER decoder */
NULL_encode_uper, /* Unaligned PER encoder */
0, /* Use generic outmost tag fetcher */
asn_DEF_NULL_tags,
sizeof(asn_DEF_NULL_tags) / sizeof(asn_DEF_NULL_tags[0]),
Expand Down Expand Up @@ -130,3 +131,17 @@ NULL_decode_uper(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td,
rv.consumed = 0;
return rv;
}

asn_enc_rval_t
NULL_encode_uper(asn_TYPE_descriptor_t *td, asn_per_constraints_t *constraints,
void *sptr, asn_per_outp_t *po) {
asn_enc_rval_t er;

(void)td;
(void)constraints;
(void)sptr;
(void)po;

er.encoded = 0;
_ASN_ENCODED_OK(er);
}
1 change: 1 addition & 0 deletions skeletons/NULL.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ der_type_encoder_f NULL_encode_der;
xer_type_decoder_f NULL_decode_xer;
xer_type_encoder_f NULL_encode_xer;
per_type_decoder_f NULL_decode_uper;
per_type_encoder_f NULL_encode_uper;

#ifdef __cplusplus
}
Expand Down
83 changes: 81 additions & 2 deletions skeletons/NativeEnumerated.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ asn_TYPE_descriptor_t asn_DEF_NativeEnumerated = {
NativeInteger_decode_xer,
NativeEnumerated_encode_xer,
NativeEnumerated_decode_uper,
NativeEnumerated_encode_uper,
0, /* Use generic outmost tag fetcher */
asn_DEF_NativeEnumerated_tags,
sizeof(asn_DEF_NativeEnumerated_tags) / sizeof(asn_DEF_NativeEnumerated_tags[0]),
Expand Down Expand Up @@ -70,8 +71,9 @@ NativeEnumerated_encode_xer(asn_TYPE_descriptor_t *td, void *sptr,
}

asn_dec_rval_t
NativeEnumerated_decode_uper(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td,
asn_per_constraints_t *constraints, void **sptr, asn_per_data_t *pd) {
NativeEnumerated_decode_uper(asn_codec_ctx_t *opt_codec_ctx,
asn_TYPE_descriptor_t *td, asn_per_constraints_t *constraints,
void **sptr, asn_per_data_t *pd) {
asn_INTEGER_specifics_t *specs = (asn_INTEGER_specifics_t *)td->specifics;
asn_dec_rval_t rval = { RC_OK, 0 };
long *native = (long *)*sptr;
Expand Down Expand Up @@ -123,3 +125,80 @@ NativeEnumerated_decode_uper(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor
return rval;
}

static int
NativeEnumerated__compar_value2enum(const void *ap, const void *bp) {
const asn_INTEGER_enum_map_t *a = ap;
const asn_INTEGER_enum_map_t *b = bp;
if(a->nat_value == b->nat_value)
return 0;
if(a->nat_value < b->nat_value)
return -1;
return 1;
}

asn_enc_rval_t
NativeEnumerated_encode_uper(asn_TYPE_descriptor_t *td,
asn_per_constraints_t *constraints, void *sptr, asn_per_outp_t *po) {
asn_INTEGER_specifics_t *specs = (asn_INTEGER_specifics_t *)td->specifics;
asn_enc_rval_t er;
long native, value;
asn_per_constraint_t *ct;
int inext = 0;
asn_INTEGER_enum_map_t key;
asn_INTEGER_enum_map_t *kf;

if(!sptr) _ASN_ENCODE_FAILED;
if(!specs) _ASN_ENCODE_FAILED;

if(constraints) ct = &constraints->value;
else if(td->per_constraints) ct = &td->per_constraints->value;
else _ASN_ENCODE_FAILED; /* Mandatory! */

ASN_DEBUG("Encoding %s as NativeEnumerated", td->name);

er.encoded = 0;

native = *(long *)sptr;
if(native < 0) _ASN_ENCODE_FAILED;

key.nat_value = native;
kf = bsearch(&key, specs->value2enum, specs->map_count,
sizeof(key), NativeEnumerated__compar_value2enum);
if(!kf) {
ASN_DEBUG("No element corresponds to %ld", native);
_ASN_ENCODE_FAILED;
}
value = kf - specs->value2enum;

if(ct->range_bits >= 0) {
int cmpWith = specs->extension
? specs->extension - 1 : specs->map_count;
if(value >= cmpWith)
inext = 1;
}
if(ct->flags & APC_EXTENSIBLE) {
if(per_put_few_bits(po, inext, 0))
_ASN_ENCODE_FAILED;
ct = 0;
} else if(inext) {
_ASN_ENCODE_FAILED;
}

if(ct && ct->range_bits >= 0) {
if(per_put_few_bits(po, value, ct->range_bits))
_ASN_ENCODE_FAILED;
_ASN_ENCODED_OK(er);
}

if(!specs->extension)
_ASN_ENCODE_FAILED;

/*
* X.691, #10.6: normally small non-negative whole number;
*/
if(uper_put_nsnnwn(po, value - (specs->extension - 1)))
_ASN_ENCODE_FAILED;

_ASN_ENCODED_OK(er);
}

4 changes: 3 additions & 1 deletion skeletons/NativeEnumerated.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*-
* Copyright (c) 2004, 2005 Lev Walkin <[email protected]>. All rights reserved.
* Copyright (c) 2004, 2005, 2006 Lev Walkin <[email protected]>.
* All rights reserved.
* Redistribution and modifications are permitted subject to BSD license.
*/
/*
Expand All @@ -22,6 +23,7 @@ extern asn_TYPE_descriptor_t asn_DEF_NativeEnumerated;

xer_type_encoder_f NativeEnumerated_encode_xer;
per_type_decoder_f NativeEnumerated_decode_uper;
per_type_encoder_f NativeEnumerated_encode_uper;

#ifdef __cplusplus
}
Expand Down
Loading

0 comments on commit 523de9e

Please sign in to comment.