---
name: "scan_asn1derlength"
section: "3"
platform: "linux"
package: "libowfat-dev"
version: "0.32-5"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/scan_asn1derlength"
---

# scan\_asn1derlength(3)

decode an unsigned integer from ASN.1 DER length encoding

## NAME

scan\_asn1derlength - decode an unsigned integer from ASN.1 DER length encoding

## SYNTAX

**#include \<libowfat/scan.h\>**

size\_t **scan\_asn1derlength**(const char \**src*,size\_t *len*,unsigned long long \**dest*);

## DESCRIPTION

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 *dest* and returns the number of bytes it read from *src*.

scan\_asn1derlength never reads more than *len* bytes from *src*.  If the sequence is longer than that, or the memory area contains an invalid sequence, scan\_asn1derlength returns 0 and does not touch *dest*.

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 sizeof(\*dest)+1.

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.

## SEE ALSO

[fmt\_asn1derlength(3)](/fmt_asn1derlength/3.md), [scan\_asn1derlengthvalue(3)](/scan_asn1derlengthvalue/3.md)
