xref: /freebsd/contrib/bsnmp/lib/asn1.3 (revision e1d581b289848ffa97c452756dc52d45efb68a01)
1f06ca4afSHartmut Brandt.\"
2165c5d31SHartmut Brandt.\" Copyright (c) 2004-2005
3165c5d31SHartmut Brandt.\"	Hartmut Brandt.
4165c5d31SHartmut Brandt.\"	All rights reserved.
5f06ca4afSHartmut Brandt.\" Copyright (c) 2001-2003
6f06ca4afSHartmut Brandt.\"	Fraunhofer Institute for Open Communication Systems (FhG Fokus).
7f06ca4afSHartmut Brandt.\"	All rights reserved.
8f06ca4afSHartmut Brandt.\"
9*4f13bbb6SUlrich Spörlein.\" Author: Harti Brandt <harti@FreeBSD.org>
10f06ca4afSHartmut Brandt.\"
11896052c1SHartmut Brandt.\" Redistribution and use in source and binary forms, with or without
12896052c1SHartmut Brandt.\" modification, are permitted provided that the following conditions
13896052c1SHartmut Brandt.\" are met:
14896052c1SHartmut Brandt.\" 1. Redistributions of source code must retain the above copyright
15896052c1SHartmut Brandt.\"    notice, this list of conditions and the following disclaimer.
16f06ca4afSHartmut Brandt.\" 2. Redistributions in binary form must reproduce the above copyright
17f06ca4afSHartmut Brandt.\"    notice, this list of conditions and the following disclaimer in the
18f06ca4afSHartmut Brandt.\"    documentation and/or other materials provided with the distribution.
19f06ca4afSHartmut Brandt.\"
20896052c1SHartmut Brandt.\" THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21896052c1SHartmut Brandt.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22896052c1SHartmut Brandt.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23896052c1SHartmut Brandt.\" ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
24896052c1SHartmut Brandt.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25896052c1SHartmut Brandt.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26896052c1SHartmut Brandt.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27896052c1SHartmut Brandt.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28896052c1SHartmut Brandt.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29896052c1SHartmut Brandt.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30896052c1SHartmut Brandt.\" SUCH DAMAGE.
31f06ca4afSHartmut Brandt.\"
32165c5d31SHartmut Brandt.\" $Begemot: bsnmp/lib/asn1.3,v 1.9 2005/10/04 08:46:49 brandt_h Exp $
33f06ca4afSHartmut Brandt.\"
34165c5d31SHartmut Brandt.Dd October 4, 2005
3594caccb3SHartmut Brandt.Dt ASN1 3
36f06ca4afSHartmut Brandt.Os
37f06ca4afSHartmut Brandt.Sh NAME
38f06ca4afSHartmut Brandt.Nm asn_get_header ,
39f06ca4afSHartmut Brandt.Nm asn_put_header ,
40f06ca4afSHartmut Brandt.Nm asn_put_temp_header ,
41f06ca4afSHartmut Brandt.Nm asn_commit_header ,
42f06ca4afSHartmut Brandt.Nm asn_get_integer_raw ,
43f06ca4afSHartmut Brandt.Nm asn_get_integer ,
44f06ca4afSHartmut Brandt.Nm asn_put_integer ,
45f06ca4afSHartmut Brandt.Nm asn_get_octetstring_raw ,
46f06ca4afSHartmut Brandt.Nm asn_get_octetstring ,
47f06ca4afSHartmut Brandt.Nm asn_put_octetstring ,
48f06ca4afSHartmut Brandt.Nm asn_get_null_raw ,
49f06ca4afSHartmut Brandt.Nm asn_get_null ,
50f06ca4afSHartmut Brandt.Nm asn_put_null ,
51f06ca4afSHartmut Brandt.Nm asn_put_exception ,
52f06ca4afSHartmut Brandt.Nm asn_get_objid_raw ,
53f06ca4afSHartmut Brandt.Nm asn_get_objid ,
54f06ca4afSHartmut Brandt.Nm asn_put_objid ,
55f06ca4afSHartmut Brandt.Nm asn_get_sequence ,
56f06ca4afSHartmut Brandt.Nm asn_get_ipaddress_raw ,
57f06ca4afSHartmut Brandt.Nm asn_get_ipaddress ,
58f06ca4afSHartmut Brandt.Nm asn_put_ipaddress ,
59f06ca4afSHartmut Brandt.Nm asn_get_uint32_raw ,
60f06ca4afSHartmut Brandt.Nm asn_put_uint32 ,
61f06ca4afSHartmut Brandt.Nm asn_get_counter64_raw ,
62f06ca4afSHartmut Brandt.Nm asn_put_counter64 ,
63f06ca4afSHartmut Brandt.Nm asn_get_timeticks ,
64f06ca4afSHartmut Brandt.Nm asn_put_timeticks ,
65f06ca4afSHartmut Brandt.Nm asn_skip ,
66f06ca4afSHartmut Brandt.Nm asn_slice_oid ,
67f06ca4afSHartmut Brandt.Nm asn_append_oid ,
68f06ca4afSHartmut Brandt.Nm asn_compare_oid ,
69f06ca4afSHartmut Brandt.Nm asn_is_suboid ,
70f06ca4afSHartmut Brandt.Nm asn_oid2str_r ,
71f06ca4afSHartmut Brandt.Nm asn_oid2str
72f06ca4afSHartmut Brandt.Nd "ASN.1 library for SNMP"
73f06ca4afSHartmut Brandt.Sh LIBRARY
74f06ca4afSHartmut BrandtBegemot SNMP library
75f06ca4afSHartmut Brandt.Pq libbsnmp, -lbsnmp
76f06ca4afSHartmut Brandt.Sh SYNOPSIS
77f06ca4afSHartmut Brandt.In bsnmp/asn1.h
78f06ca4afSHartmut Brandt.Ft enum asn_err
79f06ca4afSHartmut Brandt.Fn asn_get_header "struct asn_buf *buf" "u_char *type" "asn_len_t *lenp"
80f06ca4afSHartmut Brandt.Ft enum asn_err
81f06ca4afSHartmut Brandt.Fn asn_put_header "struct asn_buf *buf" "u_char type" "asn_len_t len"
82f06ca4afSHartmut Brandt.Ft enum asn_err
83f06ca4afSHartmut Brandt.Fn asn_put_temp_header "struct asn_buf *buf" "u_char type" "u_char **ptr"
84f06ca4afSHartmut Brandt.Ft enum asn_err
85f06ca4afSHartmut Brandt.Fn asn_commit_header "struct asn_buf *buf" "u_char *ptr"
86f06ca4afSHartmut Brandt.Ft enum asn_err
87f06ca4afSHartmut Brandt.Fn asn_get_integer_raw "struct asn_buf *buf" "asn_len_t len" "int32_t *res"
88f06ca4afSHartmut Brandt.Ft enum asn_err
89f06ca4afSHartmut Brandt.Fn asn_get_integer "struct asn_buf *buf" "int32_t *res"
90f06ca4afSHartmut Brandt.Ft enum asn_err
91f06ca4afSHartmut Brandt.Fn asn_put_integer "struct asn_buf *buf" "int32_t arg"
92f06ca4afSHartmut Brandt.Ft enum asn_err
93f06ca4afSHartmut Brandt.Fn asn_get_octetstring_raw "struct asn_buf *buf" "asn_len_t len" "u_char *out" "u_int *outsize"
94f06ca4afSHartmut Brandt.Ft enum asn_err
95f06ca4afSHartmut Brandt.Fn asn_get_octetstring "struct asn_buf *buf" "u_char *out" "u_int *outsize"
96f06ca4afSHartmut Brandt.Ft enum asn_err
97f06ca4afSHartmut Brandt.Fn asn_put_octetstring "struct asn_buf *buf" "const u_char *str" "u_int strsize"
98f06ca4afSHartmut Brandt.Ft enum asn_err
99f06ca4afSHartmut Brandt.Fn asn_get_null_raw "struct asn_buf *buf" "asn_len_t len"
100f06ca4afSHartmut Brandt.Ft enum asn_err
101f06ca4afSHartmut Brandt.Fn asn_get_null "struct asn_buf *buf"
102f06ca4afSHartmut Brandt.Ft enum asn_err
103f06ca4afSHartmut Brandt.Fn asn_put_null "struct asn_buf *buf"
104f06ca4afSHartmut Brandt.Ft enum asn_err
105f06ca4afSHartmut Brandt.Fn asn_put_exception "struct asn_buf *buf" "u_int type"
106f06ca4afSHartmut Brandt.Ft enum asn_err
107f06ca4afSHartmut Brandt.Fn asn_get_objid_raw "struct asn_buf *buf" "asn_len_t len" "struct asn_oid *oid"
108f06ca4afSHartmut Brandt.Ft enum asn_err
109f06ca4afSHartmut Brandt.Fn asn_get_objid "struct asn_buf *buf" "struct asn_oid *oid"
110f06ca4afSHartmut Brandt.Ft enum asn_err
111f06ca4afSHartmut Brandt.Fn asn_put_objid "struct asn_buf *buf" "const struct asn_oid *oid"
112f06ca4afSHartmut Brandt.Ft enum asn_err
113f06ca4afSHartmut Brandt.Fn asn_get_sequence "struct asn_buf *buf" "asn_len_t *lenp"
114f06ca4afSHartmut Brandt.Ft enum asn_err
115f06ca4afSHartmut Brandt.Fn asn_get_ipaddress_raw "struct asn_buf *buf" "asn_len_t len" "u_char *ipa"
116f06ca4afSHartmut Brandt.Ft enum asn_err
117f06ca4afSHartmut Brandt.Fn asn_get_ipaddress "struct asn_buf *buf" "u_char *ipa"
118f06ca4afSHartmut Brandt.Ft enum asn_err
119f06ca4afSHartmut Brandt.Fn asn_put_ipaddress "struct asn_buf *buf" "const u_char *ipa"
120f06ca4afSHartmut Brandt.Ft enum asn_err
121f06ca4afSHartmut Brandt.Fn asn_get_uint32_raw "struct asn_buf *buf" "asn_len_t len" "u_int32_t *res"
122f06ca4afSHartmut Brandt.Ft enum asn_err
123f06ca4afSHartmut Brandt.Fn asn_put_uint32 "struct asn_buf *buf" "u_char type" "u_int32_t val"
124f06ca4afSHartmut Brandt.Ft enum asn_err
125f06ca4afSHartmut Brandt.Fn asn_get_counter64_raw "struct asn_buf *buf" "asn_len_t len" "u_int64_t *res"
126f06ca4afSHartmut Brandt.Ft enum asn_err
127f06ca4afSHartmut Brandt.Fn asn_put_counter64 "struct asn_buf *buf" "u_int64_t val"
128f06ca4afSHartmut Brandt.Ft enum asn_err
129f06ca4afSHartmut Brandt.Fn asn_get_timeticks "struct asn_buf *buf" "u_int32_t *valp"
130f06ca4afSHartmut Brandt.Ft enum asn_err
131f06ca4afSHartmut Brandt.Fn asn_put_timeticks "struct asn_buf *buf" "u_int32_t val"
132f06ca4afSHartmut Brandt.Ft enum asn_err
133f06ca4afSHartmut Brandt.Fn asn_skip "struct asn_buf *buf" "asn_len_t len"
134f06ca4afSHartmut Brandt.Ft void
135f06ca4afSHartmut Brandt.Fn asn_slice_oid "struct asn_oid *dest" "const struct asn_oid *src" "u_int from" "u_int to"
136f06ca4afSHartmut Brandt.Ft void
137f06ca4afSHartmut Brandt.Fn asn_append_oid "struct asn_oid *to" "const struct asn_oid *from"
138f06ca4afSHartmut Brandt.Ft int
139f06ca4afSHartmut Brandt.Fn asn_compare_oid "const struct asn_oid *oid1" "const struct asn_oid *oid2"
140f06ca4afSHartmut Brandt.Ft int
141f06ca4afSHartmut Brandt.Fn asn_is_suboid "const struct asn_oid *oid1" "const struct asn_oid *oid2"
142f06ca4afSHartmut Brandt.Ft char *
143f06ca4afSHartmut Brandt.Fn asn_oid2str_r "const struct asn_oid *oid" "char *buf"
144f06ca4afSHartmut Brandt.Ft char *
145f06ca4afSHartmut Brandt.Fn asn_oid2str "const struct asn_oid *oid"
146f06ca4afSHartmut Brandt.Sh DESCRIPTION
147f06ca4afSHartmut BrandtThe ASN.1 library contains routines to handle ASN.1 encoding for SNMP.
148165c5d31SHartmut BrandtIt supports only the restricted form of ASN.1 as required by SNMP.
149165c5d31SHartmut BrandtThere are two basic structures used throughout the library:
150f06ca4afSHartmut Brandt.Bd -literal -offset indent
151f06ca4afSHartmut Brandt/* these restrictions are in the SMI */
152f06ca4afSHartmut Brandt#define ASN_MAXID	0xffffffff
153f06ca4afSHartmut Brandt#define ASN_MAXOIDLEN	128
154f06ca4afSHartmut Brandt
155f06ca4afSHartmut Brandt/* type of subidentifiers */
156f06ca4afSHartmut Brandttypedef u_int32_t asn_subid_t;
157f06ca4afSHartmut Brandt
158f06ca4afSHartmut Brandtstruct asn_oid {
159f06ca4afSHartmut Brandt	u_int	len;
160f06ca4afSHartmut Brandt	asn_subid_t subs[ASN_MAXOIDLEN];
161f06ca4afSHartmut Brandt};
162f06ca4afSHartmut Brandt.Ed
163f06ca4afSHartmut Brandt.Pp
164f06ca4afSHartmut BrandtThis structure represents an OID with the restrictions defined in the SNMP
165f06ca4afSHartmut BrandtSMI.
166f06ca4afSHartmut Brandt.Fa len
167f06ca4afSHartmut Brandtholds the current length of the OID and
168f06ca4afSHartmut Brandt.Fa subs
169f06ca4afSHartmut Brandtholds the elements of the OID.
170f06ca4afSHartmut Brandt.Bd -literal -offset indent
171f06ca4afSHartmut Brandtstruct asn_buf {
172f06ca4afSHartmut Brandt	union {
173f06ca4afSHartmut Brandt		u_char	*ptr;
174f06ca4afSHartmut Brandt		const u_char *cptr;
175f06ca4afSHartmut Brandt	}	asn_u;
176f06ca4afSHartmut Brandt	size_t	asn_len;
177f06ca4afSHartmut Brandt};
178f06ca4afSHartmut Brandt#define asn_cptr	asn_u.cptr
179f06ca4afSHartmut Brandt#define asn_ptr	asn_u.ptr
180f06ca4afSHartmut Brandt.Ed
181f06ca4afSHartmut Brandt.Pp
182165c5d31SHartmut BrandtThis structure is used to encode and decode ASN.1.
183165c5d31SHartmut BrandtIt describes the output
184f06ca4afSHartmut Brandtbuffer for encoding routines and the input buffer for decoding routines.
185f06ca4afSHartmut BrandtFor encoding
186f06ca4afSHartmut Brandt.Fa asn_len
187165c5d31SHartmut Brandtholds the number of remaining free octets in the buffer.
188165c5d31SHartmut BrandtThe first free byte is pointed to by
189f06ca4afSHartmut Brandt.Fa asn_ptr .
190f06ca4afSHartmut BrandtFor decoding
191f06ca4afSHartmut Brandt.Fa asn_len
192165c5d31SHartmut Brandtholds the number of remaining bytes to decode.
193165c5d31SHartmut BrandtThe next byte to decode is pointed to by
194f06ca4afSHartmut Brandt.Fa asn_cptr .
195f06ca4afSHartmut Brandt.Pp
196f06ca4afSHartmut BrandtMost of the functions return an error code
197f06ca4afSHartmut Brandt.Fa "enum asn_error" :
198f06ca4afSHartmut Brandt.Bd -literal -offset indent
199f06ca4afSHartmut Brandtenum asn_err {
200f06ca4afSHartmut Brandt	/* conversion was ok */
201f06ca4afSHartmut Brandt	ASN_ERR_OK	= 0,
202f06ca4afSHartmut Brandt	/* conversion failed and stopped */
203f06ca4afSHartmut Brandt	ASN_ERR_FAILED	= 1 | 0x1000,
204f06ca4afSHartmut Brandt	/* length field bad, value skipped */
205f06ca4afSHartmut Brandt	ASN_ERR_BADLEN	= 2,
206f06ca4afSHartmut Brandt	/* out of buffer, stopped */
207f06ca4afSHartmut Brandt	ASN_ERR_EOBUF	= 3 | 0x1000,
208f06ca4afSHartmut Brandt	/* length ok, but value is out of range */
209f06ca4afSHartmut Brandt	ASN_ERR_RANGE	= 4,
210f06ca4afSHartmut Brandt	/* not the expected tag, stopped */
211f06ca4afSHartmut Brandt	ASN_ERR_TAG	= 5 | 0x1000,
212f06ca4afSHartmut Brandt};
213f06ca4afSHartmut Brandt#define ASN_ERR_STOPPED(E) (((E) & 0x1000) != 0)
214f06ca4afSHartmut Brandt.Ed
215f06ca4afSHartmut Brandt.Pp
216f06ca4afSHartmut BrandtIf
217f06ca4afSHartmut Brandt.Fn ASN_ERR_STOPPED
218f06ca4afSHartmut Brandtreturns true, the error was fatal and processing has stopped at the point
219f06ca4afSHartmut Brandtof error.
220f06ca4afSHartmut Brandt.Pp
221f06ca4afSHartmut BrandtThe function
222f06ca4afSHartmut Brandt.Fn asn_get_header
223165c5d31SHartmut Brandtreads the next header from the input octet stream.
224165c5d31SHartmut BrandtIt returns the tag in the variable pointed to by
225f06ca4afSHartmut Brandt.Fa type
226f06ca4afSHartmut Brandt(note that only single byte tags are supported) and the decoded length field
227f06ca4afSHartmut Brandtin the value pointed to by
228f06ca4afSHartmut Brandt.Fa lenp
229165c5d31SHartmut Brandt(this is restricted to a unsigned 32-bit value).
230165c5d31SHartmut BrandtAll errors in this function are fatal and stop processing.
231f06ca4afSHartmut Brandt.Pp
232f06ca4afSHartmut BrandtThe function
233f06ca4afSHartmut Brandt.Fn asn_put_header
234f06ca4afSHartmut Brandtwrites an ASN.1 header.
235f06ca4afSHartmut Brandt.Fa type
236165c5d31SHartmut Brandtis the tag to write and is restricted to one byte tags (i.e., tags
237f06ca4afSHartmut Brandtlesser or equal than 0x30).
238f06ca4afSHartmut Brandt.Fa len
239f06ca4afSHartmut Brandtis the length of the value and is restricted to 16-bit.
240f06ca4afSHartmut Brandt.Pp
241f06ca4afSHartmut BrandtThe functions
242f06ca4afSHartmut Brandt.Fn asn_put_temp_header
243f06ca4afSHartmut Brandtand
244f06ca4afSHartmut Brandt.Fn asn_commit_header
245f06ca4afSHartmut Brandtare used to write a header when the length of the value is not known in
246f06ca4afSHartmut Brandtadvance, for example, for sequences.
247f06ca4afSHartmut Brandt.Fn asn_put_temp_header
248f06ca4afSHartmut Brandtwrites a header with the given tag
249f06ca4afSHartmut Brandt.Fa type
250f06ca4afSHartmut Brandtand space for the maximum supported length field and sets the pointer pointed
251f06ca4afSHartmut Brandtto by
252f06ca4afSHartmut Brandt.Fa ptr
253165c5d31SHartmut Brandtto the begin of this length field.
254165c5d31SHartmut BrandtThis pointer must then be fed into
255f06ca4afSHartmut Brandt.Fn asn_commit_header
256165c5d31SHartmut Brandtdirectly after writing the value to the buffer.
257165c5d31SHartmut BrandtThe function will compute the
258f06ca4afSHartmut Brandtlength, insert it into the right place and shift the value if the resulting
259f06ca4afSHartmut Brandtlength field is shorter than the estimated one.
260f06ca4afSHartmut Brandt.Pp
261f06ca4afSHartmut BrandtThe function
262f06ca4afSHartmut Brandt.Fn asn_get_integer_raw
263165c5d31SHartmut Brandtis used to decode a signed integer value (32-bit).
264165c5d31SHartmut BrandtIt assumes, that the
265f06ca4afSHartmut Brandtheader of the integer has been decoded already.
266f06ca4afSHartmut Brandt.Fa len
267f06ca4afSHartmut Brandtis the length obtained from the ASN.1 header and the integer will be returned
268f06ca4afSHartmut Brandtin the value pointed to by
269f06ca4afSHartmut Brandt.Fa res .
270f06ca4afSHartmut Brandt.Pp
271f06ca4afSHartmut BrandtThe function
272f06ca4afSHartmut Brandt.Fn asn_get_integer
273165c5d31SHartmut Brandtdecodes a complete 32-bit signed integer including the header.
274165c5d31SHartmut BrandtIf the tag is wrong
275f06ca4afSHartmut Brandt.Li ASN_ERR_TAG
276f06ca4afSHartmut Brandtis returned.
277f06ca4afSHartmut BrandtThe function
278f06ca4afSHartmut Brandt.Fn asn_put_integer
279f06ca4afSHartmut Brandtencodes a 32-bit signed integer.
280f06ca4afSHartmut Brandt.Pp
281f06ca4afSHartmut BrandtThe function
282f06ca4afSHartmut Brandt.Fn asn_get_octetstring_raw
283165c5d31SHartmut Brandtdecodes the value field of an ASN.1 octet string.
284165c5d31SHartmut BrandtThe length obtained from the header must be fed into the
285f06ca4afSHartmut Brandt.Fa len
286f06ca4afSHartmut Brandtargument and
287f06ca4afSHartmut Brandt.Fa out
288165c5d31SHartmut Brandtmust point to a buffer to receive the octet string.
289165c5d31SHartmut BrandtOn entry to the function
290f06ca4afSHartmut Brandt.Fa outsize
291165c5d31SHartmut Brandtmust point to the size of the buffer.
292165c5d31SHartmut BrandtOn exit
293f06ca4afSHartmut Brandt.Fa outsize
294f06ca4afSHartmut Brandtwill point to the number of octets decoded (if no error occurs this will be
295f06ca4afSHartmut Brandtequal to
296f06ca4afSHartmut Brandt.Fa len ).
297f06ca4afSHartmut BrandtThe function
298f06ca4afSHartmut Brandt.Fn asn_get_octetstring
299f06ca4afSHartmut Brandtdecodes an octetstring including the header.
300f06ca4afSHartmut Brandt.Fa out
301f06ca4afSHartmut Brandtmust point to a buffer to receive the string,
302f06ca4afSHartmut Brandt.Fa outsize
303165c5d31SHartmut Brandtmust point to the size of the buffer.
304165c5d31SHartmut BrandtOn exit of the function
305f06ca4afSHartmut Brandt.Fa outsize
306f06ca4afSHartmut Brandtwill point to the number of octets decoded.
307f06ca4afSHartmut BrandtThe function
308f06ca4afSHartmut Brandt.Fn asn_put_octetstring
309f06ca4afSHartmut Brandtencodes an octetstring (including the header).
310f06ca4afSHartmut Brandt.Fa str
311f06ca4afSHartmut Brandtpoints to the string to encode and
312f06ca4afSHartmut Brandt.Fa strsize
313f06ca4afSHartmut Brandtis the length of the string (the string may contain embedded
314f06ca4afSHartmut Brandt.Li NUL Ns s).
315f06ca4afSHartmut Brandt.Pp
316f06ca4afSHartmut BrandtThe function
317f06ca4afSHartmut Brandt.Fn asn_get_null_raw
318f06ca4afSHartmut Brandtdecodes a null value.
319f06ca4afSHartmut Brandt.Fa len
320f06ca4afSHartmut Brandtis the length obtained from the header and must be 0.
321f06ca4afSHartmut BrandtThe function
322f06ca4afSHartmut Brandt.Fn asn_get_null
323f06ca4afSHartmut Brandtdecodes a null including the header and the function
324f06ca4afSHartmut Brandt.Fn asn_put_null
325f06ca4afSHartmut Brandtencodes a null.
326f06ca4afSHartmut Brandt.Pp
327f06ca4afSHartmut BrandtThe function
328f06ca4afSHartmut Brandt.Fn asn_put_exception
329165c5d31SHartmut Brandtis used to encode an SNMPv2 exception.
330165c5d31SHartmut BrandtThe exception type is
331f06ca4afSHartmut Brandt.Fa type .
332f06ca4afSHartmut Brandt.Pp
333f06ca4afSHartmut BrandtThe function
334f06ca4afSHartmut Brandt.Fn asn_get_objid_raw
335f06ca4afSHartmut Brandtis used to decode an OID value.
336f06ca4afSHartmut Brandt.Fa len
337f06ca4afSHartmut Brandtmust be the value length obtained from the header and
338f06ca4afSHartmut Brandt.Fa oid
339f06ca4afSHartmut Brandtwill receive the decoded OID.
340f06ca4afSHartmut BrandtThe function
341f06ca4afSHartmut Brandt.Fn asn_get_objid
342f06ca4afSHartmut Brandtdecodes a complete OID (including the header) and the function
343f06ca4afSHartmut Brandt.Fn asn_put_objid
344f06ca4afSHartmut Brandtencodes a complete OID.
345f06ca4afSHartmut Brandt.Pp
346f06ca4afSHartmut BrandtThe function
347f06ca4afSHartmut Brandt.Fn asn_get_sequence
348f06ca4afSHartmut Brandtdecodes a sequence header.
349f06ca4afSHartmut BrandtThe length of the sequence value will be stored in the value pointed to by
350f06ca4afSHartmut Brandt.Fa lenp .
351f06ca4afSHartmut Brandt.Pp
352f06ca4afSHartmut BrandtThe function
353f06ca4afSHartmut Brandt.Fn asn_get_ipaddress_raw
354f06ca4afSHartmut Brandtdecodes an IP address value.
355f06ca4afSHartmut Brandt.Fa len
356f06ca4afSHartmut Brandtis the length from the header and must be 4.
357f06ca4afSHartmut Brandt.Fa ipa
358f06ca4afSHartmut Brandtwill receive the decoded IP address and must point to a buffer of at least
359f06ca4afSHartmut Brandtfour bytes.
360f06ca4afSHartmut BrandtThe function
361f06ca4afSHartmut Brandt.Fn asn_get_ipaddress
362f06ca4afSHartmut Brandtdecodes a complete IP address (including the header) and
363f06ca4afSHartmut Brandt.Fn asn_put_ipaddress
364f06ca4afSHartmut Brandtencodes an IP address.
365f06ca4afSHartmut Brandt.Pp
366f06ca4afSHartmut BrandtThe function
367f06ca4afSHartmut Brandt.Fn asn_get_uint32_raw
368f06ca4afSHartmut Brandtdecodes an unsigned 32-bit integer value.
369f06ca4afSHartmut Brandt.Fa len
370f06ca4afSHartmut Brandtis the length from the header and
371f06ca4afSHartmut Brandt.Fa res
372f06ca4afSHartmut Brandtwill get the decoded value.
373f06ca4afSHartmut BrandtThe function
374f06ca4afSHartmut Brandt.Fn asn_put_uint32
375f06ca4afSHartmut Brandtencodes an unsigned 32-bit integer value and inserts the tag given in
376f06ca4afSHartmut Brandt.Fa type
377f06ca4afSHartmut Brandtinto the header.
378f06ca4afSHartmut Brandt.Pp
379f06ca4afSHartmut BrandtThe function
380f06ca4afSHartmut Brandt.Fn asn_get_counter64_raw
381f06ca4afSHartmut Brandtdecodes an unsigned 64-bit integer value.
382f06ca4afSHartmut Brandt.Fa len
383165c5d31SHartmut Brandtmust be the value length from the header.
384165c5d31SHartmut BrandtThe resulting value is stored into the variable pointed to by
385f06ca4afSHartmut Brandt.Fa res .
386f06ca4afSHartmut BrandtThe function
387f06ca4afSHartmut Brandt.Fn asn_put_counter64
388f06ca4afSHartmut Brandtencodes a complete unsigned 64-bit value.
389f06ca4afSHartmut Brandt.Pp
390f06ca4afSHartmut BrandtThe function
391f06ca4afSHartmut Brandt.Fn asn_get_timeticks
392f06ca4afSHartmut Brandtdecodes an ASN.1 object of type
393f06ca4afSHartmut Brandt.Li TIMETICKS
394f06ca4afSHartmut Brandtand the function
395f06ca4afSHartmut Brandt.Fn asn_put_timeticks
396f06ca4afSHartmut Brandtencodes such an object.
397f06ca4afSHartmut Brandt.Pp
398f06ca4afSHartmut BrandtThe function
399f06ca4afSHartmut Brandt.Fn asn_skip
400f06ca4afSHartmut Brandtcan be used to skip
401f06ca4afSHartmut Brandt.Fa len
402f06ca4afSHartmut Brandtbytes in the input buffer.
403f06ca4afSHartmut Brandt.Pp
404f06ca4afSHartmut BrandtThe function
405f06ca4afSHartmut Brandt.Fn asn_slice_oid
406165c5d31SHartmut Brandtsplits a part out from an OID.
407165c5d31SHartmut BrandtIt takes all the subids from the OID pointed to by
408f06ca4afSHartmut Brandt.Fa src
409f06ca4afSHartmut Brandtstarting with the subid at position
410f06ca4afSHartmut Brandt.Fa from
411165c5d31SHartmut Brandt(the first subid being subid 0) up to, but not including, subid
412f06ca4afSHartmut Brandt.Fa to
413f06ca4afSHartmut Brandtand generates a new OID in
414f06ca4afSHartmut Brandt.Fa dest .
415f06ca4afSHartmut BrandtIf
416f06ca4afSHartmut Brandt.Fa to
417f06ca4afSHartmut Brandtis less or equal to
418f06ca4afSHartmut Brandt.Fa from
419f06ca4afSHartmut Brandtthe resulting OID will have a length of zero.
420f06ca4afSHartmut Brandt.Pp
421f06ca4afSHartmut BrandtThe function
422f06ca4afSHartmut Brandt.Fn asn_append_oid
423f06ca4afSHartmut Brandtappends the OID
424f06ca4afSHartmut Brandt.Fa from
425f06ca4afSHartmut Brandtto the OID
426f06ca4afSHartmut Brandt.Fa to
427165c5d31SHartmut Brandtgiven that the resulting OID is not too long.
428165c5d31SHartmut BrandtIf the maximum length is exceeded the result is undefined.
429f06ca4afSHartmut Brandt.Pp
430f06ca4afSHartmut BrandtThe function
431f06ca4afSHartmut Brandt.Fn asn_compare_oid
432f06ca4afSHartmut Brandtcompares two oids and returns the values
433f06ca4afSHartmut Brandt.Li -1 ,
434f06ca4afSHartmut Brandt.Li 0 or
435f06ca4afSHartmut Brandt.Li +1
436f06ca4afSHartmut Brandtwhen
437f06ca4afSHartmut Brandt.Fa oid1
438f06ca4afSHartmut Brandtis lesser than, equal, or larger than
439f06ca4afSHartmut Brandt.Fa oid2
440f06ca4afSHartmut Brandtresp.
441f06ca4afSHartmut Brandt.Pp
442f06ca4afSHartmut BrandtThe function
443f06ca4afSHartmut Brandt.Fn asn_is_suboid
444f06ca4afSHartmut Brandtreturns 1 if
445f06ca4afSHartmut Brandt.Fa oid1
446f06ca4afSHartmut Brandtis equal to the leading part of
447f06ca4afSHartmut Brandt.Fa oid2 .
448f06ca4afSHartmut BrandtIt returns 0 otherwise.
449f06ca4afSHartmut Brandt.Pp
450f06ca4afSHartmut BrandtThe function
451f06ca4afSHartmut Brandt.Fn asn_oid2str_r
452f06ca4afSHartmut Brandtmakes a printable string from
453f06ca4afSHartmut Brandt.Fa oid .
454f06ca4afSHartmut BrandtThe buffer pointed to by
455f06ca4afSHartmut Brandt.Fa str
456165c5d31SHartmut Brandtmust be large enough to hold the result.
457165c5d31SHartmut BrandtThe constant
458f06ca4afSHartmut Brandt.Li ASN_OIDSTRLEN
459f06ca4afSHartmut Brandtis defined to be the length of the maximum string generated by this function
460f06ca4afSHartmut Brandt(including the trailing NUL).
461f06ca4afSHartmut BrandtThe function
462f06ca4afSHartmut Brandt.Fn asn_oid2str
463f06ca4afSHartmut Brandtmakes a printable string from
464f06ca4afSHartmut Brandt.Fa oid
465f06ca4afSHartmut Brandtinto a private buffer that is overwritten by each call.
466f06ca4afSHartmut Brandt.Sh DIAGNOSTICS
467165c5d31SHartmut BrandtWhen an error occurs in any of the function the function pointed to
468f06ca4afSHartmut Brandtby the global pointer
469f06ca4afSHartmut Brandt.Bd -literal -offset indent
470f06ca4afSHartmut Brandtextern void (*asn_error)(const struct asn_buf *, const char *, ...);
471f06ca4afSHartmut Brandt.Ed
472f06ca4afSHartmut Brandt.Pp
473f06ca4afSHartmut Brandtis called with the current buffer (this may be
474f06ca4afSHartmut Brandt.Li NULL )
475f06ca4afSHartmut Brandtand a
476f06ca4afSHartmut Brandt.Xr printf 3
477f06ca4afSHartmut Brandtstyle format string.
478f06ca4afSHartmut BrandtThere is a default error handler in the library that prints a message
479f06ca4afSHartmut Brandtstarting with
480f06ca4afSHartmut Brandt.Sq ASN.1:
481f06ca4afSHartmut Brandtfollowed by the error message and an optional dump of the buffer.
482f06ca4afSHartmut Brandt.Sh SEE ALSO
483f06ca4afSHartmut Brandt.Xr gensnmptree 1 ,
484165c5d31SHartmut Brandt.Xr bsnmpd 1 ,
48594caccb3SHartmut Brandt.Xr bsnmpagent 3 ,
486f06ca4afSHartmut Brandt.Xr bsnmpclient 3 ,
48794caccb3SHartmut Brandt.Xr bsnmplib 3
488f06ca4afSHartmut Brandt.Sh STANDARDS
489f06ca4afSHartmut BrandtThis implementation conforms to the applicable IETF RFCs and ITU-T
490f06ca4afSHartmut Brandtrecommendations.
491f06ca4afSHartmut Brandt.Sh AUTHORS
492*4f13bbb6SUlrich Spörlein.An Hartmut Brandt Aq harti@FreeBSD.org
493