aboutsummaryrefslogtreecommitdiffstats
path: root/src/cmd
diff options
context:
space:
mode:
authorlloyd <[email protected]>2015-01-28 04:32:10 +0000
committerlloyd <[email protected]>2015-01-28 04:32:10 +0000
commit7b56f1bd570dc684ffd7c945dee0d9b5480354ff (patch)
tree0c50ad534280a292a1b76daee9a19b34cfd96367 /src/cmd
parentb8fa304ec981d273c45d7ef31705d65ccfb00cc1 (diff)
Add a runtime map of string->func() which when called return
Transforms and BlockCiphers. Registration for all types is done at startup but is very cheap as just a std::function and a std::map entry are created, no actual objects are created until needed. This is a huge improvement over Algorithm_Factory which used T::clone() as the function and thus kept a prototype object of each type in memory. Replace existing lookup mechanisms for ciphers, AEADs, and compression to use the transform lookup. The existing Engine framework remains in place for BlockCipher, but the engines now just call to the registry instead of having hardcoded lookups. s/Transformation/Transform/ with typedefs for compatability. Remove lib/selftest code (for runtime selftesting): not the right approach.
Diffstat (limited to 'src/cmd')
-rw-r--r--src/cmd/compress.cpp18
-rw-r--r--src/cmd/speed.cpp4
2 files changed, 17 insertions, 5 deletions
diff --git a/src/cmd/compress.cpp b/src/cmd/compress.cpp
index 8480801e9..646a4d587 100644
--- a/src/cmd/compress.cpp
+++ b/src/cmd/compress.cpp
@@ -11,7 +11,7 @@
namespace {
-void do_compress(Transformation& comp, std::ifstream& in, std::ostream& out)
+void do_compress(Transform& comp, std::ifstream& in, std::ostream& out)
{
secure_vector<byte> buf;
@@ -53,7 +53,13 @@ int compress(int argc, char* argv[])
const size_t level = 9;
const std::string suffix = argc == 3 ? argv[2] : "gz";
- std::unique_ptr<Transformation> compress(make_compressor(suffix, level));
+ std::unique_ptr<Transform> compress(make_compressor(suffix, level));
+
+ if(!compress)
+ {
+ std::cout << suffix << " compression not supported\n";
+ return 1;
+ }
const std::string out_file = in_file + "." + suffix;
std::ofstream out(out_file.c_str());
@@ -91,7 +97,13 @@ int uncompress(int argc, char* argv[])
std::ofstream out(out_file.c_str());
- std::unique_ptr<Transformation> decompress(make_decompressor(suffix));
+ std::unique_ptr<Transform> decompress(make_decompressor(suffix));
+
+ if(!decompress)
+ {
+ std::cout << suffix << " decompression not supported\n";
+ return 1;
+ }
do_compress(*decompress, in, out);
diff --git a/src/cmd/speed.cpp b/src/cmd/speed.cpp
index 8f19063be..4558c4250 100644
--- a/src/cmd/speed.cpp
+++ b/src/cmd/speed.cpp
@@ -121,7 +121,7 @@ void report_results(const std::string& algo,
std::cout << std::endl;
}
-void time_transform(std::unique_ptr<Transformation> tf,
+void time_transform(std::unique_ptr<Transform> tf,
RandomNumberGenerator& rng)
{
if(!tf)
@@ -162,7 +162,7 @@ void time_transform(std::unique_ptr<Transformation> tf,
void time_transform(const std::string& algo, RandomNumberGenerator& rng)
{
- std::unique_ptr<Transformation> tf;
+ std::unique_ptr<Transform> tf;
tf.reset(get_aead(algo, ENCRYPTION));
if(Keyed_Transform* keyed = dynamic_cast<Keyed_Transform*>(tf.get()))