| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
#include <asn_internal.h> |
| 6 |
#include <NumericString.h> |
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
static const ber_tlv_tag_t asn_DEF_NumericString_tags[] = { |
| 12 |
(ASN_TAG_CLASS_UNIVERSAL | (18 << 2)), |
| 13 |
(ASN_TAG_CLASS_UNIVERSAL | (4 << 2)) |
| 14 |
}; |
| 15 |
static int asn_DEF_NumericString_v2c(unsigned int value) { |
| 16 |
switch(value) { |
| 17 |
case 0x20: return 0; |
| 18 |
case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: |
| 19 |
case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: |
| 20 |
return value - (0x30 - 1); |
| 21 |
} |
| 22 |
return -1; |
| 23 |
} |
| 24 |
static int asn_DEF_NumericString_c2v(unsigned int code) { |
| 25 |
if(code > 0) { |
| 26 |
if(code <= 10) |
| 27 |
return code + (0x30 - 1); |
| 28 |
else |
| 29 |
return -1; |
| 30 |
} else { |
| 31 |
return 0x20; |
| 32 |
} |
| 33 |
} |
| 34 |
static asn_per_constraints_t asn_DEF_NumericString_constraints = { |
| 35 |
{ APC_CONSTRAINED, 4, 4, 0x20, 0x39 }, |
| 36 |
{ APC_SEMI_CONSTRAINED, -1, -1, 0, 0 }, |
| 37 |
asn_DEF_NumericString_v2c, |
| 38 |
asn_DEF_NumericString_c2v |
| 39 |
}; |
| 40 |
asn_TYPE_descriptor_t asn_DEF_NumericString = { |
| 41 |
"NumericString", |
| 42 |
"NumericString", |
| 43 |
OCTET_STRING_free, |
| 44 |
OCTET_STRING_print_utf8, |
| 45 |
NumericString_constraint, |
| 46 |
OCTET_STRING_decode_ber, |
| 47 |
OCTET_STRING_encode_der, |
| 48 |
OCTET_STRING_decode_xer_utf8, |
| 49 |
OCTET_STRING_encode_xer_utf8, |
| 50 |
OCTET_STRING_decode_uper, |
| 51 |
OCTET_STRING_encode_uper, |
| 52 |
0, |
| 53 |
asn_DEF_NumericString_tags, |
| 54 |
sizeof(asn_DEF_NumericString_tags) |
| 55 |
/ sizeof(asn_DEF_NumericString_tags[0]) - 1, |
| 56 |
asn_DEF_NumericString_tags, |
| 57 |
sizeof(asn_DEF_NumericString_tags) |
| 58 |
/ sizeof(asn_DEF_NumericString_tags[0]), |
| 59 |
&asn_DEF_NumericString_constraints, |
| 60 |
0, 0, |
| 61 |
0 |
| 62 |
}; |
| 63 |
|
| 64 |
int |
| 65 |
NumericString_constraint(asn_TYPE_descriptor_t *td, const void *sptr, |
| 66 |
asn_app_constraint_failed_f *ctfailcb, void *app_key) { |
| 67 |
const NumericString_t *st = (const NumericString_t *)sptr; |
| 68 |
|
| 69 |
if(st && st->buf) { |
| 70 |
uint8_t *buf = st->buf; |
| 71 |
uint8_t *end = buf + st->size; |
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
for(; buf < end; buf++) { |
| 78 |
switch(*buf) { |
| 79 |
case 0x20: |
| 80 |
case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: |
| 81 |
case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: |
| 82 |
continue; |
| 83 |
} |
| 84 |
ASN__CTFAIL(app_key, td, sptr, |
| 85 |
"%s: value byte %ld (%d) " |
| 86 |
"not in NumericString alphabet (%s:%d)", |
| 87 |
td->name, |
| 88 |
(long)((buf - st->buf) + 1), |
| 89 |
*buf, |
| 90 |
__FILE__, __LINE__); |
| 91 |
return -1; |
| 92 |
} |
| 93 |
} else { |
| 94 |
ASN__CTFAIL(app_key, td, sptr, |
| 95 |
"%s: value not given (%s:%d)", |
| 96 |
td->name, __FILE__, __LINE__); |
| 97 |
return -1; |
| 98 |
} |
| 99 |
|
| 100 |
return 0; |
| 101 |
} |