Botan  1.10.9
asn1_att.cpp
Go to the documentation of this file.
1 /*
2 * Attribute
3 * (C) 1999-2007 Jack Lloyd
4 *
5 * Distributed under the terms of the Botan license
6 */
7 
8 #include <botan/asn1_obj.h>
9 #include <botan/der_enc.h>
10 #include <botan/ber_dec.h>
11 #include <botan/oids.h>
12 
13 namespace Botan {
14 
15 /*
16 * Create an Attribute
17 */
18 Attribute::Attribute(const OID& attr_oid, const MemoryRegion<byte>& attr_value)
19  {
20  oid = attr_oid;
21  parameters = attr_value;
22  }
23 
24 /*
25 * Create an Attribute
26 */
27 Attribute::Attribute(const std::string& attr_oid,
28  const MemoryRegion<byte>& attr_value)
29  {
30  oid = OIDS::lookup(attr_oid);
31  parameters = attr_value;
32  }
33 
34 /*
35 * DER encode a Attribute
36 */
38  {
39  codec.start_cons(SEQUENCE)
40  .encode(oid)
41  .start_cons(SET)
43  .end_cons()
44  .end_cons();
45  }
46 
47 /*
48 * Decode a BER encoded Attribute
49 */
51  {
52  codec.start_cons(SEQUENCE)
53  .decode(oid)
54  .start_cons(SET)
56  .end_cons()
57  .end_cons();
58  }
59 
60 }
MemoryVector< byte > parameters
Definition: asn1_obj.h:31
DER_Encoder & raw_bytes(const byte val[], size_t len)
Definition: der_enc.cpp:188
BER_Decoder & decode(bool &)
Definition: ber_dec.cpp:338
void encode_into(class DER_Encoder &to) const
Definition: asn1_att.cpp:37
DER_Encoder & end_cons()
Definition: der_enc.cpp:145
BER_Decoder start_cons(ASN1_Tag, ASN1_Tag=UNIVERSAL)
Definition: ber_dec.cpp:232
DER_Encoder & encode(bool b)
Definition: der_enc.cpp:209
BER_Decoder & end_cons()
Definition: ber_dec.cpp:246
std::string lookup(const OID &oid)
Definition: oids.cpp:31
BER_Decoder & raw_bytes(MemoryRegion< byte > &)
Definition: ber_dec.cpp:170
DER_Encoder & start_cons(ASN1_Tag type_tag, ASN1_Tag class_tag=UNIVERSAL)
Definition: der_enc.cpp:135
void decode_from(class BER_Decoder &from)
Definition: asn1_att.cpp:50