hash_test.go 641 B

12345678910111213141516171819202122232425262728
  1. // SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
  2. // SPDX-License-Identifier: MIT
  3. package hash
  4. import (
  5. "testing"
  6. "github.com/pion/dtls/v2/pkg/crypto/fingerprint"
  7. )
  8. func TestHashAlgorithm_StringRoundtrip(t *testing.T) {
  9. for algo := range Algorithms() {
  10. if algo == Ed25519 || algo == None {
  11. continue
  12. }
  13. str := algo.String()
  14. hash1 := algo.CryptoHash()
  15. hash2, err := fingerprint.HashFromString(str)
  16. if err != nil {
  17. t.Fatalf("fingerprint.HashFromString failed: %v", err)
  18. }
  19. if hash1 != hash2 {
  20. t.Errorf("Hash algorithm mismatch, input: %d, after roundtrip: %d", int(hash1), int(hash2))
  21. }
  22. }
  23. }