Botan 1.10.17
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
13namespace Botan {
14
15/*
16* Create an AlgorithmIdentifier
17*/
19 const MemoryRegion<byte>& param)
20 {
21 oid = alg_id;
22 parameters = param;
23 }
24
25/*
26* Create an AlgorithmIdentifier
27*/
29 const MemoryRegion<byte>& param)
30 {
31 oid = OIDS::lookup(alg_id);
32 parameters = param;
33 }
34
35/*
36* Create an AlgorithmIdentifier
37*/
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*/
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*/
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*/
85 {
86 return !(a1 == a2);
87 }
88
89/*
90* DER encode an AlgorithmIdentifier
91*/
99
100/*
101* Decode a BER encoded AlgorithmIdentifier
102*/
110
111}
void encode_into(class DER_Encoder &) const
Definition alg_id.cpp:92
void decode_from(class BER_Decoder &)
Definition alg_id.cpp:103
SecureVector< byte > parameters
Definition alg_id.h:36
BER_Decoder start_cons(ASN1_Tag, ASN1_Tag=UNIVERSAL)
Definition ber_dec.cpp:238
BER_Decoder & raw_bytes(MemoryRegion< byte > &)
Definition ber_dec.cpp:173
BER_Decoder & decode(bool &)
Definition ber_dec.cpp:344
BER_Decoder & end_cons()
Definition ber_dec.cpp:252
DER_Encoder & start_cons(ASN1_Tag type_tag, ASN1_Tag class_tag=UNIVERSAL)
Definition der_enc.cpp:135
DER_Encoder & raw_bytes(const byte val[], size_t len)
Definition der_enc.cpp:188
DER_Encoder & end_cons()
Definition der_enc.cpp:145
DER_Encoder & encode(bool b)
Definition der_enc.cpp:209
std::string lookup(const OID &oid)
Definition oids.cpp:31
bool operator!=(const OctetString &s1, const OctetString &s2)
Definition symkey.cpp:106
@ SEQUENCE
Definition asn1_int.h:35
bool operator==(const OctetString &s1, const OctetString &s2)
Definition symkey.cpp:98