vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1 | /*- |
| 2 | * Copyright (c) 2003 Lev Walkin <vlm@lionet.info>. All rights reserved. |
| 3 | * Redistribution and modifications are permitted subject to BSD license. |
| 4 | */ |
vlm | 39ba4c4 | 2004-09-22 16:06:28 +0000 | [diff] [blame] | 5 | #include <asn_internal.h> |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 6 | #include <NumericString.h> |
| 7 | |
| 8 | /* |
| 9 | * NumericString basic type description. |
| 10 | */ |
| 11 | static ber_tlv_tag_t asn1_DEF_NumericString_tags[] = { |
vlm | 72425de | 2004-09-13 08:31:01 +0000 | [diff] [blame] | 12 | (ASN_TAG_CLASS_UNIVERSAL | (18 << 2)), /* [UNIVERSAL 18] IMPLICIT ...*/ |
| 13 | (ASN_TAG_CLASS_UNIVERSAL | (4 << 2)) /* ... OCTET STRING */ |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 14 | }; |
| 15 | asn1_TYPE_descriptor_t asn1_DEF_NumericString = { |
| 16 | "NumericString", |
vlm | 39ba4c4 | 2004-09-22 16:06:28 +0000 | [diff] [blame] | 17 | OCTET_STRING_free, |
| 18 | OCTET_STRING_print_ascii, /* ASCII subset */ |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 19 | NumericString_constraint, |
| 20 | OCTET_STRING_decode_ber, /* Implemented in terms of OCTET STRING */ |
| 21 | OCTET_STRING_encode_der, /* Implemented in terms of OCTET STRING */ |
vlm | 39ba4c4 | 2004-09-22 16:06:28 +0000 | [diff] [blame] | 22 | 0, /* Not implemented yet */ |
| 23 | OCTET_STRING_encode_xer_ascii,/* Implemented in terms of OCTET STRING */ |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 24 | 0, /* Use generic outmost tag fetcher */ |
| 25 | asn1_DEF_NumericString_tags, |
| 26 | sizeof(asn1_DEF_NumericString_tags) |
vlm | 72425de | 2004-09-13 08:31:01 +0000 | [diff] [blame] | 27 | / sizeof(asn1_DEF_NumericString_tags[0]) - 1, |
| 28 | asn1_DEF_NumericString_tags, |
| 29 | sizeof(asn1_DEF_NumericString_tags) |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 30 | / sizeof(asn1_DEF_NumericString_tags[0]), |
vlm | e413c12 | 2004-08-20 13:23:42 +0000 | [diff] [blame] | 31 | 0, 0, /* No members */ |
vlm | b42843a | 2004-06-05 08:17:50 +0000 | [diff] [blame] | 32 | 0 /* No specifics */ |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 33 | }; |
| 34 | |
| 35 | int |
| 36 | NumericString_constraint(asn1_TYPE_descriptor_t *td, const void *sptr, |
| 37 | asn_app_consume_bytes_f *app_errlog, void *app_key) { |
vlm | da67468 | 2004-08-11 09:07:36 +0000 | [diff] [blame] | 38 | const NumericString_t *st = (const NumericString_t *)sptr; |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 39 | |
| 40 | if(st && st->buf) { |
| 41 | uint8_t *buf = st->buf; |
| 42 | uint8_t *end = buf + st->size; |
| 43 | |
| 44 | /* |
| 45 | * Check the alphabet of the NumericString. |
| 46 | * ASN.1:1984 (X.409) |
| 47 | */ |
| 48 | for(; buf < end; buf++) { |
| 49 | switch(*buf) { |
| 50 | case 0x20: |
| 51 | case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: |
| 52 | case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: |
| 53 | continue; |
| 54 | } |
vlm | e3f0f28 | 2004-08-11 09:44:13 +0000 | [diff] [blame] | 55 | _ASN_ERRLOG(app_errlog, app_key, |
vlm | 758530a | 2004-08-22 13:47:59 +0000 | [diff] [blame] | 56 | "%s: value byte %d (%d) " |
| 57 | "not in NumericString alphabet (%s:%d)", |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 58 | td->name, |
| 59 | (buf - st->buf) + 1, |
vlm | 758530a | 2004-08-22 13:47:59 +0000 | [diff] [blame] | 60 | *buf, |
| 61 | __FILE__, __LINE__); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 62 | return -1; |
| 63 | } |
| 64 | } else { |
vlm | e3f0f28 | 2004-08-11 09:44:13 +0000 | [diff] [blame] | 65 | _ASN_ERRLOG(app_errlog, app_key, |
vlm | 758530a | 2004-08-22 13:47:59 +0000 | [diff] [blame] | 66 | "%s: value not given (%s:%d)", |
| 67 | td->name, __FILE__, __LINE__); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 68 | return -1; |
| 69 | } |
| 70 | |
| 71 | return 0; |
| 72 | } |