1.\" $OpenBSD: ober_get_string.3,v 1.6 2021/03/31 19:31:35 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: March 31 2021 $ 18.Dt OBER_GET_STRING 3 19.Os 20.Sh NAME 21.Nm ober_get_null , 22.Nm ober_get_eoc , 23.Nm ober_get_integer , 24.Nm ober_get_enumerated , 25.Nm ober_get_boolean , 26.Nm ober_get_string , 27.Nm ober_get_nstring , 28.Nm ober_get_ostring , 29.Nm ober_get_bitstring , 30.Nm ober_get_oid , 31.Nm ober_getpos , 32.Nm ober_scanf_elements 33.Nd access properties of ASN.1 objects decoded from BER 34.Sh SYNOPSIS 35.In sys/types.h 36.In ber.h 37.Ft "int" 38.Fn "ober_get_null" "struct ber_element *root" 39.Ft "int" 40.Fn "ober_get_eoc" "struct ber_element *root" 41.Ft "int" 42.Fn "ober_get_integer" "struct ber_element *root" "long long *val" 43.Ft "int" 44.Fn "ober_get_enumerated" "struct ber_element *root" "long long *val" 45.Ft "int" 46.Fn "ober_get_boolean" "struct ber_element *root" "int *bool" 47.Ft "int" 48.Fn "ober_get_string" "struct ber_element *root" "char **charbuf" 49.Ft "int" 50.Fn "ober_get_nstring" "struct ber_element *root" "void **buf" "size_t *size" 51.Ft "int" 52.Fn "ober_get_ostring" "struct ber_element *root" "struct ber_octetstring *ostring" 53.Ft "int" 54.Fn "ober_get_bitstring" "struct ber_element *root" "void **buf" "size_t *size" 55.Ft "int" 56.Fn "ober_get_oid" "struct ber_element *root" "struct ber_oid *oid" 57.Ft off_t 58.Fn "ober_getpos" "struct ber_element *elm" 59.Ft "int" 60.Fn "ober_scanf_elements" "struct ber_element *root" "char *format" "..." 61.Sh DESCRIPTION 62Functions which take two arguments save the value contained in the 63.Fa root 64element into the storage location pointed to by the second argument. 65If the storage location is 66.Dv NULL 67then only a type check is performed. 68Additionally, 69.Fn ober_get_nstring 70and 71.Fn ober_get_bitstring 72save the number of bytes contained in the string into 73.Pf * Fa size . 74If 75.Fa buf 76is 77.Dv NULL 78and size is not 79.Dv NULL , 80size is set. 81.Fa size 82must not be 83.Dv NULL 84to return a valid 85.Fa buf . 86.Pp 87.Fn ober_scanf_elements 88retrieves the values from zero or more elements starting at 89.Fa root . 90For each character in 91.Fa fmt , 92arguments of the types given in the following table are consumed 93and passed to the function listed, processing one 94.Vt ber_element 95per character. 96The following characters are valid: 97.Bl -column -offset indent\ 98 characte ober_get_enumerated_ "1: struct ber_element **" 99.It Sy character Ta Sy function Ta Sy arguments 100.It $ Ta see below Ta 0 101.It B Ta Fn ober_get_bitstring Ta 2: Vt void ** , size_t * 102.It b Ta Fn ober_get_boolean Ta 1: Vt int * 103.It d Ta Fn ober_get_integer Ta 1: Vt int * 104.It E Ta Fn ober_get_enumerated Ta 1: Vt long long * 105.It e Ta see below Ta 1: Vt struct ber_element ** 106.It i Ta Fn ober_get_integer Ta 1: Vt long long * 107.It o Ta Fn ober_get_oid Ta 1: Vt struct ber_oid * 108.It p Ta Fn ober_getpos Ta 1: Vt off_t * 109.It S Ta see below Ta 0 110.It s Ta Fn ober_get_string Ta 1: Vt char ** 111.It t Ta see below Ta 2: Vt int * , unsigned int * 112.It x Ta Fn ober_get_nstring Ta 2: Vt void **, size_t * 113.It \&( or { Ta see below Ta 0 114.It \&) or } Ta see below Ta 0 115.It \&. Ta Fn ober_get_eoc Ta 0 116.It 0 Ta Fn ober_get_null Ta 0 117.El 118.Pp 119For 120.Sq e , 121.Sq p , 122.Sq S , 123and 124.Sq t , 125the type of the element is not checked. 126For 127.Sq p 128and 129.Sq t , 130the pointer is not incremented to the next element. 131For 132.Sq e , 133a pointer to the element is stored in the corresponding pointer variable. 134For 135.Sq S , 136the element is skipped without extracting any information from it. 137For 138.Sq t , 139the class and type of the element are stored in the two corresponding 140variables, but if the element contains a value, that value is ignored. 141A 142.Sq $ 143mandates the end of a sequence or set. 144.Pp 145For an opening parenthesis or brace, it is checked that the element 146is a sequence or a set, and parsing continues with its children. 147For a closing parenthesis or brace, parsing of the current sequence 148or set is ended and parsing continues with the element following 149the sequence or set. 150.Sh RETURN VALUES 151.Fn ober_getpos 152returns the value of 153.Vt be_offs . 154.Pp 155.Fn ober_scanf_elements 156returns 0 for success or \-1 when encountering elements that do not 157agree with the expectations of 158.Fa fmt 159or when 160.Fa fmt 161is syntactically invalid. 162Even when 163.Fn ober_scanf_elements 164fails, some of the arguments may already have been filled in. 165.Pp 166The other functions return 0 if 167.Va root 168is of the requested type or \-1 otherwise. 169.Sh SEE ALSO 170.Xr ober_add_string 3 , 171.Xr ober_oid_cmp 3 , 172.Xr ober_read_elements 3 , 173.Xr ober_set_header 3 174.Sh STANDARDS 175ITU-T Recommendation X.690, also known as ISO/IEC 8825-1: 176Information technology - ASN.1 encoding rules. 177.Sh HISTORY 178These functions first appeared as internal functions in 179.Xr snmpd 8 180in 181.Ox 4.2 182and were moved to libutil in 183.Ox 6.6 . 184.Sh AUTHORS 185.An -nosplit 186The BER library was written by 187.An Claudio Jeker Aq Mt claudio@openbsd.org , 188.An Marc Balmer Aq Mt marc@openbsd.org 189and 190.An Reyk Floeter Aq Mt reyk@openbsd.org . 191