Botan 3.13.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 1026 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 1035 of file x509_ext.h.

1035 :
1036 m_safi(safi), m_ip_addr_choice(choice) {
1037 if(std::holds_alternative<IPAddressChoice<Version::IPv4>>(choice)) {
1038 m_afi = 1;
1039 } else {
1040 m_afi = 2;
1041 }
1042 }

References safi().

Member Function Documentation

◆ addr_choice()

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

Definition at line 1048 of file x509_ext.h.

1048{ return m_ip_addr_choice; }

Referenced by decode_from().

◆ afi()

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

Definition at line 1044 of file x509_ext.h.

1044{ 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 21 of file asn1_obj.cpp.

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

References encode_into().

Referenced by decode_from(), Botan::PKCS12::export_to(), 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(), and Botan::PSS_Params::PSS_Params().

◆ 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 1741 of file x509_ext.cpp.

1741 {
1742 const ASN1_Type next_tag = from.peek_next_object().type_tag();
1743 if(next_tag != ASN1_Type::Sequence) {
1744 throw Decoding_Error(fmt("Unexpected type for IPAddressFamily {}", static_cast<uint32_t>(next_tag)));
1745 }
1746
1747 BER_Decoder seq_dec = from.start_sequence();
1748
1749 std::vector<uint8_t> addr_family;
1750 seq_dec.decode(addr_family, ASN1_Type::OctetString);
1751 const size_t addr_family_length = addr_family.size();
1752
1753 if(addr_family_length != 2 && addr_family_length != 3) {
1754 throw Decoding_Error("(S)AFI can only contain 2 or 3 bytes");
1755 }
1756
1757 m_afi = (addr_family[0] << 8) | addr_family[1];
1758
1759 if(addr_family_length == 3) {
1760 m_safi = addr_family[2];
1761 }
1762
1763 if(m_afi == 1) {
1764 IPAddressChoice<Version::IPv4> addr_choice;
1765 seq_dec.decode(addr_choice);
1766 m_ip_addr_choice = addr_choice;
1767 } else if(m_afi == 2) {
1768 IPAddressChoice<Version::IPv6> addr_choice;
1769 seq_dec.decode(addr_choice);
1770 m_ip_addr_choice = addr_choice;
1771 } else {
1772 throw Decoding_Error("Only AFI IPv4 and IPv6 are supported.");
1773 }
1774
1775 seq_dec.end_cons();
1776}
const BER_Object & peek_next_object()
Definition ber_dec.cpp:505
BER_Decoder & decode(bool &out)
Definition ber_dec.h:358
BER_Decoder & end_cons()
Definition ber_dec.cpp:630
BER_Decoder start_sequence()
Definition ber_dec.h:275
ASN1_Type type_tag() const
Definition asn1_obj.h:277
std::string fmt(std::string_view format, const T &... args)
Definition fmt.h:53
ASN1_Type
Definition asn1_obj.h:47

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 1722 of file x509_ext.cpp.

1722 {
1723 into.start_sequence();
1724
1725 std::vector<uint8_t> afam = {get_byte<0>(m_afi), get_byte<1>(m_afi)};
1726
1727 if(m_safi.has_value()) {
1728 afam.push_back(m_safi.value());
1729 }
1730
1731 into.add_object(ASN1_Type::OctetString, ASN1_Class::Universal, afam);
1732
1733 if(std::holds_alternative<IPAddressChoice<Version::IPv4>>(m_ip_addr_choice)) {
1734 into.encode(std::get<IPAddressChoice<Version::IPv4>>(m_ip_addr_choice));
1735 } else {
1736 into.encode(std::get<IPAddressChoice<Version::IPv6>>(m_ip_addr_choice));
1737 }
1738 into.end_cons();
1739}
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 1046 of file x509_ext.h.

1046{ return m_safi; }

Referenced by botan_x509_ext_ip_addr_blocks_get_family(), and IPAddressFamily().


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