Botan
1.11.15
|
00001 /* 00002 * Algorithm Identifier 00003 * (C) 1999-2007 Jack Lloyd 00004 * 00005 * Botan is released under the Simplified BSD License (see license.txt) 00006 */ 00007 00008 #include <botan/alg_id.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 AlgorithmIdentifier 00017 */ 00018 AlgorithmIdentifier::AlgorithmIdentifier(const OID& alg_id, 00019 const std::vector<byte>& param) 00020 { 00021 oid = alg_id; 00022 parameters = param; 00023 } 00024 00025 /* 00026 * Create an AlgorithmIdentifier 00027 */ 00028 AlgorithmIdentifier::AlgorithmIdentifier(const std::string& alg_id, 00029 const std::vector<byte>& param) 00030 { 00031 oid = OIDS::lookup(alg_id); 00032 parameters = param; 00033 } 00034 00035 /* 00036 * Create an AlgorithmIdentifier 00037 */ 00038 AlgorithmIdentifier::AlgorithmIdentifier(const OID& alg_id, 00039 Encoding_Option option) 00040 { 00041 const byte DER_NULL[] = { 0x05, 0x00 }; 00042 00043 oid = alg_id; 00044 00045 if(option == USE_NULL_PARAM) 00046 parameters += std::pair<const byte*, size_t>(DER_NULL, sizeof(DER_NULL)); 00047 } 00048 00049 /* 00050 * Create an AlgorithmIdentifier 00051 */ 00052 AlgorithmIdentifier::AlgorithmIdentifier(const std::string& alg_id, 00053 Encoding_Option option) 00054 { 00055 const byte DER_NULL[] = { 0x05, 0x00 }; 00056 00057 oid = OIDS::lookup(alg_id); 00058 00059 if(option == USE_NULL_PARAM) 00060 parameters += std::pair<const byte*, size_t>(DER_NULL, sizeof(DER_NULL)); 00061 } 00062 00063 /* 00064 * Compare two AlgorithmIdentifiers 00065 */ 00066 bool operator==(const AlgorithmIdentifier& a1, const AlgorithmIdentifier& a2) 00067 { 00068 if(a1.oid != a2.oid) 00069 return false; 00070 if(a1.parameters != a2.parameters) 00071 return false; 00072 return true; 00073 } 00074 00075 /* 00076 * Compare two AlgorithmIdentifiers 00077 */ 00078 bool operator!=(const AlgorithmIdentifier& a1, const AlgorithmIdentifier& a2) 00079 { 00080 return !(a1 == a2); 00081 } 00082 00083 /* 00084 * DER encode an AlgorithmIdentifier 00085 */ 00086 void AlgorithmIdentifier::encode_into(DER_Encoder& codec) const 00087 { 00088 codec.start_cons(SEQUENCE) 00089 .encode(oid) 00090 .raw_bytes(parameters) 00091 .end_cons(); 00092 } 00093 00094 /* 00095 * Decode a BER encoded AlgorithmIdentifier 00096 */ 00097 void AlgorithmIdentifier::decode_from(BER_Decoder& codec) 00098 { 00099 codec.start_cons(SEQUENCE) 00100 .decode(oid) 00101 .raw_bytes(parameters) 00102 .end_cons(); 00103 } 00104 00105 }