Add Arc4CryptTests, EncryptOutIteratorUsageTest.
Harden against past-the-end write.
This commit is contained in:
@@ -107,3 +107,66 @@ TEST(Arc4CryptTests, RekeyTest)
|
||||
ciphertext);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(Arc4CryptTests, EncryptOutIteratorUsageTest)
|
||||
{
|
||||
const std::vector<uint8_t> data = StrToU8Vec("The quick brown fox jumps over the lazy dog.");
|
||||
|
||||
{
|
||||
std::array<uint8_t, 5> key = { 0x01, 0x02, 0x03, 0x04, 0x05 };
|
||||
|
||||
Arc4Crypt crypt(key.begin(), key.end());
|
||||
|
||||
std::array<uint8_t, 44> out;
|
||||
out.fill(0);
|
||||
|
||||
std::array<uint8_t, 44> expected =
|
||||
{
|
||||
0xe6, 0x51, 0x06, 0x25, 0x81, 0x48, 0xa9, 0x44, 0xa7, 0xe3, 0x30,
|
||||
0x38, 0x65, 0x66, 0x76, 0x88, 0x0f, 0xed, 0xec, 0x6f, 0x72, 0x89,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||
};
|
||||
|
||||
crypt.Encrypt(out.begin(), data.begin(), 22);
|
||||
|
||||
ASSERT_EQ(expected, out);
|
||||
}
|
||||
|
||||
{
|
||||
std::array<uint8_t, 5> key = { 0x01, 0x02, 0x03, 0x04, 0x05 };
|
||||
|
||||
Arc4Crypt crypt(key.begin(), key.end());
|
||||
|
||||
std::array<uint8_t, 44> out;
|
||||
out.fill(0);
|
||||
|
||||
std::array<uint8_t, 44> expected =
|
||||
{
|
||||
0xe6, 0x51, 0x06, 0x25, 0x81, 0x48, 0xa9, 0x44, 0xa7, 0xe3, 0x30,
|
||||
0x38, 0x65, 0x66, 0x76, 0x88, 0x0f, 0xed, 0xec, 0x6f, 0x72, 0x89,
|
||||
0xef, 0xa5, 0xfa, 0xe4, 0x6c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||
};
|
||||
|
||||
crypt.Encrypt(out.begin(), data.begin(), 27);
|
||||
|
||||
ASSERT_EQ(expected, out);
|
||||
}
|
||||
|
||||
{
|
||||
std::array<uint8_t, 5> key = { 0x01, 0x02, 0x03, 0x04, 0x05 };
|
||||
|
||||
Arc4Crypt crypt(key.begin(), key.end());
|
||||
|
||||
std::array<uint8_t, 44> out;
|
||||
out.fill(0);
|
||||
|
||||
std::array<uint8_t, 44> expected;
|
||||
expected.fill(0);
|
||||
|
||||
crypt.Encrypt(out.begin(), data.begin(), 0);
|
||||
|
||||
ASSERT_EQ(expected, out);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user