blob: 3360c2df10aef387b6843101d9817d5e8967595e [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};
Lev Walkin5e033762004-09-29 13:26:15 +000050asn_TYPE_descriptor_t asn_DEF_PrintableString = {
Lev Walkinf15320b2004-06-03 03:38:44 +000051 "PrintableString",
Lev Walkindc06f6b2004-10-20 15:50:55 +000052 "PrintableString",
Lev Walkina9cc46e2004-09-22 16:06:28 +000053 OCTET_STRING_free,
Lev Walkindc06f6b2004-10-20 15:50:55 +000054 OCTET_STRING_print_utf8, /* ASCII subset */
Lev Walkinf15320b2004-06-03 03:38:44 +000055 PrintableString_constraint,
Lev Walkindc06f6b2004-10-20 15:50:55 +000056 OCTET_STRING_decode_ber, /* Implemented in terms of OCTET STRING */
57 OCTET_STRING_encode_der,
58 OCTET_STRING_decode_xer_utf8,
59 OCTET_STRING_encode_xer_utf8,
Lev Walkin80334ed2017-07-06 07:28:21 -070060#ifdef ASN_DISABLE_PER_SUPPORT
61 0,
62 0,
63#else
Lev Walkin725883b2006-10-09 12:07:58 +000064 OCTET_STRING_decode_uper,
65 OCTET_STRING_encode_uper,
Lev Walkin80334ed2017-07-06 07:28:21 -070066#endif /* ASN_DISABLE_PER_SUPPORT */
Lev Walkincc159472017-07-06 08:26:36 -070067#ifdef ASN_DISABLE_OER_SUPPORT
68 0,
69 0,
70#else
71 0,
72 0,
73#endif /* ASN_DISABLE_OER_SUPPORT */
Lev Walkinf15320b2004-06-03 03:38:44 +000074 0, /* Use generic outmost tag fetcher */
Lev Walkin5e033762004-09-29 13:26:15 +000075 asn_DEF_PrintableString_tags,
76 sizeof(asn_DEF_PrintableString_tags)
77 / sizeof(asn_DEF_PrintableString_tags[0]) - 1,
78 asn_DEF_PrintableString_tags,
79 sizeof(asn_DEF_PrintableString_tags)
80 / sizeof(asn_DEF_PrintableString_tags[0]),
Lev Walkin76780762017-07-07 10:07:30 -070081 0, /* No OER visible constraints */
82 &asn_DEF_PrintableString_per_constraints,
Lev Walkin449f8322004-08-20 13:23:42 +000083 0, 0, /* No members */
Lev Walkind9bd7752004-06-05 08:17:50 +000084 0 /* No specifics */
Lev Walkinf15320b2004-06-03 03:38:44 +000085};
86
87
Lev Walkinf15320b2004-06-03 03:38:44 +000088int
Lev Walkin5e033762004-09-29 13:26:15 +000089PrintableString_constraint(asn_TYPE_descriptor_t *td, const void *sptr,
Lev Walkin1eded352006-07-13 11:19:01 +000090 asn_app_constraint_failed_f *ctfailcb, void *app_key) {
Lev Walkinc2346572004-08-11 09:07:36 +000091 const PrintableString_t *st = (const PrintableString_t *)sptr;
Lev Walkinf15320b2004-06-03 03:38:44 +000092
93 if(st && st->buf) {
94 uint8_t *buf = st->buf;
95 uint8_t *end = buf + st->size;
96
97 /*
98 * Check the alphabet of the PrintableString.
99 * ASN.1:1984 (X.409)
100 */
101 for(; buf < end; buf++) {
102 if(!_PrintableString_alphabet[*buf]) {
Lev Walkin7c1dc052016-03-14 03:08:15 -0700103 ASN__CTFAIL(app_key, td, sptr,
Lev Walkin426b0982004-10-26 09:59:42 +0000104 "%s: value byte %ld (%d) "
Lev Walkin16835b62004-08-22 13:47:59 +0000105 "not in PrintableString alphabet "
106 "(%s:%d)",
Lev Walkinf15320b2004-06-03 03:38:44 +0000107 td->name,
Lev Walkin426b0982004-10-26 09:59:42 +0000108 (long)((buf - st->buf) + 1),
Lev Walkin5a56c7c2004-08-23 08:34:14 +0000109 *buf,
Lev Walkin16835b62004-08-22 13:47:59 +0000110 __FILE__, __LINE__);
Lev Walkinf15320b2004-06-03 03:38:44 +0000111 return -1;
112 }
113 }
114 } else {
Lev Walkin7c1dc052016-03-14 03:08:15 -0700115 ASN__CTFAIL(app_key, td, sptr,
Lev Walkin16835b62004-08-22 13:47:59 +0000116 "%s: value not given (%s:%d)",
117 td->name, __FILE__, __LINE__);
Lev Walkinf15320b2004-06-03 03:38:44 +0000118 return -1;
119 }
120
121 return 0;
122}