@@ -17,9 +17,9 @@ BOOST_FIXTURE_TEST_SUITE(wallet_crypto_tests, BasicTestingSetup)
1717class TestCrypter
1818{
1919public:
20- static void TestPassphraseSingle (const std::vector< unsigned char >& salt, const SecureString& passphrase, uint32_t rounds,
21- const std::vector< unsigned char >& correct_key = {},
22- const std::vector< unsigned char >& correct_iv = {})
20+ static void TestPassphraseSingle (const std::span< const unsigned char > salt, const SecureString& passphrase, uint32_t rounds,
21+ const std::span< const unsigned char > correct_key = {},
22+ const std::span< const unsigned char > correct_iv = {})
2323{
2424 CCrypter crypt;
2525 crypt.SetKeyFromPassphrase (passphrase, salt, rounds, 0 );
@@ -34,18 +34,18 @@ static void TestPassphraseSingle(const std::vector<unsigned char>& salt, const S
3434 }
3535}
3636
37- static void TestPassphrase (const std::vector< unsigned char >& salt, const SecureString& passphrase, uint32_t rounds,
38- const std::vector< unsigned char >& correct_key = {},
39- const std::vector< unsigned char >& correct_iv = {})
37+ static void TestPassphrase (const std::span< const unsigned char > salt, const SecureString& passphrase, uint32_t rounds,
38+ const std::span< const unsigned char > correct_key = {},
39+ const std::span< const unsigned char > correct_iv = {})
4040{
4141 TestPassphraseSingle (salt, passphrase, rounds, correct_key, correct_iv);
4242 for (SecureString::const_iterator it{passphrase.begin ()}; it != passphrase.end (); ++it) {
4343 TestPassphraseSingle (salt, SecureString{it, passphrase.end ()}, rounds);
4444 }
4545}
4646
47- static void TestDecrypt (const CCrypter& crypt, const std::vector< unsigned char >& ciphertext,
48- const std::vector< unsigned char >& correct_plaintext = {})
47+ static void TestDecrypt (const CCrypter& crypt, const std::span< const unsigned char > ciphertext,
48+ const std::span< const unsigned char > correct_plaintext = {})
4949{
5050 CKeyingMaterial decrypted;
5151 crypt.Decrypt (ciphertext, decrypted);
@@ -55,7 +55,7 @@ static void TestDecrypt(const CCrypter& crypt, const std::vector<unsigned char>&
5555}
5656
5757static void TestEncryptSingle (const CCrypter& crypt, const CKeyingMaterial& plaintext,
58- const std::vector< unsigned char >& correct_ciphertext = {})
58+ const std::span< const unsigned char > correct_ciphertext = {})
5959{
6060 std::vector<unsigned char > ciphertext;
6161 crypt.Encrypt (plaintext, ciphertext);
@@ -64,12 +64,11 @@ static void TestEncryptSingle(const CCrypter& crypt, const CKeyingMaterial& plai
6464 BOOST_CHECK_EQUAL_COLLECTIONS (ciphertext.begin (), ciphertext.end (), correct_ciphertext.begin (), correct_ciphertext.end ());
6565 }
6666
67- const std::vector<unsigned char > plaintext2 (plaintext.begin (), plaintext.end ());
68- TestDecrypt (crypt, ciphertext, /* correct_plaintext=*/ plaintext2);
67+ TestDecrypt (crypt, ciphertext, /* correct_plaintext=*/ plaintext);
6968}
7069
71- static void TestEncrypt (const CCrypter& crypt, const std::vector< unsigned char >& plaintext,
72- const std::vector< unsigned char >& correct_ciphertext = {})
70+ static void TestEncrypt (const CCrypter& crypt, const std::span< const unsigned char > plaintext,
71+ const std::span< const unsigned char > correct_ciphertext = {})
7372{
7473 TestEncryptSingle (crypt, CKeyingMaterial{plaintext.begin (), plaintext.end ()}, correct_ciphertext);
7574 for (auto it{plaintext.begin ()}; it != plaintext.end (); ++it) {
@@ -105,7 +104,7 @@ BOOST_AUTO_TEST_CASE(encrypt) {
105104 for (int i = 0 ; i != 100 ; i++)
106105 {
107106 uint256 hash (GetRandHash ());
108- TestCrypter::TestEncrypt (crypt, std::vector <unsigned char >( hash.begin (), hash.end ()) );
107+ TestCrypter::TestEncrypt (crypt, std::span <unsigned char >{ hash.begin (), hash.end ()} );
109108 }
110109
111110}
0 commit comments