id

package
v0.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 5, 2023 License: BSD-2-Clause Imports: 11 Imported by: 149

Documentation

Overview

Package id contains the generic ID type, which is a byte array that represents an entity ID. The first bytes in the array contain the actual ID data while the last byte contains the ID type, which is either generic, gateway, node, or user. IDs can be hard coded or generated using a cryptographic function found in crypto.

Index

Constants

View Source
const (
	Generic = Type(iota)
	Gateway
	Node
	User
	Group
	NumTypes // Gives number of ID types
)

List of ID types

View Source
const (

	// ArrIDLen is the length of the full ID array.
	ArrIDLen = dataLen + 1
)

Variables

View Source
var (
	// Permissioning is the ID for the permissioning server (data is the string
	// "Permissioning").
	Permissioning = ID{80, 101, 114, 109, 105, 115, 115, 105, 111, 110, 105,
		110, 103, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
		byte(Generic)}

	// Authorizer is the ID for the authorizer (data is the string "authorizer").
	Authorizer = ID{97, 117, 116, 104, 111, 114, 105, 122, 101, 114, 0, 0, 0, 0,
		0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, byte(Generic)}

	// ClientRegistration is the ID for client registration (ID data is the
	// string "client-registration")
	ClientRegistration = ID{99, 108, 105, 101, 110, 116, 45, 114, 101, 103, 105,
		115, 116, 114, 97, 116, 105, 111, 110, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
		0, 0, byte(Generic)}

	// NotificationBot is the ID for the notification bot (data is the string
	// "notification-bot").
	NotificationBot = ID{110, 111, 116, 105, 102, 105, 99, 97, 116, 105, 111,
		110, 45, 98, 111, 116, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
		byte(Generic)}

	// TempGateway is the ID for a temporary gateway (data is the string "tmp").
	TempGateway = ID{116, 109, 112, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
		0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, byte(Gateway)}

	// ZeroUser is the ID for a user with the ID data set to all zeroes.
	ZeroUser = ID{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
		0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, byte(User)}

	// DummyUser is the ID for a dummy user (data is the string "dummy").
	DummyUser = ID{100, 117, 109, 109, 121, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
		0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, byte(User)}

	// UDB is the ID for user discovery (data is in the range of dummy IDs).
	UDB = ID{0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
		0, 0, 0, 0, 0, 0, 0, 0, 0, 0, byte(User)}
)

Functions

func CollidesWithHardCodedID

func CollidesWithHardCodedID(testID *ID) bool

CollidesWithHardCodedID searches if the given ID collides with any hard coded IDs. If it collides, then the function returns true. Otherwise, it returns false.

Types

type ID

type ID [ArrIDLen]byte

ID is a fixed-length array containing data that services as an identifier for entities. The first 32 bytes hold the ID data while the last byte holds the type, which describes the type of entity the ID belongs to.

func GetHardCodedIDs

func GetHardCodedIDs() []*ID

GetHardCodedIDs returns an array of all the hard coded IDs.

func NewIDListFromBytes

func NewIDListFromBytes(topology [][]byte) ([]*ID, error)

NewIDListFromBytes creates a list of id.ID from a list of byte slices returns it. An error is returned if any IDs fail to unmarshal.

func NewIdFromBase64String added in v0.0.4

func NewIdFromBase64String(base64String string, idType Type, x interface{}) *ID

NewIdFromBase64String creates a new ID that when base 64 encoded, looks like the passed in base64String. This function is for testing purposes only.

If the string is longer than the data portion of the base 64 string, then it is truncated. If it is shorter, then the remaining bytes are filled with zeroes. The string is made to be base 64 compatible by replacing one or more consecutive white spaces with a plus "+" and stripping all other invalid characters (any character that is not an upper- and lower-case alphabet character (A–Z, a–z), numeral (0–9), or the plus "+" and slash "/" symbols).

func NewIdFromBytes

func NewIdFromBytes(data []byte, x interface{}) *ID

NewIdFromBytes creates a new ID from the supplied byte slice. It is similar to Unmarshal but does not do any error checking. If the data is longer than ArrIDLen, then it is truncated. If it is shorter, then the remaining bytes are filled with zeroes. This function is for testing purposes only.

func NewIdFromString

func NewIdFromString(idString string, idType Type, x interface{}) *ID

NewIdFromString creates a new ID from the given string and type. If the string is longer than dataLen, then it is truncated. If it is shorter, then the remaining bytes are filled with zeroes. This function is for testing purposes only.

func NewIdFromUInt

func NewIdFromUInt(idUInt uint64, idType Type, x interface{}) *ID

NewIdFromUInt converts the specified uint64 into bytes and returns a new ID based off it with the specified ID type. The remaining space of the array is filled with zeros. This function is for testing purposes only.

func NewIdFromUInts

func NewIdFromUInts(idUInts [4]uint64, idType Type, x interface{}) *ID

NewIdFromUInts converts the specified uint64 array into bytes and returns a new ID based off it with the specified ID type. Unlike NewIdFromUInt, the four uint64s provided fill the entire ID array. This function is for testing purposes only.

func NewRandomID added in v0.0.4

func NewRandomID(r io.Reader, t Type) (*ID, error)

NewRandomID generates a random ID using the passed in io.Reader r and sets the ID to Type t. If the base64 string of the generated ID does not begin with an alphanumeric character, then another ID is generated until the encoding begins with an alphanumeric character.

func NewRandomTestID added in v0.0.4

func NewRandomTestID(r io.Reader, t Type, x interface{}) *ID

NewRandomTestID generates a random ID using the passed in io.Reader r and sets the ID to Type t. If the base64 string of the generated ID does not begin with an alphanumeric character, then another ID is generated until the encoding begins with an alphanumeric character.

This function is intended for testing purposes.

func Unmarshal

func Unmarshal(data []byte) (*ID, error)

Unmarshal unmarshalls the ID wire format into an ID object.

func (*ID) Bytes

func (id *ID) Bytes() []byte

Bytes returns a copy of an ID as a byte slice. Note that Bytes is used by Marshal and any changes made here will affect how Marshal functions.

func (*ID) Cmp deprecated

func (id *ID) Cmp(y *ID) bool

Cmp determines whether two IDs are equal. Returns true if they are equal and false otherwise.

Deprecated: Use ID.Equal instead.

func (*ID) Compare added in v0.0.4

func (id *ID) Compare(y *ID) int

Compare returns an integer comparing the two IDs lexicographically. The result will be 0 if id == y, -1 if id < y, and +1 if id > y.

func (*ID) DeepCopy

func (id *ID) DeepCopy() *ID

DeepCopy creates a copy of an ID.

func (*ID) Equal added in v0.0.4

func (id *ID) Equal(y *ID) bool

Equal determines whether two IDs are equal. Returns true if they are equal and false otherwise.

func (*ID) GetType

func (id *ID) GetType() Type

GetType returns the ID's type. It is the last byte of the array.

func (*ID) HexEncode added in v0.0.4

func (id *ID) HexEncode() string

HexEncode encodes the ID without the 33rd type byte.

func (*ID) Less added in v0.0.4

func (id *ID) Less(y *ID) bool

Less returns true if id is less than y.

func (*ID) Marshal

func (id *ID) Marshal() []byte

Marshal returns the ID bytes in wire format.

func (ID) MarshalJSON added in v0.0.4

func (id ID) MarshalJSON() ([]byte, error)

MarshalJSON marshals the ID into valid JSON. This function adheres to the json.Marshaler interface.

func (ID) MarshalText added in v0.0.4

func (id ID) MarshalText() (text []byte, err error)

MarshalText marshals the ID into base 64 encoded text. This function adheres to the encoding.TextMarshaler interface. This allows for the JSON marshalling of non-referenced IDs in maps (e.g., map[ID]int).

func (*ID) SetType

func (id *ID) SetType(idType Type)

SetType changes the ID type by setting the last byte to the specified type.

func (*ID) String

func (id *ID) String() string

String converts an ID to a string via base64 encoding.

func (*ID) UnmarshalJSON added in v0.0.4

func (id *ID) UnmarshalJSON(b []byte) error

UnmarshalJSON unmarshalls the JSON into the ID. This function adheres to the json.Unmarshaler interface.

func (*ID) UnmarshalText added in v0.0.4

func (id *ID) UnmarshalText(text []byte) error

UnmarshalText unmarshalls the text into an ID. This function adheres to the encoding.TextUnmarshaler interface. This allows for the JSON unmarshalling of non-referenced IDs in maps (e.g., map[ID]int).

type Round

type Round uint64

Round is the round ID for each round run in cMix.

func UnmarshalRound added in v0.0.4

func UnmarshalRound(b []byte) Round

UnmarshalRound deserializes the byte slice into a Round ID.

func (Round) Marshal added in v0.0.4

func (rid Round) Marshal() []byte

Marshal serialises the Round ID into a byte slice.

func (Round) String added in v0.0.4

func (rid Round) String() string

String returns the string representation of the Round ID. This functions adheres to the fmt.Stringer interface.

type Type

type Type byte

Type holds the numerical representation of the ID type.

func (Type) String

func (t Type) String() string

String returns the ID Type in a human-readable form for use in logging and debugging. This functions adheres to the fmt.Stringer interface.

Directories

Path Synopsis
Package idf contains the structure of the ID File.
Package idf contains the structure of the ID File.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL