Botan 3.5.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 192 of file asn1_obj.cpp.

192 {
193 uint8_t first_u8;
194 if(!source.peek_byte(first_u8)) {
195 BOTAN_ASSERT_EQUAL(source.read_byte(first_u8), 0, "Expected EOF");
196 throw Stream_IO_Error("ASN1::maybe_BER: Source was empty");
197 }
198
199 const auto cons_seq = static_cast<uint8_t>(ASN1_Class::Constructed) | static_cast<uint8_t>(ASN1_Type::Sequence);
200 if(first_u8 == cons_seq) {
201 return true;
202 }
203 return false;
204}
#define BOTAN_ASSERT_EQUAL(expr1, expr2, assertion_made)
Definition assert.h:68

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

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

◆ put_in_sequence() [1/2]

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

Definition at line 172 of file asn1_obj.cpp.

172 {
173 return ASN1::put_in_sequence(contents.data(), contents.size());
174}

References put_in_sequence().

Referenced by 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 176 of file asn1_obj.cpp.

176 {
177 std::vector<uint8_t> output;
178 DER_Encoder(output).start_sequence().raw_bytes(bits, len).end_cons();
179 return output;
180}
DER_Encoder & start_sequence()
Definition der_enc.h:64
DER_Encoder & raw_bytes(const uint8_t val[], size_t len)
Definition der_enc.cpp:207
DER_Encoder & end_cons()
Definition der_enc.cpp:171

References Botan::DER_Encoder::end_cons(), Botan::DER_Encoder::raw_bytes(), and Botan::DER_Encoder::start_sequence().

◆ to_string()

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

Definition at line 185 of file asn1_obj.cpp.

185 {
186 return std::string(cast_uint8_ptr_to_char(obj.bits()), obj.length());
187}
size_t length() const
Definition asn1_obj.h:153
const uint8_t * bits() const
Definition asn1_obj.h:151
const char * cast_uint8_ptr_to_char(const uint8_t *b)
Definition mem_ops.h:277

References Botan::BER_Object::bits(), Botan::cast_uint8_ptr_to_char(), and Botan::BER_Object::length().

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