BER_GET_STRING(3)

NAME
ber_get_null, ber_get_eoc, ber_get_integer, ber_get_enumerated, ber_get_boolean, ber_get_string, ber_get_nstring, ber_get_ostring, ber_get_bitstring, ber_get_oid, ber_getpos, ber_scanf_elements - access properties of ASN.1 objects decoded from BER

SYNOPSIS
#include <sys/types.h>
#include <ber.h>
int
ber_get_null(struct ber_element *root);
int
ber_get_eoc(struct ber_element *root);
int
ber_get_integer(struct ber_element *root, long long *val);
int
ber_get_enumerated(struct ber_element *root, long long *val);
int
ber_get_boolean(struct ber_element *root, int *bool);
int
ber_get_string(struct ber_element *root, char **charbuf);
int
ber_get_nstring(struct ber_element *root, void **buf, size_t *size);
int
ber_get_ostring(struct ber_element *root, struct ber_octetstring *ostring);
int
ber_get_bitstring(struct ber_element *root, void **buf, size_t *size);
int
ber_get_oid(struct ber_element *root, struct ber_oid *oid);
off_t
ber_getpos(struct ber_element *elm);
int
ber_scanf_elements(struct ber_element *root, char *format, ...);

DESCRIPTION
Functions which take two arguments save the value contained in the root element into the storage location pointed to by the second argument. Additionally, ber_get_nstring() and ber_get_bitstring() save the number of bytes contained in the string into *size.

ber_scanf_elements() retrieves the values from zero or more elements starting at root. For each byte in fmt, arguments of the types given in the following table are consumed and passed to the function listed, processing one ber_element per byte. The following bytes are valid:
byte | function | arguments
B | ber_get_bitstring() | 2: void **, size_t *
b | ber_get_boolean() | 1: int *
d | ber_get_integer() | 1: int *
E | ber_get_enumerated() | 1: long long *
e | see below | 1: struct ber_element **
i | ber_get_integer() | 1: long long *
o | ber_get_oid() | 1: struct ber_oid *
p | ber_getpos() | 1: off_t *
S | see below | 0
s | ber_get_string() | 1: char **
t | see below | 2: int *, unsigned int *
x | ber_get_nstring() | 2: void **, size_t *
(or { | see below | 0
) or } | see below | 0
. | ber_get_eoc() | 0
0 | ber_get_null() | 0

For ‘e’, ‘p’, ‘S’, and ‘t’, the type of the element is not checked. For ‘e’, a pointer to the element is stored in the corresponding pointer variable. For ‘S’, the element is skipped without extracting any information from it. For ‘t’, the class and type of the element are stored in the two corresponding variables, but if the element contains a value, that value is ignored.

For an opening parenthesis or brace, it is checked that the element is a sequence or a set, and parsing continues with its children. For a closing parenthesis or brace, parsing of the current sequence or set is ended and parsing continues with the element following the sequence or set.

RETURN VALUES
ber_getpos() returns the value of be_offs.

ber_scanf_elements() returns 0 for success or -1 when encountering elements that do not agree with the expectations of fmt or when fmt is syntactically invalid. Even when ber_scanf_elements() fails, some of the arguments may already have been filled in.

The other functions return 0 if root is of the requested type or -1 otherwise.

SEE ALSO
ber_add_string(3), ber_oid_cmp(3), ber_read_elements(3), ber_set_header(3)

STANDARDS
ITU-T Recommendation X.690, also known as ISO/IEC 8825-1: Information technology - ASN.1 encoding rules.

HISTORY
These functions first appeared as internal functions in snmpd(8) in OpenBSD 4.2 and were moved to libutil in OpenBSD 6.6.

AUTHORS
-nosplit The BER library was written by Claudio Jeker <claudio@openbsd.org>, Marc Balmer <marc@openbsd.org> and Reyk Floeter <reyk@openbsd.org>.