Botan 3.13.0
Crypto and TLS for C&
Botan::AlgorithmIdentifier Class Referencefinal

#include <asn1_obj.h>

Inheritance diagram for Botan::AlgorithmIdentifier:
Botan::ASN1_Object

Public Types

enum  Encoding_Option : uint8_t { USE_NULL_PARAM , USE_EMPTY_PARAM }

Public Member Functions

 AlgorithmIdentifier ()=default
 AlgorithmIdentifier (const OID &oid, const std::vector< uint8_t > &params)
 AlgorithmIdentifier (const OID &oid, Encoding_Option enc)
 AlgorithmIdentifier (std::string_view oid_name, const std::vector< uint8_t > &params)
 AlgorithmIdentifier (std::string_view oid_name, Encoding_Option enc)
std::vector< uint8_t > BER_encode () const
void decode_from (BER_Decoder &from) override
bool empty () const
void encode_into (DER_Encoder &to) const override
const OIDget_oid () const
const std::vector< uint8_t > & get_parameters () const
const OIDoid () const
const std::vector< uint8_t > & parameters () const
bool parameters_are_empty () const
bool parameters_are_null () const
bool parameters_are_null_or_empty () const

Detailed Description

Algorithm Identifier

Definition at line 642 of file asn1_obj.h.

Member Enumeration Documentation

◆ Encoding_Option

Selects how an absent parameters field is encoded

Enumerator
USE_NULL_PARAM 
USE_EMPTY_PARAM 

Definition at line 647 of file asn1_obj.h.

647: uint8_t { USE_NULL_PARAM, USE_EMPTY_PARAM }; /* NOLINT(*-use-enum-class) */

Constructor & Destructor Documentation

◆ AlgorithmIdentifier() [1/5]

Botan::AlgorithmIdentifier::AlgorithmIdentifier ( )
default

Create an empty AlgorithmIdentifier

References AlgorithmIdentifier(), and oid().

Referenced by AlgorithmIdentifier(), and AlgorithmIdentifier().

◆ AlgorithmIdentifier() [2/5]

Botan::AlgorithmIdentifier::AlgorithmIdentifier ( const OID & oid,
Encoding_Option enc )

Create an AlgorithmIdentifier with no parameters

Parameters
oidthe algorithm OID
encwhether the empty parameters are encoded as NULL or omitted

Definition at line 31 of file alg_id.cpp.

31 : m_oid(oid) {
32 constexpr uint8_t DER_NULL[] = {0x05, 0x00};
33
34 if(option == USE_NULL_PARAM) {
35 m_parameters.assign(DER_NULL, DER_NULL + 2);
36 }
37}
const OID & oid() const
Definition asn1_obj.h:688

References oid(), and USE_NULL_PARAM.

◆ AlgorithmIdentifier() [3/5]

Botan::AlgorithmIdentifier::AlgorithmIdentifier ( std::string_view oid_name,
Encoding_Option enc )

Create an AlgorithmIdentifier with no parameters

Parameters
oid_namea name or dotted decimal string identifying the algorithm
encwhether the empty parameters are encoded as NULL or omitted

Definition at line 42 of file alg_id.cpp.

42 : m_oid(OID::from_string(oid)) {
43 constexpr uint8_t DER_NULL[2] = {0x05, 0x00};
44
45 if(option == USE_NULL_PARAM) {
46 m_parameters.assign(DER_NULL, DER_NULL + 2);
47 }
48}
static OID from_string(std::string_view str)
Definition asn1_oid.cpp:80

References oid(), and USE_NULL_PARAM.

◆ AlgorithmIdentifier() [4/5]

Botan::AlgorithmIdentifier::AlgorithmIdentifier ( const OID & oid,
const std::vector< uint8_t > & params )

Create an AlgorithmIdentifier

Parameters
oidthe algorithm OID
paramsthe DER encoded parameters

Definition at line 19 of file alg_id.cpp.

19 :
20 m_oid(oid), m_parameters(param) {}

References oid().

◆ AlgorithmIdentifier() [5/5]

Botan::AlgorithmIdentifier::AlgorithmIdentifier ( std::string_view oid_name,
const std::vector< uint8_t > & params )

Create an AlgorithmIdentifier

Parameters
oid_namea name or dotted decimal string identifying the algorithm
paramsthe DER encoded parameters

Definition at line 25 of file alg_id.cpp.

References AlgorithmIdentifier(), and oid().

Member Function Documentation

◆ BER_encode()

std::vector< uint8_t > Botan::ASN1_Object::BER_encode ( ) const
inherited

Return the encoding of this object. This is a convenience method when just one object needs to be serialized. Use DER_Encoder for complicated encodings.

Definition at line 21 of file asn1_obj.cpp.

21 {
22 std::vector<uint8_t> output;
23 DER_Encoder der(output);
24 this->encode_into(der);
25 return output;
26}
virtual void encode_into(DER_Encoder &to) const =0

References encode_into().

Referenced by decode_from(), Botan::PKCS12::export_to(), Botan::Certificate_Store_In_SQL::find_all_certs(), Botan::Certificate_Store_In_SQL::find_cert(), Botan::X509_Certificate::fingerprint(), Botan::Certificate_Store_In_SQL::insert_cert(), Botan::X509_Object::PEM_encode(), and Botan::PSS_Params::PSS_Params().

◆ decode_from()

void Botan::AlgorithmIdentifier::decode_from ( BER_Decoder & from)
overridevirtual

Decode whatever this object is from from

Parameters
fromthe BER_Decoder that will be read from

Implements Botan::ASN1_Object.

Definition at line 72 of file alg_id.cpp.

72 {
73 codec.start_sequence().decode(m_oid).raw_bytes(m_parameters).end_cons();
74
75 /*
76 * The parameters field is OPTIONAL ANY but in practice it is one of
77 * - empty
78 * - NULL
79 * - SEQUENCE
80 * - OBJECT IDENTIFIER (namedCurve)
81 * - OCTET STRING (CBC IV in PBES2)
82 *
83 * So require it be exactly one of these values. In particular this ensures that
84 * there is not any additional trailing data (eg after the SEQUENCE encoding)
85 * that might be otherwise skipped over by a reader.
86 */
87
88 const bool acceptable_parameters = [&]() {
90 return true;
91 }
92 if(ASN1::is_der_sequence_header(m_parameters)) {
93 return true;
94 }
96 return true;
97 }
99 return true;
100 }
101 return false;
102 }();
103
104 if(!acceptable_parameters) {
105 throw Decoding_Error("AlgorithmIdentifier parameters were not NULL, a SEQUENCE, an OID, or an OCTET STRING");
106 }
107}
bool parameters_are_null_or_empty() const
Definition asn1_obj.h:720
bool is_single_der_object(std::span< const uint8_t > bytes, ASN1_Type expected_type, ASN1_Class expected_class)
Definition ber_dec.cpp:1100
bool is_der_sequence_header(std::span< const uint8_t > bytes)
Definition ber_dec.cpp:1128

References Botan::BER_Decoder::decode(), Botan::BER_Decoder::end_cons(), Botan::ASN1::is_der_sequence_header(), Botan::ASN1::is_single_der_object(), Botan::ObjectId, Botan::OctetString, parameters_are_null_or_empty(), Botan::BER_Decoder::raw_bytes(), Botan::BER_Decoder::start_sequence(), and Botan::Universal.

◆ empty()

bool Botan::AlgorithmIdentifier::empty ( ) const
inline

Return true if neither the OID nor the parameters have been set

Definition at line 725 of file asn1_obj.h.

725{ return m_oid.empty() && m_parameters.empty(); }

◆ encode_into()

void Botan::AlgorithmIdentifier::encode_into ( DER_Encoder & to) const
overridevirtual

Encode whatever this object is into to

Parameters
tothe DER_Encoder that will be written to

Implements Botan::ASN1_Object.

Definition at line 65 of file alg_id.cpp.

65 {
66 codec.start_sequence().encode(oid()).raw_bytes(parameters()).end_cons();
67}
const std::vector< uint8_t > & parameters() const
Definition asn1_obj.h:693

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

◆ get_oid()

const OID & Botan::AlgorithmIdentifier::get_oid ( ) const
inline

Return the algorithm OID

Definition at line 698 of file asn1_obj.h.

698{ return m_oid; }

References get_oid().

Referenced by get_oid().

◆ get_parameters()

const std::vector< uint8_t > & Botan::AlgorithmIdentifier::get_parameters ( ) const
inline

Return the DER encoded parameters, which may be empty

Definition at line 703 of file asn1_obj.h.

703 {
704 return m_parameters;
705 }

References get_parameters().

Referenced by get_parameters().

◆ oid()

◆ parameters()

const std::vector< uint8_t > & Botan::AlgorithmIdentifier::parameters ( ) const
inline

Return the DER encoded parameters, which may be empty

Definition at line 693 of file asn1_obj.h.

693{ return m_parameters; }

Referenced by Botan::EC_PrivateKey::EC_PrivateKey(), Botan::EC_PublicKey::EC_PublicKey(), encode_into(), Botan::operator==(), Botan::pbes2_decrypt(), and Botan::pkcs12_pbe_decrypt().

◆ parameters_are_empty()

bool Botan::AlgorithmIdentifier::parameters_are_empty ( ) const
inline

◆ parameters_are_null()

bool Botan::AlgorithmIdentifier::parameters_are_null ( ) const

Return true if the parameters consist of a single DER encoded NULL

Definition at line 50 of file alg_id.cpp.

50 {
51 return (m_parameters.size() == 2 && (m_parameters[0] == 0x05) && (m_parameters[1] == 0x00));
52}

Referenced by parameters_are_null_or_empty(), and Botan::PK_Ops::Verification_with_Hash::Verification_with_Hash().

◆ parameters_are_null_or_empty()

bool Botan::AlgorithmIdentifier::parameters_are_null_or_empty ( ) const
inline

Return true if the parameters field is absent or a single DER encoded NULL

Definition at line 720 of file asn1_obj.h.

bool parameters_are_empty() const
Definition asn1_obj.h:715
bool parameters_are_null() const
Definition alg_id.cpp:50

References parameters_are_empty(), and parameters_are_null().

Referenced by decode_from(), Botan::RSA_PrivateKey::RSA_PrivateKey(), and Botan::RSA_PublicKey::RSA_PublicKey().


The documentation for this class was generated from the following files: