Botan  2.1.0
Crypto and TLS for C++11
asn1_attribute.cpp
Go to the documentation of this file.
1 /*
2 * Attribute
3 * (C) 1999-2007 Jack Lloyd
4 *
5 * Botan is released under the Simplified BSD License (see license.txt)
6 */
7 
8 #include <botan/asn1_attribute.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 std::vector<uint8_t>& attr_value) : oid(attr_oid), parameters(attr_value)
19  {}
20 
21 /*
22 * Create an Attribute
23 */
24 Attribute::Attribute(const std::string& attr_oid,
25  const std::vector<uint8_t>& attr_value) : oid(OIDS::lookup(attr_oid)), parameters(attr_value)
26  {}
27 
28 /*
29 * DER encode a Attribute
30 */
32  {
33  codec.start_cons(SEQUENCE)
34  .encode(oid)
35  .start_cons(SET)
37  .end_cons()
38  .end_cons();
39  }
40 
41 /*
42 * Decode a BER encoded Attribute
43 */
45  {
46  codec.start_cons(SEQUENCE)
47  .decode(oid)
48  .start_cons(SET)
50  .end_cons()
51  .end_cons();
52  }
53 
54 }
BER_Decoder & decode(bool &v)
Definition: ber_dec.cpp:376
DER_Encoder & end_cons()
Definition: der_enc.cpp:147
DER_Encoder & raw_bytes(const uint8_t val[], size_t len)
Definition: der_enc.cpp:195
DER_Encoder & encode(bool b)
Definition: der_enc.cpp:216
BER_Decoder & end_cons()
Definition: ber_dec.cpp:272
std::string lookup(const OID &oid)
Definition: oids.cpp:18
std::vector< uint8_t > parameters
Attribute()=default
BER_Decoder start_cons(ASN1_Tag type_tag, ASN1_Tag class_tag=UNIVERSAL)
Definition: ber_dec.cpp:258
void encode_into(class DER_Encoder &to) const override
Definition: alg_id.cpp:13
DER_Encoder & start_cons(ASN1_Tag type_tag, ASN1_Tag class_tag=UNIVERSAL)
Definition: der_enc.cpp:137
BER_Decoder & raw_bytes(secure_vector< uint8_t > &v)
Definition: ber_dec.cpp:178
void decode_from(class BER_Decoder &from) override