blob: 33f38a64b24f7c02d9b466fea3b6fb6a09a8306e [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]),
Lev Walkinf15320b2004-06-03 03:38:44 +000024 -1, /* Both ways are fine */
Lev Walkin449f8322004-08-20 13:23:42 +000025 0, 0, /* No members */
Lev Walkind9bd7752004-06-05 08:17:50 +000026 0 /* No specifics */
Lev Walkinf15320b2004-06-03 03:38:44 +000027};
28
29int
30IA5String_constraint(asn1_TYPE_descriptor_t *td, const void *sptr,
31 asn_app_consume_bytes_f *app_errlog, void *app_key) {
Lev Walkinc2346572004-08-11 09:07:36 +000032 const IA5String_t *st = (const IA5String_t *)sptr;
Lev Walkinf15320b2004-06-03 03:38:44 +000033
34 if(st && st->buf) {
35 uint8_t *buf = st->buf;
36 uint8_t *end = buf + st->size;
37 /*
38 * IA5String is generally equivalent to 7bit ASCII.
39 * ISO/ITU-T T.50, 1963.
40 */
41 for(; buf < end; buf++) {
42 if(*buf > 0x7F) {
Lev Walkinba4e5182004-08-11 09:44:13 +000043 _ASN_ERRLOG(app_errlog, app_key,
44 "%s: value byte %d out of range: "
Lev Walkin16835b62004-08-22 13:47:59 +000045 "%d > 127 (%s:%d)",
Lev Walkinf15320b2004-06-03 03:38:44 +000046 td->name,
47 (buf - st->buf) + 1,
Lev Walkin16835b62004-08-22 13:47:59 +000048 *buf,
49 __FILE__, __LINE__);
Lev Walkinf15320b2004-06-03 03:38:44 +000050 return -1;
51 }
52 }
53 } else {
Lev Walkinba4e5182004-08-11 09:44:13 +000054 _ASN_ERRLOG(app_errlog, app_key,
Lev Walkin16835b62004-08-22 13:47:59 +000055 "%s: value not given (%s:%d)",
56 td->name, __FILE__, __LINE__);
Lev Walkinf15320b2004-06-03 03:38:44 +000057 return -1;
58 }
59
60 return 0;
61}