blob: ffc08b7c08b995ab3c71c251b4fa11b32cbde92e [file] [log] [blame]
Lev Walkinf15320b2004-06-03 03:38:44 +00001/*-
Lev Walkin725883b2006-10-09 12:07:58 +00002 * Copyright (c) 2003, 2004, 2006 Lev Walkin <vlm@lionet.info>.
3 * All rights reserved.
Lev Walkinf15320b2004-06-03 03:38:44 +00004 * Redistribution and modifications are permitted subject to BSD license.
5 */
Lev Walkina9cc46e2004-09-22 16:06:28 +00006#include <asn_internal.h>
Lev Walkinf15320b2004-06-03 03:38:44 +00007#include <PrintableString.h>
8
9/*
Lev Walkin725883b2006-10-09 12:07:58 +000010 * ASN.1:1984 (X.409)
11 */
Wim Lewis18c2ec92014-07-29 11:30:10 -070012static const int _PrintableString_alphabet[256] = {
Lev Walkin725883b2006-10-09 12:07:58 +000013 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
14 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
15 1, 0, 0, 0, 0, 0, 0, 2, 3, 4, 0, 5, 6, 7, 8, 9, /* . '() +,-./ */
1610,11,12,13,14,15,16,17,18,19,20, 0, 0,21, 0,22, /* 0123456789: = ? */
17 0,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37, /* ABCDEFGHIJKLMNO */
1838,39,40,41,42,43,44,45,46,47,48, 0, 0, 0, 0, 0, /* PQRSTUVWXYZ */
19 0,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63, /* abcdefghijklmno */
2064,65,66,67,68,69,70,71,72,73,74, 0, 0, 0, 0, 0, /* pqrstuvwxyz */
21};
Lev Walkina7591b52014-10-12 18:37:35 -070022static const int _PrintableString_code2value[74] = {
Lev Walkin725883b2006-10-09 12:07:58 +00002332,39,40,41,43,44,45,46,47,48,49,50,51,52,53,54,
2455,56,57,58,61,63,65,66,67,68,69,70,71,72,73,74,
2575,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,
2697,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,
27113,114,115,116,117,118,119,120,121,122};
28
29/*
Lev Walkinf15320b2004-06-03 03:38:44 +000030 * PrintableString basic type description.
31 */
Wim Lewis18c2ec92014-07-29 11:30:10 -070032static const ber_tlv_tag_t asn_DEF_PrintableString_tags[] = {
Lev Walkin188ed2c2004-09-13 08:31:01 +000033 (ASN_TAG_CLASS_UNIVERSAL | (19 << 2)), /* [UNIVERSAL 19] IMPLICIT ...*/
34 (ASN_TAG_CLASS_UNIVERSAL | (4 << 2)) /* ... OCTET STRING */
Lev Walkinf15320b2004-06-03 03:38:44 +000035};
Lev Walkin725883b2006-10-09 12:07:58 +000036static int asn_DEF_PrintableString_v2c(unsigned int value) {
37 return _PrintableString_alphabet[value > 255 ? 0 : value] - 1;
38}
39static int asn_DEF_PrintableString_c2v(unsigned int code) {
40 if(code < 74)
41 return _PrintableString_code2value[code];
42 return -1;
43}
Lev Walkin76780762017-07-07 10:07:30 -070044static asn_per_constraints_t asn_DEF_PrintableString_per_constraints = {
Lev Walkin725883b2006-10-09 12:07:58 +000045 { APC_CONSTRAINED, 4, 4, 0x20, 0x39 }, /* Value */
46 { APC_SEMI_CONSTRAINED, -1, -1, 0, 0 }, /* Size */
47 asn_DEF_PrintableString_v2c,
48 asn_DEF_PrintableString_c2v
49};
Bi-Ruei, Chiu1f87ac02017-08-20 01:25:45 +080050asn_TYPE_operation_t asn_OP_PrintableString = {
Lev Walkina9cc46e2004-09-22 16:06:28 +000051 OCTET_STRING_free,
Lev Walkindc06f6b2004-10-20 15:50:55 +000052 OCTET_STRING_print_utf8, /* ASCII subset */
Lev Walkincd2f48e2017-08-10 02:14:59 -070053 OCTET_STRING_compare,
Lev Walkindc06f6b2004-10-20 15:50:55 +000054 OCTET_STRING_decode_ber, /* Implemented in terms of OCTET STRING */
55 OCTET_STRING_encode_der,
56 OCTET_STRING_decode_xer_utf8,
57 OCTET_STRING_encode_xer_utf8,
Lev Walkincc159472017-07-06 08:26:36 -070058#ifdef ASN_DISABLE_OER_SUPPORT
59 0,
60 0,
61#else
Lev Walkin1d76f3c2017-07-25 07:58:05 -070062 OCTET_STRING_decode_oer,
63 OCTET_STRING_encode_oer,
Lev Walkincc159472017-07-06 08:26:36 -070064#endif /* ASN_DISABLE_OER_SUPPORT */
Lev Walkinb33425f2017-07-14 14:59:52 +040065#ifdef ASN_DISABLE_PER_SUPPORT
66 0,
67 0,
68#else
69 OCTET_STRING_decode_uper,
70 OCTET_STRING_encode_uper,
71#endif /* ASN_DISABLE_PER_SUPPORT */
Lev Walkina5972be2017-09-29 23:15:58 -070072 OCTET_STRING_random_fill,
Bi-Ruei, Chiu1f87ac02017-08-20 01:25:45 +080073 0 /* Use generic outmost tag fetcher */
74};
75asn_TYPE_descriptor_t asn_DEF_PrintableString = {
76 "PrintableString",
77 "PrintableString",
78 &asn_OP_PrintableString,
Lev Walkin5e033762004-09-29 13:26:15 +000079 asn_DEF_PrintableString_tags,
80 sizeof(asn_DEF_PrintableString_tags)
81 / sizeof(asn_DEF_PrintableString_tags[0]) - 1,
82 asn_DEF_PrintableString_tags,
83 sizeof(asn_DEF_PrintableString_tags)
84 / sizeof(asn_DEF_PrintableString_tags[0]),
Lev Walkina5972be2017-09-29 23:15:58 -070085 { 0, &asn_DEF_PrintableString_per_constraints, PrintableString_constraint },
Lev Walkin449f8322004-08-20 13:23:42 +000086 0, 0, /* No members */
Lev Walkind9bd7752004-06-05 08:17:50 +000087 0 /* No specifics */
Lev Walkinf15320b2004-06-03 03:38:44 +000088};
89
90
Lev Walkinf15320b2004-06-03 03:38:44 +000091int
Lev Walkin20696a42017-10-17 21:27:33 -070092PrintableString_constraint(const asn_TYPE_descriptor_t *td, const void *sptr,
93 asn_app_constraint_failed_f *ctfailcb,
94 void *app_key) {
95 const PrintableString_t *st = (const PrintableString_t *)sptr;
Lev Walkinf15320b2004-06-03 03:38:44 +000096
97 if(st && st->buf) {
98 uint8_t *buf = st->buf;
99 uint8_t *end = buf + st->size;
100
101 /*
102 * Check the alphabet of the PrintableString.
103 * ASN.1:1984 (X.409)
104 */
105 for(; buf < end; buf++) {
106 if(!_PrintableString_alphabet[*buf]) {
Lev Walkin7c1dc052016-03-14 03:08:15 -0700107 ASN__CTFAIL(app_key, td, sptr,
Lev Walkin426b0982004-10-26 09:59:42 +0000108 "%s: value byte %ld (%d) "
Lev Walkin16835b62004-08-22 13:47:59 +0000109 "not in PrintableString alphabet "
110 "(%s:%d)",
Lev Walkinf15320b2004-06-03 03:38:44 +0000111 td->name,
Lev Walkin426b0982004-10-26 09:59:42 +0000112 (long)((buf - st->buf) + 1),
Lev Walkin5a56c7c2004-08-23 08:34:14 +0000113 *buf,
Lev Walkin16835b62004-08-22 13:47:59 +0000114 __FILE__, __LINE__);
Lev Walkinf15320b2004-06-03 03:38:44 +0000115 return -1;
116 }
117 }
118 } else {
Lev Walkin7c1dc052016-03-14 03:08:15 -0700119 ASN__CTFAIL(app_key, td, sptr,
Lev Walkin16835b62004-08-22 13:47:59 +0000120 "%s: value not given (%s:%d)",
121 td->name, __FILE__, __LINE__);
Lev Walkinf15320b2004-06-03 03:38:44 +0000122 return -1;
123 }
124
125 return 0;
126}