Represent Bridge Fingerprint As String

This commit is contained in:
Shelikhoo 2022-05-17 15:53:15 +01:00
parent dd61e2be0f
commit f789dce6d2
No known key found for this signature in database
GPG key ID: C4D5E79D22B25316
7 changed files with 69 additions and 21 deletions

View file

@ -0,0 +1,30 @@
package bridgefingerprint
import (
"encoding/hex"
"errors"
)
type Fingerprint string
var ErrBridgeFingerprintInvalid = errors.New("bridge fingerprint invalid")
func FingerprintFromBytes(bytes []byte) (Fingerprint, error) {
n := len(bytes)
if n != 20 && n != 32 {
return Fingerprint(""), ErrBridgeFingerprintInvalid
}
return Fingerprint(bytes), nil
}
func FingerprintFromHexString(hexString string) (Fingerprint, error) {
decoded, err := hex.DecodeString(hexString)
if err != nil {
return "", err
}
return FingerprintFromBytes(decoded)
}
func (f Fingerprint) ToBytes() []byte {
return []byte(f)
}