monotone

monotone Mtn Source Tree

Root/botan/asn1_alg.cpp

1/*************************************************
2* Algorithm Identifier Source File *
3* (C) 1999-2005 The Botan Project *
4*************************************************/
5
6#include <botan/asn1_obj.h>
7#include <botan/oids.h>
8
9namespace Botan {
10
11/*************************************************
12* Create an AlgorithmIdentifier *
13*************************************************/
14AlgorithmIdentifier::AlgorithmIdentifier(const OID& o,
15 const MemoryRegion<byte>& p) :
16 oid(o), parameters(p)
17 {
18 }
19
20/*************************************************
21* Create an AlgorithmIdentifier *
22*************************************************/
23AlgorithmIdentifier::AlgorithmIdentifier(const std::string& alg_id,
24 bool use_null)
25 {
26 const byte DER_NULL[] = { 0x05, 0x00 };
27
28 oid = OIDS::lookup(alg_id);
29 if(use_null)
30 parameters.append(DER_NULL, sizeof(DER_NULL));
31 }
32
33/*************************************************
34* Compare two AlgorithmIdentifiers *
35*************************************************/
36bool operator==(const AlgorithmIdentifier& a1, const AlgorithmIdentifier& a2)
37 {
38 if(a1.oid != a2.oid)
39 return false;
40 if(a1.parameters != a2.parameters)
41 return false;
42 return true;
43 }
44
45/*************************************************
46* Compare two AlgorithmIdentifiers *
47*************************************************/
48bool operator!=(const AlgorithmIdentifier& a1, const AlgorithmIdentifier& a2)
49 {
50 return !(a1 == a2);
51 }
52
53namespace DER {
54
55/*************************************************
56* DER encode an AlgorithmIdentifier *
57*************************************************/
58void encode(DER_Encoder& encoder, const AlgorithmIdentifier& alg_id)
59 {
60 encoder.start_sequence();
61 DER::encode(encoder, alg_id.oid);
62 encoder.add_raw_octets(alg_id.parameters);
63 encoder.end_sequence();
64 }
65
66}
67
68namespace BER {
69
70/*************************************************
71* Decode a BER encoded AlgorithmIdentifier *
72*************************************************/
73void decode(BER_Decoder& source, AlgorithmIdentifier& alg_id)
74 {
75 BER_Decoder sequence = BER::get_subsequence(source);
76 BER::decode(sequence, alg_id.oid);
77 alg_id.parameters = sequence.get_remaining();
78 sequence.verify_end();
79 }
80
81}
82
83}

Archive Download this file

Branches

Tags

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