diff options
author | siddharth <s@ricketyspace.net> | 2021-10-10 10:17:10 -0400 |
---|---|---|
committer | siddharth <s@ricketyspace.net> | 2021-10-10 10:17:21 -0400 |
commit | 4aa1b6bdc168756c5af0d7ec0d4f412d038a34ca (patch) | |
tree | 84e86e53f9845b0020255eec4a3e6c234adbeb59 /lib | |
parent | 15e142c3f12fd9228b69bcaf4a2703c9d8205d59 (diff) |
lib: add test for sha1
Diffstat (limited to 'lib')
-rw-r--r-- | lib/sha1_test.go | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/lib/sha1_test.go b/lib/sha1_test.go new file mode 100644 index 0000000..93fdb6f --- /dev/null +++ b/lib/sha1_test.go @@ -0,0 +1,46 @@ +// Copyright © 2021 rsiddharth <s@ricketyspace.net> +// SPDX-License-Identifier: ISC + +package lib + +import ( + "testing" +) + +func TestSha1Hash(t *testing.T) { + sha1 := Sha1{} + sha1.Init([]uint32{}) + + // Test 1 + m := "abc" + sha1.Message(StrToBytes(m)) + h := sha1.Hash() + e := "a9993e364706816aba3e25717850c26c9cd0d89d" // Expected hash. + if BytesToHexStr(h) != e { + t.Errorf("sha1 test 1 failed: %x != %s\n", h, e) + } + + // Test 2 + m = "abcdbcdecdefdefgefghfghighijhi" + m += "jkijkljklmklmnlmnomnopnopq" + sha1.Message(StrToBytes(m)) + h = sha1.Hash() + e = "84983e441c3bd26ebaae4aa1f95129e5e54670f1" // Expected hash. + if BytesToHexStr(h) != e { + t.Errorf("sha1 test 2 failed: %x != %s\n", h, e) + } + + // Test 3 + m = "" + m1 := "01234567012345670123456701234567" + m1 += "01234567012345670123456701234567" + for i := 0; i < 10; i++ { + m += m1 + } + sha1.Message(StrToBytes(m)) + h = sha1.Hash() + e = "dea356a2cddd90c7a7ecedc5ebb563934f460452" // Expected hash. + if BytesToHexStr(h) != e { + t.Errorf("sha1 test 3 failed: %x != %s\n", h, e) + } +} |