blob: a23e39f130cfb81e2b16bac0ddfc319e2e793121 [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[] = {
Lev Walkin188ed2c2004-09-13 08:31:01 +000011 (ASN_TAG_CLASS_UNIVERSAL | (18 << 2)), /* [UNIVERSAL 18] IMPLICIT ...*/
12 (ASN_TAG_CLASS_UNIVERSAL | (4 << 2)) /* ... OCTET STRING */
Lev Walkinf15320b2004-06-03 03:38:44 +000013};
14asn1_TYPE_descriptor_t asn1_DEF_NumericString = {
15 "NumericString",
16 NumericString_constraint,
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_NumericString_tags,
23 sizeof(asn1_DEF_NumericString_tags)
Lev Walkin188ed2c2004-09-13 08:31:01 +000024 / sizeof(asn1_DEF_NumericString_tags[0]) - 1,
25 asn1_DEF_NumericString_tags,
26 sizeof(asn1_DEF_NumericString_tags)
Lev Walkinf15320b2004-06-03 03:38:44 +000027 / sizeof(asn1_DEF_NumericString_tags[0]),
Lev Walkinf15320b2004-06-03 03:38:44 +000028 -1, /* Both ways are fine */
Lev Walkin449f8322004-08-20 13:23:42 +000029 0, 0, /* No members */
Lev Walkind9bd7752004-06-05 08:17:50 +000030 0 /* No specifics */
Lev Walkinf15320b2004-06-03 03:38:44 +000031};
32
33int
34NumericString_constraint(asn1_TYPE_descriptor_t *td, const void *sptr,
35 asn_app_consume_bytes_f *app_errlog, void *app_key) {
Lev Walkinc2346572004-08-11 09:07:36 +000036 const NumericString_t *st = (const NumericString_t *)sptr;
Lev Walkinf15320b2004-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 /*
43 * Check the alphabet of the NumericString.
44 * ASN.1:1984 (X.409)
45 */
46 for(; buf < end; buf++) {
47 switch(*buf) {
48 case 0x20:
49 case 0x30: case 0x31: case 0x32: case 0x33: case 0x34:
50 case 0x35: case 0x36: case 0x37: case 0x38: case 0x39:
51 continue;
52 }
Lev Walkinba4e5182004-08-11 09:44:13 +000053 _ASN_ERRLOG(app_errlog, app_key,
Lev Walkin16835b62004-08-22 13:47:59 +000054 "%s: value byte %d (%d) "
55 "not in NumericString alphabet (%s:%d)",
Lev Walkinf15320b2004-06-03 03:38:44 +000056 td->name,
57 (buf - st->buf) + 1,
Lev Walkin16835b62004-08-22 13:47:59 +000058 *buf,
59 __FILE__, __LINE__);
Lev Walkinf15320b2004-06-03 03:38:44 +000060 return -1;
61 }
62 } else {
Lev Walkinba4e5182004-08-11 09:44:13 +000063 _ASN_ERRLOG(app_errlog, app_key,
Lev Walkin16835b62004-08-22 13:47:59 +000064 "%s: value not given (%s:%d)",
65 td->name, __FILE__, __LINE__);
Lev Walkinf15320b2004-06-03 03:38:44 +000066 return -1;
67 }
68
69 return 0;
70}