ber_get_stringbv - Linux


ber_get_stringbv extracts a string value from a BER encoded data element and returns the value as a pointer to null-terminated string, which is allocated in memory.


#include <ber.h>

const char *ber_get_stringbv(const struct ber_element *element,
			       int tag, int implicit);


  • tag: The tag of the string element to be retrieved.
  • implicit: Whether the element is implicitly tagged.


#include <ber.h>
#include <stdio.h>

int main(void) {
    const char *data = "...";
    struct ber_element *element;
    const char *value;

    ber_init(&element, data, strlen(data));
    value = ber_get_stringbv(element, BER_CLASS_UNI, 0);
    printf("String value: %s\n", value);
    return 0;

Common Issues

  • Error retrieving value: Ensure that the specified tag matches the element in the BER encoded data.
  • Memory allocation: ber_get_stringbv allocates memory for the returned string. The memory should be freed when no longer needed.


ber_get_stringbv can be used in conjunction with other BER decoding functions to extract specific string values from BER encoded data.

Related Commands

  • ber_get_stringa: Similar to ber_get_stringbv but returns a pointer to a Ber Element containing the string.
  • ber_peek_tag: Peeks at the tag of an element without extracting its value.