monotone

monotone Mtn Source Tree

Root/botan/alg_id.cpp

1/*************************************************
2* Algorithm Identifier Source File *
3* (C) 1999-2007 The Botan Project *
4*************************************************/
5
6#include <botan/alg_id.h>
7#include <botan/der_enc.h>
8#include <botan/ber_dec.h>
9#include <botan/oids.h>
10
11namespace Botan {
12
13/*************************************************
14* Create an AlgorithmIdentifier *
15*************************************************/
16AlgorithmIdentifier::AlgorithmIdentifier(const OID& alg_id,
17 const MemoryRegion<byte>& param)
18 {
19 oid = alg_id;
20 parameters = param;
21 }
22
23/*************************************************
24* Create an AlgorithmIdentifier *
25*************************************************/
26AlgorithmIdentifier::AlgorithmIdentifier(const std::string& alg_id,
27 const MemoryRegion<byte>& param)
28 {
29 oid = OIDS::lookup(alg_id);
30 parameters = param;
31 }
32
33/*************************************************
34* Create an AlgorithmIdentifier *
35*************************************************/
36AlgorithmIdentifier::AlgorithmIdentifier(const OID& alg_id,
37 Encoding_Option option)
38 {
39 const byte DER_NULL[] = { 0x05, 0x00 };
40
41 oid = alg_id;
42 if(option == USE_NULL_PARAM)
43 parameters.append(DER_NULL, sizeof(DER_NULL));
44 }
45
46/*************************************************
47* Create an AlgorithmIdentifier *
48*************************************************/
49AlgorithmIdentifier::AlgorithmIdentifier(const std::string& alg_id,
50 Encoding_Option option)
51 {
52 const byte DER_NULL[] = { 0x05, 0x00 };
53
54 oid = OIDS::lookup(alg_id);
55 if(option == USE_NULL_PARAM)
56 parameters.append(DER_NULL, sizeof(DER_NULL));
57 }
58
59/*************************************************
60* Compare two AlgorithmIdentifiers *
61*************************************************/
62bool operator==(const AlgorithmIdentifier& a1, const AlgorithmIdentifier& a2)
63 {
64 if(a1.oid != a2.oid)
65 return false;
66 if(a1.parameters != a2.parameters)
67 return false;
68 return true;
69 }
70
71/*************************************************
72* Compare two AlgorithmIdentifiers *
73*************************************************/
74bool operator!=(const AlgorithmIdentifier& a1, const AlgorithmIdentifier& a2)
75 {
76 return !(a1 == a2);
77 }
78
79/*************************************************
80* DER encode an AlgorithmIdentifier *
81*************************************************/
82void AlgorithmIdentifier::encode_into(DER_Encoder& codec) const
83 {
84 codec.start_cons(SEQUENCE)
85 .encode(oid)
86 .raw_bytes(parameters)
87 .end_cons();
88 }
89
90/*************************************************
91* Decode a BER encoded AlgorithmIdentifier *
92*************************************************/
93void AlgorithmIdentifier::decode_from(BER_Decoder& codec)
94 {
95 codec.start_cons(SEQUENCE)
96 .decode(oid)
97 .raw_bytes(parameters)
98 .end_cons();
99 }
100
101}

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status