Botan: src/asn1/alg_id.cpp Source File

Botan 1.10.16

alg_id.cpp
Go to the documentation of this file.
1 /*
2 * Algorithm Identifier
3 * (C) 1999-2007 Jack Lloyd
4 *
5 * Distributed under the terms of the Botan license
6 */
7
8 #include <botan/alg_id.h>
9 #include <botan/der_enc.h>
10 #include <botan/ber_dec.h>
11 #include <botan/oids.h>
12
13 namespace Botan {
14
15 /*
16 * Create an AlgorithmIdentifier
17 */
18 AlgorithmIdentifier::AlgorithmIdentifier(const OID& alg_id,
19 const MemoryRegion<byte>& param)
20 {
21 oid = alg_id;
22 parameters = param;
23 }
24
25 /*
26 * Create an AlgorithmIdentifier
27 */
28 AlgorithmIdentifier::AlgorithmIdentifier(const std::string& alg_id,
29 const MemoryRegion<byte>& param)
30 {
31 oid = OIDS::lookup(alg_id);
32 parameters = param;
33 }
34
35 /*
36 * Create an AlgorithmIdentifier
37 */
38 AlgorithmIdentifier::AlgorithmIdentifier(const OID& alg_id,
39 Encoding_Option option)
40 {
41 const byte DER_NULL[] = { 0x05, 0x00 };
42
43 oid = alg_id;
44
45 if(option == USE_NULL_PARAM)
46 {
47 parameters += std::pair<const byte*, size_t>(
48 DER_NULL, sizeof(DER_NULL));
49 }
50 }
51
52 /*
53 * Create an AlgorithmIdentifier
54 */
55 AlgorithmIdentifier::AlgorithmIdentifier(const std::string& alg_id,
56 Encoding_Option option)
57 {
58 const byte DER_NULL[] = { 0x05, 0x00 };
59
60 oid = OIDS::lookup(alg_id);
61
62 if(option == USE_NULL_PARAM)
63 {
64 parameters += std::pair<const byte*, size_t>(
65 DER_NULL, sizeof(DER_NULL));
66 }
67 }
68
69 /*
70 * Compare two AlgorithmIdentifiers
71 */
72 bool operator==(const AlgorithmIdentifier& a1, const AlgorithmIdentifier& a2)
73 {
74 if(a1.oid != a2.oid)
75 return false;
76 if(a1.parameters != a2.parameters)
77 return false;
78 return true;
79 }
80
81 /*
82 * Compare two AlgorithmIdentifiers
83 */
84 bool operator!=(const AlgorithmIdentifier& a1, const AlgorithmIdentifier& a2)
85 {
86 return !(a1 == a2);
87 }
88
89 /*
90 * DER encode an AlgorithmIdentifier
91 */
92 void AlgorithmIdentifier::encode_into(DER_Encoder& codec) const
93 {
94 codec.start_cons(SEQUENCE)
95 .encode(oid)
96 .raw_bytes(parameters)
97 .end_cons();
98 }
99
100 /*
101 * Decode a BER encoded AlgorithmIdentifier
102 */
103 void AlgorithmIdentifier::decode_from(BER_Decoder& codec)
104 {
105 codec.start_cons(SEQUENCE)
106 .decode(oid)
107 .raw_bytes(parameters)
108 .end_cons();
109 }
110
111 }
Botan::AlgorithmIdentifier::encode_into
void encode_into(class DER_Encoder &) const
Definition: alg_id.cpp:92
Botan::AlgorithmIdentifier::AlgorithmIdentifier
AlgorithmIdentifier()
Definition: alg_id.h:28
Botan::operator!=
bool operator!=(const OctetString &s1, const OctetString &s2)
Definition: symkey.cpp:106
Botan::DER_Encoder::raw_bytes
DER_Encoder & raw_bytes(const byte val[], size_t len)
Definition: der_enc.cpp:188
Botan::BER_Decoder::decode
BER_Decoder & decode(bool &)
Definition: ber_dec.cpp:344
Botan::operator==
bool operator==(const OctetString &s1, const OctetString &s2)
Definition: symkey.cpp:98
Botan::AlgorithmIdentifier::parameters
SecureVector< byte > parameters
Definition: alg_id.h:36
Botan::DER_Encoder::end_cons
DER_Encoder & end_cons()
Definition: der_enc.cpp:145
Botan::AlgorithmIdentifier::Encoding_Option
Encoding_Option
Definition: alg_id.h:23
Botan::BER_Decoder::start_cons
BER_Decoder start_cons(ASN1_Tag, ASN1_Tag=UNIVERSAL)
Definition: ber_dec.cpp:238
Botan::byte
unsigned char byte
Definition: types.h:22
Botan::DER_Encoder::encode
DER_Encoder & encode(bool b)
Definition: der_enc.cpp:209
Botan::DER_Encoder
Definition: der_enc.h:22
Botan::BER_Decoder::end_cons
BER_Decoder & end_cons()
Definition: ber_dec.cpp:252
Botan::AlgorithmIdentifier::decode_from
void decode_from(class BER_Decoder &)
Definition: alg_id.cpp:103
Botan::OIDS::lookup
std::string lookup(const OID &oid)
Definition: oids.cpp:31
Botan::AlgorithmIdentifier::oid
OID oid
Definition: alg_id.h:35
Botan::SEQUENCE
Definition: asn1_int.h:35
Botan::MemoryRegion< byte >
Botan
Definition: algo_base.h:14
Botan::BER_Decoder::raw_bytes
BER_Decoder & raw_bytes(MemoryRegion< byte > &)
Definition: ber_dec.cpp:173
Botan::AlgorithmIdentifier
Definition: alg_id.h:20
Botan::DER_Encoder::start_cons
DER_Encoder & start_cons(ASN1_Tag type_tag, ASN1_Tag class_tag=UNIVERSAL)
Definition: der_enc.cpp:135
Botan::AlgorithmIdentifier::USE_NULL_PARAM
Definition: alg_id.h:23
Botan::OID
Definition: asn1_oid.h:20
Botan::BER_Decoder
Definition: ber_dec.h:19