aboutsummaryrefslogtreecommitdiffstats
path: root/src/asn1_ext.cpp
blob: 557e7712c8f890d551739580edf670a21a0e3acd (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
/*************************************************
* Extension Source File                          *
* (C) 1999-2006 The Botan Project                *
*************************************************/

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

namespace Botan {

/*************************************************
* Create an Extension                            *
*************************************************/
Extension::Extension(const OID& extn_oid, const MemoryRegion<byte>& extn_value)
   {
   oid = extn_oid;
   value = extn_value;
   critical = false;
   }

/*************************************************
* Create an Extension                            *
*************************************************/
Extension::Extension(const std::string& extn_oid,
                     const MemoryRegion<byte>& extn_value)
   {
   oid = OIDS::lookup(extn_oid);
   value = extn_value;
   critical = false;
   }

/*************************************************
* DER encode a Extension                         *
*************************************************/
void Extension::encode_into(DER_Encoder& codec) const
   {
   codec.start_cons(SEQUENCE)
         .encode(oid)
         .encode_optional(critical, false)
         .encode(value, OCTET_STRING)
      .end_cons();
   }

/*************************************************
* Decode a BER encoded Extension                 *
*************************************************/
void Extension::decode_from(BER_Decoder& codec)
   {
   codec.start_cons(SEQUENCE)
         .decode(oid)
         .decode_optional(critical, BOOLEAN, UNIVERSAL, false)
         .decode(value, OCTET_STRING)
      .end_cons();
   }

}