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