diff options
author | lloyd <[email protected]> | 2010-04-19 23:20:41 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2010-04-19 23:20:41 +0000 |
commit | 358a943a1772bb491983a3f227bf03dc861dbf76 (patch) | |
tree | d93f564051e0976df7ac35921aeb45b33ceebf1e | |
parent | 90de8014d379f1f81b57cabc9a6a52a548ff262a (diff) |
In the string constructor of EC_Domain_Params, check if the PEM decoding
failed. If so, assume the input string was an OID and try that.
-rw-r--r-- | src/pubkey/ec_dompar/ec_dompar.cpp | 15 | ||||
-rw-r--r-- | src/pubkey/ec_dompar/ec_dompar.h | 7 |
2 files changed, 16 insertions, 6 deletions
diff --git a/src/pubkey/ec_dompar/ec_dompar.cpp b/src/pubkey/ec_dompar/ec_dompar.cpp index b0aa7a87a..512d8d769 100644 --- a/src/pubkey/ec_dompar/ec_dompar.cpp +++ b/src/pubkey/ec_dompar/ec_dompar.cpp @@ -30,12 +30,21 @@ EC_Domain_Params::EC_Domain_Params(const OID& domain_oid) EC_Domain_Params::EC_Domain_Params(const std::string& pem) { - if(pem != "") + if(pem == "") + return; // no initialization / uninitialized + + try { DataSource_Memory input(pem); - *this = EC_Domain_Params( - PEM_Code::decode_check_label(input, "EC PARAMETERS")); + SecureVector<byte> ber = + PEM_Code::decode_check_label(input, "EC PARAMETERS"); + + *this = EC_Domain_Params(ber); + } + catch(Decoding_Error) // hmm, not PEM? + { + *this = EC_Domain_Params(OID(pem)); } } diff --git a/src/pubkey/ec_dompar/ec_dompar.h b/src/pubkey/ec_dompar/ec_dompar.h index 7da2120cc..15143373a 100644 --- a/src/pubkey/ec_dompar/ec_dompar.h +++ b/src/pubkey/ec_dompar/ec_dompar.h @@ -60,10 +60,11 @@ class BOTAN_DLL EC_Domain_Params EC_Domain_Params(const OID& oid); /** - * Create an EC domain from PEM encoding (as from PEM_encode) - * @param pem data + * Create an EC domain from PEM encoding (as from PEM_encode), + * or from an OID name (eg "secp16r1", or "1.3.132.0.8") + * @param pem_or_oid PEM-encoded data, or an OID */ - EC_Domain_Params(const std::string& pem = ""); + EC_Domain_Params(const std::string& pem_or_oid = ""); /** * Create the DER encoding of this domain |