32 lines
1.4 KiB
Raw Normal View History

.TH scan_asn1derlength 3
scan_asn1derlength \- decode an unsigned integer from ASN.1 DER length encoding
.B #include <scan.h>
size_t \fBscan_asn1derlength\fP(const char *\fIsrc\fR,size_t \fIlen\fR,unsigned long long *\fIdest\fR);
scan_asn1derlength decodes an unsigned integer in ASN.1 DER length encoding
from a memory area holding binary data. It writes the decode value in
\fIdest\fR and returns the number of bytes it read from \fIsrc\fR.
scan_asn1derlength never reads more than \fIlen\fR bytes from \fIsrc\fR. If the
sequence is longer than that, or the memory area contains an invalid
sequence, scan_asn1derlength returns 0 and does not touch \fIdest\fR.
The length of the longest spec-compliant ASN.1 DER length is 128 bytes,
but this implementation will return an error if the value does not fit
into the target integer type. In practice the largest sequence is
This implementation will reject values that are not encoded in the
minimum amount of bytes.
In addition to reading the length value, this implementation will also
validate the length value. If the length value is so large that the data
would not fit in the source buffer, it will return a failure. If you
only want to parse the length value without this check, use
scan_asn1derlengthvalue() instead.
fmt_asn1derlength(3), scan_asn1derlengthvalue(3)