aboutsummaryrefslogtreecommitdiffstats
path: root/src/asn1_alg.cpp
blob: 4dd5af88eefc10fa533a1df932f26b42da9483fd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*************************************************
* Algorithm Identifier Source File               *
* (C) 1999-2006 The Botan Project                *
*************************************************/

#include <botan/asn1_obj.h>
#include <botan/oids.h>

namespace Botan {

/*************************************************
* Create an AlgorithmIdentifier                  *
*************************************************/
AlgorithmIdentifier::AlgorithmIdentifier(const OID& alg_id,
                                         const MemoryRegion<byte>& param) :
   oid(alg_id), parameters(param) { }

/*************************************************
* Create an AlgorithmIdentifier                  *
*************************************************/
AlgorithmIdentifier::AlgorithmIdentifier(const std::string& alg_id,
                                         const MemoryRegion<byte>& param) :
   oid(OIDS::lookup(alg_id)), parameters(param) { }

/*************************************************
* DER encode an AlgorithmIdentifier              *
*************************************************/
void AlgorithmIdentifier::encode_into(DER_Encoder& der) const
   {
   der.start_sequence()
      .encode(oid)
      .add_raw_octets(parameters)
   .end_sequence();
   }

/*************************************************
* Compare two AlgorithmIdentifiers               *
*************************************************/
bool operator==(const AlgorithmIdentifier& a1, const AlgorithmIdentifier& a2)
   {
   if(a1.oid != a2.oid)
      return false;
   if(a1.parameters != a2.parameters)
      return false;
   return true;
   }

/*************************************************
* Compare two AlgorithmIdentifiers               *
*************************************************/
bool operator!=(const AlgorithmIdentifier& a1, const AlgorithmIdentifier& a2)
   {
   return !(a1 == a2);
   }

namespace BER {

/*************************************************
* Decode a BER encoded AlgorithmIdentifier       *
*************************************************/
void decode(BER_Decoder& source, AlgorithmIdentifier& alg_id)
   {
   BER_Decoder sequence = BER::get_subsequence(source);
   BER::decode(sequence, alg_id.oid);
   alg_id.parameters = sequence.get_remaining();
   sequence.verify_end();
   }

}

}