blob: c4afcb00d2e0444f43002a275f697e6880cb7a85 [file] [log] [blame]
Lev Walkinf15320b2004-06-03 03:38:44 +00001/*-
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 */
10static ber_tlv_tag_t asn1_DEF_IA5String_tags[] = {
11 (ASN_TAG_CLASS_UNIVERSAL | (22 << 2))
12};
13asn1_TYPE_descriptor_t asn1_DEF_IA5String = {
14 "IA5String",
15 IA5String_constraint, /* Constraint on the alphabet */
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_IA5String_tags,
22 sizeof(asn1_DEF_IA5String_tags)
23 / sizeof(asn1_DEF_IA5String_tags[0]),
24 1, /* Single UNIVERSAL tag may be implicitly overriden */
25 -1, /* Both ways are fine */
26};
27
28int
29IA5String_constraint(asn1_TYPE_descriptor_t *td, const void *sptr,
30 asn_app_consume_bytes_f *app_errlog, void *app_key) {
31 const IA5String_t *st = sptr;
32
33 if(st && st->buf) {
34 uint8_t *buf = st->buf;
35 uint8_t *end = buf + st->size;
36 /*
37 * IA5String is generally equivalent to 7bit ASCII.
38 * ISO/ITU-T T.50, 1963.
39 */
40 for(; buf < end; buf++) {
41 if(*buf > 0x7F) {
42 _ASN_ERRLOG("%s: value byte %d out of range: "
43 "%d > 127",
44 td->name,
45 (buf - st->buf) + 1,
46 *buf
47 );
48 return -1;
49 }
50 }
51 } else {
52 _ASN_ERRLOG("%s: value not given", td->name);
53 return -1;
54 }
55
56 return 0;
57}