1
0

sha_test.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. package cryptoutil
  2. import (
  3. "testing"
  4. "github.com/stretchr/testify/assert"
  5. )
  6. func TestSHA1(t *testing.T) {
  7. tests := []struct {
  8. input string
  9. output string
  10. }{
  11. {input: "", output: "da39a3ee5e6b4b0d3255bfef95601890afd80709"},
  12. {input: "The quick brown fox jumps over the lazy dog", output: "2fd4e1c67a2d28fced849ee1bb76e7391b93eb12"},
  13. {input: "The quick brown fox jumps over the lazy dog.", output: "408d94384216f890ff7a0c3528e8bed1e0b01621"},
  14. }
  15. for _, test := range tests {
  16. t.Run(test.input, func(t *testing.T) {
  17. assert.Equal(t, test.output, SHA1(test.input))
  18. })
  19. }
  20. }
  21. func TestSHA256(t *testing.T) {
  22. tests := []struct {
  23. input string
  24. output string
  25. }{
  26. {input: "", output: "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"},
  27. {input: "The quick brown fox jumps over the lazy dog", output: "d7a8fbb307d7809469ca9abcb0082e4f8d5651e46d3cdb762d02d0bf37c9e592"},
  28. {input: "The quick brown fox jumps over the lazy dog.", output: "ef537f25c895bfa782526529a9b63d97aa631564d5d789c2b765448c8635fb6c"},
  29. }
  30. for _, test := range tests {
  31. t.Run(test.input, func(t *testing.T) {
  32. assert.Equal(t, test.output, SHA256(test.input))
  33. })
  34. }
  35. }