Botan
1.11.15
|
#include <ber_dec.h>
Definition at line 277 of file ber_dec.cpp.
References Botan::BER_Object::class_tag, Botan::NO_OBJECT, and Botan::BER_Object::type_tag.
Referenced by decode_optional().
Botan::BER_Decoder::BER_Decoder | ( | const byte | data[], |
size_t | length | ||
) |
Definition at line 288 of file ber_dec.cpp.
References Botan::BER_Object::class_tag, Botan::NO_OBJECT, and Botan::BER_Object::type_tag.
Botan::BER_Decoder::BER_Decoder | ( | const secure_vector< byte > & | data | ) |
Definition at line 299 of file ber_dec.cpp.
References Botan::BER_Object::class_tag, Botan::NO_OBJECT, and Botan::BER_Object::type_tag.
Botan::BER_Decoder::BER_Decoder | ( | const std::vector< byte > & | vec | ) |
Definition at line 310 of file ber_dec.cpp.
References Botan::BER_Object::class_tag, Botan::NO_OBJECT, and Botan::BER_Object::type_tag.
Botan::BER_Decoder::BER_Decoder | ( | const BER_Decoder & | other | ) |
Definition at line 321 of file ber_dec.cpp.
References Botan::BER_Object::class_tag, Botan::NO_OBJECT, and Botan::BER_Object::type_tag.
Definition at line 337 of file ber_dec.cpp.
{ if(owns) delete source; source = nullptr; }
BER_Decoder & Botan::BER_Decoder::decode | ( | bool & | v | ) |
Definition at line 369 of file ber_dec.cpp.
References Botan::BOOLEAN, and Botan::UNIVERSAL.
Referenced by Botan::DL_Group::BER_decode(), Botan::PK_Verifier::check_signature(), Botan::Curve25519_PrivateKey::Curve25519_PrivateKey(), Botan::Curve25519_PublicKey::Curve25519_PublicKey(), decode(), decode_constrained_integer(), Botan::Attribute::decode_from(), Botan::AlternativeName::decode_from(), Botan::X509_DN::decode_from(), Botan::AlgorithmIdentifier::decode_from(), Botan::OCSP::CertID::decode_from(), Botan::CRL_Entry::decode_from(), Botan::OCSP::SingleResponse::decode_from(), Botan::Extensions::decode_from(), Botan::X509_Object::decode_from(), Botan::EAC1_1_gen_CVC< Derived >::decode_info(), decode_list(), decode_octet_string_bigint(), decode_optional(), decode_optional_implicit(), decode_optional_string(), Botan::DL_Scheme_PrivateKey::DL_Scheme_PrivateKey(), Botan::DL_Scheme_PublicKey::DL_Scheme_PublicKey(), Botan::EC_Group::EC_Group(), Botan::ECDSA_Signature::ECDSA_Signature(), get_next_octet_string(), Botan::GOST_3410_PublicKey::GOST_3410_PublicKey(), Botan::IF_Scheme_PublicKey::IF_Scheme_PublicKey(), Botan::X509::load_key(), Botan::McEliece_PrivateKey::McEliece_PrivateKey(), Botan::McEliece_PublicKey::McEliece_PublicKey(), Botan::pbes2_decrypt(), Botan::OCSP::Response::Response(), and Botan::TLS::Session::Session().
BER_Decoder & Botan::BER_Decoder::decode | ( | size_t & | v | ) |
Definition at line 377 of file ber_dec.cpp.
References decode(), Botan::INTEGER, and Botan::UNIVERSAL.
BER_Decoder & Botan::BER_Decoder::decode | ( | class BigInt & | v | ) |
Definition at line 385 of file ber_dec.cpp.
References decode(), Botan::INTEGER, and Botan::UNIVERSAL.
BER_Decoder & Botan::BER_Decoder::decode | ( | std::vector< byte > & | v, |
ASN1_Tag | type_tag | ||
) |
Definition at line 507 of file ber_dec.cpp.
References decode(), and Botan::UNIVERSAL.
BER_Decoder & Botan::BER_Decoder::decode | ( | secure_vector< byte > & | v, |
ASN1_Tag | type_tag | ||
) |
Definition at line 499 of file ber_dec.cpp.
References decode(), and Botan::UNIVERSAL.
BER_Decoder & Botan::BER_Decoder::decode | ( | bool & | v, |
ASN1_Tag | type_tag, | ||
ASN1_Tag | class_tag = CONTEXT_SPECIFIC |
||
) |
Definition at line 408 of file ber_dec.cpp.
References Botan::BER_Object::assert_is_a(), get_next_object(), and Botan::BER_Object::value.
{ BER_Object obj = get_next_object(); obj.assert_is_a(type_tag, class_tag); if(obj.value.size() != 1) throw BER_Decoding_Error("BER boolean value had invalid size"); out = (obj.value[0]) ? true : false; return (*this); }
BER_Decoder & Botan::BER_Decoder::decode | ( | size_t & | v, |
ASN1_Tag | type_tag, | ||
ASN1_Tag | class_tag = CONTEXT_SPECIFIC |
||
) |
Definition at line 424 of file ber_dec.cpp.
References Botan::BigInt::bits(), Botan::BigInt::byte_at(), and decode().
{ BigInt integer; decode(integer, type_tag, class_tag); if(integer.bits() > 32) throw BER_Decoding_Error("Decoded integer value larger than expected"); out = 0; for(size_t i = 0; i != 4; ++i) out = (out << 8) | integer.byte_at(3-i); return (*this); }
BER_Decoder & Botan::BER_Decoder::decode | ( | class BigInt & | v, |
ASN1_Tag | type_tag, | ||
ASN1_Tag | class_tag = CONTEXT_SPECIFIC |
||
) |
Definition at line 466 of file ber_dec.cpp.
References Botan::BER_Object::assert_is_a(), Botan::BigInt::flip_sign(), get_next_object(), and Botan::BER_Object::value.
{ BER_Object obj = get_next_object(); obj.assert_is_a(type_tag, class_tag); if(obj.value.empty()) out = 0; else { const bool negative = (obj.value[0] & 0x80) ? true : false; if(negative) { for(size_t i = obj.value.size(); i > 0; --i) if(obj.value[i-1]--) break; for(size_t i = 0; i != obj.value.size(); ++i) obj.value[i] = ~obj.value[i]; } out = BigInt(&obj.value[0], obj.value.size()); if(negative) out.flip_sign(); } return (*this); }
BER_Decoder & Botan::BER_Decoder::decode | ( | std::vector< byte > & | v, |
ASN1_Tag | real_type, | ||
ASN1_Tag | type_tag, | ||
ASN1_Tag | class_tag = CONTEXT_SPECIFIC |
||
) |
Definition at line 538 of file ber_dec.cpp.
References Botan::BER_Object::assert_is_a(), Botan::BIT_STRING, Botan::copy_mem(), get_next_object(), Botan::OCTET_STRING, Botan::unlock(), and Botan::BER_Object::value.
{ if(real_type != OCTET_STRING && real_type != BIT_STRING) throw BER_Bad_Tag("Bad tag for {BIT,OCTET} STRING", real_type); BER_Object obj = get_next_object(); obj.assert_is_a(type_tag, class_tag); if(real_type == OCTET_STRING) buffer = unlock(obj.value); else { if(obj.value[0] >= 8) throw BER_Decoding_Error("Bad number of unused bits in BIT STRING"); buffer.resize(obj.value.size() - 1); copy_mem(&buffer[0], &obj.value[1], obj.value.size() - 1); } return (*this); }
BER_Decoder & Botan::BER_Decoder::decode | ( | secure_vector< byte > & | v, |
ASN1_Tag | real_type, | ||
ASN1_Tag | type_tag, | ||
ASN1_Tag | class_tag = CONTEXT_SPECIFIC |
||
) |
Definition at line 515 of file ber_dec.cpp.
References Botan::BER_Object::assert_is_a(), Botan::BIT_STRING, Botan::copy_mem(), get_next_object(), Botan::OCTET_STRING, and Botan::BER_Object::value.
{ if(real_type != OCTET_STRING && real_type != BIT_STRING) throw BER_Bad_Tag("Bad tag for {BIT,OCTET} STRING", real_type); BER_Object obj = get_next_object(); obj.assert_is_a(type_tag, class_tag); if(real_type == OCTET_STRING) buffer = obj.value; else { if(obj.value[0] >= 8) throw BER_Decoding_Error("Bad number of unused bits in BIT STRING"); buffer.resize(obj.value.size() - 1); copy_mem(&buffer[0], &obj.value[1], obj.value.size() - 1); } return (*this); }
BER_Decoder & Botan::BER_Decoder::decode | ( | class ASN1_Object & | obj, |
ASN1_Tag | type_tag = NO_OBJECT , |
||
ASN1_Tag | class_tag = NO_OBJECT |
||
) |
Definition at line 347 of file ber_dec.cpp.
References Botan::ASN1_Object::decode_from().
{ obj.decode_from(*this); return (*this); }
BER_Decoder& Botan::BER_Decoder::decode_and_check | ( | const T & | expected, |
const std::string & | error_msg | ||
) | [inline] |
Definition at line 114 of file ber_dec.h.
References Botan::BER::decode().
Referenced by Botan::EC_Group::EC_Group(), Botan::EC_PrivateKey::EC_PrivateKey(), Botan::IF_Scheme_PrivateKey::IF_Scheme_PrivateKey(), Botan::OCSP::Response::Response(), and Botan::TLS::Session::Session().
{ T actual; decode(actual); if(actual != expected) throw Decoding_Error(error_msg); return (*this); }
u64bit Botan::BER_Decoder::decode_constrained_integer | ( | ASN1_Tag | type_tag, |
ASN1_Tag | class_tag, | ||
size_t | T_bytes | ||
) |
Definition at line 443 of file ber_dec.cpp.
References Botan::BigInt::bits(), Botan::BigInt::byte_at(), and decode().
{ if(T_bytes > 8) throw BER_Decoding_Error("Can't decode small integer over 8 bytes"); BigInt integer; decode(integer, type_tag, class_tag); if(integer.bits() > 8*T_bytes) throw BER_Decoding_Error("Decoded integer value larger than expected"); u64bit out = 0; for(size_t i = 0; i != 8; ++i) out = (out << 8) | integer.byte_at(7-i); return out; }
BER_Decoder& Botan::BER_Decoder::decode_integer_type | ( | T & | out | ) | [inline] |
Definition at line 79 of file ber_dec.h.
References Botan::INTEGER, and Botan::UNIVERSAL.
Referenced by Botan::TLS::Session::Session().
BER_Decoder& Botan::BER_Decoder::decode_integer_type | ( | T & | out, |
ASN1_Tag | type_tag, | ||
ASN1_Tag | class_tag = CONTEXT_SPECIFIC |
||
) | [inline] |
Definition at line 85 of file ber_dec.h.
{ out = decode_constrained_integer(type_tag, class_tag, sizeof(out)); return (*this); }
BER_Decoder & Botan::BER_Decoder::decode_list | ( | std::vector< T > & | out, |
ASN1_Tag | type_tag = SEQUENCE , |
||
ASN1_Tag | class_tag = UNIVERSAL |
||
) |
Definition at line 240 of file ber_dec.h.
References decode(), end_cons(), more_items(), push_back(), and start_cons().
Referenced by Botan::OCSP::Response::Response().
{ BER_Decoder list = start_cons(type_tag, class_tag); while(list.more_items()) { T value; list.decode(value); vec.push_back(value); } list.end_cons(); return (*this); }
Definition at line 357 of file ber_dec.cpp.
References Botan::BER_Object::assert_is_a(), get_next_object(), Botan::NULL_TAG, Botan::UNIVERSAL, and Botan::BER_Object::value.
{ BER_Object obj = get_next_object(); obj.assert_is_a(NULL_TAG, UNIVERSAL); if(obj.value.size()) throw BER_Decoding_Error("NULL object had nonzero size"); return (*this); }
BER_Decoder & Botan::BER_Decoder::decode_octet_string_bigint | ( | class BigInt & | b | ) |
Definition at line 390 of file ber_dec.cpp.
References decode(), and Botan::OCTET_STRING.
Referenced by Botan::EC_Group::EC_Group().
{ secure_vector<byte> out_vec; decode(out_vec, OCTET_STRING); out = BigInt::decode(&out_vec[0], out_vec.size()); return (*this); }
BER_Decoder & Botan::BER_Decoder::decode_optional | ( | T & | out, |
ASN1_Tag | type_tag, | ||
ASN1_Tag | class_tag, | ||
const T & | default_value = T() |
||
) |
Definition at line 181 of file ber_dec.h.
References BER_Decoder(), Botan::BER_Object::class_tag, Botan::CONSTRUCTED, Botan::CONTEXT_SPECIFIC, decode(), get_next_object(), push_back(), Botan::BER_Object::type_tag, and Botan::BER_Object::value.
Referenced by Botan::OCSP::SingleResponse::decode_from(), Botan::Extensions::decode_from(), Botan::EC_PrivateKey::EC_PrivateKey(), Botan::pbes2_decrypt(), and Botan::OCSP::Response::Response().
{ BER_Object obj = get_next_object(); if(obj.type_tag == type_tag && obj.class_tag == class_tag) { if((class_tag & CONSTRUCTED) && (class_tag & CONTEXT_SPECIFIC)) BER_Decoder(obj.value).decode(out).verify_end(); else { push_back(obj); decode(out, type_tag, class_tag); } } else { out = default_value; push_back(obj); } return (*this); }
BER_Decoder & Botan::BER_Decoder::decode_optional_implicit | ( | T & | out, |
ASN1_Tag | type_tag, | ||
ASN1_Tag | class_tag, | ||
ASN1_Tag | real_type, | ||
ASN1_Tag | real_class, | ||
const T & | default_value = T() |
||
) |
Definition at line 211 of file ber_dec.h.
References Botan::BER_Object::class_tag, decode(), get_next_object(), push_back(), and Botan::BER_Object::type_tag.
Referenced by Botan::Cert_Extension::CRL_Distribution_Points::Distribution_Point::decode_from().
{ BER_Object obj = get_next_object(); if(obj.type_tag == type_tag && obj.class_tag == class_tag) { obj.type_tag = real_type; obj.class_tag = real_class; push_back(obj); decode(out, real_type, real_class); } else { out = default_value; push_back(obj); } return (*this); }
BER_Decoder& Botan::BER_Decoder::decode_optional_string | ( | std::vector< byte, Alloc > & | out, |
ASN1_Tag | real_type, | ||
u16bit | type_no, | ||
ASN1_Tag | class_tag = CONTEXT_SPECIFIC |
||
) | [inline] |
Definition at line 130 of file ber_dec.h.
References Botan::BER_Object::class_tag, Botan::CONSTRUCTED, Botan::CONTEXT_SPECIFIC, Botan::BER::decode(), decode(), Botan::BER_Object::type_tag, Botan::BER_Object::value, and verify_end().
Referenced by Botan::EC_PrivateKey::EC_PrivateKey(), and Botan::OCSP::Response::Response().
{ BER_Object obj = get_next_object(); ASN1_Tag type_tag = static_cast<ASN1_Tag>(type_no); if(obj.type_tag == type_tag && obj.class_tag == class_tag) { if((class_tag & CONSTRUCTED) && (class_tag & CONTEXT_SPECIFIC)) BER_Decoder(obj.value).decode(out, real_type).verify_end(); else { push_back(obj); decode(out, real_type, type_tag, class_tag); } } else { out.clear(); push_back(obj); } return (*this); }
Definition at line 195 of file ber_dec.cpp.
References Botan::DataSource::read_byte().
Referenced by Botan::DL_Group::BER_decode().
Definition at line 265 of file ber_dec.cpp.
References Botan::DataSource::end_of_data().
Referenced by Botan::Curve25519_PrivateKey::Curve25519_PrivateKey(), Botan::Curve25519_PublicKey::Curve25519_PublicKey(), Botan::Attribute::decode_from(), Botan::AlgorithmIdentifier::decode_from(), Botan::X509_DN::decode_from(), Botan::OCSP::CertID::decode_from(), Botan::CRL_Entry::decode_from(), Botan::OCSP::SingleResponse::decode_from(), Botan::Extensions::decode_from(), Botan::X509_Object::decode_from(), Botan::Cert_Extension::CRL_Distribution_Points::Distribution_Point::decode_from(), Botan::EAC1_1_gen_CVC< Derived >::decode_info(), decode_list(), Botan::EC_Group::EC_Group(), Botan::EC_PrivateKey::EC_PrivateKey(), Botan::ECDSA_Signature::ECDSA_Signature(), Botan::IF_Scheme_PublicKey::IF_Scheme_PublicKey(), Botan::X509::load_key(), Botan::McEliece_PrivateKey::McEliece_PrivateKey(), Botan::McEliece_PublicKey::McEliece_PublicKey(), Botan::pbes2_decrypt(), Botan::OCSP::Response::Response(), and Botan::TLS::Session::Session().
{ if(!parent) throw Invalid_State("BER_Decoder::end_cons called with NULL parent"); if(!source->end_of_data()) throw Decoding_Error("BER_Decoder::end_cons called with data left"); return (*parent); }
BER_Decoder & Botan::BER_Decoder::get_next | ( | BER_Object & | ber | ) |
Definition at line 232 of file ber_dec.cpp.
References get_next_object().
Referenced by Botan::OCSP::SingleResponse::decode_from().
{ ber = get_next_object(); return (*this); }
Definition at line 206 of file ber_dec.cpp.
References Botan::BER_Object::class_tag, Botan::EOC, Botan::NO_OBJECT, Botan::DataSource::read(), Botan::BER_Object::type_tag, Botan::UNIVERSAL, and Botan::BER_Object::value.
Referenced by Botan::BER::decode(), decode(), Botan::ASN1_String::decode_from(), Botan::X509_Time::decode_from(), Botan::OID::decode_from(), Botan::AlternativeName::decode_from(), Botan::EAC_Time::decode_from(), Botan::ASN1_EAC_String::decode_from(), decode_null(), decode_optional(), decode_optional_implicit(), Botan::EC_Group::EC_Group(), get_next(), and start_cons().
{ BER_Object next; if(pushed.type_tag != NO_OBJECT) { next = pushed; pushed.class_tag = pushed.type_tag = NO_OBJECT; return next; } decode_tag(source, next.type_tag, next.class_tag); if(next.type_tag == NO_OBJECT) return next; size_t length = decode_length(source); next.value.resize(length); if(source->read(&next.value[0], length) != length) throw BER_Decoding_Error("Value truncated"); if(next.type_tag == EOC && next.class_tag == UNIVERSAL) return get_next_object(); return next; }
std::vector< byte > Botan::BER_Decoder::get_next_octet_string | ( | ) |
Definition at line 398 of file ber_dec.cpp.
References decode(), and Botan::OCTET_STRING.
Referenced by Botan::OCSP::Response::Response().
{ std::vector<byte> out_vec; decode(out_vec, OCTET_STRING); return out_vec; }
bool Botan::BER_Decoder::more_items | ( | ) | const |
Definition at line 154 of file ber_dec.cpp.
References Botan::DataSource::end_of_data(), Botan::NO_OBJECT, and Botan::BER_Object::type_tag.
Referenced by Botan::PK_Verifier::check_signature(), Botan::X509_DN::decode_from(), Botan::AlternativeName::decode_from(), Botan::CRL_Entry::decode_from(), Botan::Extensions::decode_from(), decode_list(), and Botan::OCSP::Response::Response().
{ if(source->end_of_data() && (pushed.type_tag == NO_OBJECT)) return false; return true; }
BER_Decoder& Botan::BER_Decoder::operator= | ( | const BER_Decoder & | ) |
void Botan::BER_Decoder::push_back | ( | const BER_Object & | obj | ) |
Definition at line 241 of file ber_dec.cpp.
References Botan::NO_OBJECT, and Botan::BER_Object::type_tag.
Referenced by decode_list(), decode_optional(), decode_optional_implicit(), Botan::McEliece_PrivateKey::McEliece_PrivateKey(), raw_bytes(), and Botan::OCSP::Response::Response().
BER_Decoder & Botan::BER_Decoder::raw_bytes | ( | secure_vector< byte > & | v | ) |
Definition at line 174 of file ber_dec.cpp.
References push_back(), and Botan::DataSource::read_byte().
Referenced by Botan::Attribute::decode_from(), Botan::AlgorithmIdentifier::decode_from(), Botan::X509_DN::decode_from(), Botan::X509_Object::decode_from(), Botan::EAC1_1_gen_CVC< Derived >::decode_info(), and Botan::OCSP::Response::Response().
BER_Decoder & Botan::BER_Decoder::raw_bytes | ( | std::vector< byte > & | v | ) |
Definition at line 183 of file ber_dec.cpp.
References push_back(), and Botan::DataSource::read_byte().
BER_Decoder Botan::BER_Decoder::start_cons | ( | ASN1_Tag | type_tag, |
ASN1_Tag | class_tag = UNIVERSAL |
||
) |
Definition at line 251 of file ber_dec.cpp.
References Botan::BER_Object::assert_is_a(), Botan::CONSTRUCTED, get_next_object(), and Botan::BER_Object::value.
Referenced by Botan::DL_Group::BER_decode(), Botan::PK_Verifier::check_signature(), Botan::Curve25519_PrivateKey::Curve25519_PrivateKey(), Botan::Curve25519_PublicKey::Curve25519_PublicKey(), Botan::Attribute::decode_from(), Botan::AlternativeName::decode_from(), Botan::X509_DN::decode_from(), Botan::AlgorithmIdentifier::decode_from(), Botan::OCSP::CertID::decode_from(), Botan::CRL_Entry::decode_from(), Botan::OCSP::SingleResponse::decode_from(), Botan::Extensions::decode_from(), Botan::X509_Object::decode_from(), Botan::Cert_Extension::CRL_Distribution_Points::Distribution_Point::decode_from(), Botan::EAC1_1_gen_CVC< Derived >::decode_info(), decode_list(), Botan::EC_Group::EC_Group(), Botan::EC_PrivateKey::EC_PrivateKey(), Botan::ECDSA_Signature::ECDSA_Signature(), Botan::GOST_3410_PublicKey::GOST_3410_PublicKey(), Botan::IF_Scheme_PrivateKey::IF_Scheme_PrivateKey(), Botan::IF_Scheme_PublicKey::IF_Scheme_PublicKey(), Botan::X509::load_key(), Botan::McEliece_PrivateKey::McEliece_PrivateKey(), Botan::McEliece_PublicKey::McEliece_PublicKey(), Botan::pbes2_decrypt(), Botan::OCSP::Response::Response(), and Botan::TLS::Session::Session().
{ BER_Object obj = get_next_object(); obj.assert_is_a(type_tag, ASN1_Tag(class_tag | CONSTRUCTED)); BER_Decoder result(&obj.value[0], obj.value.size()); result.parent = this; return result; }
Definition at line 164 of file ber_dec.cpp.
References Botan::DataSource::end_of_data(), Botan::NO_OBJECT, and Botan::BER_Object::type_tag.
Referenced by Botan::DL_Group::BER_decode(), Botan::Curve25519_PrivateKey::Curve25519_PrivateKey(), Botan::Curve25519_PublicKey::Curve25519_PublicKey(), Botan::AlternativeName::decode_from(), Botan::X509_DN::decode_from(), Botan::Extensions::decode_from(), Botan::X509_Object::decode_from(), decode_optional_string(), Botan::EC_Group::EC_Group(), Botan::ECDSA_Signature::ECDSA_Signature(), Botan::IF_Scheme_PublicKey::IF_Scheme_PublicKey(), Botan::X509::load_key(), Botan::pbes2_decrypt(), and Botan::TLS::Session::Session().
{ if(!source->end_of_data() || (pushed.type_tag != NO_OBJECT)) throw Invalid_State("BER_Decoder::verify_end called, but data remains"); return (*this); }