4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
30 #pragma ident "%Z%%M% %I% %E% SMI"
37 * ASN.1 values are encoded as octet strings based on the use of a
38 * Type-Length-Value (TLV) structure. The Type indicates the ASN.1
39 * type, the class of the type, and whether the encoding is primitive
40 * or constructed. The Length indicates the length of the actual value
41 * representation and the Value represents the value as a string
44 * +------------+--------+----------+
45 * | Identifier | Length | Contents |
46 * +------------+--------+----------+
48 * The encoding of the Identifier field is shown below (for tags less than 31):
50 * +-------+-----+------------+
51 * | Class | P/C | Tag number |
52 * +-------+-----+------------+
55 * The class field specifies one of four classes, the P/C bit specifies
56 * whether this is a primitive/constructed encoding and the tag number
57 * distinguishes one data type from another within the class.
63 #define ASN_UNIVERSAL ((uchar_t)0x00)
64 #define ASN_APPLICATION ((uchar_t)0x40)
65 #define ASN_CONTEXT ((uchar_t)0x80)
66 #define ASN_PRIVATE ((uchar_t)0xc0)
71 #define ASN_PRIMITIVE ((uchar_t)0x00)
72 #define ASN_CONSTRUCTOR ((uchar_t)0x20)
75 * Tag numbers for the Universal class of ASN.1 values
77 #define ASN_BOOLEAN ((uchar_t)0x01)
78 #define ASN_INTEGER ((uchar_t)0x02)
79 #define ASN_BIT_STR ((uchar_t)0x03)
80 #define ASN_OCTET_STR ((uchar_t)0x04)
81 #define ASN_NULL ((uchar_t)0x05)
82 #define ASN_OBJECT_ID ((uchar_t)0x06)
83 #define ASN_SEQUENCE ((uchar_t)0x10)
84 #define ASN_SET ((uchar_t)0x11)
87 * ASN Extension Tag in the identifier
89 #define ASN_EXT_TAG ((uchar_t)0x1f)
92 * Application class ASN.1 identifiers
94 #define ASN_COUNTER (ASN_APPLICATION | ASN_PRIMITIVE | (uchar_t)0x01)
95 #define ASN_TIMETICKS (ASN_APPLICATION | ASN_PRIMITIVE | (uchar_t)0x03)
98 * The Length field in the TLV structure described above is represented
99 * in many ways depending on the value.
101 * If the length is less than 128, the length field consists of a
102 * single octet beginning with a zero.
108 * If the length is greater than 127, the first octet of the length field
109 * contains a seven-bit integer that specifies the number of additional
110 * length octets and the additional octets specify the actual length.
112 * <-- one octet --><----- K octets ----->
113 * +---------------+---------------------+
114 * | 1 | K | Length(L) |
115 * +---------------+---------------------+
118 #define ASN_LONG_LEN ((uchar_t)0x80)
119 #define ASN_BIT8 ((uchar_t)0x80)
122 * Some parts of the code assumes a few things -- big-endian ordering,
123 * sizeof int, etc. to simplify things.
125 #define BUILD_INT_SHIFT 23
126 #define BUILD_INT_MASK 0x1ff
129 * Exported ASN.1 encoding related interfaces (only exported within
130 * snmplib, we need to do ld versioning to limit the scope of these to
133 uchar_t
*asn_build_sequence(uchar_t
*, size_t *, uchar_t
, size_t);
134 uchar_t
*asn_build_header(uchar_t
*, size_t *, uchar_t
, size_t);
135 uchar_t
*asn_build_length(uchar_t
*, size_t *, size_t);
136 uchar_t
*asn_build_int(uchar_t
*, size_t *, uchar_t
, int);
137 uchar_t
*asn_build_string(uchar_t
*, size_t *, uchar_t
, uchar_t
*, size_t);
138 uchar_t
*asn_build_objid(uchar_t
*, size_t *, uchar_t
, void *, size_t);
139 uchar_t
*asn_build_null(uchar_t
*, size_t *, uchar_t
);
141 uchar_t
*asn_parse_sequence(uchar_t
*, size_t *, uchar_t
);
142 uchar_t
*asn_parse_header(uchar_t
*, size_t *, uchar_t
*);
143 uchar_t
*asn_parse_length(uchar_t
*, size_t *);
144 uchar_t
*asn_parse_int(uchar_t
*, size_t *, int *);
145 uchar_t
*asn_parse_uint(uchar_t
*, size_t *, uint_t
*);
146 uchar_t
*asn_parse_string(uchar_t
*, size_t *, uchar_t
**, size_t *);
147 uchar_t
*asn_parse_objid(uchar_t
*, size_t *, void *, size_t *);
148 uchar_t
*asn_parse_objval(uchar_t
*, size_t *, void *);