Botan
1.11.15
|
00001 /* 00002 * Attribute 00003 * (C) 1999-2007 Jack Lloyd 00004 * 00005 * Botan is released under the Simplified BSD License (see license.txt) 00006 */ 00007 00008 #include <botan/asn1_attribute.h> 00009 #include <botan/der_enc.h> 00010 #include <botan/ber_dec.h> 00011 #include <botan/oids.h> 00012 00013 namespace Botan { 00014 00015 /* 00016 * Create an Attribute 00017 */ 00018 Attribute::Attribute(const OID& attr_oid, const std::vector<byte>& attr_value) 00019 { 00020 oid = attr_oid; 00021 parameters = attr_value; 00022 } 00023 00024 /* 00025 * Create an Attribute 00026 */ 00027 Attribute::Attribute(const std::string& attr_oid, 00028 const std::vector<byte>& attr_value) 00029 { 00030 oid = OIDS::lookup(attr_oid); 00031 parameters = attr_value; 00032 } 00033 00034 /* 00035 * DER encode a Attribute 00036 */ 00037 void Attribute::encode_into(DER_Encoder& codec) const 00038 { 00039 codec.start_cons(SEQUENCE) 00040 .encode(oid) 00041 .start_cons(SET) 00042 .raw_bytes(parameters) 00043 .end_cons() 00044 .end_cons(); 00045 } 00046 00047 /* 00048 * Decode a BER encoded Attribute 00049 */ 00050 void Attribute::decode_from(BER_Decoder& codec) 00051 { 00052 codec.start_cons(SEQUENCE) 00053 .decode(oid) 00054 .start_cons(SET) 00055 .raw_bytes(parameters) 00056 .end_cons() 00057 .end_cons(); 00058 } 00059 00060 }