From 514c4e35119eca7132ca9ab38cc0de2b701da492 Mon Sep 17 00:00:00 2001 From: lloyd Date: Wed, 1 Oct 2008 15:55:40 +0000 Subject: Move get_pbe from libstate to new pbe_base module (in pbe/) --- src/core/libstate/get_pbe.cpp | 87 ------------------------------------------- src/core/libstate/get_pbe.h | 22 ----------- src/core/libstate/info.txt | 2 - src/pbe/pbe_base/get_pbe.cpp | 87 +++++++++++++++++++++++++++++++++++++++++++ src/pbe/pbe_base/get_pbe.h | 22 +++++++++++ src/pbe/pbe_base/info.txt | 15 ++++++++ src/pbe/pbes1/info.txt | 3 +- src/pbe/pbes2/info.txt | 3 +- src/pubkey/pubkey/info.txt | 5 ++- 9 files changed, 129 insertions(+), 117 deletions(-) delete mode 100644 src/core/libstate/get_pbe.cpp delete mode 100644 src/core/libstate/get_pbe.h create mode 100644 src/pbe/pbe_base/get_pbe.cpp create mode 100644 src/pbe/pbe_base/get_pbe.h create mode 100644 src/pbe/pbe_base/info.txt (limited to 'src') diff --git a/src/core/libstate/get_pbe.cpp b/src/core/libstate/get_pbe.cpp deleted file mode 100644 index cd1ed2aa4..000000000 --- a/src/core/libstate/get_pbe.cpp +++ /dev/null @@ -1,87 +0,0 @@ -/************************************************* -* PBE Retrieval Source File * -* (C) 1999-2007 Jack Lloyd * -*************************************************/ - -#include -#include -#include - -#if defined(BOTAN_HAS_PBE_PKCS_V15) - #include -#endif - -#if defined(BOTAN_HAS_PBE_PKCS_V20) - #include -#endif - -namespace Botan { - -/************************************************* -* Get an encryption PBE, set new parameters * -*************************************************/ -PBE* get_pbe(const std::string& pbe_name) - { - std::vector algo_name; - algo_name = parse_algorithm_name(pbe_name); - - if(algo_name.size() != 3) - throw Invalid_Algorithm_Name(pbe_name); - - const std::string pbe = algo_name[0]; - const std::string digest = algo_name[1]; - const std::string cipher = algo_name[2]; - - PBE* pbe_obj = 0; - -#if defined(BOTAN_HAS_PBE_PKCS_V15) - if(!pbe_obj && pbe == "PBE-PKCS5v15") - pbe_obj = new PBE_PKCS5v15(digest, cipher, ENCRYPTION); -#endif - -#if defined(BOTAN_HAS_PBE_PKCS_V20) - if(!pbe_obj && pbe == "PBE-PKCS5v20") - pbe_obj = new PBE_PKCS5v20(digest, cipher); -#endif - - if(!pbe_obj) - throw Algorithm_Not_Found(pbe_name); - - return pbe_obj; - } - -/************************************************* -* Get a decryption PBE, decode parameters * -*************************************************/ -PBE* get_pbe(const OID& pbe_oid, DataSource& params) - { - std::vector algo_name; - algo_name = parse_algorithm_name(OIDS::lookup(pbe_oid)); - - if(algo_name.size() < 1) - throw Invalid_Algorithm_Name(pbe_oid.as_string()); - const std::string pbe_algo = algo_name[0]; - - if(pbe_algo == "PBE-PKCS5v15") - { -#if defined(BOTAN_HAS_PBE_PKCS_V15) - if(algo_name.size() != 3) - throw Invalid_Algorithm_Name(pbe_oid.as_string()); - const std::string digest = algo_name[1]; - const std::string cipher = algo_name[2]; - PBE* pbe = new PBE_PKCS5v15(digest, cipher, DECRYPTION); - pbe->decode_params(params); - return pbe; -#endif - } - else if(pbe_algo == "PBE-PKCS5v20") - { -#if defined(BOTAN_HAS_PBE_PKCS_V20) - return new PBE_PKCS5v20(params); -#endif - } - - throw Algorithm_Not_Found(pbe_oid.as_string()); - } - -} diff --git a/src/core/libstate/get_pbe.h b/src/core/libstate/get_pbe.h deleted file mode 100644 index e7b434c1f..000000000 --- a/src/core/libstate/get_pbe.h +++ /dev/null @@ -1,22 +0,0 @@ -/************************************************* -* PBE Lookup Header File * -* (C) 1999-2007 Jack Lloyd * -*************************************************/ - -#ifndef BOTAN_LOOKUP_PBE_H__ -#define BOTAN_LOOKUP_PBE_H__ - -#include -#include - -namespace Botan { - -/************************************************* -* Get a PBE object * -*************************************************/ -BOTAN_DLL PBE* get_pbe(const std::string&); -BOTAN_DLL PBE* get_pbe(const OID&, DataSource&); - -} - -#endif diff --git a/src/core/libstate/info.txt b/src/core/libstate/info.txt index 81076718d..59f318a95 100644 --- a/src/core/libstate/info.txt +++ b/src/core/libstate/info.txt @@ -13,8 +13,6 @@ eng_def.h engine.cpp engine.h get_enc.cpp -get_pbe.cpp -get_pbe.h init.h init_def.cpp init_opt.cpp diff --git a/src/pbe/pbe_base/get_pbe.cpp b/src/pbe/pbe_base/get_pbe.cpp new file mode 100644 index 000000000..cd1ed2aa4 --- /dev/null +++ b/src/pbe/pbe_base/get_pbe.cpp @@ -0,0 +1,87 @@ +/************************************************* +* PBE Retrieval Source File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#include +#include +#include + +#if defined(BOTAN_HAS_PBE_PKCS_V15) + #include +#endif + +#if defined(BOTAN_HAS_PBE_PKCS_V20) + #include +#endif + +namespace Botan { + +/************************************************* +* Get an encryption PBE, set new parameters * +*************************************************/ +PBE* get_pbe(const std::string& pbe_name) + { + std::vector algo_name; + algo_name = parse_algorithm_name(pbe_name); + + if(algo_name.size() != 3) + throw Invalid_Algorithm_Name(pbe_name); + + const std::string pbe = algo_name[0]; + const std::string digest = algo_name[1]; + const std::string cipher = algo_name[2]; + + PBE* pbe_obj = 0; + +#if defined(BOTAN_HAS_PBE_PKCS_V15) + if(!pbe_obj && pbe == "PBE-PKCS5v15") + pbe_obj = new PBE_PKCS5v15(digest, cipher, ENCRYPTION); +#endif + +#if defined(BOTAN_HAS_PBE_PKCS_V20) + if(!pbe_obj && pbe == "PBE-PKCS5v20") + pbe_obj = new PBE_PKCS5v20(digest, cipher); +#endif + + if(!pbe_obj) + throw Algorithm_Not_Found(pbe_name); + + return pbe_obj; + } + +/************************************************* +* Get a decryption PBE, decode parameters * +*************************************************/ +PBE* get_pbe(const OID& pbe_oid, DataSource& params) + { + std::vector algo_name; + algo_name = parse_algorithm_name(OIDS::lookup(pbe_oid)); + + if(algo_name.size() < 1) + throw Invalid_Algorithm_Name(pbe_oid.as_string()); + const std::string pbe_algo = algo_name[0]; + + if(pbe_algo == "PBE-PKCS5v15") + { +#if defined(BOTAN_HAS_PBE_PKCS_V15) + if(algo_name.size() != 3) + throw Invalid_Algorithm_Name(pbe_oid.as_string()); + const std::string digest = algo_name[1]; + const std::string cipher = algo_name[2]; + PBE* pbe = new PBE_PKCS5v15(digest, cipher, DECRYPTION); + pbe->decode_params(params); + return pbe; +#endif + } + else if(pbe_algo == "PBE-PKCS5v20") + { +#if defined(BOTAN_HAS_PBE_PKCS_V20) + return new PBE_PKCS5v20(params); +#endif + } + + throw Algorithm_Not_Found(pbe_oid.as_string()); + } + +} diff --git a/src/pbe/pbe_base/get_pbe.h b/src/pbe/pbe_base/get_pbe.h new file mode 100644 index 000000000..e7b434c1f --- /dev/null +++ b/src/pbe/pbe_base/get_pbe.h @@ -0,0 +1,22 @@ +/************************************************* +* PBE Lookup Header File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#ifndef BOTAN_LOOKUP_PBE_H__ +#define BOTAN_LOOKUP_PBE_H__ + +#include +#include + +namespace Botan { + +/************************************************* +* Get a PBE object * +*************************************************/ +BOTAN_DLL PBE* get_pbe(const std::string&); +BOTAN_DLL PBE* get_pbe(const OID&, DataSource&); + +} + +#endif diff --git a/src/pbe/pbe_base/info.txt b/src/pbe/pbe_base/info.txt new file mode 100644 index 000000000..59cdae61f --- /dev/null +++ b/src/pbe/pbe_base/info.txt @@ -0,0 +1,15 @@ +realname "PBE Base" + +load_on auto + +define PASSWORD_BASED_ENCRYPTION + + +filters +asn1 + + + +get_pbe.cpp +get_pbe.h + diff --git a/src/pbe/pbes1/info.txt b/src/pbe/pbes1/info.txt index 96692a691..b00f4d60d 100644 --- a/src/pbe/pbes1/info.txt +++ b/src/pbe/pbes1/info.txt @@ -10,6 +10,5 @@ pbes1.h -asn1 -filters +pbe_base diff --git a/src/pbe/pbes2/info.txt b/src/pbe/pbes2/info.txt index a32f95cf0..e1e5807c2 100644 --- a/src/pbe/pbes2/info.txt +++ b/src/pbe/pbes2/info.txt @@ -10,6 +10,5 @@ pbes2.h -asn1 -filters +pbe_base diff --git a/src/pubkey/pubkey/info.txt b/src/pubkey/pubkey/info.txt index f6bb64a41..07fe1589f 100644 --- a/src/pubkey/pubkey/info.txt +++ b/src/pubkey/pubkey/info.txt @@ -1,13 +1,14 @@ realname "Public Key Base" -define PUBKEY_BASE +define PUBLIC_KEY_CRYPTO load_on dep +asn1 bigint numbertheory -asn1 +pbe_base -- cgit v1.2.3