summaryrefslogtreecommitdiff
path: root/Tests/LibCrypto/TestHash.cpp
diff options
context:
space:
mode:
authorsin-ack <sin-ack@users.noreply.github.com>2022-07-11 17:32:29 +0000
committerAndreas Kling <kling@serenityos.org>2022-07-12 23:11:35 +0200
commit3f3f45580ab7266258e97cb3cecf1e24716d61c5 (patch)
tree152c7a187c98184d58bf91a326357e0af435edcf /Tests/LibCrypto/TestHash.cpp
parente5f09ea1703bacfbb79a4ad3c587a7d5d3d7bb13 (diff)
downloadserenity-3f3f45580ab7266258e97cb3cecf1e24716d61c5.zip
Everywhere: Add sv suffix to strings relying on StringView(char const*)
Each of these strings would previously rely on StringView's char const* constructor overload, which would call __builtin_strlen on the string. Since we now have operator ""sv, we can replace these with much simpler versions. This opens the door to being able to remove StringView(char const*). No functional changes.
Diffstat (limited to 'Tests/LibCrypto/TestHash.cpp')
-rw-r--r--Tests/LibCrypto/TestHash.cpp80
1 files changed, 40 insertions, 40 deletions
diff --git a/Tests/LibCrypto/TestHash.cpp b/Tests/LibCrypto/TestHash.cpp
index 29fd33f88c..d59ba7defd 100644
--- a/Tests/LibCrypto/TestHash.cpp
+++ b/Tests/LibCrypto/TestHash.cpp
@@ -23,7 +23,7 @@ TEST_CASE(test_MD5_hash_string)
u8 result[] {
0xaf, 0x04, 0x3a, 0x08, 0x94, 0x38, 0x6e, 0x7f, 0xbf, 0x73, 0xe4, 0xaa, 0xf0, 0x8e, 0xee, 0x4c
};
- auto digest = Crypto::Hash::MD5::hash("Well hello friends");
+ auto digest = Crypto::Hash::MD5::hash("Well hello friends"sv);
EXPECT(memcmp(result, digest.data, Crypto::Hash::MD5::digest_size()) == 0);
}
@@ -32,7 +32,7 @@ TEST_CASE(test_MD5_hash_empty_string)
u8 result[] {
0xd4, 0x1d, 0x8c, 0xd9, 0x8f, 0x00, 0xb2, 0x04, 0xe9, 0x80, 0x09, 0x98, 0xec, 0xf8, 0x42, 0x7e
};
- auto digest = Crypto::Hash::MD5::hash("");
+ auto digest = Crypto::Hash::MD5::hash(""sv);
EXPECT(memcmp(result, digest.data, Crypto::Hash::MD5::digest_size()) == 0);
}
@@ -41,7 +41,7 @@ TEST_CASE(test_MD5_hash_single_character)
u8 result[] {
0x0c, 0xc1, 0x75, 0xb9, 0xc0, 0xf1, 0xb6, 0xa8, 0x31, 0xc3, 0x99, 0xe2, 0x69, 0x77, 0x26, 0x61
};
- auto digest = Crypto::Hash::MD5::hash("a");
+ auto digest = Crypto::Hash::MD5::hash("a"sv);
EXPECT(memcmp(result, digest.data, Crypto::Hash::MD5::digest_size()) == 0);
}
@@ -50,7 +50,7 @@ TEST_CASE(test_MD5_hash_alphabet)
u8 result[] {
0xc3, 0xfc, 0xd3, 0xd7, 0x61, 0x92, 0xe4, 0x00, 0x7d, 0xfb, 0x49, 0x6c, 0xca, 0x67, 0xe1, 0x3b
};
- auto digest = Crypto::Hash::MD5::hash("abcdefghijklmnopqrstuvwxyz");
+ auto digest = Crypto::Hash::MD5::hash("abcdefghijklmnopqrstuvwxyz"sv);
EXPECT(memcmp(result, digest.data, Crypto::Hash::MD5::digest_size()) == 0);
}
@@ -59,7 +59,7 @@ TEST_CASE(test_MD5_hash_long_sequence)
u8 result[] {
0x57, 0xed, 0xf4, 0xa2, 0x2b, 0xe3, 0xc9, 0x55, 0xac, 0x49, 0xda, 0x2e, 0x21, 0x07, 0xb6, 0x7a
};
- auto digest = Crypto::Hash::MD5::hash("12345678901234567890123456789012345678901234567890123456789012345678901234567890");
+ auto digest = Crypto::Hash::MD5::hash("12345678901234567890123456789012345678901234567890123456789012345678901234567890"sv);
EXPECT(memcmp(result, digest.data, Crypto::Hash::MD5::digest_size()) == 0);
}
@@ -70,9 +70,9 @@ TEST_CASE(test_MD5_consecutive_multiple_updates)
};
Crypto::Hash::MD5 md5;
- md5.update("Well");
- md5.update(" hello ");
- md5.update("friends");
+ md5.update("Well"sv);
+ md5.update(" hello "sv);
+ md5.update("friends"sv);
auto digest = md5.digest();
EXPECT(memcmp(result, digest.data, Crypto::Hash::MD5::digest_size()) == 0);
@@ -82,14 +82,14 @@ TEST_CASE(test_MD5_consecutive_updates_reuse)
{
Crypto::Hash::MD5 md5;
- md5.update("Well");
- md5.update(" hello ");
- md5.update("friends");
+ md5.update("Well"sv);
+ md5.update(" hello "sv);
+ md5.update("friends"sv);
auto digest0 = md5.digest();
- md5.update("Well");
- md5.update(" hello ");
- md5.update("friends");
+ md5.update("Well"sv);
+ md5.update(" hello "sv);
+ md5.update("friends"sv);
auto digest1 = md5.digest();
EXPECT(memcmp(digest0.data, digest1.data, Crypto::Hash::MD5::digest_size()) == 0);
@@ -98,7 +98,7 @@ TEST_CASE(test_MD5_consecutive_updates_reuse)
TEST_CASE(test_SHA1_name)
{
Crypto::Hash::SHA1 sha;
- EXPECT(sha.class_name() == "SHA1");
+ EXPECT(sha.class_name() == "SHA1"sv);
}
TEST_CASE(test_SHA1_hash_empty_string)
@@ -106,7 +106,7 @@ TEST_CASE(test_SHA1_hash_empty_string)
u8 result[] {
0xda, 0x39, 0xa3, 0xee, 0x5e, 0x6b, 0x4b, 0x0d, 0x32, 0x55, 0xbf, 0xef, 0x95, 0x60, 0x18, 0x90, 0xaf, 0xd8, 0x07, 0x09
};
- auto digest = Crypto::Hash::SHA1::hash("");
+ auto digest = Crypto::Hash::SHA1::hash(""sv);
EXPECT(memcmp(result, digest.data, Crypto::Hash::SHA1::digest_size()) == 0);
}
@@ -115,7 +115,7 @@ TEST_CASE(test_SHA1_hash_long_string)
u8 result[] {
0x12, 0x15, 0x1f, 0xb1, 0x04, 0x44, 0x93, 0xcc, 0xed, 0x54, 0xa6, 0xb8, 0x7e, 0x93, 0x37, 0x7b, 0xb2, 0x13, 0x39, 0xdb
};
- auto digest = Crypto::Hash::SHA1::hash("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
+ auto digest = Crypto::Hash::SHA1::hash("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"sv);
EXPECT(memcmp(result, digest.data, Crypto::Hash::SHA1::digest_size()) == 0);
}
@@ -125,19 +125,19 @@ TEST_CASE(test_SHA1_hash_successive_updates)
0xd6, 0x6e, 0xce, 0xd1, 0xf4, 0x08, 0xc6, 0xd8, 0x35, 0xab, 0xf0, 0xc9, 0x05, 0x26, 0xa4, 0xb2, 0xb8, 0xa3, 0x7c, 0xd3
};
auto hasher = Crypto::Hash::SHA1 {};
- hasher.update("aaaaaaaaaaaaaaa");
- hasher.update("aaaaaaaaaaaaaaa");
- hasher.update("aaaaaaaaaaaaaaa");
- hasher.update("aaaaaaaaaaaaaaa");
- hasher.update("aaaaaaaaaaaaaaa");
- hasher.update("aaaaaaaaaaaaaaa");
- hasher.update("aaaaaaaaaaaaaaa");
- hasher.update("aaaaaaaaaaaaaaa");
- hasher.update("aaaaaaaaaaaaaaa");
- hasher.update("aaaaaaaaaaaaaaa");
- hasher.update("aaaaaaaaaaaaaaa");
- hasher.update("aaaaaaaaaaaaaaa");
- hasher.update("aaaaaaaaa");
+ hasher.update("aaaaaaaaaaaaaaa"sv);
+ hasher.update("aaaaaaaaaaaaaaa"sv);
+ hasher.update("aaaaaaaaaaaaaaa"sv);
+ hasher.update("aaaaaaaaaaaaaaa"sv);
+ hasher.update("aaaaaaaaaaaaaaa"sv);
+ hasher.update("aaaaaaaaaaaaaaa"sv);
+ hasher.update("aaaaaaaaaaaaaaa"sv);
+ hasher.update("aaaaaaaaaaaaaaa"sv);
+ hasher.update("aaaaaaaaaaaaaaa"sv);
+ hasher.update("aaaaaaaaaaaaaaa"sv);
+ hasher.update("aaaaaaaaaaaaaaa"sv);
+ hasher.update("aaaaaaaaaaaaaaa"sv);
+ hasher.update("aaaaaaaaa"sv);
auto digest = hasher.digest();
EXPECT(memcmp(result, digest.data, Crypto::Hash::SHA1::digest_size()) == 0);
}
@@ -145,7 +145,7 @@ TEST_CASE(test_SHA1_hash_successive_updates)
TEST_CASE(test_SHA256_name)
{
Crypto::Hash::SHA256 sha;
- EXPECT_EQ(sha.class_name(), "SHA256");
+ EXPECT_EQ(sha.class_name(), "SHA256"sv);
}
TEST_CASE(test_SHA256_hash_string)
@@ -153,7 +153,7 @@ TEST_CASE(test_SHA256_hash_string)
u8 result[] {
0x9a, 0xcd, 0x50, 0xf9, 0xa2, 0xaf, 0x37, 0xe4, 0x71, 0xf7, 0x61, 0xc3, 0xfe, 0x7b, 0x8d, 0xea, 0x56, 0x17, 0xe5, 0x1d, 0xac, 0x80, 0x2f, 0xe6, 0xc1, 0x77, 0xb7, 0x4a, 0xbf, 0x0a, 0xbb, 0x5a
};
- auto digest = Crypto::Hash::SHA256::hash("Well hello friends");
+ auto digest = Crypto::Hash::SHA256::hash("Well hello friends"sv);
EXPECT(memcmp(result, digest.data, Crypto::Hash::SHA256::digest_size()) == 0);
}
@@ -162,14 +162,14 @@ TEST_CASE(test_SHA256_hash_empty_string)
u8 result[] {
0xe3, 0xb0, 0xc4, 0x42, 0x98, 0xfc, 0x1c, 0x14, 0x9a, 0xfb, 0xf4, 0xc8, 0x99, 0x6f, 0xb9, 0x24, 0x27, 0xae, 0x41, 0xe4, 0x64, 0x9b, 0x93, 0x4c, 0xa4, 0x95, 0x99, 0x1b, 0x78, 0x52, 0xb8, 0x55
};
- auto digest = Crypto::Hash::SHA256::hash("");
+ auto digest = Crypto::Hash::SHA256::hash(""sv);
EXPECT(memcmp(result, digest.data, Crypto::Hash::SHA256::digest_size()) == 0);
}
TEST_CASE(test_SHA384_name)
{
Crypto::Hash::SHA384 sha;
- EXPECT_EQ(sha.class_name(), "SHA384");
+ EXPECT_EQ(sha.class_name(), "SHA384"sv);
}
TEST_CASE(test_SHA384_hash_string)
@@ -177,7 +177,7 @@ TEST_CASE(test_SHA384_hash_string)
u8 result[] {
0x2f, 0x01, 0x8e, 0x9a, 0x4f, 0xd1, 0x36, 0xb9, 0x0f, 0xcc, 0x21, 0xde, 0x1a, 0xd4, 0x49, 0x51, 0x57, 0x82, 0x86, 0x84, 0x54, 0x09, 0x82, 0x7b, 0x54, 0x56, 0x93, 0xac, 0x2c, 0x46, 0x0c, 0x1f, 0x5e, 0xec, 0xe0, 0xf7, 0x8b, 0x0b, 0x84, 0x27, 0xc8, 0xb8, 0xbe, 0x49, 0xce, 0x8f, 0x1c, 0xff
};
- auto digest = Crypto::Hash::SHA384::hash("Well hello friends");
+ auto digest = Crypto::Hash::SHA384::hash("Well hello friends"sv);
EXPECT(memcmp(result, digest.data, Crypto::Hash::SHA384::digest_size()) == 0);
}
@@ -187,14 +187,14 @@ TEST_CASE(test_SHA384_hash_bug)
0x09, 0x33, 0x0c, 0x33, 0xf7, 0x11, 0x47, 0xe8, 0x3d, 0x19, 0x2f, 0xc7, 0x82, 0xcd, 0x1b, 0x47, 0x53, 0x11, 0x1b, 0x17, 0x3b, 0x3b, 0x05, 0xd2, 0x2f, 0xa0, 0x80, 0x86, 0xe3, 0xb0, 0xf7, 0x12, 0xfc, 0xc7, 0xc7, 0x1a, 0x55, 0x7e, 0x2d, 0xb9, 0x66, 0xc3, 0xe9, 0xfa, 0x91, 0x74, 0x60, 0x39
};
ReadonlyBytes result_bytes { result, 48 };
- auto digest = Crypto::Hash::SHA384::hash("abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
+ auto digest = Crypto::Hash::SHA384::hash("abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"sv);
EXPECT_EQ(result_bytes, digest.bytes());
}
TEST_CASE(test_SHA512_name)
{
Crypto::Hash::SHA512 sha;
- EXPECT_EQ(sha.class_name(), "SHA512");
+ EXPECT_EQ(sha.class_name(), "SHA512"sv);
}
TEST_CASE(test_SHA512_hash_string)
@@ -202,7 +202,7 @@ TEST_CASE(test_SHA512_hash_string)
u8 result[] {
0x00, 0xfe, 0x68, 0x09, 0x71, 0x0e, 0xcb, 0x2b, 0xe9, 0x58, 0x00, 0x13, 0x69, 0x6a, 0x9e, 0x9e, 0xbd, 0x09, 0x1b, 0xfe, 0x14, 0xc9, 0x13, 0x82, 0xc7, 0x40, 0x34, 0xfe, 0xca, 0xe6, 0x87, 0xcb, 0x26, 0x36, 0x92, 0xe6, 0x34, 0x94, 0x3a, 0x11, 0xe5, 0xbb, 0xb5, 0xeb, 0x8e, 0x70, 0xef, 0x64, 0xca, 0xf7, 0x21, 0xb1, 0xde, 0xf2, 0x34, 0x85, 0x6f, 0xa8, 0x56, 0xd8, 0x23, 0xa1, 0x3b, 0x29
};
- auto digest = Crypto::Hash::SHA512::hash("Well hello friends");
+ auto digest = Crypto::Hash::SHA512::hash("Well hello friends"sv);
EXPECT(memcmp(result, digest.data, Crypto::Hash::SHA512::digest_size()) == 0);
}
@@ -212,7 +212,7 @@ TEST_CASE(test_SHA512_hash_bug)
0x8e, 0x95, 0x9b, 0x75, 0xda, 0xe3, 0x13, 0xda, 0x8c, 0xf4, 0xf7, 0x28, 0x14, 0xfc, 0x14, 0x3f, 0x8f, 0x77, 0x79, 0xc6, 0xeb, 0x9f, 0x7f, 0xa1, 0x72, 0x99, 0xae, 0xad, 0xb6, 0x88, 0x90, 0x18, 0x50, 0x1d, 0x28, 0x9e, 0x49, 0x00, 0xf7, 0xe4, 0x33, 0x1b, 0x99, 0xde, 0xc4, 0xb5, 0x43, 0x3a, 0xc7, 0xd3, 0x29, 0xee, 0xb6, 0xdd, 0x26, 0x54, 0x5e, 0x96, 0xe5, 0x5b, 0x87, 0x4b, 0xe9, 0x09
};
ReadonlyBytes result_bytes { result, 64 };
- auto digest = Crypto::Hash::SHA512::hash("abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
+ auto digest = Crypto::Hash::SHA512::hash("abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"sv);
EXPECT_EQ(result_bytes, digest.bytes());
}
@@ -221,7 +221,7 @@ TEST_CASE(test_SHA512_hash_empty_string)
u8 result[] {
0xcf, 0x83, 0xe1, 0x35, 0x7e, 0xef, 0xb8, 0xbd, 0xf1, 0x54, 0x28, 0x50, 0xd6, 0x6d, 0x80, 0x07, 0xd6, 0x20, 0xe4, 0x05, 0x0b, 0x57, 0x15, 0xdc, 0x83, 0xf4, 0xa9, 0x21, 0xd3, 0x6c, 0xe9, 0xce, 0x47, 0xd0, 0xd1, 0x3c, 0x5d, 0x85, 0xf2, 0xb0, 0xff, 0x83, 0x18, 0xd2, 0x87, 0x7e, 0xec, 0x2f, 0x63, 0xb9, 0x31, 0xbd, 0x47, 0x41, 0x7a, 0x81, 0xa5, 0x38, 0x32, 0x7a, 0xf9, 0x27, 0xda, 0x3e
};
- auto digest = Crypto::Hash::SHA512::hash("");
+ auto digest = Crypto::Hash::SHA512::hash(""sv);
EXPECT(memcmp(result, digest.data, Crypto::Hash::SHA512::digest_size()) == 0);
}