fingerprint.go 617 B

12345678910111213141516171819202122232425262728293031
  1. package bridgefingerprint
  2. import (
  3. "encoding/hex"
  4. "errors"
  5. )
  6. type Fingerprint string
  7. var ErrBridgeFingerprintInvalid = errors.New("bridge fingerprint invalid")
  8. func FingerprintFromBytes(bytes []byte) (Fingerprint, error) {
  9. n := len(bytes)
  10. if n != 20 && n != 32 {
  11. return Fingerprint(""), ErrBridgeFingerprintInvalid
  12. }
  13. return Fingerprint(bytes), nil
  14. }
  15. func FingerprintFromHexString(hexString string) (Fingerprint, error) {
  16. decoded, err := hex.DecodeString(hexString)
  17. if err != nil {
  18. return "", err
  19. }
  20. return FingerprintFromBytes(decoded)
  21. }
  22. func (f Fingerprint) ToBytes() []byte {
  23. return []byte(f)
  24. }