Botan 3.12.0
Crypto and TLS for C&
Botan::ASN1 Namespace Reference

Functions

bool maybe_BER (DataSource &source)
std::vector< uint8_t > put_in_sequence (const std::vector< uint8_t > &contents)
std::vector< uint8_t > put_in_sequence (const uint8_t bits[], size_t len)
std::string to_string (const BER_Object &obj)

Function Documentation

◆ maybe_BER()

bool Botan::ASN1::maybe_BER ( DataSource & src)

Heuristics tests; is this object possibly BER?

Parameters
srca data source that will be peeked at but not modified

Definition at line 197 of file asn1_obj.cpp.

197 {
198 uint8_t first_u8 = 0;
199 if(source.peek_byte(first_u8) == 0) {
200 BOTAN_ASSERT_EQUAL(source.read_byte(first_u8), 0, "Expected EOF");
201 throw Stream_IO_Error("ASN1::maybe_BER: Source was empty");
202 }
203
204 const auto cons_seq = static_cast<uint8_t>(ASN1_Class::Constructed) | static_cast<uint8_t>(ASN1_Type::Sequence);
205 return first_u8 == cons_seq;
206}
#define BOTAN_ASSERT_EQUAL(expr1, expr2, assertion_made)
Definition assert.h:88
Stream_IO_Error(std::string_view err)
Definition exceptn.cpp:135

References BOTAN_ASSERT_EQUAL, Botan::Constructed, maybe_BER(), Botan::DataSource::peek_byte(), Botan::DataSource::read_byte(), Botan::Sequence, and Botan::Stream_IO_Error::Stream_IO_Error().

Referenced by Botan::X509_Object::load_data(), Botan::X509::load_key(), and maybe_BER().

◆ put_in_sequence() [1/2]

std::vector< uint8_t > Botan::ASN1::put_in_sequence ( const std::vector< uint8_t > & contents)

Definition at line 177 of file asn1_obj.cpp.

177 {
178 return ASN1::put_in_sequence(contents.data(), contents.size());
179}
std::vector< uint8_t > put_in_sequence(const std::vector< uint8_t > &contents)
Definition asn1_obj.cpp:177

References put_in_sequence().

Referenced by Botan::GeneralName::binary_name(), botan_x509_crl_view_binary_values(), put_in_sequence(), put_in_sequence(), Botan::X509_Object::tbs_data(), and Botan::OCSP::Response::verify_signature().

◆ put_in_sequence() [2/2]

std::vector< uint8_t > Botan::ASN1::put_in_sequence ( const uint8_t bits[],
size_t len )

Definition at line 181 of file asn1_obj.cpp.

181 {
182 std::vector<uint8_t> output;
183 DER_Encoder(output).start_sequence().raw_bytes(bits, len).end_cons();
184 return output;
185}
DER_Encoder()=default

References Botan::DER_Encoder::DER_Encoder(), and put_in_sequence().

◆ to_string()

std::string Botan::ASN1::to_string ( const BER_Object & obj)

Definition at line 190 of file asn1_obj.cpp.

190 {
191 return bytes_to_string(obj.data());
192}
std::span< const uint8_t > data() const
Definition asn1_obj.h:154
std::string bytes_to_string(std::span< const uint8_t > bytes)
Definition mem_utils.h:76

References Botan::bytes_to_string(), Botan::BER_Object::data(), and to_string().

Referenced by Botan::AlternativeName::decode_from(), Botan::ASN1_String::decode_from(), Botan::ASN1_Time::decode_from(), Botan::GeneralName::decode_from(), and to_string().