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