Botan 3.14.1
Crypto and TLS for C&
Botan::Cert_Extension::TNAuthList::Entry Class Referencefinal

#include <x509_ext.h>

Inheritance diagram for Botan::Cert_Extension::TNAuthList::Entry:
Botan::ASN1_Object

Classes

struct  TelephoneNumberRangeData

Public Types

using DataContainer = std::variant<ASN1_String, RangeContainer>
using RangeContainer = std::vector<TelephoneNumberRangeData>
enum  Type : uint8_t { ServiceProviderCode = 0 , TelephoneNumberRange = 1 , TelephoneNumber = 2 }

Public Member Functions

std::vector< uint8_t > BER_encode () const
void decode_from (BER_Decoder &from) override
void encode_into (DER_Encoder &to) const override
 Entry ()=default
const Botan::TelephoneNumber & number () const
const Botan::TelephoneNumberRange & range () const
const std::string & service_provider_code () const
const std::string & telephone_number () const
const RangeContainer & telephone_number_range () const
Type type () const

Static Public Member Functions

static Entry from_service_provider_code (std::string_view spc)
static Entry from_telephone_number (const Botan::TelephoneNumber &tn)
static Entry from_telephone_number_range (const Botan::TelephoneNumberRange &range)

Detailed Description

Definition at line 870 of file x509_ext.h.

Member Typedef Documentation

◆ DataContainer

◆ RangeContainer

Member Enumeration Documentation

◆ Type

The TNEntry CHOICE alternative; the values are the context specific tags

Enumerator
ServiceProviderCode 
TelephoneNumberRange 
TelephoneNumber 

Definition at line 875 of file x509_ext.h.

Constructor & Destructor Documentation

◆ Entry()

Botan::Cert_Extension::TNAuthList::Entry::Entry ( )
default

Default constructor; the entry is only meaningful once decoded

References decode_from(), and encode_into().

Referenced by from_service_provider_code(), from_telephone_number(), and from_telephone_number_range().

Member Function Documentation

◆ 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::TNAuthList::Entry::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 1667 of file x509_ext.cpp.

1667 {
1668 const auto decode_ia5_string = [](BER_Decoder& from, std::string_view what) {
1669 ASN1_String str;
1670 from.decode(str);
1671 if(str.tagging() != ASN1_Type::Ia5String) {
1672 throw Decoding_Error(fmt("TNAuthList {} must be an IA5String", what));
1673 }
1674 return str.value();
1675 };
1676
1677 const BER_Object obj = ber.get_next_object();
1678
1679 // The TNEntry alternatives are explicitly tagged so each is constructed
1680 if(obj.get_class() != (ASN1_Class::ContextSpecific | ASN1_Class::Constructed)) {
1681 throw Decoding_Error(fmt("Unexpected TNEntry class tag {}", static_cast<uint32_t>(obj.get_class())));
1682 }
1683
1684 const uint32_t type_tag = static_cast<uint32_t>(obj.type_tag());
1685 BER_Decoder inner(obj, ber.limits());
1686
1687 if(type_tag == ServiceProviderCode) {
1688 m_type = ServiceProviderCode;
1689 m_data = decode_ia5_string(inner, "ServiceProviderCode");
1690 } else if(type_tag == TelephoneNumberRange) {
1691 BER_Decoder range = inner.start_sequence();
1692
1693 const auto start = Botan::TelephoneNumber::from_string(decode_ia5_string(range, "TelephoneNumberRange start"));
1694 if(!start.has_value()) {
1695 throw Decoding_Error("Invalid TelephoneNumberRange start");
1696 }
1697
1698 BigInt count;
1699 range.decode(count);
1700 // count INTEGER (2..MAX), but no value over 64 bits fits within a 15 digit number
1701 if(count.is_negative() || count.bits() > 64) {
1702 throw Decoding_Error("Invalid TelephoneNumberRange count");
1703 }
1704 uint64_t count_value = 0;
1705 for(size_t i = 0; i != 8; ++i) {
1706 count_value = (count_value << 8) | count.byte_at(7 - i);
1707 }
1708 if(count_value < 2) {
1709 throw Decoding_Error("Invalid TelephoneNumberRange count");
1710 }
1711
1712 auto tn_range = Botan::TelephoneNumberRange::from(*start, count_value);
1713 if(!tn_range.has_value()) {
1714 throw Decoding_Error("Invalid TelephoneNumberRange");
1715 }
1716
1717 // TelephoneNumberRange is extensible; skip any additions following count
1718 while(range.more_items()) {
1719 range.get_next_object();
1720 }
1721 range.end_cons();
1722
1723 set_range(std::move(*tn_range));
1724 } else if(type_tag == TelephoneNumber) {
1725 m_type = TelephoneNumber;
1726 auto tn = Botan::TelephoneNumber::from_string(decode_ia5_string(inner, "TelephoneNumber"));
1727 if(!tn.has_value()) {
1728 throw Decoding_Error("Invalid TelephoneNumber");
1729 }
1730 m_data = std::move(*tn);
1731 } else {
1732 throw Decoding_Error(fmt("Unexpected TNEntry type code {}", type_tag));
1733 }
1734
1735 inner.verify_end();
1736}
const Botan::TelephoneNumberRange & range() const
static std::optional< TelephoneNumberRange > from(const TelephoneNumber &start, uint64_t count)
static std::optional< TelephoneNumber > from_string(std::string_view tn)
std::string fmt(std::string_view format, const T &... args)
Definition fmt.h:53

References Botan::BigInt::bits(), Botan::BigInt::byte_at(), Botan::Constructed, Botan::ContextSpecific, Botan::BER_Decoder::decode(), Botan::fmt(), Botan::TelephoneNumberRange::from(), Botan::TelephoneNumber::from_string(), Botan::BER_Object::get_class(), Botan::BER_Decoder::get_next_object(), Botan::Ia5String, Botan::BigInt::is_negative(), Botan::BER_Decoder::limits(), range(), ServiceProviderCode, Botan::BER_Decoder::start_sequence(), Botan::ASN1_String::tagging(), TelephoneNumber, TelephoneNumberRange, Botan::BER_Object::type_tag(), Botan::ASN1_String::value(), and Botan::BER_Decoder::verify_end().

Referenced by Entry().

◆ encode_into()

void Botan::Cert_Extension::TNAuthList::Entry::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 1644 of file x509_ext.cpp.

1644 {
1645 switch(m_type) {
1647 to.start_explicit(ServiceProviderCode)
1648 .encode(ASN1_String(service_provider_code(), ASN1_Type::Ia5String))
1649 .end_cons();
1650 return;
1652 to.start_explicit(TelephoneNumberRange)
1653 .start_sequence()
1654 .encode(ASN1_String(range().start().to_string(), ASN1_Type::Ia5String))
1655 .encode(BigInt::from_u64(range().count()))
1656 .end_cons()
1657 .end_cons();
1658 return;
1659 case TelephoneNumber:
1660 to.start_explicit(TelephoneNumber).encode(ASN1_String(number().to_string(), ASN1_Type::Ia5String)).end_cons();
1661 return;
1662 }
1663
1664 throw Invalid_State("TNAuthList::Entry has an invalid type");
1665}
static BigInt from_u64(uint64_t n)
Definition bigint.cpp:31
const std::string & service_provider_code() const
const Botan::TelephoneNumber & number() const
std::string to_string(ErrorType type)
Convert an ErrorType to string.
Definition exceptn.cpp:13

References Botan::DER_Encoder::encode(), Botan::DER_Encoder::end_cons(), Botan::BigInt::from_u64(), Botan::Ia5String, number(), range(), service_provider_code(), ServiceProviderCode, Botan::DER_Encoder::start_explicit(), Botan::DER_Encoder::start_sequence(), TelephoneNumber, TelephoneNumberRange, and Botan::to_string().

Referenced by Entry().

◆ from_service_provider_code()

TNAuthList::Entry Botan::Cert_Extension::TNAuthList::Entry::from_service_provider_code ( std::string_view spc)
static

Create a service provider code entry, for instance an OCN or SPID

Throws Invalid_Argument if spc is empty or not IA5

Definition at line 1616 of file x509_ext.cpp.

1616 {
1617 if(spc.empty()) {
1618 throw Invalid_Argument("TNAuthList service provider code cannot be empty");
1619 }
1620 Entry entry;
1621 entry.m_type = ServiceProviderCode;
1622 // Constructing the ASN1_String checks that the code is valid IA5
1623 entry.m_data = ASN1_String(spc, ASN1_Type::Ia5String).value();
1624 return entry;
1625}

References Entry(), Botan::Ia5String, ServiceProviderCode, and Botan::ASN1_String::value().

◆ from_telephone_number()

TNAuthList::Entry Botan::Cert_Extension::TNAuthList::Entry::from_telephone_number ( const Botan::TelephoneNumber & tn)
static

Create a single telephone number entry

Definition at line 1637 of file x509_ext.cpp.

1637 {
1638 Entry entry;
1639 entry.m_type = TelephoneNumber;
1640 entry.m_data = tn;
1641 return entry;
1642}

References Entry(), and TelephoneNumber.

◆ from_telephone_number_range()

TNAuthList::Entry Botan::Cert_Extension::TNAuthList::Entry::from_telephone_number_range ( const Botan::TelephoneNumberRange & range)
static

Create a telephone number range entry

Throws Invalid_Argument if range holds fewer than two numbers

Definition at line 1627 of file x509_ext.cpp.

1627 {
1628 // count INTEGER (2..MAX)
1629 if(range.count() < 2) {
1630 throw Invalid_Argument("TNAuthList range must contain at least two numbers");
1631 }
1632 Entry entry;
1633 entry.set_range(range);
1634 return entry;
1635}

References Entry(), and range().

◆ number()

const Botan::TelephoneNumber & Botan::Cert_Extension::TNAuthList::Entry::number ( ) const

Return the telephone number; throws unless type() is TelephoneNumber

Definition at line 1775 of file x509_ext.cpp.

1775 {
1777 return std::get<Botan::TelephoneNumber>(m_data);
1778}
#define BOTAN_STATE_CHECK(expr)
Definition assert.h:49

References BOTAN_STATE_CHECK, TelephoneNumber, and type().

Referenced by encode_into(), and telephone_number().

◆ range()

const Botan::TelephoneNumberRange & Botan::Cert_Extension::TNAuthList::Entry::range ( ) const

Return the range; throws unless type() is TelephoneNumberRange

Definition at line 1770 of file x509_ext.cpp.

1770 {
1772 return std::get<Botan::TelephoneNumberRange>(m_data);
1773}

References BOTAN_STATE_CHECK, TelephoneNumberRange, and type().

Referenced by decode_from(), encode_into(), and from_telephone_number_range().

◆ service_provider_code()

const std::string & Botan::Cert_Extension::TNAuthList::Entry::service_provider_code ( ) const

Return the service provider code; throws unless type() is ServiceProviderCode

Definition at line 1765 of file x509_ext.cpp.

1765 {
1767 return std::get<std::string>(m_data);
1768}

References BOTAN_STATE_CHECK, ServiceProviderCode, and type().

Referenced by encode_into().

◆ telephone_number()

const std::string & Botan::Cert_Extension::TNAuthList::Entry::telephone_number ( ) const

Return the telephone number as a string; throws unless type() is TelephoneNumber

Definition at line 1798 of file x509_ext.cpp.

1798 {
1799 return number().to_string();
1800}
const std::string & to_string() const

References number().

◆ telephone_number_range()

const TNAuthList::Entry::RangeContainer & Botan::Cert_Extension::TNAuthList::Entry::telephone_number_range ( ) const

Return the range as a single element list; throws unless type() is TelephoneNumberRange

Definition at line 1790 of file x509_ext.cpp.

1790 {
1792 if(m_legacy_range.empty()) {
1793 throw Invalid_State("TNAuthList range count does not fit in size_t, use range() instead");
1794 }
1795 return m_legacy_range;
1796}

References BOTAN_STATE_CHECK, TelephoneNumberRange, and type().

◆ type()

Type Botan::Cert_Extension::TNAuthList::Entry::type ( ) const
inline

Definition at line 919 of file x509_ext.h.

919{ return m_type; }

Referenced by number(), range(), service_provider_code(), and telephone_number_range().


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