summaryrefslogtreecommitdiff
path: root/lib/libutil/ober_oid_cmp.3
blob: 391fbbcf462eb3c45233281b6783483795a23dd4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
.\" $OpenBSD: ober_oid_cmp.3,v 1.2 2019/12/31 10:34:14 martijn Exp $
.\"
.\" Copyright (c) 2007, 2012 Reyk Floeter <reyk@openbsd.org>
.\"
.\" Permission to use, copy, modify, and distribute this software for any
.\" purpose with or without fee is hereby granted, provided that the above
.\" copyright notice and this permission notice appear in all copies.
.\"
.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
.Dd $Mdocdate: December 31 2019 $
.Dt OBER_OID_CMP 3
.Os
.Sh NAME
.Nm ober_oid_cmp ,
.Nm ober_oid2ber ,
.Nm ober_string2oid
.Nd OID helper functions for the BER library
.Sh SYNOPSIS
.In sys/types.h
.In ber.h
.Ft "int"
.Fn "ober_oid_cmp" "struct ber_oid *a" "struct ber_oid *b"
.Ft "size_t"
.Fn "ober_oid2ber" "struct ber_oid *oid" "u_int8_t *buf" "size_t size"
.Ft "int"
.Fn "ober_string2oid" "const char *string" "struct ber_oid *oid"
.Sh DESCRIPTION
Object Identifiers are commonly used in ASN.1-based protocols.
These functions provide an interface to parse OIDs.
For internal representation of OIDs, the following structure
.Vt struct ber_oid
is being used:
.Bd -literal
#define BER_MIN_OID_LEN		2
#define BER_MAX_OID_LEN		64

struct ber_oid {
	u_int32_t	bo_id[BER_MAX_OID_LEN + 1];
	size_t		bo_n;
};
.Ed
.Pp
The
.Fn ober_oid2ber
and
.Fn ober_string2oid
functions may be used to convert from and to
.Vt struct ber_oid .
.Pp
.Fn ober_oid_cmp
may be used to compare two
.Vt ber_oid
structures.
.Sh RETURN VALUES
.Fn ober_oid2ber
returns the number of bytes written or 0 on faliure.
.Pp
.Fn ober_string2oid
returns 0 on success or -1 on failure.
.Pp
.Fn ober_oid_cmp
returns 0 when oids
.Fa a
and
.Fa b
are identical.
If
.Fa b
is a successor of
.Fa a ,
1 is returned.
If
.Fa b
is a predecessor of
.Fa a ,
-1 is returned.
If
.Fa b
is larger, but a child of
.Fa a ,
2 is returned.
.Sh SEE ALSO
.Xr ober_add_string 3 ,
.Xr ober_get_string 3 ,
.Xr ober_read_elements 3 ,
.Xr ober_set_header 3
.Sh HISTORY
These functions first appeared as internal functions in
.Xr snmpd 8
in
.Ox 4.2
and were moved to libutil in
.Ox 6.6 .
.Sh AUTHORS
.An -nosplit
The BER library was written by
.An Claudio Jeker Aq Mt claudio@openbsd.org ,
.An Marc Balmer Aq Mt marc@openbsd.org
and
.An Reyk Floeter Aq Mt reyk@openbsd.org .