From 327115405b0f483c2b432e2233f355a349b1f9d7 Mon Sep 17 00:00:00 2001 From: lloyd Date: Wed, 1 Apr 2009 16:38:08 +0000 Subject: Replace the (deprecated) auto_ptr with unique_ptr. This was mostly a s/auto_ptr/unique_ptr/, except in the CVC code and one function in ECDSA, which relied on auto_ptr's move semantics (ugh) and had to be modified in various ways. --- checks/ecdsa.cpp | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'checks/ecdsa.cpp') diff --git a/checks/ecdsa.cpp b/checks/ecdsa.cpp index 532a1c546..37880b755 100644 --- a/checks/ecdsa.cpp +++ b/checks/ecdsa.cpp @@ -70,7 +70,7 @@ void test_hash_larger_than_n(RandomNumberGenerator& rng) { format = "EMSA1_BSI(SHA-1)"; } - std::auto_ptr pk_signer(get_pk_signer(priv_key, format)); + std::unique_ptr pk_signer(get_pk_signer(priv_key, format)); SecureVector signature; bool sig_exc = false; try @@ -93,7 +93,7 @@ void test_hash_larger_than_n(RandomNumberGenerator& rng) if(i==0) // makes no sense to check for sha224 { - std::auto_ptr pk_verifier(get_pk_verifier(priv_key, format)); + std::unique_ptr pk_verifier(get_pk_verifier(priv_key, format)); bool ver = pk_verifier->verify_message(message, signature); CHECK(ver); } @@ -103,10 +103,10 @@ void test_hash_larger_than_n(RandomNumberGenerator& rng) // now check that verification alone fails // sign it with the normal EMSA1 - std::auto_ptr pk_signer(get_pk_signer(priv_key, "EMSA1(SHA-224)")); + std::unique_ptr pk_signer(get_pk_signer(priv_key, "EMSA1(SHA-224)")); SecureVector signature = pk_signer->sign_message(message, rng); - std::auto_ptr pk_verifier(get_pk_verifier(priv_key, "EMSA1_BSI(SHA-224)")); + std::unique_ptr pk_verifier(get_pk_verifier(priv_key, "EMSA1_BSI(SHA-224)")); // verify against EMSA1_BSI // we make sure it doesn't fail because of the invalid signature, @@ -164,7 +164,7 @@ void test_decode_ecdsa_X509() CHECK_MESSAGE(to_hex(cert.authority_key_id()) == "0096452DE588F966C4CCDF161DD1F3F5341B71E7", "error reading authority key id from x509 ecdsa certificate"); CHECK_MESSAGE(to_hex(cert.subject_key_id()) == "0096452DE588F966C4CCDF161DD1F3F5341B71E7", "error reading Subject key id from x509 ecdsa certificate"); - std::auto_ptr pubkey(cert.subject_public_key()); + std::unique_ptr pubkey(cert.subject_public_key()); bool ver_ec = cert.check_signature(*pubkey); CHECK_MESSAGE(ver_ec, "could not positively verify correct selfsigned x509-ecdsa certificate"); } @@ -176,7 +176,7 @@ void test_decode_ver_link_SHA256() X509_Certificate root_cert(TEST_DATA_DIR "/root2_SHA256.cer"); X509_Certificate link_cert(TEST_DATA_DIR "/link_SHA256.cer"); - std::auto_ptr pubkey(root_cert.subject_public_key()); + std::unique_ptr pubkey(root_cert.subject_public_key()); bool ver_ec = link_cert.check_signature(*pubkey); CHECK_MESSAGE(ver_ec, "could not positively verify correct SHA256 link x509-ecdsa certificate"); @@ -188,7 +188,7 @@ void test_decode_ver_link_SHA1() X509_Certificate root_cert(TEST_DATA_DIR "/root_SHA1.163.crt"); X509_Certificate link_cert(TEST_DATA_DIR "/link_SHA1.166.crt"); - std::auto_ptr pubkey(root_cert.subject_public_key()); + std::unique_ptr pubkey(root_cert.subject_public_key()); bool ver_ec = link_cert.check_signature(*pubkey); CHECK_MESSAGE(ver_ec, "could not positively verify correct SHA1 link x509-ecdsa certificate"); } @@ -231,8 +231,8 @@ bool test_ec_sign(RandomNumberGenerator& rng) ECDSA_PrivateKey priv_key(rng, dom_pars); std::string pem_encoded_key = PKCS8::PEM_encode(priv_key); - std::auto_ptr signer(get_pk_signer(priv_key, "EMSA1(SHA-224)")); - std::auto_ptr verifier(get_pk_verifier(priv_key, "EMSA1(SHA-224)")); + std::unique_ptr signer(get_pk_signer(priv_key, "EMSA1(SHA-224)")); + std::unique_ptr verifier(get_pk_verifier(priv_key, "EMSA1(SHA-224)")); for(u32bit i = 0; i != 256; ++i) signer->update((byte)i); @@ -313,11 +313,11 @@ void test_create_and_verify(RandomNumberGenerator& rng) std::ofstream priv_key(TEST_DATA_DIR "/dompar_private.pkcs8.pem"); priv_key << PKCS8::PEM_encode(key); - std::auto_ptr loaded_key(PKCS8::load_key(TEST_DATA_DIR "/wo_dompar_private.pkcs8.pem", rng)); + std::unique_ptr loaded_key(PKCS8::load_key(TEST_DATA_DIR "/wo_dompar_private.pkcs8.pem", rng)); ECDSA_PrivateKey* loaded_ec_key = dynamic_cast(loaded_key.get()); CHECK_MESSAGE(loaded_ec_key, "the loaded key could not be converted into an ECDSA_PrivateKey"); - std::auto_ptr loaded_key_1(PKCS8::load_key(TEST_DATA_DIR "/rsa_private.pkcs8.pem", rng)); + std::unique_ptr loaded_key_1(PKCS8::load_key(TEST_DATA_DIR "/rsa_private.pkcs8.pem", rng)); ECDSA_PrivateKey* loaded_rsa_key = dynamic_cast(loaded_key_1.get()); CHECK_MESSAGE(!loaded_rsa_key, "the loaded key is ECDSA_PrivateKey -> shouldn't be, is a RSA-Key"); @@ -350,7 +350,7 @@ void test_create_and_verify(RandomNumberGenerator& rng) std::string key_odd_oid_str = PKCS8::PEM_encode(key_odd_oid); DataSource_Memory key_data_src(key_odd_oid_str); - std::auto_ptr loaded_key2(PKCS8::load_key(key_data_src, rng)); + std::unique_ptr loaded_key2(PKCS8::load_key(key_data_src, rng)); if(!dynamic_cast(loaded_key.get())) { @@ -420,7 +420,7 @@ void test_read_pkcs8(RandomNumberGenerator& rng) std::cout << "." << std::flush; try { - std::auto_ptr loaded_key(PKCS8::load_key(TEST_DATA_DIR "/wo_dompar_private.pkcs8.pem", rng)); + std::unique_ptr loaded_key(PKCS8::load_key(TEST_DATA_DIR "/wo_dompar_private.pkcs8.pem", rng)); ECDSA_PrivateKey* loaded_ec_key = dynamic_cast(loaded_key.get()); CHECK_MESSAGE(loaded_ec_key, "the loaded key could not be converted into an ECDSA_PrivateKey"); @@ -431,7 +431,7 @@ void test_read_pkcs8(RandomNumberGenerator& rng) bool ver_success = loaded_ec_key->verify(sv_message.begin(), sv_message.size(), signature.begin(), signature.size()); CHECK_MESSAGE(ver_success, "generated signature could not be verified positively"); - std::auto_ptr loaded_key_nodp(PKCS8::load_key(TEST_DATA_DIR "/nodompar_private.pkcs8.pem", rng)); + std::unique_ptr loaded_key_nodp(PKCS8::load_key(TEST_DATA_DIR "/nodompar_private.pkcs8.pem", rng)); // anew in each test with unregistered domain-parameters ECDSA_PrivateKey* loaded_ec_key_nodp = dynamic_cast(loaded_key_nodp.get()); CHECK_MESSAGE(loaded_ec_key_nodp, "the loaded key could not be converted into an ECDSA_PrivateKey"); @@ -442,7 +442,7 @@ void test_read_pkcs8(RandomNumberGenerator& rng) CHECK_MESSAGE(ver_success_nodp, "generated signature could not be verified positively (no_dom)"); try { - std::auto_ptr loaded_key_withdp(PKCS8::load_key(TEST_DATA_DIR "/withdompar_private.pkcs8.pem", rng)); + std::unique_ptr loaded_key_withdp(PKCS8::load_key(TEST_DATA_DIR "/withdompar_private.pkcs8.pem", rng)); std::cout << "Unexpected success: loaded key with unknown OID\n"; } @@ -461,7 +461,7 @@ void test_cp_and_as_ctors(RandomNumberGenerator& rng) { std::cout << "." << std::flush; - std::auto_ptr loaded_key(PKCS8::load_key(TEST_DATA_DIR "/wo_dompar_private.pkcs8.pem", rng)); + std::unique_ptr loaded_key(PKCS8::load_key(TEST_DATA_DIR "/wo_dompar_private.pkcs8.pem", rng)); ECDSA_PrivateKey* loaded_ec_key = dynamic_cast(loaded_key.get()); CHECK_MESSAGE(loaded_ec_key, "the loaded key could not be converted into an ECDSA_PrivateKey"); std::string str_message = ("12345678901234567890abcdef12"); @@ -497,7 +497,7 @@ void test_non_init_ecdsa_keys(RandomNumberGenerator& rng) { std::cout << "." << std::flush; - std::auto_ptr loaded_key(PKCS8::load_key(TEST_DATA_DIR "/wo_dompar_private.pkcs8.pem", rng)); + std::unique_ptr loaded_key(PKCS8::load_key(TEST_DATA_DIR "/wo_dompar_private.pkcs8.pem", rng)); //ECDSA_PrivateKey* loaded_ec_key = dynamic_cast(loaded_key.get()); //CHECK_MESSAGE(loaded_ec_key, "the loaded key could not be converted into an ECDSA_PrivateKey"); std::string str_message = ("12345678901234567890abcdef12"); -- cgit v1.2.3 From c8e8fdab5f0253f5143ab9eb1a250ad69ffc4420 Mon Sep 17 00:00:00 2001 From: lloyd Date: Wed, 10 Mar 2010 16:47:39 +0000 Subject: s/auto_ptr/unique_ptr/ --- checks/ecdsa.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'checks/ecdsa.cpp') diff --git a/checks/ecdsa.cpp b/checks/ecdsa.cpp index 7e585b584..7b8b65ed2 100644 --- a/checks/ecdsa.cpp +++ b/checks/ecdsa.cpp @@ -387,7 +387,7 @@ void test_read_pkcs8(RandomNumberGenerator& rng) try { - std::auto_ptr loaded_key(PKCS8::load_key(TEST_DATA_DIR "/wo_dompar_private.pkcs8.pem", rng)); + std::unique_ptr loaded_key(PKCS8::load_key(TEST_DATA_DIR "/wo_dompar_private.pkcs8.pem", rng)); ECDSA_PrivateKey* ecdsa = dynamic_cast(loaded_key.get()); CHECK_MESSAGE(ecdsa, "the loaded key could not be converted into an ECDSA_PrivateKey"); @@ -407,7 +407,7 @@ void test_read_pkcs8(RandomNumberGenerator& rng) try { - std::auto_ptr loaded_key_nodp(PKCS8::load_key(TEST_DATA_DIR "/nodompar_private.pkcs8.pem", rng)); + std::unique_ptr loaded_key_nodp(PKCS8::load_key(TEST_DATA_DIR "/nodompar_private.pkcs8.pem", rng)); // anew in each test with unregistered domain-parameters ECDSA_PrivateKey* ecdsa_nodp = dynamic_cast(loaded_key_nodp.get()); CHECK_MESSAGE(ecdsa_nodp, "the loaded key could not be converted into an ECDSA_PrivateKey"); @@ -422,7 +422,7 @@ void test_read_pkcs8(RandomNumberGenerator& rng) try { - std::auto_ptr loaded_key_withdp( + std::unique_ptr loaded_key_withdp( PKCS8::load_key(TEST_DATA_DIR "/withdompar_private.pkcs8.pem", rng)); std::cout << "Unexpected success: loaded key with unknown OID\n"; -- cgit v1.2.3