Botan
1.11.15
|
#include <der_enc.h>
Classes | |
class | DER_Sequence |
Public Member Functions | |
DER_Encoder & | add_object (ASN1_Tag type_tag, ASN1_Tag class_tag, const byte rep[], size_t length) |
DER_Encoder & | add_object (ASN1_Tag type_tag, ASN1_Tag class_tag, const std::vector< byte > &rep) |
DER_Encoder & | add_object (ASN1_Tag type_tag, ASN1_Tag class_tag, const secure_vector< byte > &rep) |
DER_Encoder & | add_object (ASN1_Tag type_tag, ASN1_Tag class_tag, const std::string &str) |
DER_Encoder & | add_object (ASN1_Tag type_tag, ASN1_Tag class_tag, byte val) |
DER_Encoder & | encode (bool b) |
DER_Encoder & | encode (size_t s) |
DER_Encoder & | encode (const BigInt &n) |
DER_Encoder & | encode (const secure_vector< byte > &v, ASN1_Tag real_type) |
DER_Encoder & | encode (const std::vector< byte > &v, ASN1_Tag real_type) |
DER_Encoder & | encode (const byte val[], size_t len, ASN1_Tag real_type) |
DER_Encoder & | encode (bool b, ASN1_Tag type_tag, ASN1_Tag class_tag=CONTEXT_SPECIFIC) |
DER_Encoder & | encode (size_t s, ASN1_Tag type_tag, ASN1_Tag class_tag=CONTEXT_SPECIFIC) |
DER_Encoder & | encode (const BigInt &n, ASN1_Tag type_tag, ASN1_Tag class_tag=CONTEXT_SPECIFIC) |
DER_Encoder & | encode (const std::vector< byte > &v, ASN1_Tag real_type, ASN1_Tag type_tag, ASN1_Tag class_tag=CONTEXT_SPECIFIC) |
DER_Encoder & | encode (const secure_vector< byte > &v, ASN1_Tag real_type, ASN1_Tag type_tag, ASN1_Tag class_tag=CONTEXT_SPECIFIC) |
DER_Encoder & | encode (const byte v[], size_t len, ASN1_Tag real_type, ASN1_Tag type_tag, ASN1_Tag class_tag=CONTEXT_SPECIFIC) |
DER_Encoder & | encode (const ASN1_Object &obj) |
DER_Encoder & | encode_if (bool pred, DER_Encoder &enc) |
DER_Encoder & | encode_if (bool pred, const ASN1_Object &obj) |
template<typename T > | |
DER_Encoder & | encode_list (const std::vector< T > &values) |
DER_Encoder & | encode_null () |
template<typename T > | |
DER_Encoder & | encode_optional (const T &value, const T &default_value) |
DER_Encoder & | end_cons () |
DER_Encoder & | end_explicit () |
secure_vector< byte > | get_contents () |
std::vector< byte > | get_contents_unlocked () |
DER_Encoder & | raw_bytes (const byte val[], size_t len) |
DER_Encoder & | raw_bytes (const secure_vector< byte > &val) |
DER_Encoder & | raw_bytes (const std::vector< byte > &val) |
DER_Encoder & | start_cons (ASN1_Tag type_tag, ASN1_Tag class_tag=UNIVERSAL) |
DER_Encoder & | start_explicit (u16bit type_tag) |
DER_Encoder & Botan::DER_Encoder::add_object | ( | ASN1_Tag | type_tag, |
ASN1_Tag | class_tag, | ||
const byte | rep[], | ||
size_t | length | ||
) |
Definition at line 379 of file der_enc.cpp.
References raw_bytes().
Referenced by add_object(), encode(), Botan::ASN1_String::encode_into(), Botan::X509_Time::encode_into(), Botan::OID::encode_into(), Botan::EAC_Time::encode_into(), Botan::ASN1_EAC_String::encode_into(), and encode_null().
{ secure_vector<byte> buffer; buffer += encode_tag(type_tag, class_tag); buffer += encode_length(length); buffer += std::make_pair(rep, length); return raw_bytes(buffer); }
DER_Encoder& Botan::DER_Encoder::add_object | ( | ASN1_Tag | type_tag, |
ASN1_Tag | class_tag, | ||
const std::vector< byte > & | rep | ||
) | [inline] |
Definition at line 99 of file der_enc.h.
{ return add_object(type_tag, class_tag, &rep[0], rep.size()); }
DER_Encoder& Botan::DER_Encoder::add_object | ( | ASN1_Tag | type_tag, |
ASN1_Tag | class_tag, | ||
const secure_vector< byte > & | rep | ||
) | [inline] |
Definition at line 105 of file der_enc.h.
{ return add_object(type_tag, class_tag, &rep[0], rep.size()); }
DER_Encoder & Botan::DER_Encoder::add_object | ( | ASN1_Tag | type_tag, |
ASN1_Tag | class_tag, | ||
const std::string & | str | ||
) |
Definition at line 393 of file der_enc.cpp.
References add_object().
{ const byte* rep = reinterpret_cast<const byte*>(rep_str.data()); const size_t rep_len = rep_str.size(); return add_object(type_tag, class_tag, rep, rep_len); }
DER_Encoder & Botan::DER_Encoder::add_object | ( | ASN1_Tag | type_tag, |
ASN1_Tag | class_tag, | ||
byte | val | ||
) |
Definition at line 404 of file der_enc.cpp.
References add_object().
{ return add_object(type_tag, class_tag, &rep, 1); }
DER_Encoder & Botan::DER_Encoder::encode | ( | bool | b | ) |
Definition at line 214 of file der_enc.cpp.
References Botan::BOOLEAN, and Botan::UNIVERSAL.
Referenced by Botan::GOST_3410_PublicKey::algorithm_identifier(), Botan::X509::BER_encode(), Botan::OCSP::Request::BER_encode(), Botan::PKCS8::BER_encode(), Botan::CVC_EAC::create_ado_req(), Botan::X509::create_cert_req(), Botan::CVC_EAC::create_cvc_req(), Botan::ECDSA_Signature::DER_encode(), Botan::TLS::Session::DER_encode(), Botan::EC_Group::DER_encode(), Botan::DL_Group::DER_encode(), encode(), Botan::EAC1_1_gen_CVC< Derived >::encode(), encode_if(), Botan::Attribute::encode_into(), Botan::AlternativeName::encode_into(), Botan::AlgorithmIdentifier::encode_into(), Botan::OCSP::CertID::encode_into(), Botan::CRL_Entry::encode_into(), Botan::Extensions::encode_into(), Botan::X509_Object::encode_into(), Botan::make_cvc_cert(), Botan::EAC1_1_ADO::make_signed(), Botan::X509_Object::make_signed(), Botan::EAC1_1_gen_CVC< Derived >::make_signed(), Botan::Curve25519_PrivateKey::pkcs8_private_key(), Botan::IF_Scheme_PrivateKey::pkcs8_private_key(), Botan::DL_Scheme_PrivateKey::pkcs8_private_key(), Botan::EC_PrivateKey::pkcs8_private_key(), Botan::McEliece_PrivateKey::pkcs8_private_key(), Botan::DL_Scheme_PublicKey::x509_subject_public_key(), Botan::Curve25519_PublicKey::x509_subject_public_key(), Botan::IF_Scheme_PublicKey::x509_subject_public_key(), and Botan::GOST_3410_PublicKey::x509_subject_public_key().
DER_Encoder & Botan::DER_Encoder::encode | ( | size_t | s | ) |
Definition at line 222 of file der_enc.cpp.
References encode(), Botan::INTEGER, and Botan::UNIVERSAL.
DER_Encoder & Botan::DER_Encoder::encode | ( | const BigInt & | n | ) |
Definition at line 230 of file der_enc.cpp.
References encode(), Botan::INTEGER, and Botan::UNIVERSAL.
DER_Encoder & Botan::DER_Encoder::encode | ( | const secure_vector< byte > & | v, |
ASN1_Tag | real_type | ||
) |
Definition at line 238 of file der_enc.cpp.
References encode(), and Botan::UNIVERSAL.
DER_Encoder & Botan::DER_Encoder::encode | ( | const std::vector< byte > & | v, |
ASN1_Tag | real_type | ||
) |
Definition at line 248 of file der_enc.cpp.
References encode(), and Botan::UNIVERSAL.
DER_Encoder & Botan::DER_Encoder::encode | ( | const byte | val[], |
size_t | len, | ||
ASN1_Tag | real_type | ||
) |
Definition at line 258 of file der_enc.cpp.
References encode(), and Botan::UNIVERSAL.
DER_Encoder & Botan::DER_Encoder::encode | ( | bool | b, |
ASN1_Tag | type_tag, | ||
ASN1_Tag | class_tag = CONTEXT_SPECIFIC |
||
) |
Definition at line 267 of file der_enc.cpp.
References add_object().
{ byte val = is_true ? 0xFF : 0x00; return add_object(type_tag, class_tag, &val, 1); }
DER_Encoder & Botan::DER_Encoder::encode | ( | size_t | s, |
ASN1_Tag | type_tag, | ||
ASN1_Tag | class_tag = CONTEXT_SPECIFIC |
||
) |
Definition at line 277 of file der_enc.cpp.
References encode().
DER_Encoder & Botan::DER_Encoder::encode | ( | const BigInt & | n, |
ASN1_Tag | type_tag, | ||
ASN1_Tag | class_tag = CONTEXT_SPECIFIC |
||
) |
Definition at line 286 of file der_enc.cpp.
References add_object(), Botan::BigInt::bits(), Botan::BigInt::bytes(), and encode().
{ if(n == 0) return add_object(type_tag, class_tag, 0); bool extra_zero = (n.bits() % 8 == 0); secure_vector<byte> contents(extra_zero + n.bytes()); BigInt::encode(&contents[extra_zero], n); if(n < 0) { for(size_t i = 0; i != contents.size(); ++i) contents[i] = ~contents[i]; for(size_t i = contents.size(); i > 0; --i) if(++contents[i-1]) break; } return add_object(type_tag, class_tag, contents); }
DER_Encoder & Botan::DER_Encoder::encode | ( | const std::vector< byte > & | v, |
ASN1_Tag | real_type, | ||
ASN1_Tag | type_tag, | ||
ASN1_Tag | class_tag = CONTEXT_SPECIFIC |
||
) |
Definition at line 321 of file der_enc.cpp.
References encode().
{ return encode(&bytes[0], bytes.size(), real_type, type_tag, class_tag); }
DER_Encoder & Botan::DER_Encoder::encode | ( | const secure_vector< byte > & | v, |
ASN1_Tag | real_type, | ||
ASN1_Tag | type_tag, | ||
ASN1_Tag | class_tag = CONTEXT_SPECIFIC |
||
) |
Definition at line 310 of file der_enc.cpp.
References encode().
{ return encode(&bytes[0], bytes.size(), real_type, type_tag, class_tag); }
DER_Encoder & Botan::DER_Encoder::encode | ( | const byte | v[], |
size_t | len, | ||
ASN1_Tag | real_type, | ||
ASN1_Tag | type_tag, | ||
ASN1_Tag | class_tag = CONTEXT_SPECIFIC |
||
) |
Definition at line 332 of file der_enc.cpp.
References add_object(), Botan::BIT_STRING, and Botan::OCTET_STRING.
{ if(real_type != OCTET_STRING && real_type != BIT_STRING) throw Invalid_Argument("DER_Encoder: Invalid tag for byte/bit string"); if(real_type == BIT_STRING) { secure_vector<byte> encoded; encoded.push_back(0); encoded += std::make_pair(bytes, length); return add_object(type_tag, class_tag, encoded); } else return add_object(type_tag, class_tag, bytes, length); }
DER_Encoder & Botan::DER_Encoder::encode | ( | const ASN1_Object & | obj | ) |
Definition at line 370 of file der_enc.cpp.
References Botan::ASN1_Object::encode_into().
{ obj.encode_into(*this); return (*this); }
DER_Encoder & Botan::DER_Encoder::encode_if | ( | bool | pred, |
DER_Encoder & | enc | ||
) |
Definition at line 353 of file der_enc.cpp.
References get_contents(), and raw_bytes().
{ if(cond) return raw_bytes(codec.get_contents()); return (*this); }
DER_Encoder & Botan::DER_Encoder::encode_if | ( | bool | pred, |
const ASN1_Object & | obj | ||
) |
Definition at line 360 of file der_enc.cpp.
References encode().
{ if(cond) encode(obj); return (*this); }
DER_Encoder& Botan::DER_Encoder::encode_list | ( | const std::vector< T > & | values | ) | [inline] |
Definition at line 85 of file der_enc.h.
References Botan::PEM_Code::encode().
Referenced by Botan::PK_Signer::signature().
{ for(size_t i = 0; i != values.size(); ++i) encode(values[i]); return (*this); }
Definition at line 206 of file der_enc.cpp.
References add_object(), Botan::NULL_TAG, and Botan::UNIVERSAL.
Referenced by Botan::EC_Group::DER_encode().
{ return add_object(NULL_TAG, UNIVERSAL, nullptr, 0); }
DER_Encoder& Botan::DER_Encoder::encode_optional | ( | const T & | value, |
const T & | default_value | ||
) | [inline] |
Definition at line 77 of file der_enc.h.
References Botan::PEM_Code::encode().
{ if(value != default_value) encode(value); return (*this); }
Definition at line 145 of file der_enc.cpp.
References raw_bytes().
Referenced by Botan::GOST_3410_PublicKey::algorithm_identifier(), Botan::OCSP::Request::BER_encode(), Botan::PKCS8::BER_encode(), Botan::EAC1_1_gen_CVC< Derived >::build_cert_body(), Botan::X509::create_cert_req(), Botan::ECDSA_Signature::DER_encode(), Botan::TLS::Session::DER_encode(), Botan::EC_Group::DER_encode(), Botan::DL_Group::DER_encode(), Botan::EAC1_1_gen_CVC< Derived >::encode(), Botan::Attribute::encode_into(), Botan::AlternativeName::encode_into(), Botan::X509_DN::encode_into(), Botan::AlgorithmIdentifier::encode_into(), Botan::OCSP::CertID::encode_into(), Botan::CRL_Entry::encode_into(), Botan::X509_Object::encode_into(), end_explicit(), Botan::make_cvc_cert(), Botan::EAC1_1_ADO::make_signed(), Botan::EAC1_1_gen_CVC< Derived >::make_signed(), Botan::Curve25519_PrivateKey::pkcs8_private_key(), Botan::IF_Scheme_PrivateKey::pkcs8_private_key(), Botan::EC_PrivateKey::pkcs8_private_key(), Botan::McEliece_PrivateKey::pkcs8_private_key(), Botan::ASN1::put_in_sequence(), Botan::PK_Signer::signature(), Botan::Curve25519_PublicKey::x509_subject_public_key(), and Botan::IF_Scheme_PublicKey::x509_subject_public_key().
{ if(subsequences.empty()) throw Invalid_State("DER_Encoder::end_cons: No such sequence"); secure_vector<byte> seq = subsequences[subsequences.size()-1].get_contents(); subsequences.pop_back(); raw_bytes(seq); return (*this); }
Definition at line 172 of file der_enc.cpp.
References end_cons().
Referenced by Botan::OCSP::Request::BER_encode(), Botan::X509::create_cert_req(), and Botan::AlternativeName::encode_into().
{ return end_cons(); }
secure_vector< byte > Botan::DER_Encoder::get_contents | ( | ) |
Definition at line 122 of file der_enc.cpp.
Referenced by Botan::CVC_EAC::create_ado_req(), Botan::X509::create_cert_req(), Botan::TLS::Session::DER_encode(), encode_if(), Botan::Curve25519_PrivateKey::pkcs8_private_key(), Botan::IF_Scheme_PrivateKey::pkcs8_private_key(), Botan::DL_Scheme_PrivateKey::pkcs8_private_key(), Botan::EC_PrivateKey::pkcs8_private_key(), and Botan::McEliece_PrivateKey::pkcs8_private_key().
{ if(subsequences.size() != 0) throw Invalid_State("DER_Encoder: Sequence hasn't been marked done"); secure_vector<byte> output; std::swap(output, contents); return output; }
std::vector<byte> Botan::DER_Encoder::get_contents_unlocked | ( | ) | [inline] |
Definition at line 27 of file der_enc.h.
References Botan::unlock().
Referenced by Botan::GOST_3410_PublicKey::algorithm_identifier(), Botan::OCSP::Request::BER_encode(), Botan::X509_Object::BER_encode(), Botan::PKCS8::BER_encode(), Botan::EAC1_1_gen_CVC< Derived >::build_cert_body(), Botan::CVC_EAC::create_cvc_req(), Botan::ECDSA_Signature::DER_encode(), Botan::EC_Group::DER_encode(), Botan::DL_Group::DER_encode(), Botan::EAC1_1_gen_CVC< Derived >::encode(), Botan::make_cvc_cert(), Botan::EAC1_1_ADO::make_signed(), Botan::X509_Object::make_signed(), Botan::EAC1_1_gen_CVC< Derived >::make_signed(), Botan::ASN1::put_in_sequence(), Botan::PK_Signer::signature(), Botan::DL_Scheme_PublicKey::x509_subject_public_key(), Botan::Curve25519_PublicKey::x509_subject_public_key(), Botan::IF_Scheme_PublicKey::x509_subject_public_key(), and Botan::GOST_3410_PublicKey::x509_subject_public_key().
{ return unlock(get_contents()); }
DER_Encoder & Botan::DER_Encoder::raw_bytes | ( | const byte | val[], |
size_t | len | ||
) |
Definition at line 193 of file der_enc.cpp.
Referenced by add_object(), Botan::EAC1_1_gen_CVC< Derived >::build_cert_body(), Botan::X509::create_cert_req(), Botan::CVC_EAC::create_cvc_req(), Botan::EAC1_1_gen_CVC< Derived >::encode(), encode_if(), Botan::Attribute::encode_into(), Botan::AlgorithmIdentifier::encode_into(), Botan::X509_DN::encode_into(), Botan::X509_Object::encode_into(), end_cons(), Botan::make_cvc_cert(), Botan::EAC1_1_ADO::make_signed(), Botan::X509_Object::make_signed(), Botan::EAC1_1_gen_CVC< Derived >::make_signed(), Botan::ASN1::put_in_sequence(), and raw_bytes().
{ if(subsequences.size()) subsequences[subsequences.size()-1].add_bytes(bytes, length); else contents += std::make_pair(bytes, length); return (*this); }
DER_Encoder & Botan::DER_Encoder::raw_bytes | ( | const secure_vector< byte > & | val | ) |
Definition at line 180 of file der_enc.cpp.
References raw_bytes().
{ return raw_bytes(&val[0], val.size()); }
DER_Encoder & Botan::DER_Encoder::raw_bytes | ( | const std::vector< byte > & | val | ) |
Definition at line 185 of file der_enc.cpp.
References raw_bytes().
{ return raw_bytes(&val[0], val.size()); }
DER_Encoder & Botan::DER_Encoder::start_cons | ( | ASN1_Tag | type_tag, |
ASN1_Tag | class_tag = UNIVERSAL |
||
) |
Definition at line 135 of file der_enc.cpp.
Referenced by Botan::GOST_3410_PublicKey::algorithm_identifier(), Botan::X509::BER_encode(), Botan::OCSP::Request::BER_encode(), Botan::PKCS8::BER_encode(), Botan::EAC1_1_gen_CVC< Derived >::build_cert_body(), Botan::X509::create_cert_req(), Botan::ECDSA_Signature::DER_encode(), Botan::TLS::Session::DER_encode(), Botan::EC_Group::DER_encode(), Botan::DL_Group::DER_encode(), Botan::EAC1_1_gen_CVC< Derived >::encode(), Botan::Attribute::encode_into(), Botan::AlternativeName::encode_into(), Botan::AlgorithmIdentifier::encode_into(), Botan::X509_DN::encode_into(), Botan::OCSP::CertID::encode_into(), Botan::CRL_Entry::encode_into(), Botan::Extensions::encode_into(), Botan::X509_Object::encode_into(), Botan::make_cvc_cert(), Botan::EAC1_1_ADO::make_signed(), Botan::X509_Object::make_signed(), Botan::EAC1_1_gen_CVC< Derived >::make_signed(), Botan::Curve25519_PrivateKey::pkcs8_private_key(), Botan::IF_Scheme_PrivateKey::pkcs8_private_key(), Botan::EC_PrivateKey::pkcs8_private_key(), Botan::McEliece_PrivateKey::pkcs8_private_key(), Botan::ASN1::put_in_sequence(), Botan::PK_Signer::signature(), start_explicit(), Botan::Curve25519_PublicKey::x509_subject_public_key(), and Botan::IF_Scheme_PublicKey::x509_subject_public_key().
{ subsequences.push_back(DER_Sequence(type_tag, class_tag)); return (*this); }
DER_Encoder & Botan::DER_Encoder::start_explicit | ( | u16bit | type_tag | ) |
Definition at line 159 of file der_enc.cpp.
References Botan::CONTEXT_SPECIFIC, Botan::SET, and start_cons().
Referenced by Botan::OCSP::Request::BER_encode(), Botan::X509::create_cert_req(), and Botan::AlternativeName::encode_into().
{ ASN1_Tag type_tag = static_cast<ASN1_Tag>(type_no); if(type_tag == SET) throw Internal_Error("DER_Encoder.start_explicit(SET); cannot perform"); return start_cons(type_tag, CONTEXT_SPECIFIC); }