LIBDER_READ(3)

NAME
libder_read, libder_read_fd, libder_read_file - reading DER encoded streams

LIBRARY
libder

SYNOPSIS
#include <libder.h>
struct libder_object *
libder_read(struct libder_ctx *ctx, const uint8_t *buf, size_t *bufsz);
struct libder_object *
libder_read_fd(struct libder_ctx *ctx, int fd, size_t *readsz);
struct libder_object *
libder_read_file(struct libder_ctx *ctx, FILE *fp, size_t *readsz);

DESCRIPTION
The libder_read family of functions are used to parse BER/DER encoded data into an object tree that libder(3) can work with. All of these functions will return an object on success and update *readsz with the number of bytes consumed, or NULL on failure.

The libder_read() function will read from a buffer buf of known size bufsz. It is not considered an error for buf to have contents past the first valid object encountered. The application is expected to check *bufsz upon success and determine if any residual buffer exists, and if that residual is OK.

libder(3) can also stream a BER encoded object with either of the libder_read_fd() or libder_read_file() functions from a file descriptor or stdio(3) stream respectively. Both functions will try very hard not to over-read from the stream to avoid putting it in a precarious state, but bogus looking data may still cause them to consume more of the stream than intended.

Note that libder_read_fd() will ignore an EINTR return value from read(2) by default and continue reading from the fd. If the application is signalled, it can abort the read(2) operation instead with libder_abort(3). Note that libder does not currently have other points that an abort can be signalled from, so if libder_read_fd() is not specifically waiting for data from the fd when a signal hits, then the operation will continue until successful with one exception. If libder_abort(3) is called at any other point in the middle of libder_read_fd(), then the abort flag will not be cleared until it does receive an interrupted read(2) call, or until the next call to one of the libder_read family of functions. In the future, libder_read may support resuming an aborted operation and allow cancellation at other specific points within the operation.

SEE ALSO
libder(3), libder_obj(3), libder_type(3), libder_write(3)