Botan 3.12.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 702 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 711 of file x509_ext.h.

711 :
712 m_safi(safi), m_ip_addr_choice(choice) {
713 if(std::holds_alternative<IPAddressChoice<Version::IPv4>>(choice)) {
714 m_afi = 1;
715 } else {
716 m_afi = 2;
717 }
718 }

References safi().

Member Function Documentation

◆ addr_choice()

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

Definition at line 724 of file x509_ext.h.

724{ return m_ip_addr_choice; }

Referenced by decode_from().

◆ afi()

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

Definition at line 720 of file x509_ext.h.

720{ 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 20 of file asn1_obj.cpp.

20 {
21 std::vector<uint8_t> output;
22 DER_Encoder der(output);
23 this->encode_into(der);
24 return output;
25}
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 1066 of file x509_ext.cpp.

1066 {
1067 const ASN1_Type next_tag = from.peek_next_object().type_tag();
1068 if(next_tag != ASN1_Type::Sequence) {
1069 throw Decoding_Error(fmt("Unexpected type for IPAddressFamily {}", static_cast<uint32_t>(next_tag)));
1070 }
1071
1072 BER_Decoder seq_dec = from.start_sequence();
1073
1074 std::vector<uint8_t> addr_family;
1075 seq_dec.decode(addr_family, ASN1_Type::OctetString);
1076 const size_t addr_family_length = addr_family.size();
1077
1078 if(addr_family_length != 2 && addr_family_length != 3) {
1079 throw Decoding_Error("(S)AFI can only contain 2 or 3 bytes");
1080 }
1081
1082 m_afi = (addr_family[0] << 8) | addr_family[1];
1083
1084 if(addr_family_length == 3) {
1085 m_safi = addr_family[2];
1086 }
1087
1088 if(m_afi == 1) {
1089 IPAddressChoice<Version::IPv4> addr_choice;
1090 seq_dec.decode(addr_choice);
1091 m_ip_addr_choice = addr_choice;
1092 } else if(m_afi == 2) {
1093 IPAddressChoice<Version::IPv6> addr_choice;
1094 seq_dec.decode(addr_choice);
1095 m_ip_addr_choice = addr_choice;
1096 } else {
1097 throw Decoding_Error("Only AFI IPv4 and IPv6 are supported.");
1098 }
1099
1100 seq_dec.end_cons();
1101}
const BER_Object & peek_next_object()
Definition ber_dec.cpp:415
BER_Decoder & decode(bool &out)
Definition ber_dec.h:220
BER_Decoder & end_cons()
Definition ber_dec.cpp:524
BER_Decoder start_sequence()
Definition ber_dec.h:160
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 1047 of file x509_ext.cpp.

1047 {
1048 into.start_sequence();
1049
1050 std::vector<uint8_t> afam = {get_byte<0>(m_afi), get_byte<1>(m_afi)};
1051
1052 if(m_safi.has_value()) {
1053 afam.push_back(m_safi.value());
1054 }
1055
1056 into.add_object(ASN1_Type::OctetString, ASN1_Class::Universal, afam);
1057
1058 if(std::holds_alternative<IPAddressChoice<Version::IPv4>>(m_ip_addr_choice)) {
1059 into.encode(std::get<IPAddressChoice<Version::IPv4>>(m_ip_addr_choice));
1060 } else {
1061 into.encode(std::get<IPAddressChoice<Version::IPv6>>(m_ip_addr_choice));
1062 }
1063 into.end_cons();
1064}
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 722 of file x509_ext.h.

722{ return m_safi; }

Referenced by IPAddressFamily().


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