You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
986 B

  1. // Use of this source code is governed by an ISC
  2. // license that can be found in the LICENSE file.
  3. package x11
  4. import (
  5. "bytes"
  6. "encoding/hex"
  7. "testing"
  8. )
  9. func TestHash(t *testing.T) {
  10. hs := New()
  11. out := [32]byte{}
  12. for i := range tsInfo {
  13. ln := len(tsInfo[i].out)
  14. dest := make([]byte, ln)
  15. hs.Hash(tsInfo[i].in[:], out[:])
  16. if ln != hex.Encode(dest, out[:]) {
  17. t.Errorf("%s: invalid length", tsInfo[i])
  18. }
  19. if !bytes.Equal(dest[:], tsInfo[i].out[:]) {
  20. t.Errorf("%s: invalid hash", tsInfo[i].id)
  21. }
  22. }
  23. }
  24. ////////////////
  25. var tsInfo = []struct {
  26. id string
  27. in []byte
  28. out []byte
  29. }{
  30. {
  31. "Empty",
  32. []byte(""),
  33. []byte("51b572209083576ea221c27e62b4e22063257571ccb6cc3dc3cd17eb67584eba"),
  34. },
  35. {
  36. "Dash",
  37. []byte("DASH"),
  38. []byte("fe809ebca8753d907f6ad32cdcf8e5c4e090d7bece5df35b2147e10b88c12d26"),
  39. },
  40. {
  41. "Fox",
  42. []byte("The quick brown fox jumps over the lazy dog"),
  43. []byte("534536a4e4f16b32447f02f77200449dc2f23b532e3d9878fe111c9de666bc5c"),
  44. },
  45. }