@@ -17,9 +17,9 @@ BOOST_FIXTURE_TEST_SUITE(wallet_crypto_tests, BasicTestingSetup)
17
17
class TestCrypter
18
18
{
19
19
public:
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 = {})
23
23
{
24
24
CCrypter crypt;
25
25
crypt.SetKeyFromPassphrase (passphrase, salt, rounds, 0 );
@@ -34,18 +34,18 @@ static void TestPassphraseSingle(const std::vector<unsigned char>& salt, const S
34
34
}
35
35
}
36
36
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 = {})
40
40
{
41
41
TestPassphraseSingle (salt, passphrase, rounds, correct_key, correct_iv);
42
42
for (SecureString::const_iterator it{passphrase.begin ()}; it != passphrase.end (); ++it) {
43
43
TestPassphraseSingle (salt, SecureString{it, passphrase.end ()}, rounds);
44
44
}
45
45
}
46
46
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 = {})
49
49
{
50
50
CKeyingMaterial decrypted;
51
51
crypt.Decrypt (ciphertext, decrypted);
@@ -55,7 +55,7 @@ static void TestDecrypt(const CCrypter& crypt, const std::vector<unsigned char>&
55
55
}
56
56
57
57
static 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 = {})
59
59
{
60
60
std::vector<unsigned char > ciphertext;
61
61
crypt.Encrypt (plaintext, ciphertext);
@@ -64,12 +64,11 @@ static void TestEncryptSingle(const CCrypter& crypt, const CKeyingMaterial& plai
64
64
BOOST_CHECK_EQUAL_COLLECTIONS (ciphertext.begin (), ciphertext.end (), correct_ciphertext.begin (), correct_ciphertext.end ());
65
65
}
66
66
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);
69
68
}
70
69
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 = {})
73
72
{
74
73
TestEncryptSingle (crypt, CKeyingMaterial{plaintext.begin (), plaintext.end ()}, correct_ciphertext);
75
74
for (auto it{plaintext.begin ()}; it != plaintext.end (); ++it) {
@@ -105,7 +104,7 @@ BOOST_AUTO_TEST_CASE(encrypt) {
105
104
for (int i = 0 ; i != 100 ; i++)
106
105
{
107
106
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 ()} );
109
108
}
110
109
111
110
}
0 commit comments