Botan 3.9.0
Crypto and TLS for C&
alg_id.cpp
Go to the documentation of this file.
1/*
2* Algorithm Identifier
3* (C) 1999-2007 Jack Lloyd
4*
5* Botan is released under the Simplified BSD License (see license.txt)
6*/
7
8#include <botan/asn1_obj.h>
9
10#include <botan/ber_dec.h>
11#include <botan/der_enc.h>
12
13namespace Botan {
14
15/*
16* Create an AlgorithmIdentifier
17*/
18AlgorithmIdentifier::AlgorithmIdentifier(const OID& oid, const std::vector<uint8_t>& param) :
19 m_oid(oid), m_parameters(param) {}
20
21/*
22* Create an AlgorithmIdentifier
23*/
24AlgorithmIdentifier::AlgorithmIdentifier(std::string_view oid, const std::vector<uint8_t>& param) :
25 AlgorithmIdentifier(OID::from_string(oid), param) {}
26
27/*
28* Create an AlgorithmIdentifier
29*/
31 constexpr uint8_t DER_NULL[] = {0x05, 0x00};
32
33 if(option == USE_NULL_PARAM) {
34 m_parameters.assign(DER_NULL, DER_NULL + 2);
35 }
36}
37
38/*
39* Create an AlgorithmIdentifier
40*/
41AlgorithmIdentifier::AlgorithmIdentifier(std::string_view oid, Encoding_Option option) : m_oid(OID::from_string(oid)) {
42 constexpr uint8_t DER_NULL[2] = {0x05, 0x00};
43
44 if(option == USE_NULL_PARAM) {
45 m_parameters.assign(DER_NULL, DER_NULL + 2);
46 }
47}
48
50 return (m_parameters.size() == 2 && (m_parameters[0] == 0x05) && (m_parameters[1] == 0x00));
51}
52
54 if(a1.oid() != a2.oid()) {
55 return false;
56 }
57
58 /*
59 * Treat NULL and empty as equivalent
60 */
62 return true;
63 }
64
65 return (a1.parameters() == a2.parameters());
66}
67
69 return !(a1 == a2);
70}
71
72/*
73* DER encode an AlgorithmIdentifier
74*/
78
79/*
80* Decode a BER encoded AlgorithmIdentifier
81*/
83 codec.start_sequence().decode(m_oid).raw_bytes(m_parameters).end_cons();
84}
85
86} // namespace Botan
void encode_into(DER_Encoder &to) const override
Definition alg_id.cpp:75
bool parameters_are_null_or_empty() const
Definition asn1_obj.h:493
const std::vector< uint8_t > & parameters() const
Definition asn1_obj.h:481
bool parameters_are_null() const
Definition alg_id.cpp:49
void decode_from(BER_Decoder &from) override
Definition alg_id.cpp:82
const OID & oid() const
Definition asn1_obj.h:479
BER_Decoder & decode(bool &out)
Definition ber_dec.h:188
BER_Decoder & raw_bytes(std::vector< uint8_t, Alloc > &out)
Definition ber_dec.h:174
BER_Decoder & end_cons()
Definition ber_dec.cpp:312
BER_Decoder start_sequence()
Definition ber_dec.h:125
DER_Encoder & start_sequence()
Definition der_enc.h:65
DER_Encoder & raw_bytes(const uint8_t val[], size_t len)
Definition der_enc.cpp:209
DER_Encoder & end_cons()
Definition der_enc.cpp:173
DER_Encoder & encode(bool b)
Definition der_enc.cpp:252
bool operator!=(const AlgorithmIdentifier &a1, const AlgorithmIdentifier &a2)
Definition alg_id.cpp:68
bool operator==(const AlgorithmIdentifier &a1, const AlgorithmIdentifier &a2)
Definition alg_id.cpp:53