Botan 3.0.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#include <botan/der_enc.h>
10#include <botan/ber_dec.h>
11
12namespace Botan {
13
14/*
15* Create an AlgorithmIdentifier
16*/
18 const std::vector<uint8_t>& param) :
19 m_oid(oid),
20 m_parameters(param)
21 {}
22
23/*
24* Create an AlgorithmIdentifier
25*/
27 const std::vector<uint8_t>& param) :
28 AlgorithmIdentifier(OID::from_string(oid), param)
29 {}
30
31/*
32* Create an AlgorithmIdentifier
33*/
35 Encoding_Option option) :
36 m_oid(oid),
37 m_parameters()
38 {
39 const uint8_t DER_NULL[] = { 0x05, 0x00 };
40
41 if(option == USE_NULL_PARAM)
42 m_parameters.assign(DER_NULL, DER_NULL + 2);
43 }
44
45/*
46* Create an AlgorithmIdentifier
47*/
49 Encoding_Option option) :
50 m_oid(OID::from_string(oid)),
51 m_parameters()
52 {
53 const uint8_t DER_NULL[] = { 0x05, 0x00 };
54
55 if(option == USE_NULL_PARAM)
56 m_parameters.assign(DER_NULL, DER_NULL + 2);
57 }
58
60 {
61 return (m_parameters.size() == 2 && (m_parameters[0] == 0x05) && (m_parameters[1] == 0x00));
62 }
63
65 {
66 if(a1.oid() != a2.oid())
67 return false;
68
69 /*
70 * Treat NULL and empty as equivalent
71 */
74 {
75 return true;
76 }
77
78 return (a1.parameters() == a2.parameters());
79 }
80
82 {
83 return !(a1 == a2);
84 }
85
86/*
87* DER encode an AlgorithmIdentifier
88*/
90 {
91 codec.start_sequence()
92 .encode(oid())
94 .end_cons();
95 }
96
97/*
98* Decode a BER encoded AlgorithmIdentifier
99*/
101 {
102 codec.start_sequence()
103 .decode(m_oid)
104 .raw_bytes(m_parameters)
105 .end_cons();
106 }
107
108}
void decode_from(BER_Decoder &) override
Definition: alg_id.cpp:100
void encode_into(DER_Encoder &) const override
Definition: alg_id.cpp:89
bool parameters_are_null_or_empty() const
Definition: asn1_obj.h:489
const std::vector< uint8_t > & parameters() const
Definition: asn1_obj.h:478
bool parameters_are_null() const
Definition: alg_id.cpp:59
const OID & oid() const
Definition: asn1_obj.h:477
BER_Decoder & decode(bool &out)
Definition: ber_dec.h:193
BER_Decoder & end_cons()
Definition: ber_dec.cpp:304
BER_Decoder start_sequence()
Definition: ber_dec.h:117
DER_Encoder & start_sequence()
Definition: der_enc.h:66
DER_Encoder & raw_bytes(const uint8_t val[], size_t len)
Definition: der_enc.cpp:233
DER_Encoder & end_cons()
Definition: der_enc.cpp:196
DER_Encoder & encode(bool b)
Definition: der_enc.cpp:290
Definition: alg_id.cpp:12
bool operator!=(const AlgorithmIdentifier &a1, const AlgorithmIdentifier &a2)
Definition: alg_id.cpp:81
bool operator==(const AlgorithmIdentifier &a1, const AlgorithmIdentifier &a2)
Definition: alg_id.cpp:64