2 * Copyright (c) 2003, 2006 Lev Walkin <vlm@lionet.info>. All rights reserved.
3 * Redistribution and modifications are permitted subject to BSD license.
5 #include <asn_internal.h>
6 #include <NumericString.h>
9 * NumericString basic type description.
11 static const ber_tlv_tag_t asn_DEF_NumericString_tags[] = {
12 (ASN_TAG_CLASS_UNIVERSAL | (18 << 2)), /* [UNIVERSAL 18] IMPLICIT ...*/
13 (ASN_TAG_CLASS_UNIVERSAL | (4 << 2)) /* ... OCTET STRING */
15 static int asn_DEF_NumericString_v2c(unsigned int value) {
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);
24 static int asn_DEF_NumericString_c2v(unsigned int code) {
27 return code + (0x30 - 1);
34 static asn_per_constraints_t asn_DEF_NumericString_per_constraints = {
35 { APC_CONSTRAINED, 4, 4, 0x20, 0x39 }, /* Value */
36 { APC_SEMI_CONSTRAINED, -1, -1, 0, 0 }, /* Size */
37 asn_DEF_NumericString_v2c,
38 asn_DEF_NumericString_c2v
40 asn_TYPE_operation_t asn_OP_NumericString = {
42 OCTET_STRING_print_utf8, /* ASCII subset */
44 OCTET_STRING_decode_ber, /* Implemented in terms of OCTET STRING */
45 OCTET_STRING_encode_der,
46 OCTET_STRING_decode_xer_utf8,
47 OCTET_STRING_encode_xer_utf8,
48 #ifdef ASN_DISABLE_OER_SUPPORT
52 OCTET_STRING_decode_oer,
53 OCTET_STRING_encode_oer,
54 #endif /* ASN_DISABLE_OER_SUPPORT */
55 #ifdef ASN_DISABLE_PER_SUPPORT
61 OCTET_STRING_decode_uper,
62 OCTET_STRING_encode_uper,
63 OCTET_STRING_decode_aper,
64 OCTET_STRING_encode_aper,
65 #endif /* ASN_DISABLE_PER_SUPPORT */
66 OCTET_STRING_random_fill,
67 0 /* Use generic outmost tag fetcher */
69 asn_TYPE_descriptor_t asn_DEF_NumericString = {
72 &asn_OP_NumericString,
73 asn_DEF_NumericString_tags,
74 sizeof(asn_DEF_NumericString_tags)
75 / sizeof(asn_DEF_NumericString_tags[0]) - 1,
76 asn_DEF_NumericString_tags,
77 sizeof(asn_DEF_NumericString_tags)
78 / sizeof(asn_DEF_NumericString_tags[0]),
79 { 0, &asn_DEF_NumericString_per_constraints, NumericString_constraint },
80 0, 0, /* No members */
85 NumericString_constraint(const asn_TYPE_descriptor_t *td, const void *sptr,
86 asn_app_constraint_failed_f *ctfailcb, void *app_key) {
87 const NumericString_t *st = (const NumericString_t *)sptr;
90 uint8_t *buf = st->buf;
91 uint8_t *end = buf + st->size;
94 * Check the alphabet of the NumericString.
97 for(; buf < end; buf++) {
100 case 0x30: case 0x31: case 0x32: case 0x33: case 0x34:
101 case 0x35: case 0x36: case 0x37: case 0x38: case 0x39:
104 ASN__CTFAIL(app_key, td, sptr,
105 "%s: value byte %ld (%d) "
106 "not in NumericString alphabet (%s:%d)",
108 (long)((buf - st->buf) + 1),
114 ASN__CTFAIL(app_key, td, sptr,
115 "%s: value not given (%s:%d)",
116 td->name, __FILE__, __LINE__);