xref: /openbsd-src/lib/libutil/ober_oid_cmp.3 (revision 893ac8ce76059d9b03d6af2b2bc0e32767cc4f0b)
1.\" $OpenBSD: ober_oid_cmp.3,v 1.5 2021/10/21 08:17:34 martijn Exp $
2.\"
3.\" Copyright (c) 2007, 2012 Reyk Floeter <reyk@openbsd.org>
4.\"
5.\" Permission to use, copy, modify, and distribute this software for any
6.\" purpose with or without fee is hereby granted, provided that the above
7.\" copyright notice and this permission notice appear in all copies.
8.\"
9.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16.\"
17.Dd $Mdocdate: October 21 2021 $
18.Dt OBER_OID_CMP 3
19.Os
20.Sh NAME
21.Nm ober_oid_cmp ,
22.Nm ober_oid2ber ,
23.Nm ober_string2oid
24.Nd OID helper functions for the BER library
25.Sh SYNOPSIS
26.In sys/types.h
27.In ber.h
28.Ft "int"
29.Fn "ober_oid_cmp" "struct ber_oid *a" "struct ber_oid *b"
30.Ft "size_t"
31.Fn "ober_oid2ber" "struct ber_oid *oid" "u_int8_t *buf" "size_t size"
32.Ft "int"
33.Fn "ober_string2oid" "const char *string" "struct ber_oid *oid"
34.Sh DESCRIPTION
35Object Identifiers are commonly used in ASN.1-based protocols.
36These functions provide an interface to parse OIDs.
37For internal representation of OIDs, the following structure
38.Vt struct ber_oid
39is being used:
40.Bd -literal
41#define BER_MIN_OID_LEN		2
42#define BER_MAX_OID_LEN		64
43
44struct ber_oid {
45	u_int32_t	bo_id[BER_MAX_OID_LEN + 1];
46	size_t		bo_n;
47};
48.Ed
49.Pp
50The
51.Fn ober_oid2ber
52and
53.Fn ober_string2oid
54functions may be used to convert from and to
55.Vt struct ber_oid .
56.Pp
57.Fn ober_oid_cmp
58may be used to compare two
59.Vt ber_oid
60structures.
61.Sh RETURN VALUES
62.Fn ober_oid2ber
63returns the number of bytes written or 0 on failure.
64.Pp
65.Fn ober_string2oid
66returns 0 on success or -1 on failure.
67.Pp
68.Fn ober_oid_cmp
69returns an integer greater than, equal to, or less than 0, according to whether
70the oid
71.Fa a
72is greater than, equal to, or less than the oid
73.Fa b .
74If the shortest length from
75.Fa a
76and
77.Fa b
78matches
79the weight of the integer is 2, else it is 1.
80.Sh SEE ALSO
81.Xr ober_add_string 3 ,
82.Xr ober_get_string 3 ,
83.Xr ober_read_elements 3 ,
84.Xr ober_set_header 3
85.Sh HISTORY
86These functions first appeared as internal functions in
87.Xr snmpd 8
88in
89.Ox 4.2
90and were moved to libutil in
91.Ox 6.6 .
92.Sh AUTHORS
93.An -nosplit
94The BER library was written by
95.An Claudio Jeker Aq Mt claudio@openbsd.org ,
96.An Marc Balmer Aq Mt marc@openbsd.org
97and
98.An Reyk Floeter Aq Mt reyk@openbsd.org .
99