opensc/doc/api/asn1/sc_asn1_decode.xml

63 lines
2.3 KiB
XML

<?xml version="1.0" encoding="UTF-8"?>
<refentry id="scasn1decode">
<refentryinfo><title>OpenSC API Reference</title></refentryinfo>
<refmeta>
<refentrytitle>sc_asn1_decode</refentrytitle>
<manvolnum>3</manvolnum>
<refmiscinfo>opensc</refmiscinfo>
</refmeta>
<refnamediv>
<refname>sc_asn1_decode</refname>
<refpurpose>Extract entries from an ASN.1 stream</refpurpose>
</refnamediv>
<refsect1>
<title>Synopsis</title>
<para>
<programlisting>
#include &lt;opensc.h&gt;
int sc_asn1_decode(struct sc_context *ctx, struct sc_asn1_entry *asn1,
const unsigned char *inbuf, size_t len,
const unsigned char **newbuf, size_t *len_left);
</programlisting>
</para>
</refsect1>
<refsect1>
<title>Description</title>
<para>
This function extracts information from the ASN.1 stream pointed to by <emphasis>inbuf</emphasis>
(which is <emphasis>len</emphasis> bytes in size) and stores it into the array of
<link linkend="scasn1entry"><structname>struct sc_asn_1</structname></link> entries pointed to by
<emphasis>asn1</emphasis>. The array must be big enough to contain all the entries that will be
found, or an error will be flagged. The last entry in the array must be a NULL entry, i.e. the
<structfield>name</structfield> field must be set to NULL.
</para>
<para>
The structure of the expected data must be encoded in the entries in <emphasis>asn1</emphasis>
before calling this function; specifically the <structfield>name</structfield>,
<structfield>type</structfield>, <structfield>tag</structfield> and
<structfield>flags</structfield> fields must be filled in.
</para>
<para>
The function will then scan the stream and fill in the remaining fields.
<emphasis>newbuf</emphasis> will point to the byte immediately following the extracted record, and
<emphasis>len_left</emphasis> will contain the number of bytes left in the buffer. Thus, the
<emphasis>newbuf</emphasis> and <emphasis>len_left</emphasis> fields may be passed in to
sc_asn1_decode() again, as the <emphasis>inbuf</emphasis> and <emphasis>len</emphasis> parameters,
until <emphasis>len</emphasis> reaches 0.
</para>
</refsect1>
<refsect1>
<title>Return value</title>
<para>
Returns 0 if successful, or a negative value in case of error.
</para>
</refsect1>
</refentry>