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
- Variables
- func CollidesWithHardCodedID(testID *ID) bool
- type ID
- func GetHardCodedIDs() []*ID
- func NewIDListFromBytes(topology [][]byte) ([]*ID, error)
- func NewIdFromBase64String(base64String string, idType Type, x interface{}) *ID
- func NewIdFromBytes(data []byte, x interface{}) *ID
- func NewIdFromString(idString string, idType Type, x interface{}) *ID
- func NewIdFromUInt(idUInt uint64, idType Type, x interface{}) *ID
- func NewIdFromUInts(idUInts [4]uint64, idType Type, x interface{}) *ID
- func NewRandomID(r io.Reader, t Type) (*ID, error)
- func NewRandomTestID(r io.Reader, t Type, x interface{}) *ID
- func Unmarshal(data []byte) (*ID, error)
- func (id *ID) Bytes() []byte
- func (id *ID) Cmp(y *ID) booldeprecated
- func (id *ID) Compare(y *ID) int
- func (id *ID) DeepCopy() *ID
- func (id *ID) Equal(y *ID) bool
- func (id *ID) GetType() Type
- func (id *ID) HexEncode() string
- func (id *ID) Less(y *ID) bool
- func (id *ID) Marshal() []byte
- func (id ID) MarshalJSON() ([]byte, error)
- func (id ID) MarshalText() (text []byte, err error)
- func (id *ID) SetType(idType Type)
- func (id *ID) String() string
- func (id *ID) UnmarshalJSON(b []byte) error
- func (id *ID) UnmarshalText(text []byte) error
- type Round
- type Type
Constants ¶
const ( Generic = Type(iota) Gateway Node User Group NumTypes // Gives number of ID types )
List of ID types
const (
// ArrIDLen is the length of the full ID array.
ArrIDLen = dataLen + 1
)
Variables ¶
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 ¶
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 ¶
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 ¶
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
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 ¶
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 ¶
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 ¶
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 ¶
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
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
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 (*ID) Bytes ¶
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) Compare ¶ added in v0.0.4
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) Equal ¶ added in v0.0.4
Equal determines whether two IDs are equal. Returns true if they are equal and false otherwise.
func (ID) MarshalJSON ¶ added in v0.0.4
MarshalJSON marshals the ID into valid JSON. This function adheres to the json.Marshaler interface.
func (ID) MarshalText ¶ added in v0.0.4
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) UnmarshalJSON ¶ added in v0.0.4
UnmarshalJSON unmarshalls the JSON into the ID. This function adheres to the json.Unmarshaler interface.
func (*ID) UnmarshalText ¶ added in v0.0.4
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).