aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/misc
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2016-11-03 13:11:18 -0400
committerJack Lloyd <[email protected]>2016-11-03 13:11:18 -0400
commit660d985e92d030f4ec0c3503bc14363825183371 (patch)
tree8daeec407eab8f5dc7c00f83b08fc687abe9a8d9 /src/lib/misc
parente42d1513fd6f80dcd2ae4109fddf53b61e935116 (diff)
Simplify some code by using T::create_or_throw
Diffstat (limited to 'src/lib/misc')
-rw-r--r--src/lib/misc/rfc3394/rfc3394.cpp8
-rw-r--r--src/lib/misc/srp6/srp6.cpp10
2 files changed, 4 insertions, 14 deletions
diff --git a/src/lib/misc/rfc3394/rfc3394.cpp b/src/lib/misc/rfc3394/rfc3394.cpp
index 1044e4de4..9ec053ef3 100644
--- a/src/lib/misc/rfc3394/rfc3394.cpp
+++ b/src/lib/misc/rfc3394/rfc3394.cpp
@@ -22,9 +22,7 @@ secure_vector<byte> rfc3394_keywrap(const secure_vector<byte>& key,
throw Invalid_Argument("Bad KEK length " + std::to_string(kek.size()) + " for NIST key wrap");
const std::string cipher_name = "AES-" + std::to_string(8*kek.size());
- std::unique_ptr<BlockCipher> aes(BlockCipher::create(cipher_name));
- if(!aes)
- throw Algorithm_Not_Found(cipher_name);
+ std::unique_ptr<BlockCipher> aes(BlockCipher::create_or_throw(cipher_name));
aes->set_key(kek);
const size_t n = key.size() / 8;
@@ -69,9 +67,7 @@ secure_vector<byte> rfc3394_keyunwrap(const secure_vector<byte>& key,
throw Invalid_Argument("Bad KEK length " + std::to_string(kek.size()) + " for NIST key unwrap");
const std::string cipher_name = "AES-" + std::to_string(8*kek.size());
- std::unique_ptr<BlockCipher> aes(BlockCipher::create(cipher_name));
- if(!aes)
- throw Algorithm_Not_Found(cipher_name);
+ std::unique_ptr<BlockCipher> aes(BlockCipher::create_or_throw(cipher_name));
aes->set_key(kek);
const size_t n = (key.size() - 8) / 8;
diff --git a/src/lib/misc/srp6/srp6.cpp b/src/lib/misc/srp6/srp6.cpp
index 7fca6461f..f54726151 100644
--- a/src/lib/misc/srp6/srp6.cpp
+++ b/src/lib/misc/srp6/srp6.cpp
@@ -18,10 +18,7 @@ BigInt hash_seq(const std::string& hash_id,
const BigInt& in1,
const BigInt& in2)
{
- std::unique_ptr<HashFunction> hash_fn(HashFunction::create(hash_id));
-
- if(!hash_fn)
- throw Algorithm_Not_Found(hash_id);
+ std::unique_ptr<HashFunction> hash_fn(HashFunction::create_or_throw(hash_id));
hash_fn->update(BigInt::encode_1363(in1, pad_to));
hash_fn->update(BigInt::encode_1363(in2, pad_to));
@@ -34,10 +31,7 @@ BigInt compute_x(const std::string& hash_id,
const std::string& password,
const std::vector<byte>& salt)
{
- std::unique_ptr<HashFunction> hash_fn(HashFunction::create(hash_id));
-
- if(!hash_fn)
- throw Algorithm_Not_Found(hash_id);
+ std::unique_ptr<HashFunction> hash_fn(HashFunction::create_or_throw(hash_id));
hash_fn->update(identifier);
hash_fn->update(":");