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

#include <pk_options.h>

Public Member Functions

PK_Encryption_Options & operator= (const PK_Encryption_Options &other)=default
PK_Encryption_Options & operator= (PK_Encryption_Options &&other)=default
 PK_Encryption_Options ()=default
 PK_Encryption_Options (const PK_Encryption_Options &)=default
 PK_Encryption_Options (PK_Encryption_Options &&other)=default
std::string to_string () const
PK_Encryption_Options with_context (std::span< const uint8_t > context)
PK_Encryption_Options with_context (std::string_view context)
PK_Encryption_Options with_hash (std::string_view hash)
PK_Encryption_Options with_mgf1_hash (std::string_view hash)
PK_Encryption_Options with_padding (std::string_view padding)
PK_Encryption_Options with_provider (std::string_view provider)
 ~PK_Encryption_Options ()

Friends

class PK_Encryption_Options_Reader

Detailed Description

Public key encryption/decryption options

The normal usage of this is in a builder style, eg

PK_Encryption_Options() .with_padding("OAEP") .with_hash("SHA-256") .with_context(label)

As with PK_Signature_Options, every option that is set must be understood by the encryption scheme in use; constructing the PK_Encryptor_EME or PK_Decryptor_EME throws an exception otherwise. An option is never silently ignored.

Definition at line 219 of file pk_options.h.

Constructor & Destructor Documentation

◆ PK_Encryption_Options() [1/3]

◆ PK_Encryption_Options() [2/3]

Botan::PK_Encryption_Options::PK_Encryption_Options ( PK_Encryption_Options && other)
default

◆ PK_Encryption_Options() [3/3]

Botan::PK_Encryption_Options::PK_Encryption_Options ( const PK_Encryption_Options & )
default

◆ ~PK_Encryption_Options()

Botan::PK_Encryption_Options::~PK_Encryption_Options ( )
default

Member Function Documentation

◆ operator=() [1/2]

PK_Encryption_Options & Botan::PK_Encryption_Options::operator= ( const PK_Encryption_Options & other)
default

◆ operator=() [2/2]

PK_Encryption_Options & Botan::PK_Encryption_Options::operator= ( PK_Encryption_Options && other)
default

◆ to_string()

std::string Botan::PK_Encryption_Options::to_string ( ) const

Format this PK_Encryption_Options as a string

This is primarily intended for debugging and error messages; the format is not fixed

Definition at line 372 of file pk_options.cpp.

372 {
373 std::ostringstream out;
374
375 const auto print_str = [&](std::string_view name, const std::optional<std::string>& val) {
376 if(val.has_value()) {
377 out << name << "='" << val.value() << "' ";
378 }
379 };
380
381 print_str("Padding", m_padding);
382 print_str("Hash", m_hash_fn);
383 print_str("MGF1Hash", m_mgf1_hash_fn);
384 print_str("Provider", m_provider);
385
386 if(m_context) {
387 out << "Context=" << hex_encode(*m_context) << " ";
388 }
389
390 return out.str();
391}
const char * name
Definition ffi_tls.h:59
void hex_encode(char output[], const uint8_t input[], size_t input_length, bool uppercase)
Definition hex.cpp:34

References Botan::hex_encode(), and name.

Referenced by ~PK_Encryption_Options().

◆ with_context() [1/2]

PK_Encryption_Options Botan::PK_Encryption_Options::with_context ( std::span< const uint8_t > context)

Specify a context

For OAEP this is the label ("L" in RFC 8017). Schemes without such a parameter reject this option.

Definition at line 299 of file pk_options.cpp.

299 {
300 BOTAN_STATE_CHECK_MSG(!m_context.has_value(), "PK_Encryption_Options::with_context cannot specify context twice");
301 auto next = (*this);
302 next.m_context = std::vector<uint8_t>(context.begin(), context.end());
303 return next;
304}
#define BOTAN_STATE_CHECK_MSG(expr, msg)
Definition assert.h:59

References BOTAN_STATE_CHECK_MSG, and PK_Encryption_Options().

Referenced by with_context(), and ~PK_Encryption_Options().

◆ with_context() [2/2]

PK_Encryption_Options Botan::PK_Encryption_Options::with_context ( std::string_view context)

Specify a context as a string

Equivalent to the version taking a span above; just uses the bytes of the string instead.

Definition at line 306 of file pk_options.cpp.

306 {
307 return this->with_context(as_span_of_bytes(context));
308}
PK_Encryption_Options with_context(std::span< const uint8_t > context)
std::span< const uint8_t > as_span_of_bytes(const char *s, size_t len)
Definition mem_utils.h:59

References Botan::as_span_of_bytes(), PK_Encryption_Options(), and with_context().

◆ with_hash()

PK_Encryption_Options Botan::PK_Encryption_Options::with_hash ( std::string_view hash)

Specify the hash function

For OAEP this selects the hash used for the label and (unless with_mgf1_hash is also used) for the mask generation function. For SM2 it selects the KDF hash, and defaults to SM3.

Definition at line 280 of file pk_options.cpp.

280 {
281 BOTAN_STATE_CHECK_MSG(!m_hash_fn.has_value(), "PK_Encryption_Options::with_hash cannot specify hash twice");
282 auto next = (*this);
283 if(!hash.empty()) {
284 next.m_hash_fn = hash;
285 }
286 return next;
287}

References BOTAN_STATE_CHECK_MSG, and PK_Encryption_Options().

Referenced by Botan::parse_legacy_enc_options(), and ~PK_Encryption_Options().

◆ with_mgf1_hash()

PK_Encryption_Options Botan::PK_Encryption_Options::with_mgf1_hash ( std::string_view hash)

Specify a different hash function for OAEP's MGF1

Only OAEP supports this; by default MGF1 uses the same hash as OAEP

Definition at line 289 of file pk_options.cpp.

289 {
290 BOTAN_STATE_CHECK_MSG(!m_mgf1_hash_fn.has_value(),
291 "PK_Encryption_Options::with_mgf1_hash cannot specify MGF1 hash twice");
292 auto next = (*this);
293 if(!hash.empty()) {
294 next.m_mgf1_hash_fn = hash;
295 }
296 return next;
297}

References BOTAN_STATE_CHECK_MSG, and PK_Encryption_Options().

Referenced by ~PK_Encryption_Options().

◆ with_padding()

PK_Encryption_Options Botan::PK_Encryption_Options::with_padding ( std::string_view padding)

Specify the padding scheme

For RSA (and ElGamal) this is required, and is one of "OAEP", "PKCS1v15" or "Raw". Other schemes do not use padding.

Definition at line 271 of file pk_options.cpp.

271 {
272 BOTAN_STATE_CHECK_MSG(!m_padding.has_value(), "PK_Encryption_Options::with_padding cannot specify padding twice");
273 auto next = (*this);
274 if(!padding.empty()) {
275 next.m_padding = padding;
276 }
277 return next;
278}

References BOTAN_STATE_CHECK_MSG, and PK_Encryption_Options().

Referenced by Botan::parse_legacy_enc_options(), and ~PK_Encryption_Options().

◆ with_provider()

PK_Encryption_Options Botan::PK_Encryption_Options::with_provider ( std::string_view provider)

Specify a provider that should be used

This is rarely relevant

Definition at line 310 of file pk_options.cpp.

310 {
311 BOTAN_STATE_CHECK_MSG(provider.empty() || !m_provider.has_value(),
312 "PK_Encryption_Options::with_provider cannot specify provider twice");
313 auto next = (*this);
314 if(!provider.empty()) {
315 next.m_provider = provider;
316 }
317 return next;
318}

References BOTAN_STATE_CHECK_MSG, and PK_Encryption_Options().

Referenced by Botan::Private_Key::create_decryption_op(), Botan::Public_Key::create_encryption_op(), and ~PK_Encryption_Options().

◆ PK_Encryption_Options_Reader

friend class PK_Encryption_Options_Reader
friend

Definition at line 272 of file pk_options.h.

References PK_Encryption_Options_Reader.

Referenced by PK_Encryption_Options_Reader.


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