jcs's openbsd hax
openbsd
1.\" $OpenBSD: ober_oid_cmp.3,v 1.7 2025/06/13 18:34:00 schwarze 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: June 13 2025 $
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.Lb libutil
27.In sys/types.h
28.In ber.h
29.Ft int
30.Fn "ober_oid_cmp" "struct ber_oid *a" "struct ber_oid *b"
31.Ft size_t
32.Fn "ober_oid2ber" "struct ber_oid *oid" "u_int8_t *buf" "size_t size"
33.Ft int
34.Fn "ober_string2oid" "const char *string" "struct ber_oid *oid"
35.Sh DESCRIPTION
36Object Identifiers are commonly used in ASN.1-based protocols.
37These functions provide an interface to parse OIDs.
38For internal representation of OIDs, the following structure
39.Vt struct ber_oid
40is being used:
41.Bd -literal
42#define BER_MIN_OID_LEN 2
43#define BER_MAX_OID_LEN 64
44
45struct ber_oid {
46 u_int32_t bo_id[BER_MAX_OID_LEN + 1];
47 size_t bo_n;
48};
49.Ed
50.Pp
51The
52.Fn ober_oid2ber
53and
54.Fn ober_string2oid
55functions may be used to convert from and to
56.Vt struct ber_oid .
57.Pp
58.Fn ober_oid_cmp
59may be used to compare two
60.Vt ber_oid
61structures.
62.Sh RETURN VALUES
63.Fn ober_oid2ber
64returns the number of bytes written or 0 on failure.
65.Pp
66.Fn ober_string2oid
67returns 0 on success or -1 on failure.
68.Pp
69.Fn ober_oid_cmp
70returns an integer greater than, equal to, or less than 0, according to whether
71the oid
72.Fa a
73is greater than, equal to, or less than the oid
74.Fa b .
75If the shortest length from
76.Fa a
77and
78.Fa b
79matches
80the weight of the integer is 2, else it is 1.
81.Sh SEE ALSO
82.Xr ober_add_string 3 ,
83.Xr ober_get_string 3 ,
84.Xr ober_read_elements 3 ,
85.Xr ober_set_header 3
86.Sh HISTORY
87These functions first appeared as internal functions in
88.Xr snmpd 8
89in
90.Ox 4.2
91and were moved to libutil in
92.Ox 6.6 .
93.Sh AUTHORS
94.An -nosplit
95The BER library was written by
96.An Claudio Jeker Aq Mt claudio@openbsd.org ,
97.An Marc Balmer Aq Mt marc@openbsd.org
98and
99.An Reyk Floeter Aq Mt reyk@openbsd.org .