tsha1.nim 955 B

12345678910111213141516171819202122232425
  1. import std/sha1
  2. import std/assertions
  3. let hash1 = secureHash("a93tgj0p34jagp9[agjp98ajrhp9aej]")
  4. doAssert hash1 == hash1
  5. doAssert parseSecureHash($hash1) == hash1
  6. template checkVector(s, exp: string) =
  7. doAssert secureHash(s) == parseSecureHash(exp)
  8. checkVector("", "da39a3ee5e6b4b0d3255bfef95601890afd80709")
  9. checkVector("abc", "a9993e364706816aba3e25717850c26c9cd0d89d")
  10. checkVector("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
  11. "84983e441c3bd26ebaae4aa1f95129e5e54670f1")
  12. proc testIsValidSha1Hash =
  13. doAssert not isValidSha1Hash("")
  14. doAssert not isValidSha1Hash("042D4BE2B90ED0672E717D71850ABDB0A2D19CD11")
  15. doAssert not isValidSha1Hash("042G4BE2B90ED0672E717D71850ABDB0A2D19CD1")
  16. doAssert isValidSha1Hash("042D4BE2B90ED0672E717D71850ABDB0A2D19CD1")
  17. doAssert isValidSha1Hash("042d4be2b90ed0672e717d71850abdb0a2d19cd1")
  18. doAssert isValidSha1Hash("042d4be2b90ed0672e717D71850ABDB0A2D19CD1")
  19. testIsValidSha1Hash()