Botan 3.14.1
Crypto and TLS for C&
enc_padding.cpp
Go to the documentation of this file.
1/*
2* (C) 1999-2008 Jack Lloyd
3*
4* Botan is released under the Simplified BSD License (see license.txt)
5*/
6
7#include <botan/internal/enc_padding.h>
8
9#include <botan/exceptn.h>
10#include <botan/pk_options_readers.h>
11
12#if defined(BOTAN_HAS_EME_OAEP)
13 #include <botan/internal/oaep.h>
14#endif
15
16#if defined(BOTAN_HAS_EME_PKCS1)
17 #include <botan/internal/eme_pkcs.h>
18#endif
19
20#if defined(BOTAN_HAS_EME_RAW)
21 #include <botan/internal/eme_raw.h>
22#endif
23
24namespace Botan {
25
26std::unique_ptr<EncryptionPaddingScheme> EncryptionPaddingScheme::create_or_throw(
27 const PK_Encryption_Options_Reader& options) {
28 // Encrypting without padding is dangerous, so it must be requested explicitly
29 if(!options.using_padding()) {
30 throw Lookup_Error("Public key encryption requires specifying a padding scheme");
31 }
32
33 const std::string& padding = options.padding().value();
34
35 // Any option not examined by the selected scheme is rejected by the caller
36
37#if defined(BOTAN_HAS_EME_RAW)
38 if(padding == "Raw") {
39 return std::make_unique<EME_Raw>();
40 }
41#endif
42
43#if defined(BOTAN_HAS_EME_PKCS1)
44 if(padding == "PKCS1v15") {
45 return std::make_unique<EME_PKCS1v15>();
46 }
47#endif
48
49#if defined(BOTAN_HAS_EME_OAEP)
50 if(padding == "OAEP") {
51 return std::make_unique<OAEP>(options);
52 }
53#endif
54
55 throw Lookup_Error("Invalid or unavailable encryption padding scheme " + options.to_string());
56}
57
59
60} // namespace Botan
static std::unique_ptr< EncryptionPaddingScheme > create_or_throw(const PK_Encryption_Options_Reader &options)
std::string to_string() const
Format the options as a string, for error messages.
const std::optional< std::string > & padding() const