Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1 | /*- |
Lev Walkin | 725883b | 2006-10-09 12:07:58 +0000 | [diff] [blame] | 2 | * Copyright (c) 2003, 2004, 2006 Lev Walkin <vlm@lionet.info>. |
| 3 | * All rights reserved. |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 4 | * Redistribution and modifications are permitted subject to BSD license. |
| 5 | */ |
Lev Walkin | a9cc46e | 2004-09-22 16:06:28 +0000 | [diff] [blame] | 6 | #include <asn_internal.h> |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 7 | #include <PrintableString.h> |
| 8 | |
| 9 | /* |
Lev Walkin | 725883b | 2006-10-09 12:07:58 +0000 | [diff] [blame] | 10 | * ASN.1:1984 (X.409) |
| 11 | */ |
Wim Lewis | 18c2ec9 | 2014-07-29 11:30:10 -0700 | [diff] [blame] | 12 | static const int _PrintableString_alphabet[256] = { |
Lev Walkin | 725883b | 2006-10-09 12:07:58 +0000 | [diff] [blame] | 13 | 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, /* . '() +,-./ */ |
| 16 | 10,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 */ |
| 18 | 38,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 */ |
| 20 | 64,65,66,67,68,69,70,71,72,73,74, 0, 0, 0, 0, 0, /* pqrstuvwxyz */ |
| 21 | }; |
Lev Walkin | a7591b5 | 2014-10-12 18:37:35 -0700 | [diff] [blame] | 22 | static const int _PrintableString_code2value[74] = { |
Lev Walkin | 725883b | 2006-10-09 12:07:58 +0000 | [diff] [blame] | 23 | 32,39,40,41,43,44,45,46,47,48,49,50,51,52,53,54, |
| 24 | 55,56,57,58,61,63,65,66,67,68,69,70,71,72,73,74, |
| 25 | 75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90, |
| 26 | 97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112, |
| 27 | 113,114,115,116,117,118,119,120,121,122}; |
| 28 | |
| 29 | /* |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 30 | * PrintableString basic type description. |
| 31 | */ |
Wim Lewis | 18c2ec9 | 2014-07-29 11:30:10 -0700 | [diff] [blame] | 32 | static const ber_tlv_tag_t asn_DEF_PrintableString_tags[] = { |
Lev Walkin | 188ed2c | 2004-09-13 08:31:01 +0000 | [diff] [blame] | 33 | (ASN_TAG_CLASS_UNIVERSAL | (19 << 2)), /* [UNIVERSAL 19] IMPLICIT ...*/ |
| 34 | (ASN_TAG_CLASS_UNIVERSAL | (4 << 2)) /* ... OCTET STRING */ |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 35 | }; |
Lev Walkin | 725883b | 2006-10-09 12:07:58 +0000 | [diff] [blame] | 36 | static int asn_DEF_PrintableString_v2c(unsigned int value) { |
| 37 | return _PrintableString_alphabet[value > 255 ? 0 : value] - 1; |
| 38 | } |
| 39 | static int asn_DEF_PrintableString_c2v(unsigned int code) { |
| 40 | if(code < 74) |
| 41 | return _PrintableString_code2value[code]; |
| 42 | return -1; |
| 43 | } |
Lev Walkin | 7678076 | 2017-07-07 10:07:30 -0700 | [diff] [blame] | 44 | static asn_per_constraints_t asn_DEF_PrintableString_per_constraints = { |
Lev Walkin | 725883b | 2006-10-09 12:07:58 +0000 | [diff] [blame] | 45 | { 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 Walkin | 5e03376 | 2004-09-29 13:26:15 +0000 | [diff] [blame] | 50 | asn_TYPE_descriptor_t asn_DEF_PrintableString = { |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 51 | "PrintableString", |
Lev Walkin | dc06f6b | 2004-10-20 15:50:55 +0000 | [diff] [blame] | 52 | "PrintableString", |
Lev Walkin | a9cc46e | 2004-09-22 16:06:28 +0000 | [diff] [blame] | 53 | OCTET_STRING_free, |
Lev Walkin | dc06f6b | 2004-10-20 15:50:55 +0000 | [diff] [blame] | 54 | OCTET_STRING_print_utf8, /* ASCII subset */ |
Lev Walkin | cd2f48e | 2017-08-10 02:14:59 -0700 | [diff] [blame] | 55 | OCTET_STRING_compare, |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 56 | PrintableString_constraint, |
Lev Walkin | dc06f6b | 2004-10-20 15:50:55 +0000 | [diff] [blame] | 57 | OCTET_STRING_decode_ber, /* Implemented in terms of OCTET STRING */ |
| 58 | OCTET_STRING_encode_der, |
| 59 | OCTET_STRING_decode_xer_utf8, |
| 60 | OCTET_STRING_encode_xer_utf8, |
Lev Walkin | cc15947 | 2017-07-06 08:26:36 -0700 | [diff] [blame] | 61 | #ifdef ASN_DISABLE_OER_SUPPORT |
| 62 | 0, |
| 63 | 0, |
| 64 | #else |
Lev Walkin | 1d76f3c | 2017-07-25 07:58:05 -0700 | [diff] [blame] | 65 | OCTET_STRING_decode_oer, |
| 66 | OCTET_STRING_encode_oer, |
Lev Walkin | cc15947 | 2017-07-06 08:26:36 -0700 | [diff] [blame] | 67 | #endif /* ASN_DISABLE_OER_SUPPORT */ |
Lev Walkin | b33425f | 2017-07-14 14:59:52 +0400 | [diff] [blame] | 68 | #ifdef ASN_DISABLE_PER_SUPPORT |
| 69 | 0, |
| 70 | 0, |
| 71 | #else |
| 72 | OCTET_STRING_decode_uper, |
| 73 | OCTET_STRING_encode_uper, |
| 74 | #endif /* ASN_DISABLE_PER_SUPPORT */ |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 75 | 0, /* Use generic outmost tag fetcher */ |
Lev Walkin | 5e03376 | 2004-09-29 13:26:15 +0000 | [diff] [blame] | 76 | asn_DEF_PrintableString_tags, |
| 77 | sizeof(asn_DEF_PrintableString_tags) |
| 78 | / sizeof(asn_DEF_PrintableString_tags[0]) - 1, |
| 79 | asn_DEF_PrintableString_tags, |
| 80 | sizeof(asn_DEF_PrintableString_tags) |
| 81 | / sizeof(asn_DEF_PrintableString_tags[0]), |
Lev Walkin | 7678076 | 2017-07-07 10:07:30 -0700 | [diff] [blame] | 82 | 0, /* No OER visible constraints */ |
| 83 | &asn_DEF_PrintableString_per_constraints, |
Lev Walkin | 449f832 | 2004-08-20 13:23:42 +0000 | [diff] [blame] | 84 | 0, 0, /* No members */ |
Lev Walkin | d9bd775 | 2004-06-05 08:17:50 +0000 | [diff] [blame] | 85 | 0 /* No specifics */ |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 86 | }; |
| 87 | |
| 88 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 89 | int |
Lev Walkin | 5e03376 | 2004-09-29 13:26:15 +0000 | [diff] [blame] | 90 | PrintableString_constraint(asn_TYPE_descriptor_t *td, const void *sptr, |
Lev Walkin | 1eded35 | 2006-07-13 11:19:01 +0000 | [diff] [blame] | 91 | asn_app_constraint_failed_f *ctfailcb, void *app_key) { |
Lev Walkin | c234657 | 2004-08-11 09:07:36 +0000 | [diff] [blame] | 92 | const PrintableString_t *st = (const PrintableString_t *)sptr; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 93 | |
| 94 | if(st && st->buf) { |
| 95 | uint8_t *buf = st->buf; |
| 96 | uint8_t *end = buf + st->size; |
| 97 | |
| 98 | /* |
| 99 | * Check the alphabet of the PrintableString. |
| 100 | * ASN.1:1984 (X.409) |
| 101 | */ |
| 102 | for(; buf < end; buf++) { |
| 103 | if(!_PrintableString_alphabet[*buf]) { |
Lev Walkin | 7c1dc05 | 2016-03-14 03:08:15 -0700 | [diff] [blame] | 104 | ASN__CTFAIL(app_key, td, sptr, |
Lev Walkin | 426b098 | 2004-10-26 09:59:42 +0000 | [diff] [blame] | 105 | "%s: value byte %ld (%d) " |
Lev Walkin | 16835b6 | 2004-08-22 13:47:59 +0000 | [diff] [blame] | 106 | "not in PrintableString alphabet " |
| 107 | "(%s:%d)", |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 108 | td->name, |
Lev Walkin | 426b098 | 2004-10-26 09:59:42 +0000 | [diff] [blame] | 109 | (long)((buf - st->buf) + 1), |
Lev Walkin | 5a56c7c | 2004-08-23 08:34:14 +0000 | [diff] [blame] | 110 | *buf, |
Lev Walkin | 16835b6 | 2004-08-22 13:47:59 +0000 | [diff] [blame] | 111 | __FILE__, __LINE__); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 112 | return -1; |
| 113 | } |
| 114 | } |
| 115 | } else { |
Lev Walkin | 7c1dc05 | 2016-03-14 03:08:15 -0700 | [diff] [blame] | 116 | ASN__CTFAIL(app_key, td, sptr, |
Lev Walkin | 16835b6 | 2004-08-22 13:47:59 +0000 | [diff] [blame] | 117 | "%s: value not given (%s:%d)", |
| 118 | td->name, __FILE__, __LINE__); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 119 | return -1; |
| 120 | } |
| 121 | |
| 122 | return 0; |
| 123 | } |