Harald Welte | 92c45f3 | 2010-06-12 18:59:38 +0200 | [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 <asn_internal.h> |
| 6 | #include <VisibleString.h> |
| 7 | |
| 8 | /* |
| 9 | * VisibleString basic type description. |
| 10 | */ |
| 11 | static ber_tlv_tag_t asn_DEF_VisibleString_tags[] = { |
| 12 | (ASN_TAG_CLASS_UNIVERSAL | (26 << 2)), /* [UNIVERSAL 26] IMPLICIT ...*/ |
| 13 | (ASN_TAG_CLASS_UNIVERSAL | (4 << 2)) /* ... OCTET STRING */ |
| 14 | }; |
| 15 | asn_TYPE_descriptor_t asn_DEF_VisibleString = { |
| 16 | "VisibleString", |
| 17 | "VisibleString", |
| 18 | OCTET_STRING_free, |
| 19 | OCTET_STRING_print_utf8, /* ASCII subset */ |
| 20 | VisibleString_constraint, |
| 21 | OCTET_STRING_decode_ber, /* Implemented in terms of OCTET STRING */ |
| 22 | OCTET_STRING_encode_der, |
| 23 | OCTET_STRING_decode_xer_utf8, |
| 24 | OCTET_STRING_encode_xer_utf8, |
| 25 | 0, 0, |
| 26 | 0, /* Use generic outmost tag fetcher */ |
| 27 | asn_DEF_VisibleString_tags, |
| 28 | sizeof(asn_DEF_VisibleString_tags) |
| 29 | / sizeof(asn_DEF_VisibleString_tags[0]) - 1, |
| 30 | asn_DEF_VisibleString_tags, |
| 31 | sizeof(asn_DEF_VisibleString_tags) |
| 32 | / sizeof(asn_DEF_VisibleString_tags[0]), |
| 33 | 0, /* No PER visible constraints */ |
| 34 | 0, 0, /* No members */ |
| 35 | 0 /* No specifics */ |
| 36 | }; |
| 37 | |
| 38 | int |
| 39 | VisibleString_constraint(asn_TYPE_descriptor_t *td, const void *sptr, |
| 40 | asn_app_constraint_failed_f *ctfailcb, void *app_key) { |
| 41 | const VisibleString_t *st = (const VisibleString_t *)sptr; |
| 42 | |
| 43 | if(st && st->buf) { |
| 44 | uint8_t *buf = st->buf; |
| 45 | uint8_t *end = buf + st->size; |
| 46 | |
| 47 | /* |
| 48 | * Check the alphabet of the VisibleString. |
| 49 | * ISO646, ISOReg#6 |
| 50 | * The alphabet is a subset of ASCII between the space |
| 51 | * and "~" (tilde). |
| 52 | */ |
| 53 | for(; buf < end; buf++) { |
| 54 | if(*buf < 0x20 || *buf > 0x7e) { |
| 55 | _ASN_CTFAIL(app_key, td, |
| 56 | "%s: value byte %ld (%d) " |
| 57 | "not in VisibleString alphabet (%s:%d)", |
| 58 | td->name, |
| 59 | (long)((buf - st->buf) + 1), |
| 60 | *buf, |
| 61 | __FILE__, __LINE__); |
| 62 | return -1; |
| 63 | } |
| 64 | } |
| 65 | } else { |
| 66 | _ASN_CTFAIL(app_key, td, |
| 67 | "%s: value not given (%s:%d)", |
| 68 | td->name, __FILE__, __LINE__); |
| 69 | return -1; |
| 70 | } |
| 71 | |
| 72 | return 0; |
| 73 | } |