3 * Copyright (c) 2003, 2004, 2006 Lev Walkin <vlm@lionet.info>.
5 * Redistribution and modifications are permitted subject to BSD license.
7 #include <asn_internal.h>
8 #include <PrintableString.h>
13 static const int _PrintableString_alphabet[256] = {
14 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
15 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
16 1, 0, 0, 0, 0, 0, 0, 2, 3, 4, 0, 5, 6, 7, 8, 9, /* . '() +,-./ */
17 10,11,12,13,14,15,16,17,18,19,20, 0, 0,21, 0,22, /* 0123456789: = ? */
18 0,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37, /* ABCDEFGHIJKLMNO */
19 38,39,40,41,42,43,44,45,46,47,48, 0, 0, 0, 0, 0, /* PQRSTUVWXYZ */
20 0,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63, /* abcdefghijklmno */
21 64,65,66,67,68,69,70,71,72,73,74, 0, 0, 0, 0, 0, /* pqrstuvwxyz */
23 static const int _PrintableString_code2value[74] = {
24 32,39,40,41,43,44,45,46,47,48,49,50,51,52,53,54,
25 55,56,57,58,61,63,65,66,67,68,69,70,71,72,73,74,
26 75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,
27 97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,
28 113,114,115,116,117,118,119,120,121,122};
31 * PrintableString basic type description.
33 static const ber_tlv_tag_t asn_DEF_PrintableString_tags[] = {
34 (ASN_TAG_CLASS_UNIVERSAL | (19 << 2)), /* [UNIVERSAL 19] IMPLICIT ...*/
35 (ASN_TAG_CLASS_UNIVERSAL | (4 << 2)) /* ... OCTET STRING */
37 static int asn_DEF_PrintableString_v2c(unsigned int value) {
38 return _PrintableString_alphabet[value > 255 ? 0 : value] - 1;
40 static int asn_DEF_PrintableString_c2v(unsigned int code) {
42 return _PrintableString_code2value[code];
45 static asn_per_constraints_t asn_DEF_PrintableString_per_constraints = {
46 { APC_CONSTRAINED, 4, 4, 0x20, 0x39 }, /* Value */
47 { APC_SEMI_CONSTRAINED, -1, -1, 0, 0 }, /* Size */
48 asn_DEF_PrintableString_v2c,
49 asn_DEF_PrintableString_c2v
51 asn_TYPE_operation_t asn_OP_PrintableString = {
53 OCTET_STRING_print_utf8, /* ASCII subset */
55 OCTET_STRING_decode_ber, /* Implemented in terms of OCTET STRING */
56 OCTET_STRING_encode_der,
57 OCTET_STRING_decode_xer_utf8,
58 OCTET_STRING_encode_xer_utf8,
59 #ifdef ASN_DISABLE_OER_SUPPORT
63 OCTET_STRING_decode_oer,
64 OCTET_STRING_encode_oer,
65 #endif /* ASN_DISABLE_OER_SUPPORT */
66 #ifdef ASN_DISABLE_PER_SUPPORT
72 OCTET_STRING_decode_uper,
73 OCTET_STRING_encode_uper,
74 OCTET_STRING_decode_aper,
75 OCTET_STRING_encode_aper,
76 #endif /* ASN_DISABLE_PER_SUPPORT */
77 OCTET_STRING_random_fill,
78 0 /* Use generic outmost tag fetcher */
80 asn_TYPE_descriptor_t asn_DEF_PrintableString = {
83 &asn_OP_PrintableString,
84 asn_DEF_PrintableString_tags,
85 sizeof(asn_DEF_PrintableString_tags)
86 / sizeof(asn_DEF_PrintableString_tags[0]) - 1,
87 asn_DEF_PrintableString_tags,
88 sizeof(asn_DEF_PrintableString_tags)
89 / sizeof(asn_DEF_PrintableString_tags[0]),
90 { 0, &asn_DEF_PrintableString_per_constraints, PrintableString_constraint },
91 0, 0, /* No members */
97 PrintableString_constraint(const asn_TYPE_descriptor_t *td, const void *sptr,
98 asn_app_constraint_failed_f *ctfailcb,
100 const PrintableString_t *st = (const PrintableString_t *)sptr;
103 uint8_t *buf = st->buf;
104 uint8_t *end = buf + st->size;
107 * Check the alphabet of the PrintableString.
110 for(; buf < end; buf++) {
111 if(!_PrintableString_alphabet[*buf]) {
112 ASN__CTFAIL(app_key, td, sptr,
113 "%s: value byte %ld (%d) "
114 "not in PrintableString alphabet "
117 (long)((buf - st->buf) + 1),
124 ASN__CTFAIL(app_key, td, sptr,
125 "%s: value not given (%s:%d)",
126 td->name, __FILE__, __LINE__);