-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcommunityid.go
More file actions
32 lines (29 loc) · 832 Bytes
/
communityid.go
File metadata and controls
32 lines (29 loc) · 832 Bytes
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
31
32
package gommunityid
import (
"fmt"
"hash"
)
// CommunityID is an interface defining the supported operations
// on a component calculating a specific community ID version.
type CommunityID interface {
Calc(FlowTuple) []byte
CalcHex(FlowTuple) string
CalcBase64(FlowTuple) string
Hash(FlowTuple) hash.Hash
Render(hash.Hash) []byte
RenderHex(hash.Hash) string
RenderBase64(hash.Hash) string
}
// GetCommunityIDByVersion returns, for a given version number and seed, an
// object implementing the CommunityID interface for the specified version.
// This will be preconfigured with the given seed.
func GetCommunityIDByVersion(version uint, seed uint16) (CommunityID, error) {
switch version {
case 1:
return CommunityIDv1{
Seed: seed,
}, nil
default:
return nil, fmt.Errorf("invalid version: %d", version)
}
}