monotone

monotone Mtn Source Tree

Root/botan/asn1_ext.cpp

1/*************************************************
2* Extension 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 Extension *
13*************************************************/
14Extension::Extension(const OID& extn_oid, const MemoryRegion<byte>& extn_value)
15 {
16 oid = extn_oid;
17 value = extn_value;
18 critical = false;
19 }
20
21/*************************************************
22* Create an Extension *
23*************************************************/
24Extension::Extension(const std::string& extn_oid,
25 const MemoryRegion<byte>& extn_value)
26 {
27 oid = OIDS::lookup(extn_oid);
28 value = extn_value;
29 critical = false;
30 }
31
32namespace DER {
33
34/*************************************************
35* DER encode a Extension *
36*************************************************/
37void encode(DER_Encoder& encoder, const Extension& extn)
38 {
39 encoder.start_sequence();
40 DER::encode(encoder, extn.oid);
41 if(extn.critical)
42 DER::encode(encoder, true);
43 DER::encode(encoder, extn.value, OCTET_STRING);
44 encoder.end_sequence();
45 }
46
47}
48
49namespace BER {
50
51/*************************************************
52* Decode a BER encoded Extension *
53*************************************************/
54void decode(BER_Decoder& source, Extension& extn)
55 {
56 BER_Decoder extension = BER::get_subsequence(source);
57 BER::decode(extension, extn.oid);
58 BER::decode_optional(extension, extn.critical, BOOLEAN, UNIVERSAL, false);
59 BER::decode(extension, extn.value, OCTET_STRING);
60 extension.verify_end();
61 }
62
63}
64
65}

Archive Download this file

Branches

Tags

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