aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlloyd <[email protected]>2008-10-26 21:02:33 +0000
committerlloyd <[email protected]>2008-10-26 21:02:33 +0000
commita5572385088e399eecf5531074aecabadf24d611 (patch)
tree2735cbd23715bff478ca9f004e94ac6287e32f7e
parent9b7cd20217d1134754daf2b2046249607ab7a3a7 (diff)
Remove lookup.h use from OpenPGP S2K
-rw-r--r--src/libstate/def_alg.cpp15
-rw-r--r--src/s2k/pgps2k/pgp_s2k.cpp14
-rw-r--r--src/s2k/pgps2k/pgp_s2k.h8
3 files changed, 14 insertions, 23 deletions
diff --git a/src/libstate/def_alg.cpp b/src/libstate/def_alg.cpp
index 6f89fa121..3c3cc5f7a 100644
--- a/src/libstate/def_alg.cpp
+++ b/src/libstate/def_alg.cpp
@@ -275,14 +275,6 @@ namespace Botan {
throw Invalid_Algorithm_Name(algo_spec); \
}
-#define HANDLE_TYPE_ONE_STRING(NAME, TYPE) \
- if(algo_name == NAME) \
- { \
- if(name.size() == 2) \
- return new TYPE(name[1]); \
- throw Invalid_Algorithm_Name(algo_spec); \
- }
-
/*************************************************
* Look for an algorithm with this name *
*************************************************/
@@ -629,7 +621,12 @@ S2K* Default_Engine::find_s2k(const std::string& algo_spec) const
#endif
#if defined(BOTAN_HAS_PGPS2K)
- HANDLE_TYPE_ONE_STRING("OpenPGP-S2K", OpenPGP_S2K);
+ if(algo_name == "OpenPGP-S2K")
+ {
+ if(name.size() == 2)
+ return new OpenPGP_S2K(get_hash(name[1]));
+ throw Invalid_Algorithm_Name(algo_spec);
+ }
#endif
return 0;
diff --git a/src/s2k/pgps2k/pgp_s2k.cpp b/src/s2k/pgps2k/pgp_s2k.cpp
index 66a243e45..b96fdf83b 100644
--- a/src/s2k/pgps2k/pgp_s2k.cpp
+++ b/src/s2k/pgps2k/pgp_s2k.cpp
@@ -4,7 +4,6 @@
*************************************************/
#include <botan/pgp_s2k.h>
-#include <botan/lookup.h>
#include <algorithm>
#include <memory>
@@ -23,8 +22,6 @@ OctetString OpenPGP_S2K::derive(u32bit key_len, const std::string& passphrase,
total_size = passphrase.size() + salt_size;
u32bit to_hash = std::max(iterations, total_size);
- std::auto_ptr<HashFunction> hash(get_hash(hash_name));
-
hash->clear();
while(key_len > generated)
{
@@ -61,7 +58,7 @@ OctetString OpenPGP_S2K::derive(u32bit key_len, const std::string& passphrase,
*************************************************/
std::string OpenPGP_S2K::name() const
{
- return "OpenPGP-S2K(" + hash_name + ")";
+ return "OpenPGP-S2K(" + hash->name() + ")";
}
/*************************************************
@@ -69,14 +66,7 @@ std::string OpenPGP_S2K::name() const
*************************************************/
S2K* OpenPGP_S2K::clone() const
{
- return new OpenPGP_S2K(hash_name);
- }
-
-/*************************************************
-* OpenPGP S2K Constructor *
-*************************************************/
-OpenPGP_S2K::OpenPGP_S2K(const std::string& h) : hash_name(h)
- {
+ return new OpenPGP_S2K(hash->clone());
}
}
diff --git a/src/s2k/pgps2k/pgp_s2k.h b/src/s2k/pgps2k/pgp_s2k.h
index cd263a735..80fd3ab29 100644
--- a/src/s2k/pgps2k/pgp_s2k.h
+++ b/src/s2k/pgps2k/pgp_s2k.h
@@ -7,6 +7,7 @@
#define BOTAN_OPENPGP_S2K_H__
#include <botan/s2k.h>
+#include <botan/base.h>
namespace Botan {
@@ -18,11 +19,14 @@ class BOTAN_DLL OpenPGP_S2K : public S2K
public:
std::string name() const;
S2K* clone() const;
- OpenPGP_S2K(const std::string&);
+
+ OpenPGP_S2K(HashFunction* hash_in) : hash(hash_in) {}
+ ~OpenPGP_S2K() { delete hash; }
private:
OctetString derive(u32bit, const std::string&,
const byte[], u32bit, u32bit) const;
- const std::string hash_name;
+
+ HashFunction* hash;
};
}