// 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 fingerprintimport ()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) := 0for , := range { [] = ++if ()%2 != 0 && < -1 { [] = byte(':') ++ } }returnstring(), nil}
The pages are generated with Goldsv0.8.2. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.