aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2020-10-09 20:35:28 -0400
committerJack Lloyd <[email protected]>2020-10-09 20:35:28 -0400
commit0a2ac792feef493d9eddb80e01c5a588fec06458 (patch)
tree2ebf8411c16fff308318be0cd2a94d6413bcf7eb /src/lib
parentc7b26c732bcd8830c47aaf7fda40e5b028cfb280 (diff)
parentfe7394d2bf6dabff6fc146dc0b3d9e9a5f6ea861 (diff)
Merge GH #2419 Prevent requesting DER-encoded signature on algos that don't support it
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/pubkey/pubkey.cpp11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/lib/pubkey/pubkey.cpp b/src/lib/pubkey/pubkey.cpp
index d98b5dc9e..3834489ef 100644
--- a/src/lib/pubkey/pubkey.cpp
+++ b/src/lib/pubkey/pubkey.cpp
@@ -223,6 +223,12 @@ SymmetricKey PK_Key_Agreement::derive_key(size_t key_len,
return m_op->agree(key_len, in, in_len, salt, salt_len);
}
+static void check_der_format_supported(Signature_Format format, size_t parts)
+ {
+ if(format != IEEE_1363 && parts == 1)
+ throw Invalid_Argument("PK: This algorithm does not support DER encoding");
+ }
+
PK_Signer::PK_Signer(const Private_Key& key,
RandomNumberGenerator& rng,
const std::string& emsa,
@@ -235,6 +241,7 @@ PK_Signer::PK_Signer(const Private_Key& key,
m_sig_format = format;
m_parts = key.message_parts();
m_part_size = key.message_part_size();
+ check_der_format_supported(format, m_parts);
}
PK_Signer::~PK_Signer() { /* for unique_ptr */ }
@@ -310,14 +317,14 @@ PK_Verifier::PK_Verifier(const Public_Key& key,
m_sig_format = format;
m_parts = key.message_parts();
m_part_size = key.message_part_size();
+ check_der_format_supported(format, m_parts);
}
PK_Verifier::~PK_Verifier() { /* for unique_ptr */ }
void PK_Verifier::set_input_format(Signature_Format format)
{
- if(format != IEEE_1363 && m_parts == 1)
- throw Invalid_Argument("PK_Verifier: This algorithm does not support DER encoding");
+ check_der_format_supported(format, m_parts);
m_sig_format = format;
}