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