diff options
author | lloyd <[email protected]> | 2010-03-04 05:09:19 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2010-03-04 05:09:19 +0000 |
commit | d490c5bed4331a4336556e08873fe03a792ad127 (patch) | |
tree | ac9f3e857e1849bec29de5dfee1a630a37d07bae /checks/pk.cpp | |
parent | 14f73d8df8f6728ab35a0ae39f669665e948b0e8 (diff) |
Split up load/store tests public vs private
Diffstat (limited to 'checks/pk.cpp')
-rw-r--r-- | checks/pk.cpp | 40 |
1 files changed, 29 insertions, 11 deletions
diff --git a/checks/pk.cpp b/checks/pk.cpp index 3749b283a..b3de4bf2f 100644 --- a/checks/pk.cpp +++ b/checks/pk.cpp @@ -82,31 +82,49 @@ void dump_data(const SecureVector<byte>& out, std::cout << "Exp: " << pipe.read_all_as_string(1) << std::endl; } -void validate_save_and_load(const Public_Key* public_key, +void validate_save_and_load(const Private_Key* priv_key, RandomNumberGenerator& rng) { - std::string name = public_key->algo_name(); + std::string name = priv_key->algo_name(); - std::string pem = X509::PEM_encode(*public_key); + std::string pub_pem = X509::PEM_encode(*priv_key); try { - DataSource_Memory input(pem); - std::auto_ptr<Public_Key> restored(X509::load_key(input)); + DataSource_Memory input_pub(pub_pem); + std::auto_ptr<Public_Key> restored_pub(X509::load_key(input_pub)); - if(restored.get() == 0) - std::cout << "Could not recover " << name << " key\n"; - else if(restored->check_key(rng, true) == false) - std::cout << "Restored key failed self tests " << name << "\n"; + if(restored_pub.get() == 0) + std::cout << "Could not recover " << name << " public key\n"; + else if(restored_pub->check_key(rng, true) == false) + std::cout << "Restored pubkey failed self tests " << name << "\n"; } catch(std::exception& e) { std::cout << "Exception during load of " << name << " key: " << e.what() << "\n"; - std::cout << "PEM was:\n" << pem << "\n"; + std::cout << "PEM for pubkey was:\n" << pub_pem << "\n"; } - // Check equivalence somehow? + std::string priv_pem = PKCS8::PEM_encode(*priv_key); + + try + { + DataSource_Memory input_priv(priv_pem); + std::auto_ptr<Private_Key> restored_priv( + PKCS8::load_key(input_priv, rng)); + + if(restored_priv.get() == 0) + std::cout << "Could not recover " << name << " privlic key\n"; + else if(restored_priv->check_key(rng, true) == false) + std::cout << "Restored privkey failed self tests " << name << "\n"; + } + catch(std::exception& e) + { + std::cout << "Exception during load of " << name + << " key: " << e.what() << "\n"; + std::cout << "PEM for privkey was:\n" << priv_pem << "\n"; + } } void validate_decryption(PK_Decryptor* d, const std::string& algo, |