Botan 3.14.1
Crypto and TLS for C&
Botan::TelephoneNumber Class Referencefinal

#include <telephone_number.h>

Public Member Functions

bool is_wildcard () const
size_t length () const
std::optional< uint64_t > numeric_value () const
auto operator<=> (const TelephoneNumber &) const =default
const std::string & to_string () const

Static Public Member Functions

static std::optional< TelephoneNumber > from_string (std::string_view tn)

Detailed Description

A telephone number as used in RFC 8226 STIR certificates

TelephoneNumber ::= IA5String (SIZE (1..15)) (FROM ("0123456789#*"))

This is the dialed form rather than E.164: '*' and '#' may appear, and leading zeros are significant, so "0123" and "123" are distinct numbers.

Definition at line 25 of file telephone_number.h.

Member Function Documentation

◆ from_string()

std::optional< TelephoneNumber > Botan::TelephoneNumber::from_string ( std::string_view tn)
static

Parse a telephone number

Returns
the number, or nullopt unless tn is 1 to 15 characters from "0123456789#*"

Definition at line 13 of file telephone_number.cpp.

13 {
14 // TelephoneNumber ::= IA5String (SIZE (1..15)) (FROM ("0123456789#*"))
15 if(tn.empty() || tn.size() > 15 || tn.find_first_not_of("0123456789#*") != std::string_view::npos) {
16 return std::nullopt;
17 }
18 return TelephoneNumber(std::string(tn));
19}

Referenced by Botan::Cert_Extension::TNAuthList::Entry::decode_from(), and Botan::TelephoneNumberRange::last().

◆ is_wildcard()

bool Botan::TelephoneNumber::is_wildcard ( ) const
Returns
true if the number contains '*' or '#'

Definition at line 21 of file telephone_number.cpp.

21 {
22 return m_number.find_first_of("*#") != std::string::npos;
23}

Referenced by numeric_value().

◆ length()

size_t Botan::TelephoneNumber::length ( ) const
inline
Returns
the length of the number in characters

Definition at line 46 of file telephone_number.h.

46{ return m_number.size(); }

Referenced by Botan::TelephoneNumberRange::contains(), Botan::TelephoneNumberRange::contains(), and Botan::Cert_Extension::TNAuthList::encompasses().

◆ numeric_value()

std::optional< uint64_t > Botan::TelephoneNumber::numeric_value ( ) const
Returns
the number as an integer, or nullopt if is_wildcard()

Definition at line 25 of file telephone_number.cpp.

25 {
26 if(is_wildcard()) {
27 return std::nullopt;
28 }
29 uint64_t value = 0;
30 for(const char c : m_number) {
31 value = (value * 10) + static_cast<uint64_t>(c - '0');
32 }
33 return value;
34}

References is_wildcard().

Referenced by Botan::TelephoneNumberRange::contains(), Botan::TelephoneNumberRange::contains(), Botan::Cert_Extension::TNAuthList::encompasses(), and Botan::TelephoneNumberRange::last().

◆ operator<=>()

auto Botan::TelephoneNumber::operator<=> ( const TelephoneNumber & ) const
default

Numbers are ordered by their string form

◆ to_string()

const std::string & Botan::TelephoneNumber::to_string ( ) const
inline
Returns
the number as it was given

Definition at line 36 of file telephone_number.h.

36{ return m_number; }

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