// SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
// SPDX-License-Identifier: MIT

// Package fingerprint provides a helper to create fingerprint string from certificate
package fingerprint import ( ) var ( errHashUnavailable = errors.New("fingerprint: hash algorithm is not linked into the binary") errInvalidFingerprintLength = errors.New("fingerprint: invalid fingerprint length") ) // Fingerprint creates a fingerprint for a certificate using the specified hash algorithm. func ( *x509.Certificate, crypto.Hash) (string, error) { if !.Available() { return "", errHashUnavailable } := .New() for := 0; < len(.Raw); { , := .Write(.Raw[:]) // Hash.Writer is specified to be never returning an error. // https://golang.org/pkg/hash/#Hash += } := []byte(fmt.Sprintf("%x", .Sum(nil))) := len() if == 0 { return "", nil } if %2 != 0 { return "", errInvalidFingerprintLength } := make([]byte, >>1+-1) := 0 for , := range { [] = ++ if ()%2 != 0 && < -1 { [] = byte(':') ++ } } return string(), nil }