asn1c: What is the ‘write_stream’ parameter in the example code 1


The following post is for the https://lionet.info/asn1c/ (repository: https://github.com/vlm/asn1c/)

The asn1c usage manual (PDF), mentions an element called write_stream but it does not define what it is.

What write_stream is can be found in converter-sample.c  and in the manual under the name write_out:


/* Dump the buffer out to the specified FILE */
static int write_out(const void *buffer, size_t size, void *key) {
  FILE *fp = (FILE *)key;
  return (fwrite(buffer, 1, size, fp) == size) ? 0 : -1;
}

write_out is function that has the following signature write_out(const void *buffer, size_t size, void *app_key) and is used as a callback by der_encode() and other functions.

This callback receives as input the pointer to an element (const void *buffer), the size of that element (size_t size) and some context (void *app_key).
In this example, we can see that the user is using der_encode() which accepts a FILE * as the last parameter, which later is passed to write_out() as the context.

This post is also available in: Greek


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

One thought on “asn1c: What is the ‘write_stream’ parameter in the example code

  • Daniel

    The documentation of asn1c could use some improvements, need to dig around the source code to know how to use it. Reminds of good ol’ libcrypto (OpenSSL).