Skip to content

Instantly share code, notes, and snippets.

@mistotebe
Created March 29, 2017 17:43
Show Gist options
  • Save mistotebe/5f00bfc3a1d2f9b5a79f7f56a5f24f9f to your computer and use it in GitHub Desktop.
Save mistotebe/5f00bfc3a1d2f9b5a79f7f56a5f24f9f to your computer and use it in GitHub Desktop.
#include <lber.h>
int main( int argc, char **argv )
{
BerElement *write, *read, *compare;
BerValue xfer, seq, *array;
ber_tag_t tag;
ber_len_t len;
int i;
write = ber_alloc();
read = ber_alloc();
compare = ber_alloc();
array = ber_memcalloc( argc+1, sizeof( BerValue ) );
for ( i=0; i <= argc; i++ ) {
ber_str2bv( argv[i], 0, 0, &array[i] );
}
len = ber_printf( write, "{i{W}}", argc, array );
ber_flatten2( write, &xfer, 0 );
ber_init2( read, &xfer, 0 );
ber_dump( read, 1 );
tag = ber_scanf( read, "{i" /* "}" */, &i );
ber_peek_element( read, &xfer );
ber_start_seq( compare, LBER_SEQUENCE );
ber_put_int( compare, i, LBER_INTEGER );
/* doesn't work
ber_put_berval( compare, &xfer, LBER_SEQUENCE );
*/
ber_start_seq( compare, LBER_SEQUENCE );
ber_write( compare, xfer.bv_val, xfer.bv_len, 0 );
ber_put_seq( compare );
ber_put_seq( compare );
ber_flatten2( compare, &xfer, 0 );
ber_init2( read, &xfer, 0 );
ber_dump( read, 1 );
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment