Documentation ¶
Overview ¶
Package kee simplifies generating, parsing, composing, encoding and decoding resource identifiers
Index ¶
- Variables
- func ClockSequence() int
- func SetClockSequence(seq int)
- type APIIDCtrl
- type FPIIDConfig
- type FPIIDCtrl
- type GenericID
- type Handler
- type JUMCtrl
- type KAPIID
- type KFPIID
- type KJUMBLE
- type KTOTP
- type KUUID
- func (id *KUUID) A85() string
- func (id KUUID) Arr() (res [16]byte)
- func (id *KUUID) B32() string
- func (id *KUUID) B64() string
- func (id KUUID) ClockSequence() (int, bool)
- func (id *KUUID) Hex() string
- func (id KUUID) IsValid() (valid bool)
- func (id KUUID) NodeID() []byte
- func (id KUUID) Slc() []byte
- func (id KUUID) String() string
- func (id KUUID) Time() (Time, bool)
- func (id *KUUID) URL32() string
- func (id *KUUID) URL64() string
- func (id *KUUID) URN() string
- func (id KUUID) Variant() uuidVariant
- func (id KUUID) Version() uuidVersion
- type TOTPConfig
- type TOTPCtrl
- type Time
- type UUIDConfig
- type UUIDCtrl
- func (c UUIDCtrl) Decode(s string) (KUUID, error)
- func (_ UUIDCtrl) Match(ida, idb KUUID) bool
- func (c UUIDCtrl) New() KUUID
- func (c UUIDCtrl) NewV1() (KUUID, error)
- func (c UUIDCtrl) NewV2() (KUUID, error)
- func (c UUIDCtrl) NewV3(id KUUID, data []byte) (KUUID, error)
- func (c UUIDCtrl) NewV4() (KUUID, error)
- func (c UUIDCtrl) NewV5(id KUUID, data []byte) (KUUID, error)
- func (c UUIDCtrl) NodeID() []byte
- func (_ UUIDCtrl) NodeInterface() string
- func (c UUIDCtrl) Set(arr [16]byte) KUUID
- func (c UUIDCtrl) SetNodeID(id []byte) bool
- func (c UUIDCtrl) SetNodeInterface(name string) bool
Constants ¶
This section is empty.
Variables ¶
var ( // UUID handler for creating Universally Unique Identifiers UUID UUIDCtrl // FPIID handler for creating Fixed Precision Integer Identifiers FPIID FPIIDCtrl // APIID handler for creating Arbitrary Precision Integer Identifiers APIID APIIDCtrl // TOTP handler for One-time Time Based Passwords TOTP TOTPCtrl // JUMBLE handler for word-jumble identifiers JUMBLE JUMCtrl )
var APIIDOptions = apiidConfig{ Cache: true, }
APIIDOptions defines the configuration used by the `kee.APIID` handler. Options can also be changed through `kee.APIID.Options`.
var FPIIDOptions = FPIIDConfig{ Cache: true, ShortStr: true, PadB64: true, PadB32: true, HyphURL32: true, }
FPIIDOptions defines the configuration used by the `kee.FPIID` handler. Options can also be changed through `kee.FPIID.Options`.
var TOTPOptions = TOTPConfig{ LookAhead: 1, LookBehind: 1, B32Blocks: 8, HyphB32: true, }
TOTPOptions defines the configuration used by the `kee.TOTP` handler. Options can also be changed through `kee.TOTP.Options`.
var UUIDOptions = UUIDConfig{ Cache: true, AllowInvalid: false, MinVer: 1, MaxVer: 5, PadB64: true, PadB32: true, WrapA85: false, HyphURL32: true, }
UUIDOptions defines the configuration used by the `kee.UUID` handler. Options can also be changed through `kee.UUID.Options`.
Functions ¶
func ClockSequence ¶
func ClockSequence() int
ClockSequence returns the current clock sequence, generating one if not already set. The clock sequence is only used for Version 1 UUIDs.
The UUID package does not use global static storage for the clock sequence or the last time a UUID was generated. Unless SetClockSequence a new random clock sequence is generated the first time a clock sequence is requested by ClockSequence, GetTime, or NewUUID. (section 4.2.1.1) sequence is generated for
func SetClockSequence ¶
func SetClockSequence(seq int)
SetClockSequence sets the clock sequence to the lower 14 bits of seq. Setting to -1 causes a new sequence to be generated.
Types ¶
type APIIDCtrl ¶ added in v0.2.0
type APIIDCtrl struct {
Options *apiidConfig
}
APIIDCtrl is a struct for the APIID handler. Unless another handler with different options is needed simply use instance `kee.APIID`.
func (APIIDCtrl) Decode ¶ added in v0.2.0
Decode takes base 58 encoded string of APIID and returns KAPIID instance
func (APIIDCtrl) FromBigInt ¶ added in v0.2.0
FromBigInt takes math/big Int and return KAPIID instance
func (APIIDCtrl) FromString ¶ added in v0.2.0
FromString takes string representation of arbitrary precision integer and return KAPIID instance
type FPIIDConfig ¶ added in v0.2.5
FPIIDConfig is the struct for FPIIDOptions. It should only be used if another handler with a different set of options is being created.
type FPIIDCtrl ¶ added in v0.2.0
type FPIIDCtrl struct {
Options *FPIIDConfig
}
FPIIDCtrl is a struct for the APIID handler. Unless another handler with different options is needed simply use instance `kee.FPIID`.
func (FPIIDCtrl) Decode ¶ added in v0.2.0
Decode takes encoded string of FPIID and returns KFPIID instance
type GenericID ¶
type GenericID struct {
// contains filtered or unexported fields
}
GenericID type is for custom identifiers
type Handler ¶ added in v0.2.5
type Handler struct {
// contains filtered or unexported fields
}
Handler is a handler for custom IDs. Use NewHandler to instantiate.
func NewHandler ¶
NewHandler returns a custom ID handler with provided pattern and template
type JUMCtrl ¶ added in v0.2.0
type JUMCtrl struct {
// contains filtered or unexported fields
}
JUMCtrl is a struct for the JUMBLE handler. Unless another handler is needed simply use instance `kee.JUMBLE`.
type KAPIID ¶ added in v0.2.0
type KAPIID struct {
// contains filtered or unexported fields
}
KAPIID type represents an arbitrary precision integer identifier. It is exported only for reference and should be instantiated through its handler's methods.
type KFPIID ¶ added in v0.2.0
type KFPIID struct {
// contains filtered or unexported fields
}
KFPIID type represents a fixed precision integer identifier. It is exported only for reference and should be instantiated through its handler's methods.
type KJUMBLE ¶ added in v0.2.0
type KJUMBLE struct {
// contains filtered or unexported fields
}
KJUMBLE type represents a word jumble phrase. It is exported only for reference and should be instantiated through its handler's methods.
func (KJUMBLE) SampleSpace ¶ added in v0.2.0
SampleSpace returns the sample space (number of variations) possible for this phrase
type KTOTP ¶ added in v0.2.0
type KTOTP struct {
// contains filtered or unexported fields
}
KTOTP type represents a secret capable of producing time-based one time passwords. (RFC 6238) It is exported only for reference and should be instantiated through its handler's methods.
func (*KTOTP) MakePassword ¶ added in v0.2.0
MakePassword returns a slice of 6-digit time based passwords
type KUUID ¶ added in v0.2.0
type KUUID struct {
// contains filtered or unexported fields
}
KUUID type represents a Universally unique identifier. (RFC 4122) It is exported only for reference and should be instantiated through its handler's methods.
func (KUUID) ClockSequence ¶ added in v0.2.0
ClockSequence returns the clock sequence encoded in UUID. It returns false if UUID is not valid. The clock sequence is only well defined for version 1 and 2 UUIDs.
func (*KUUID) Hex ¶ added in v0.2.0
Hex returns canonical hex string representation of UUID, as in RFC 4122
func (KUUID) IsValid ¶ added in v0.2.0
IsValid returns true if the the UUID is valid according to settings, false if not
func (KUUID) NodeID ¶ added in v0.2.0
NodeID returns the 6 byte node id encoded in UUID. It returns nil if UUID is not valid. The NodeID is only well defined for version 1 and 2 UUIDs.
func (KUUID) Time ¶ added in v0.2.0
Time returns the time in 100s of nanoseconds since 15 Oct 1582 encoded in UUID. It returns false if UUID is not valid. The time is only well defined for version 1 and 2 UUIDs.
func (*KUUID) URL32 ¶ added in v0.2.0
URL32 returns formatted, URL-safe base 32 representation of UUID
type TOTPConfig ¶ added in v0.2.5
TOTPConfig is the struct for TOTPOptions. It should only be used if another handler with a different set of options is being created.
type TOTPCtrl ¶ added in v0.2.0
type TOTPCtrl struct {
Options *TOTPConfig
}
TOTPCtrl is a struct for the TOTP handler. Unless another handler with different options is needed simply use instance `kee.TOTP`.
func (TOTPCtrl) Decode ¶ added in v0.2.0
Decode takes base 32 encoded string of secret and returns KTOTP instance
func (TOTPCtrl) MatchPasswords ¶ added in v0.2.0
MatchPasswords compares expected and received secrets, return true if they match, false if not
type Time ¶
type Time int64
A Time represents a time as the number of 100's of nanoseconds since 15 Oct 1582.
type UUIDConfig ¶ added in v0.2.5
type UUIDConfig struct {
Cache, AllowInvalid bool
MinVer, MaxVer uint8
PadB64, PadB32, WrapA85, HyphURL32 bool
}
UUIDConfig is the struct for UUIDOptions. It should only be used if another handler with a different set of options is being created.
type UUIDCtrl ¶ added in v0.2.0
type UUIDCtrl struct { Options *UUIDConfig NS map[string]string // Namespaces }
UUIDCtrl is a struct for the UUID handler. Unless another handler with different options is needed simply use instance `kee.UUID`.
func (UUIDCtrl) Decode ¶ added in v0.2.0
Decode takes encoded string of UUID and returns KUUID instance
func (UUIDCtrl) Match ¶ added in v0.2.0
Match takes two KUUID instances; returns `true` if they are identical or false if not
func (UUIDCtrl) New ¶ added in v0.2.0
New is alias for NewV4; returns random Version 4 UUID and as KUUID instance
func (UUIDCtrl) NewV1 ¶ added in v0.2.0
NewV1 returns a Version 1 UUID based on the current NodeID and clock sequence, and the current time. If the NodeID has not been set by SetNodeID or SetNodeInterface then it will be set automatically. If the NodeID cannot be set NewUUID returns nil. If clock sequence has not been set by SetClockSequence then it will be set automatically. If GetTime fails to return the current NewUUID returns nil.
func (UUIDCtrl) NewV3 ¶ added in v0.2.0
NewMD5 returns a new MD5 (Version 3) UUID based on the supplied name space and data. Furst
func (UUIDCtrl) NewV4 ¶ added in v0.2.0
NewV4 returns a Random (Version 4) UUID or panics.
The strength of the UUIDs is based on the strength of the crypto/rand package.
A note about uniqueness derived from from the UUID Wikipedia entry:
Randomly generated UUIDs have 122 random bits. One's annual risk of being hit by a meteorite is estimated to be one chance in 17 billion, that means the probability is about 0.00000000006 (6 × 10−11), equivalent to the odds of creating a few tens of trillions of UUIDs in a year and having one duplicate.
func (UUIDCtrl) NewV5 ¶ added in v0.2.0
NewV5 returns a new SHA1 (Version 5) UUID based on the supplied name space and data.
func (UUIDCtrl) NodeID ¶ added in v0.2.0
NodeID returns a slice of a copy of the current Node ID, setting the Node ID if not already set.
func (UUIDCtrl) NodeInterface ¶ added in v0.2.0
NodeInterface returns the name of the interface from which the NodeID was derived. The interface "user" is returned if the NodeID was set by SetNodeID.
func (UUIDCtrl) SetNodeID ¶ added in v0.2.0
SetNodeID sets the Node ID to be used for Version 1 UUIDs. The first 6 bytes of id are used. If id is less than 6 bytes then false is returned and the Node ID is not set.
func (UUIDCtrl) SetNodeInterface ¶ added in v0.2.0
SetNodeInterface selects the hardware address to be used for Version 1 UUIDs. If name is "" then the first usable interface found will be used or a random Node ID will be generated. If a named interface cannot be found then false is returned.
SetNodeInterface never fails when name is "".