Basic Encoding Rules (BER)¶
Welcome to the BER library documentation. This is a simple library for parsing data encoed using the Basic Encoding Rules (BER) of ASN.1. Since the Distinguished Encoding Rules (DER) is a restricted subset of BER, it should also work on DER-encoded data.
Example¶
This is a basic example of how to use it:
FILE* fp = fopen("myfile.ber", "rb");
struct ber_element element;
struct ber_event event;
struct ber_parser* parser = ber_parser_new();
while (ber_parser_parser(&event, &element, parser) == 0 && event != BER_NO_EVENT) {
printf("Tag: %d\n", element.tag);
printf("Data: ");
for (int i = 0; i < element.length; i++) {
printf("%02x", element.data[i]);
}
printf("\n");
}
API¶
-
enum
ber_event
¶
-
enum
ber_tag_class
¶
-
struct
ber_element
¶ -
enum tag_class
tag_class
¶ The class of the tag
-
int
constructed
¶ Whether the element is constructed
-
size_t
tag
¶ The tag of the element
-
int
definite
¶ Whether the element has a definite (has a pre-defined length)
-
size_t
length
¶ The length of the value
-
char *
value
¶ The value encoded
-
enum tag_class
-
struct
ber_parser
¶ A BER parser object that holds the state of the parsing.
-
const char *
ber_get_version
()¶ Gets the version string
- Returns
A pointer to the static version string
-
struct ber_parser *
ber_parser_new
()¶ Creates a new BER parser.
- Returns
An instance of
ber_parser
-
int
ber_parser_parse
(enum ber_event *event, ber_element *element, struct ber_parser *parser)¶ - Returns
0 on success, or -1 on error
Warning
This is not thread-safe.
-
void
ber_parser_free
(struct ber_parser *parser)¶ Frees the parsero bject