OBER_GET_STRING(3)

NAME
ober_get_null, ober_get_eoc, ober_get_integer, ober_get_enumerated, ober_get_boolean, ober_get_string, ober_get_nstring, ober_get_ostring, ober_get_bitstring, ober_get_oid, ober_getpos, ober_scanf_elements - access properties of ASN.1 objects decoded from BER

SYNOPSIS
#include <sys/types.h>
#include <ber.h>
int
ober_get_null(struct ber_element *root);
int
ober_get_eoc(struct ber_element *root);
int
ober_get_integer(struct ber_element *root, long long *val);
int
ober_get_enumerated(struct ber_element *root, long long *val);
int
ober_get_boolean(struct ber_element *root, int *bool);
int
ober_get_string(struct ber_element *root, char **charbuf);
int
ober_get_nstring(struct ber_element *root, void **buf, size_t *size);
int
ober_get_ostring(struct ber_element *root, struct ber_octetstring *ostring);
int
ober_get_bitstring(struct ber_element *root, void **buf, size_t *size);
int
ober_get_oid(struct ber_element *root, struct ber_oid *oid);
off_t
ober_getpos(struct ber_element *elm);
int
ober_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. If the storage location is NULL then only a type check is performed. Additionally, ober_get_nstring() and ober_get_bitstring() save the number of bytes contained in the string into *size. If buf is NULL and size is not NULL, size is set. size must not be NULL to return a valid buf.

ober_scanf_elements() retrieves the values from zero or more elements starting at root. For each character in fmt, arguments of the types given in the following table are consumed and passed to the function listed, processing one ber_element per character. The following characters are valid:
character | function | arguments
$ | see below | 0
B | ober_get_bitstring() | 2: void **, size_t *
b | ober_get_boolean() | 1: int *
d | ober_get_integer() | 1: int *
E | ober_get_enumerated() | 1: long long *
e | see below | 1: struct ber_element **
i | ober_get_integer() | 1: long long *
o | ober_get_oid() | 1: struct ber_oid *
p | ober_getpos() | 1: off_t *
S | see below | 0
s | ober_get_string() | 1: char **
t | see below | 2: int *, unsigned int *
x | ober_get_nstring() | 2: void **, size_t *
(or { | see below | 0
) or } | see below | 0
. | ober_get_eoc() | 0
0 | ober_get_null() | 0

For ‘e’, ‘p’, ‘S’, and ‘t’, the type of the element is not checked. For ‘p’ and ‘t’, the pointer is not incremented to the next element. 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. A ‘$’ mandates the end of a sequence or set.

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
ober_getpos() returns the value of be_offs.

ober_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 ober_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
ober_add_string(3), ober_oid_cmp(3), ober_read_elements(3), ober_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>.