Skip to content

Commit

Permalink
return concrete type
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoPolo committed Jan 23, 2025
1 parent 0d67dd8 commit ac80c8a
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion p2p/transport/webtransport/crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,15 @@ func generateCert(key ic.PrivKey, start, end time.Time) (*x509.Certificate, *ecd
return ca, caPrivateKey, nil
}

type ErrCertHashMismatch struct {
Expected [][]byte
Actual []byte
}

func (e ErrCertHashMismatch) Error() string {
return fmt.Sprintf("cert hash mismatch: expected %#x, got %#x", e.Expected, e.Actual)
}

func verifyRawCerts(rawCerts [][]byte, certHashes []multihash.DecodedMultihash) error {
if len(rawCerts) < 1 {
return errors.New("no cert")
Expand All @@ -105,7 +114,7 @@ func verifyRawCerts(rawCerts [][]byte, certHashes []multihash.DecodedMultihash)
for _, h := range certHashes {
digests = append(digests, h.Digest)
}
return fmt.Errorf("cert hash not found: %#x (expected: %#x)", hash, digests)
return ErrCertHashMismatch{Expected: digests, Actual: hash[:]}
}

cert, err := x509.ParseCertificate(leaf)
Expand Down

0 comments on commit ac80c8a

Please sign in to comment.