sha_test.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Copyright 2020 The Gogs Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package cryptoutil
  5. import (
  6. "testing"
  7. "github.com/stretchr/testify/assert"
  8. )
  9. func TestSHA1(t *testing.T) {
  10. tests := []struct {
  11. input string
  12. output string
  13. }{
  14. {input: "", output: "da39a3ee5e6b4b0d3255bfef95601890afd80709"},
  15. {input: "The quick brown fox jumps over the lazy dog", output: "2fd4e1c67a2d28fced849ee1bb76e7391b93eb12"},
  16. {input: "The quick brown fox jumps over the lazy dog.", output: "408d94384216f890ff7a0c3528e8bed1e0b01621"},
  17. }
  18. for _, test := range tests {
  19. t.Run(test.input, func(t *testing.T) {
  20. assert.Equal(t, test.output, SHA1(test.input))
  21. })
  22. }
  23. }
  24. func TestSHA256(t *testing.T) {
  25. tests := []struct {
  26. input string
  27. output string
  28. }{
  29. {input: "", output: "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"},
  30. {input: "The quick brown fox jumps over the lazy dog", output: "d7a8fbb307d7809469ca9abcb0082e4f8d5651e46d3cdb762d02d0bf37c9e592"},
  31. {input: "The quick brown fox jumps over the lazy dog.", output: "ef537f25c895bfa782526529a9b63d97aa631564d5d789c2b765448c8635fb6c"},
  32. }
  33. for _, test := range tests {
  34. t.Run(test.input, func(t *testing.T) {
  35. assert.Equal(t, test.output, SHA256(test.input))
  36. })
  37. }
  38. }