monotone

monotone Mtn Source Tree

Root/botan/asn1_att.cpp

1/*************************************************
2* Attribute 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 Attribute *
13*************************************************/
14Attribute::Attribute(const OID& attr_oid, const MemoryRegion<byte>& attr_value)
15 {
16 oid = attr_oid;
17 parameters = attr_value;
18 }
19
20/*************************************************
21* Create an Attribute *
22*************************************************/
23Attribute::Attribute(const std::string& attr_oid,
24 const MemoryRegion<byte>& attr_value)
25 {
26 oid = OIDS::lookup(attr_oid);
27 parameters = attr_value;
28 }
29
30namespace DER {
31
32/*************************************************
33* DER encode a Attribute *
34*************************************************/
35void encode(DER_Encoder& encoder, const Attribute& attr)
36 {
37 encoder.start_sequence();
38 DER::encode(encoder, attr.oid);
39 encoder.start_set();
40 encoder.add_raw_octets(attr.parameters);
41 encoder.end_set();
42 encoder.end_sequence();
43 }
44
45}
46
47namespace BER {
48
49/*************************************************
50* Decode a BER encoded Attribute *
51*************************************************/
52void decode(BER_Decoder& source, Attribute& attr)
53 {
54 BER_Decoder decoder = BER::get_subsequence(source);
55 BER::decode(decoder, attr.oid);
56
57 BER_Decoder attributes = BER::get_subset(decoder);
58 attr.parameters = attributes.get_remaining();
59 attributes.verify_end();
60
61 decoder.verify_end();
62 }
63
64}
65
66}

Archive Download this file

Branches

Tags

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