aboutsummaryrefslogtreecommitdiffstats
path: root/src/core/get_pbe.cpp
diff options
context:
space:
mode:
authorlloyd <[email protected]>2008-09-29 00:15:14 +0000
committerlloyd <[email protected]>2008-09-29 00:15:14 +0000
commit68d3d539ad7752dc80c20c1a2ade909b1a4c4a6e (patch)
treec7e588d28427960c95eca9900844d5bf36c079df /src/core/get_pbe.cpp
parent8269e2897e0a652bbd949d38b74873976a98adeb (diff)
Move what is left of the uncategorized library to 'core'. There is still
a lot of public key stuff in here that needs to be extracted however, and probably 2-3 other modules worth of stuff to split off (engines, etc)
Diffstat (limited to 'src/core/get_pbe.cpp')
-rw-r--r--src/core/get_pbe.cpp88
1 files changed, 88 insertions, 0 deletions
diff --git a/src/core/get_pbe.cpp b/src/core/get_pbe.cpp
new file mode 100644
index 000000000..6bd85b3e1
--- /dev/null
+++ b/src/core/get_pbe.cpp
@@ -0,0 +1,88 @@
+/*************************************************
+* PBE Retrieval Source File *
+* (C) 1999-2007 Jack Lloyd *
+*************************************************/
+
+#include <botan/lookup.h>
+#include <botan/pbe.h>
+#include <botan/oids.h>
+#include <botan/parsing.h>
+
+#if defined(BOTAN_HAS_PBE_PKCS_V15)
+ #include <botan/pbes1.h>
+#endif
+
+#if defined(BOTAN_HAS_PBE_PKCS_V20)
+ #include <botan/pbes2.h>
+#endif
+
+namespace Botan {
+
+/*************************************************
+* Get an encryption PBE, set new parameters *
+*************************************************/
+PBE* get_pbe(const std::string& pbe_name)
+ {
+ std::vector<std::string> 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<std::string> 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());
+ }
+
+}