Botan 3.9.0
Crypto and TLS for C&
Botan::Cert_Extension::IPAddressBlocks::IPAddressFamily Class Referencefinal

#include <x509_ext.h>

Inheritance diagram for Botan::Cert_Extension::IPAddressBlocks::IPAddressFamily:
Botan::ASN1_Object

Public Types

typedef std::variant< IPAddressChoice< Version::IPv4 >, IPAddressChoice< Version::IPv6 > > AddrChoice

Public Member Functions

const AddrChoiceaddr_choice () const
uint16_t afi () const
std::vector< uint8_t > BER_encode () const
void decode_from (BER_Decoder &from) override
void encode_into (DER_Encoder &to) const override
 IPAddressFamily ()=default
 IPAddressFamily (const AddrChoice &choice, std::optional< uint8_t > safi=std::nullopt)
std::optional< uint8_t > safi () const

Detailed Description

Definition at line 686 of file x509_ext.h.

Member Typedef Documentation

◆ AddrChoice

Constructor & Destructor Documentation

◆ IPAddressFamily() [1/2]

Botan::Cert_Extension::IPAddressBlocks::IPAddressFamily::IPAddressFamily ( )
default

◆ IPAddressFamily() [2/2]

Botan::Cert_Extension::IPAddressBlocks::IPAddressFamily::IPAddressFamily ( const AddrChoice & choice,
std::optional< uint8_t > safi = std::nullopt )
inlineexplicit

Definition at line 695 of file x509_ext.h.

695 :
696 m_safi(safi), m_ip_addr_choice(choice) {
697 if(std::holds_alternative<IPAddressChoice<Version::IPv4>>(choice)) {
698 m_afi = 1;
699 } else {
700 m_afi = 2;
701 }
702 }

References safi().

Member Function Documentation

◆ addr_choice()

const AddrChoice & Botan::Cert_Extension::IPAddressBlocks::IPAddressFamily::addr_choice ( ) const
inline

Definition at line 708 of file x509_ext.h.

708{ return m_ip_addr_choice; }

Referenced by decode_from().

◆ afi()

uint16_t Botan::Cert_Extension::IPAddressBlocks::IPAddressFamily::afi ( ) const
inline

Definition at line 704 of file x509_ext.h.

704{ return m_afi; }

◆ BER_encode()

std::vector< uint8_t > Botan::ASN1_Object::BER_encode ( ) const
inherited

Return the encoding of this object. This is a convenience method when just one object needs to be serialized. Use DER_Encoder for complicated encodings.

Definition at line 19 of file asn1_obj.cpp.

19 {
20 std::vector<uint8_t> output;
21 DER_Encoder der(output);
22 this->encode_into(der);
23 return output;
24}
virtual void encode_into(DER_Encoder &to) const =0

References encode_into().

Referenced by decode_from(), Botan::Certificate_Store_In_SQL::find_all_certs(), Botan::Certificate_Store_In_SQL::find_cert(), Botan::X509_Certificate::fingerprint(), Botan::Certificate_Store_In_SQL::insert_cert(), Botan::X509_Object::PEM_encode(), Botan::PSS_Params::PSS_Params(), and Botan::Certificate_Store_In_SQL::revoke_cert().

◆ decode_from()

void Botan::Cert_Extension::IPAddressBlocks::IPAddressFamily::decode_from ( BER_Decoder & from)
overridevirtual

Decode whatever this object is from from

Parameters
fromthe BER_Decoder that will be read from

Implements Botan::ASN1_Object.

Definition at line 907 of file x509_ext.cpp.

907 {
908 const ASN1_Type next_tag = from.peek_next_object().type_tag();
909 if(next_tag != ASN1_Type::Sequence) {
910 throw Decoding_Error(fmt("Unexpected type for IPAddressFamily {}", static_cast<uint32_t>(next_tag)));
911 }
912
913 BER_Decoder seq_dec = from.start_sequence();
914
915 std::vector<uint8_t> addr_family;
916 seq_dec.decode(addr_family, ASN1_Type::OctetString);
917 const size_t addr_family_length = addr_family.size();
918
919 if(addr_family_length != 2 && addr_family_length != 3) {
920 throw Decoding_Error("(S)AFI can only contain 2 or 3 bytes");
921 }
922
923 m_afi = (addr_family[0] << 8) | addr_family[1];
924
925 if(addr_family_length == 3) {
926 m_safi = addr_family[2];
927 }
928
929 if(m_afi == 1) {
930 IPAddressChoice<Version::IPv4> addr_choice;
931 seq_dec.decode(addr_choice);
932 m_ip_addr_choice = addr_choice;
933 } else if(m_afi == 2) {
934 IPAddressChoice<Version::IPv6> addr_choice;
935 seq_dec.decode(addr_choice);
936 m_ip_addr_choice = addr_choice;
937 } else {
938 throw Decoding_Error("Only AFI IPv4 and IPv6 are supported.");
939 }
940
941 seq_dec.end_cons();
942}
const BER_Object & peek_next_object()
Definition ber_dec.cpp:237
BER_Decoder & decode(bool &out)
Definition ber_dec.h:188
BER_Decoder & end_cons()
Definition ber_dec.cpp:312
BER_Decoder start_sequence()
Definition ber_dec.h:125
ASN1_Type type_tag() const
Definition asn1_obj.h:142
std::string fmt(std::string_view format, const T &... args)
Definition fmt.h:53
ASN1_Type
Definition asn1_obj.h:43

References addr_choice(), Botan::BER_Decoder::decode(), Botan::BER_Decoder::end_cons(), Botan::fmt(), Botan::OctetString, Botan::BER_Decoder::peek_next_object(), Botan::Sequence, Botan::BER_Decoder::start_sequence(), and Botan::BER_Object::type_tag().

◆ encode_into()

void Botan::Cert_Extension::IPAddressBlocks::IPAddressFamily::encode_into ( DER_Encoder & to) const
overridevirtual

Encode whatever this object is into to

Parameters
tothe DER_Encoder that will be written to

Implements Botan::ASN1_Object.

Definition at line 888 of file x509_ext.cpp.

888 {
889 into.start_sequence();
890
891 std::vector<uint8_t> afam = {get_byte<0>(m_afi), get_byte<1>(m_afi)};
892
893 if(m_safi.has_value()) {
894 afam.push_back(m_safi.value());
895 }
896
897 into.add_object(ASN1_Type::OctetString, ASN1_Class::Universal, afam);
898
899 if(std::holds_alternative<IPAddressChoice<Version::IPv4>>(m_ip_addr_choice)) {
900 into.encode(std::get<IPAddressChoice<Version::IPv4>>(m_ip_addr_choice));
901 } else {
902 into.encode(std::get<IPAddressChoice<Version::IPv6>>(m_ip_addr_choice));
903 }
904 into.end_cons();
905}
constexpr uint8_t get_byte(T input)
Definition loadstor.h:79

References Botan::DER_Encoder::add_object(), Botan::DER_Encoder::encode(), Botan::DER_Encoder::end_cons(), Botan::get_byte(), Botan::OctetString, Botan::DER_Encoder::start_sequence(), and Botan::Universal.

◆ safi()

std::optional< uint8_t > Botan::Cert_Extension::IPAddressBlocks::IPAddressFamily::safi ( ) const
inline

Definition at line 706 of file x509_ext.h.

706{ return m_safi; }

Referenced by IPAddressFamily().


The documentation for this class was generated from the following files: