1.\" $OpenBSD: ober_get_string.3,v 1.2 2019/10/25 04:00:10 tb 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 25 2019 $ 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. 65Additionally, 66.Fn ober_get_nstring 67and 68.Fn ober_get_bitstring 69save the number of bytes contained in the string into 70.Pf * Fa size . 71.Pp 72.Fn ober_scanf_elements 73retrieves the values from zero or more elements starting at 74.Fa root . 75For each byte in 76.Fa fmt , 77arguments of the types given in the following table are consumed 78and passed to the function listed, processing one 79.Vt ber_element 80per byte. 81The following bytes are valid: 82.Bl -column -offset indent bytes ober_get_enumerated() "1: struct ber_element **" 83.It Sy byte Ta Sy function Ta Sy arguments 84.It B Ta Fn ober_get_bitstring Ta 2: Vt void ** , size_t * 85.It b Ta Fn ober_get_boolean Ta 1: Vt int * 86.It d Ta Fn ober_get_integer Ta 1: Vt int * 87.It E Ta Fn ober_get_enumerated Ta 1: Vt long long * 88.It e Ta see below Ta 1: Vt struct ber_element ** 89.It i Ta Fn ober_get_integer Ta 1: Vt long long * 90.It o Ta Fn ober_get_oid Ta 1: Vt struct ber_oid * 91.It p Ta Fn ober_getpos Ta 1: Vt off_t * 92.It S Ta see below Ta 0 93.It s Ta Fn ober_get_string Ta 1: Vt char ** 94.It t Ta see below Ta 2: Vt int * , unsigned int * 95.It x Ta Fn ober_get_nstring Ta 2: Vt void **, size_t * 96.It \&( or { Ta see below Ta 0 97.It \&) or } Ta see below Ta 0 98.It \&. Ta Fn ober_get_eoc Ta 0 99.It 0 Ta Fn ober_get_null Ta 0 100.El 101.Pp 102For 103.Sq e , 104.Sq p , 105.Sq S , 106and 107.Sq t , 108the type of the element is not checked. 109For 110.Sq p 111and 112.Sq t , 113the pointer is not incremented to the next element. 114For 115.Sq e , 116a pointer to the element is stored in the corresponding pointer variable. 117For 118.Sq S , 119the element is skipped without extracting any information from it. 120For 121.Sq t , 122the class and type of the element are stored in the two corresponding 123variables, but if the element contains a value, that value is ignored. 124.Pp 125For an opening parenthesis or brace, it is checked that the element 126is a sequence or a set, and parsing continues with its children. 127For a closing parenthesis or brace, parsing of the current sequence 128or set is ended and parsing continues with the element following 129the sequence or set. 130.Sh RETURN VALUES 131.Fn ober_getpos 132returns the value of 133.Vt be_offs . 134.Pp 135.Fn ober_scanf_elements 136returns 0 for success or \-1 when encountering elements that do not 137agree with the expectations of 138.Fa fmt 139or when 140.Fa fmt 141is syntactically invalid. 142Even when 143.Fn ober_scanf_elements 144fails, some of the arguments may already have been filled in. 145.Pp 146The other functions return 0 if 147.Va root 148is of the requested type or \-1 otherwise. 149.Sh SEE ALSO 150.Xr ober_add_string 3 , 151.Xr ober_oid_cmp 3 , 152.Xr ober_read_elements 3 , 153.Xr ober_set_header 3 154.Sh STANDARDS 155ITU-T Recommendation X.690, also known as ISO/IEC 8825-1: 156Information technology - ASN.1 encoding rules. 157.Sh HISTORY 158These functions first appeared as internal functions in 159.Xr snmpd 8 160in 161.Ox 4.2 162and were moved to libutil in 163.Ox 6.6 . 164.Sh AUTHORS 165.An -nosplit 166The BER library was written by 167.An Claudio Jeker Aq Mt claudio@openbsd.org , 168.An Marc Balmer Aq Mt marc@openbsd.org 169and 170.An Reyk Floeter Aq Mt reyk@openbsd.org . 171