Botan 2.19.5 Crypto and TLS for C&

x509_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/pkix_types.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) :
19 oid(attr_oid),
20 parameters(attr_value)
21 {}
22
23/*
24* Create an Attribute
25*/
26 Attribute::Attribute(const std::string& attr_oid,
27 const std::vector<uint8_t>& attr_value) :
28 oid(OID::from_string(attr_oid)),
29 parameters(attr_value)
30 {}
31
32/*
33* DER encode a Attribute
34*/
35 void Attribute::encode_into(DER_Encoder& codec) const
36 {
37 codec.start_cons(SEQUENCE)
38 .encode(oid)
39 .start_cons(SET)
40 .raw_bytes(parameters)
41 .end_cons()
42 .end_cons();
43 }
44
45/*
46* Decode a BER encoded Attribute
47*/
48 void Attribute::decode_from(BER_Decoder& codec)
49 {
50 codec.start_cons(SEQUENCE)
51 .decode(oid)
52 .start_cons(SET)
53 .raw_bytes(parameters)
54 .end_cons()
55 .end_cons();
56 }
57
58}
Botan::Attribute::parameters
std::vector< uint8_t > parameters
Definition: pkix_types.h:185
Botan::Attribute::decode_from
void decode_from(BER_Decoder &from) override
Definition: x509_attribute.cpp:48
Botan::Attribute::encode_into
void encode_into(DER_Encoder &to) const override
Definition: x509_attribute.cpp:35
Botan::Attribute::Attribute
Attribute()=default
Botan::BER_Decoder
Definition: ber_dec.h:22
Botan::BER_Decoder::start_cons
BER_Decoder start_cons(ASN1_Tag type_tag, ASN1_Tag class_tag=UNIVERSAL)
Definition: ber_dec.cpp:290
Botan::BER_Decoder::decode
BER_Decoder & decode(bool &out)
Definition: ber_dec.h:170
Botan::BER_Decoder::raw_bytes
BER_Decoder & raw_bytes(std::vector< uint8_t, Alloc > &out)
Definition: ber_dec.h:156
Botan::BER_Decoder::end_cons
BER_Decoder & end_cons()
Definition: ber_dec.cpp:300
Botan::DER_Encoder
Definition: der_enc.h:23
Botan::DER_Encoder::start_cons
DER_Encoder & start_cons(ASN1_Tag type_tag, ASN1_Tag class_tag=UNIVERSAL)
Definition: der_enc.cpp:181
Botan::DER_Encoder::raw_bytes
DER_Encoder & raw_bytes(const uint8_t val[], size_t len)
Definition: der_enc.cpp:228
Botan::DER_Encoder::end_cons
DER_Encoder & end_cons()
Definition: der_enc.cpp:191
Botan::DER_Encoder::encode
DER_Encoder & encode(bool b)
Definition: der_enc.cpp:285
Botan::OID
Definition: asn1_obj.h:194
Botan
Definition: alg_id.cpp:13
Botan::SEQUENCE
@ SEQUENCE
Definition: asn1_obj.h:42
Botan::SET
@ SET
Definition: asn1_obj.h:43