blob: a8d4ed8c79c80d3a07b509d7d5ff82eea4af5393 [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 <NumericString.h>
6
7/*
8 * NumericString basic type description.
9 */
10static ber_tlv_tag_t asn1_DEF_NumericString_tags[] = {
11 (ASN_TAG_CLASS_UNIVERSAL | (18 << 2))
12};
13asn1_TYPE_descriptor_t asn1_DEF_NumericString = {
14 "NumericString",
15 NumericString_constraint,
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_NumericString_tags,
22 sizeof(asn1_DEF_NumericString_tags)
23 / sizeof(asn1_DEF_NumericString_tags[0]),
24 1, /* Single UNIVERSAL tag may be implicitly overriden */
25 -1, /* Both ways are fine */
Lev Walkind9bd7752004-06-05 08:17:50 +000026 0 /* No specifics */
Lev Walkinf15320b2004-06-03 03:38:44 +000027};
28
29int
30NumericString_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 NumericString_t *st = (const NumericString_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 /*
39 * Check the alphabet of the NumericString.
40 * ASN.1:1984 (X.409)
41 */
42 for(; buf < end; buf++) {
43 switch(*buf) {
44 case 0x20:
45 case 0x30: case 0x31: case 0x32: case 0x33: case 0x34:
46 case 0x35: case 0x36: case 0x37: case 0x38: case 0x39:
47 continue;
48 }
Lev Walkinba4e5182004-08-11 09:44:13 +000049 _ASN_ERRLOG(app_errlog, app_key,
50 "%s: value byte %d "
Lev Walkinf15320b2004-06-03 03:38:44 +000051 "not in NumericString alphabet (%d)",
52 td->name,
53 (buf - st->buf) + 1,
54 *buf
55 );
56 return -1;
57 }
58 } else {
Lev Walkinba4e5182004-08-11 09:44:13 +000059 _ASN_ERRLOG(app_errlog, app_key,
60 "%s: value not given", td->name);
Lev Walkinf15320b2004-06-03 03:38:44 +000061 return -1;
62 }
63
64 return 0;
65}