Botan 3.14.1
Crypto and TLS for C&
Botan::HPKE::AEAD_Id Class Referencefinal

#include <hpke.h>

Public Member Functions

constexpr AEAD_Id (AEAD_Code code)
constexpr AEAD_Id (uint16_t code)
constexpr AEAD_Code code () const
bool is_available () const
constexpr bool is_export_only () const
constexpr bool is_known () const
size_t key_length () const
 Return the constant Nk from RFC 9180 Section 7.3, throws for invalid code points.
size_t nonce_length () const
 Return the constant Nn from RFC 9180 Section 7.3, throws for invalid code points.
constexpr bool operator== (AEAD_Code code) const
constexpr bool operator== (const AEAD_Id &other) const
size_t tag_length () const
 Return the constant Nt from RFC 9180 Section 7.3, throws for invalid code points.
std::optional< std::string > to_string () const
constexpr uint16_t wire_code () const

Detailed Description

Identifies the AEAD used by an HPKE ciphersuite

Definition at line 183 of file hpke.h.

Constructor & Destructor Documentation

◆ AEAD_Id() [1/2]

Botan::HPKE::AEAD_Id::AEAD_Id ( AEAD_Code code)
inlineconstexpr

Definition at line 188 of file hpke.h.

188: m_code(code) {}
constexpr AEAD_Code code() const
Definition hpke.h:194

References code().

Referenced by operator==().

◆ AEAD_Id() [2/2]

Botan::HPKE::AEAD_Id::AEAD_Id ( uint16_t code)
inlineconstexpr

Definition at line 192 of file hpke.h.

192: m_code(static_cast<AEAD_Code>(code)) {}

References code().

Member Function Documentation

◆ code()

AEAD_Code Botan::HPKE::AEAD_Id::code ( ) const
inlineconstexpr

Definition at line 194 of file hpke.h.

194{ return m_code; }

Referenced by AEAD_Id(), AEAD_Id(), and operator==().

◆ is_available()

bool Botan::HPKE::AEAD_Id::is_available ( ) const

Definition at line 172 of file hpke.cpp.

172 {
173 if(is_export_only()) {
174 return true;
175 }
176 if(const auto info = aead_info(m_code)) {
177 return AEAD_Mode::create(info->spec, Cipher_Dir::Encryption) != nullptr;
178 }
179 return false;
180}
static std::unique_ptr< AEAD_Mode > create(std::string_view algo, Cipher_Dir direction, std::string_view provider="")
Definition aead.cpp:61
constexpr bool is_export_only() const
Definition hpke.h:217

References Botan::AEAD_Mode::create(), Botan::Encryption, and is_export_only().

◆ is_export_only()

bool Botan::HPKE::AEAD_Id::is_export_only ( ) const
inlineconstexpr

An export-only suite creates contexts usable only for export_secret See RFC 9180 Section 5.3

Definition at line 217 of file hpke.h.

217{ return m_code == AEAD_Code::ExportOnly; }

References Botan::HPKE::ExportOnly.

Referenced by is_available(), and to_string().

◆ is_known()

bool Botan::HPKE::AEAD_Id::is_known ( ) const
inlineconstexpr

Definition at line 202 of file hpke.h.

202 {
203 switch(m_code) {
208 return true;
209 }
210 return false;
211 }

References Botan::HPKE::AES_128_GCM, Botan::HPKE::AES_256_GCM, Botan::HPKE::ChaCha20Poly1305, and Botan::HPKE::ExportOnly.

◆ key_length()

size_t Botan::HPKE::AEAD_Id::key_length ( ) const

Return the constant Nk from RFC 9180 Section 7.3, throws for invalid code points.

Definition at line 182 of file hpke.cpp.

182 {
183 if(const auto info = aead_info(m_code)) {
184 return info->nk;
185 }
186 throw Invalid_State(fmt("HPKE AEAD {} does not define a key length", wire_code()));
187}
constexpr uint16_t wire_code() const
Definition hpke.h:196
std::string fmt(std::string_view format, const T &... args)
Definition fmt.h:53

References Botan::fmt(), and wire_code().

◆ nonce_length()

size_t Botan::HPKE::AEAD_Id::nonce_length ( ) const

Return the constant Nn from RFC 9180 Section 7.3, throws for invalid code points.

Definition at line 189 of file hpke.cpp.

189 {
190 if(const auto info = aead_info(m_code)) {
191 return info->nn;
192 }
193 throw Invalid_State(fmt("HPKE AEAD {} does not define a nonce length", wire_code()));
194}

References Botan::fmt(), and wire_code().

◆ operator==() [1/2]

bool Botan::HPKE::AEAD_Id::operator== ( AEAD_Code code) const
inlineconstexpr

Definition at line 200 of file hpke.h.

200{ return m_code == code; }

References code().

◆ operator==() [2/2]

bool Botan::HPKE::AEAD_Id::operator== ( const AEAD_Id & other) const
inlineconstexpr

Definition at line 198 of file hpke.h.

198{ return m_code == other.m_code; }

References AEAD_Id().

◆ tag_length()

size_t Botan::HPKE::AEAD_Id::tag_length ( ) const

Return the constant Nt from RFC 9180 Section 7.3, throws for invalid code points.

Definition at line 196 of file hpke.cpp.

196 {
197 if(const auto info = aead_info(m_code)) {
198 return info->nt;
199 }
200 throw Invalid_State(fmt("HPKE AEAD {} does not define a tag length", wire_code()));
201}

References Botan::fmt(), and wire_code().

◆ to_string()

std::optional< std::string > Botan::HPKE::AEAD_Id::to_string ( ) const

Definition at line 203 of file hpke.cpp.

203 {
204 if(is_export_only()) {
205 return std::string("export-only");
206 }
207 if(const auto info = aead_info(m_code)) {
208 return std::string(info->name);
209 }
210 return std::nullopt;
211}

References is_export_only().

◆ wire_code()

uint16_t Botan::HPKE::AEAD_Id::wire_code ( ) const
inlineconstexpr

Definition at line 196 of file hpke.h.

196{ return static_cast<uint16_t>(m_code); }

Referenced by key_length(), nonce_length(), and tag_length().


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