File: fingerprint.go

package info (click to toggle)
snowflake 2.10.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,104 kB
  • sloc: makefile: 5
file content (30 lines) | stat: -rw-r--r-- 617 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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)
}