Botan 3.5.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*/
30AlgorithmIdentifier::AlgorithmIdentifier(const OID& oid, Encoding_Option option) : m_oid(oid), m_parameters() {
31 const 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*/
42 m_oid(OID::from_string(oid)), m_parameters() {
43 const uint8_t DER_NULL[] = {0x05, 0x00};
44
45 if(option == USE_NULL_PARAM) {
46 m_parameters.assign(DER_NULL, DER_NULL + 2);
47 }
48}
49
51 return (m_parameters.size() == 2 && (m_parameters[0] == 0x05) && (m_parameters[1] == 0x00));
52}
53
55 if(a1.oid() != a2.oid()) {
56 return false;
57 }
58
59 /*
60 * Treat NULL and empty as equivalent
61 */
63 return true;
64 }
65
66 return (a1.parameters() == a2.parameters());
67}
68
70 return !(a1 == a2);
71}
72
73/*
74* DER encode an AlgorithmIdentifier
75*/
79
80/*
81* Decode a BER encoded AlgorithmIdentifier
82*/
84 codec.start_sequence().decode(m_oid).raw_bytes(m_parameters).end_cons();
85}
86
87} // namespace Botan
void decode_from(BER_Decoder &) override
Definition alg_id.cpp:83
void encode_into(DER_Encoder &) const override
Definition alg_id.cpp:76
bool parameters_are_null_or_empty() const
Definition asn1_obj.h:478
const std::vector< uint8_t > & parameters() const
Definition asn1_obj.h:466
bool parameters_are_null() const
Definition alg_id.cpp:50
const OID & oid() const
Definition asn1_obj.h:464
BER_Decoder & decode(bool &out)
Definition ber_dec.h:186
BER_Decoder & raw_bytes(std::vector< uint8_t, Alloc > &out)
Definition ber_dec.h:172
BER_Decoder & end_cons()
Definition ber_dec.cpp:309
BER_Decoder start_sequence()
Definition ber_dec.h:123
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
DER_Encoder & encode(bool b)
Definition der_enc.cpp:250
bool operator!=(const AlgorithmIdentifier &a1, const AlgorithmIdentifier &a2)
Definition alg_id.cpp:69
bool operator==(const AlgorithmIdentifier &a1, const AlgorithmIdentifier &a2)
Definition alg_id.cpp:54