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 <IA5String.h> |
| 6 | |
| 7 | /* |
| 8 | * IA5String basic type description. |
| 9 | */ |
| 10 | static ber_tlv_tag_t asn1_DEF_IA5String_tags[] = { |
vlm | 72425de | 2004-09-13 08:31:01 +0000 | [diff] [blame] | 11 | (ASN_TAG_CLASS_UNIVERSAL | (22 << 2)), /* [UNIVERSAL 22] IMPLICIT ...*/ |
| 12 | (ASN_TAG_CLASS_UNIVERSAL | (4 << 2)) /* ... OCTET STRING */ |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 13 | }; |
| 14 | asn1_TYPE_descriptor_t asn1_DEF_IA5String = { |
| 15 | "IA5String", |
| 16 | IA5String_constraint, /* Constraint on the alphabet */ |
| 17 | OCTET_STRING_decode_ber, /* Implemented in terms of OCTET STRING */ |
| 18 | OCTET_STRING_encode_der, /* Implemented in terms of OCTET STRING */ |
| 19 | OCTET_STRING_print_ascii, /* ASCII subset */ |
| 20 | OCTET_STRING_free, |
| 21 | 0, /* Use generic outmost tag fetcher */ |
| 22 | asn1_DEF_IA5String_tags, |
| 23 | sizeof(asn1_DEF_IA5String_tags) |
vlm | 72425de | 2004-09-13 08:31:01 +0000 | [diff] [blame] | 24 | / sizeof(asn1_DEF_IA5String_tags[0]) - 1, |
| 25 | asn1_DEF_IA5String_tags, |
| 26 | sizeof(asn1_DEF_IA5String_tags) |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 27 | / sizeof(asn1_DEF_IA5String_tags[0]), |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 28 | -1, /* Both ways are fine */ |
vlm | e413c12 | 2004-08-20 13:23:42 +0000 | [diff] [blame] | 29 | 0, 0, /* No members */ |
vlm | b42843a | 2004-06-05 08:17:50 +0000 | [diff] [blame] | 30 | 0 /* No specifics */ |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 31 | }; |
| 32 | |
| 33 | int |
| 34 | IA5String_constraint(asn1_TYPE_descriptor_t *td, const void *sptr, |
| 35 | asn_app_consume_bytes_f *app_errlog, void *app_key) { |
vlm | da67468 | 2004-08-11 09:07:36 +0000 | [diff] [blame] | 36 | const IA5String_t *st = (const IA5String_t *)sptr; |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 37 | |
| 38 | if(st && st->buf) { |
| 39 | uint8_t *buf = st->buf; |
| 40 | uint8_t *end = buf + st->size; |
| 41 | /* |
| 42 | * IA5String is generally equivalent to 7bit ASCII. |
| 43 | * ISO/ITU-T T.50, 1963. |
| 44 | */ |
| 45 | for(; buf < end; buf++) { |
| 46 | if(*buf > 0x7F) { |
vlm | e3f0f28 | 2004-08-11 09:44:13 +0000 | [diff] [blame] | 47 | _ASN_ERRLOG(app_errlog, app_key, |
| 48 | "%s: value byte %d out of range: " |
vlm | 758530a | 2004-08-22 13:47:59 +0000 | [diff] [blame] | 49 | "%d > 127 (%s:%d)", |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 50 | td->name, |
| 51 | (buf - st->buf) + 1, |
vlm | 758530a | 2004-08-22 13:47:59 +0000 | [diff] [blame] | 52 | *buf, |
| 53 | __FILE__, __LINE__); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 54 | return -1; |
| 55 | } |
| 56 | } |
| 57 | } else { |
vlm | e3f0f28 | 2004-08-11 09:44:13 +0000 | [diff] [blame] | 58 | _ASN_ERRLOG(app_errlog, app_key, |
vlm | 758530a | 2004-08-22 13:47:59 +0000 | [diff] [blame] | 59 | "%s: value not given (%s:%d)", |
| 60 | td->name, __FILE__, __LINE__); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 61 | return -1; |
| 62 | } |
| 63 | |
| 64 | return 0; |
| 65 | } |