|
|
|
@@ -240,28 +240,34 @@ class SHA256Tests : public UnitTest |
|
|
|
public:
|
|
|
|
SHA256Tests() : UnitTest ("SHA-256") {}
|
|
|
|
|
|
|
|
void runTest()
|
|
|
|
void test (const char* input, const char* expected)
|
|
|
|
{
|
|
|
|
beginTest ("SHA-256");
|
|
|
|
|
|
|
|
{
|
|
|
|
char n[] = "";
|
|
|
|
SHA256 sha (n, 0);
|
|
|
|
expectEquals (sha.toHexString(), String ("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"));
|
|
|
|
SHA256 hash (input, strlen (input));
|
|
|
|
expectEquals (hash.toHexString(), String (expected));
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
const char n[] = "The quick brown fox jumps over the lazy dog";
|
|
|
|
SHA256 sha (n, sizeof (n) - 1);
|
|
|
|
expectEquals (sha.toHexString(), String ("d7a8fbb307d7809469ca9abcb0082e4f8d5651e46d3cdb762d02d0bf37c9e592"));
|
|
|
|
CharPointer_UTF8 utf8 (input);
|
|
|
|
SHA256 hash (utf8);
|
|
|
|
expectEquals (hash.toHexString(), String (expected));
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
const char n[] = "The quick brown fox jumps over the lazy dog.";
|
|
|
|
SHA256 sha (n, sizeof (n) - 1);
|
|
|
|
expectEquals (sha.toHexString(), String ("ef537f25c895bfa782526529a9b63d97aa631564d5d789c2b765448c8635fb6c"));
|
|
|
|
MemoryInputStream m (input, strlen (input), false);
|
|
|
|
SHA256 hash (m);
|
|
|
|
expectEquals (hash.toHexString(), String (expected));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void runTest()
|
|
|
|
{
|
|
|
|
beginTest ("SHA256");
|
|
|
|
|
|
|
|
test ("", "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855");
|
|
|
|
test ("The quick brown fox jumps over the lazy dog", "d7a8fbb307d7809469ca9abcb0082e4f8d5651e46d3cdb762d02d0bf37c9e592");
|
|
|
|
test ("The quick brown fox jumps over the lazy dog.", "ef537f25c895bfa782526529a9b63d97aa631564d5d789c2b765448c8635fb6c");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static SHA256Tests sha256UnitTests;
|
|
|
|
|