Botan 3.13.0
Crypto and TLS for C&
asn1_utils.h
Go to the documentation of this file.
1/*
2* (C) 2026 Jack Lloyd
3*
4* Botan is released under the Simplified BSD License (see license.txt)
5*/
6
7#ifndef BOTAN_ASN1_UTILS_H_
8#define BOTAN_ASN1_UTILS_H_
9
10#include <botan/asn1_obj.h>
11#include <span>
12#include <vector>
13
14namespace Botan {
15
16class BigInt;
17
18}
19
20namespace Botan::ASN1 {
21
22/**
23* Return the contents octets of the DER encoding of the INTEGER @p n:
24* big-endian two's complement, minimal length. Zero encodes as a single
25* 0x00 octet.
26*/
27std::vector<uint8_t> integer_contents(const BigInt& n);
28
29/**
30* Decode the contents octets of a BER INTEGER (big-endian two's
31* complement). Redundant leading octets are accepted; an empty input is
32* rejected.
33*/
34BigInt integer_from_contents(std::span<const uint8_t> contents);
35
36/*
37* Return true if the bytes are exactly one DER-encoded value of the expected
38* type and class, that is a TLV whose tag plus length header plus contents
39* span the entire buffer with no trailing data. The contents themselves are
40* not otherwise validated.
41*/
42bool is_single_der_object(std::span<const uint8_t> bytes, ASN1_Type expected_type, ASN1_Class expected_class);
43
44/**
45* Return true if the bytes are exactly one DER-encoded SEQUENCE, that is a
46* SEQUENCE whose tag plus length header plus contents span the entire buffer
47* with no trailing data. The contents themselves are not otherwise validated.
48*/
49bool is_der_sequence_header(std::span<const uint8_t> bytes);
50
51} // namespace Botan::ASN1
52
53#endif
bool is_single_der_object(std::span< const uint8_t > bytes, ASN1_Type expected_type, ASN1_Class expected_class)
Definition ber_dec.cpp:1100
std::vector< uint8_t > integer_contents(const BigInt &n)
Definition der_enc.cpp:356
BigInt integer_from_contents(std::span< const uint8_t > contents)
Definition ber_dec.cpp:801
bool is_der_sequence_header(std::span< const uint8_t > bytes)
Definition ber_dec.cpp:1128
ASN1_Class
Definition asn1_obj.h:32
ASN1_Type
Definition asn1_obj.h:47