blob: 9fc308b170b490b3bedaa37ccd90769d9124c68b [file] [log] [blame]
vlmfa67ddc2004-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[] = {
vlm72425de2004-09-13 08:31:01 +000011 (ASN_TAG_CLASS_UNIVERSAL | (22 << 2)), /* [UNIVERSAL 22] IMPLICIT ...*/
12 (ASN_TAG_CLASS_UNIVERSAL | (4 << 2)) /* ... OCTET STRING */
vlmfa67ddc2004-06-03 03:38:44 +000013};
14asn1_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)
vlm72425de2004-09-13 08:31:01 +000024 / sizeof(asn1_DEF_IA5String_tags[0]) - 1,
25 asn1_DEF_IA5String_tags,
26 sizeof(asn1_DEF_IA5String_tags)
vlmfa67ddc2004-06-03 03:38:44 +000027 / sizeof(asn1_DEF_IA5String_tags[0]),
vlmfa67ddc2004-06-03 03:38:44 +000028 -1, /* Both ways are fine */
vlme413c122004-08-20 13:23:42 +000029 0, 0, /* No members */
vlmb42843a2004-06-05 08:17:50 +000030 0 /* No specifics */
vlmfa67ddc2004-06-03 03:38:44 +000031};
32
33int
34IA5String_constraint(asn1_TYPE_descriptor_t *td, const void *sptr,
35 asn_app_consume_bytes_f *app_errlog, void *app_key) {
vlmda674682004-08-11 09:07:36 +000036 const IA5String_t *st = (const IA5String_t *)sptr;
vlmfa67ddc2004-06-03 03:38:44 +000037
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) {
vlme3f0f282004-08-11 09:44:13 +000047 _ASN_ERRLOG(app_errlog, app_key,
48 "%s: value byte %d out of range: "
vlm758530a2004-08-22 13:47:59 +000049 "%d > 127 (%s:%d)",
vlmfa67ddc2004-06-03 03:38:44 +000050 td->name,
51 (buf - st->buf) + 1,
vlm758530a2004-08-22 13:47:59 +000052 *buf,
53 __FILE__, __LINE__);
vlmfa67ddc2004-06-03 03:38:44 +000054 return -1;
55 }
56 }
57 } else {
vlme3f0f282004-08-11 09:44:13 +000058 _ASN_ERRLOG(app_errlog, app_key,
vlm758530a2004-08-22 13:47:59 +000059 "%s: value not given (%s:%d)",
60 td->name, __FILE__, __LINE__);
vlmfa67ddc2004-06-03 03:38:44 +000061 return -1;
62 }
63
64 return 0;
65}