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