aboutsummaryrefslogtreecommitdiffstats
path: root/src/asn1_att.cpp
blob: 58ed761b466f4381ea37cef1a1a2a2831412ba1f (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
/*************************************************
* Attribute Source File                          *
* (C) 1999-2006 The Botan Project                *
*************************************************/

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

namespace Botan {

/*************************************************
* Create an Attribute                            *
*************************************************/
Attribute::Attribute(const OID& attr_oid, const MemoryRegion<byte>& attr_value)
   {
   oid = attr_oid;
   parameters = attr_value;
   }

/*************************************************
* Create an Attribute                            *
*************************************************/
Attribute::Attribute(const std::string& attr_oid,
                     const MemoryRegion<byte>& attr_value)
   {
   oid = OIDS::lookup(attr_oid);
   parameters = attr_value;
   }

/*************************************************
* DER encode a Attribute                         *
*************************************************/
void Attribute::encode_into(DER_Encoder& der) const
   {
   der.start_sequence()
      .encode(oid)
      .start_set()
         .add_raw_octets(parameters)
      .end_set()
   .end_sequence();
   }

namespace BER {

/*************************************************
* Decode a BER encoded Attribute                 *
*************************************************/
void decode(BER_Decoder& source, Attribute& attr)
   {
   BER_Decoder decoder = BER::get_subsequence(source);
   BER::decode(decoder, attr.oid);

   BER_Decoder attributes = BER::get_subset(decoder);
   attr.parameters = attributes.get_remaining();
   attributes.verify_end();

   decoder.verify_end();
   }

}

}