Documentation
¶
Overview ¶
Package objectid implements ASN.1 Object Identifier types and methods.
Features ¶
• Unsigned 128-bit arc support (i.e.: such as the registrations found below {joint-iso-itu-t(2) uuid(25)})
• Flexible index support, allowing interrogation through negative indices without the risk of panic
• Convenient Leaf, Parent and Root index alias methods, wherever allowed
Uint128 Support ¶
Unsigned 128-bit integer support for individual NumberForm values is made possible due to the private incorporation of Luke Champine's awesome Uint128 type, which manifests here through instances of the package-provided NumberForm type.
Valid NumberForm instances may fall between the minimum decimal value of zero (0) and the maximum decimal value of 340,282,366,920,938,463,463,374,607,431,768,211,455 (three hundred forty undecillion and change). This ensures no panics occur when parsing valid UUID-based object identifiers.
Index ¶
- type ASN1Notation
- func (a ASN1Notation) Index(idx int) (nanf NameAndNumberForm, ok bool)
- func (a ASN1Notation) Leaf() NameAndNumberForm
- func (a ASN1Notation) Len() int
- func (a ASN1Notation) Parent() NameAndNumberForm
- func (a ASN1Notation) Root() NameAndNumberForm
- func (a ASN1Notation) String() string
- func (a ASN1Notation) Valid() bool
- type DotNotation
- type NameAndNumberForm
- type NumberForm
- func (a NumberForm) Compare(v NumberForm) int
- func (a NumberForm) Compare64(v uint64) int
- func (a NumberForm) Equal(v NumberForm) bool
- func (a NumberForm) Equal64(v uint64) bool
- func (a *NumberForm) IsZero() bool
- func (a *NumberForm) Scan(s fmt.ScanState, ch rune) error
- func (a NumberForm) String() string
- func (a NumberForm) Valid() bool
- type OID
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ASN1Notation ¶
type ASN1Notation []NameAndNumberForm
ASN1Notation contains an ordered sequence of NameAndNumberForm instances.
func NewASN1Notation ¶
func NewASN1Notation(x any) (a *ASN1Notation, err error)
NewASN1Notation returns an instance of *ASN1Notation alongside an error.
Valid input forms for ASN.1 values are string (e.g.: "{iso(1)}") and string slices (e.g.: []string{"iso(1)", "identified-organization(3)" ...}).
NumberForm values CANNOT be negative, and CANNOT overflow NumberForm (uint128).
Example ¶
a := `{iso(1) identified-organization(3) dod(6)}` id, err := NewASN1Notation(a) if err != nil { fmt.Println(err) return } fmt.Printf("Leaf node: %s", id.Leaf())
Output: Leaf node: dod(6)
func (ASN1Notation) Index ¶
func (a ASN1Notation) Index(idx int) (nanf NameAndNumberForm, ok bool)
Index returns the nth index from the receiver, alongside a boolean value indicative of success. This method supports the use of negative indices.
func (ASN1Notation) Leaf ¶
func (a ASN1Notation) Leaf() NameAndNumberForm
Leaf returns the leaf node (-1) string value from the receiver.
func (ASN1Notation) Len ¶
func (a ASN1Notation) Len() int
Len returns the integer length of the receiver.
func (ASN1Notation) Parent ¶
func (a ASN1Notation) Parent() NameAndNumberForm
Parent returns the leaf node's parent (-2) string value from the receiver.
func (ASN1Notation) Root ¶
func (a ASN1Notation) Root() NameAndNumberForm
Root returns the root node (0) string value from the receiver.
func (ASN1Notation) String ¶
func (a ASN1Notation) String() string
String is a stringer method that returns a properly formatted ASN.1 string value.
func (ASN1Notation) Valid ¶
func (a ASN1Notation) Valid() bool
Valid returns a boolean value indicative of whether the receiver's length is greater than or equal to one (1) slice member.
type DotNotation ¶
type DotNotation []NumberForm
DotNotation contains an ordered sequence of NumberForm instances.
func NewDotNotation ¶
func NewDotNotation(id string) (d *DotNotation, err error)
NewDotNotation returns an instance of *DotNotation alongside a boolean value indicative of success.
Example ¶
a := `2.25.987895962269883002155146617097157934` id, err := NewDotNotation(a) if err != nil { fmt.Println(err) return } fmt.Printf("dotNotation: %s", id)
Output: dotNotation: 2.25.987895962269883002155146617097157934
func (DotNotation) Index ¶
func (d DotNotation) Index(idx int) (a NumberForm, ok bool)
Index returns the nth index from the receiver, alongside a boolean value indicative of success. This method supports the use of negative indices.
func (DotNotation) IntSlice ¶
func (d DotNotation) IntSlice() (slice []int, err error)
IntSlice returns slices of integer values based upon the contents of the receiver
Example ¶
a := `1.3.6.1.4.1.56521.999.5` dot, _ := NewDotNotation(a) // If needed, slice instance can be // cast as an asn1.ObjectIdentifier. slice, err := dot.IntSlice() if err != nil { fmt.Println(err) return } fmt.Printf("%v", slice)
Output: [1 3 6 1 4 1 56521 999 5]
Example (Overflow) ¶
a := `2.25.987895962269883002155146617097157934` dot, _ := NewDotNotation(a) if _, err := dot.IntSlice(); err != nil { fmt.Println(err) return }
Output: strconv.Atoi: parsing "987895962269883002155146617097157934": value out of range
func (DotNotation) Leaf ¶
func (d DotNotation) Leaf() NumberForm
Leaf returns the leaf-node (-1) NumberForm instance.
Example ¶
a := `2.25.987895962269883002155146617097157934` id, err := NewDotNotation(a) if err != nil { fmt.Println(err) return } fmt.Printf("Leaf node: %s", id.Leaf())
Output: Leaf node: 987895962269883002155146617097157934
func (DotNotation) Parent ¶
func (d DotNotation) Parent() NumberForm
Parent returns the leaf-node's parent (-2) NumberForm instance.
Example ¶
a := `2.25.987895962269883002155146617097157934` id, err := NewDotNotation(a) if err != nil { fmt.Println(err) return } fmt.Printf("Leaf node parent: %s", id.Parent())
Output: Leaf node parent: 25
func (DotNotation) Root ¶
func (d DotNotation) Root() NumberForm
Root returns the root node (0) NumberForm instance.
Example ¶
a := `2.25.987895962269883002155146617097157934` id, err := NewDotNotation(a) if err != nil { fmt.Println(err) return } fmt.Printf("Root node: %s", id.Root())
Output: Root node: 2
func (DotNotation) String ¶
func (d DotNotation) String() string
String is a stringer method that returns the dotNotation form of the receiver (e.g.: "1.3.6.1").
type NameAndNumberForm ¶
type NameAndNumberForm struct {
// contains filtered or unexported fields
}
NameAndNumberForm contains either an identifier with a parenthesis-enclosed decimal value, or a decimal value alone. An ordered sequence of instances of this type comprise an instance of ASN1Notation.
func NewNameAndNumberForm ¶
func NewNameAndNumberForm(x any) (nanf *NameAndNumberForm, err error)
NewNameAndNumberForm returns an instance of *NameAndNumberForm alongside an error. Valid input forms are:
• nameAndNumberForm (e.g.: "enterprise(1)"), or ...
• numberForm (e.g.: 1)
NumberForm components CANNOT be negative and CANNOT overflow NumberForm (uint128).
func (NameAndNumberForm) Equal ¶
func (nanf NameAndNumberForm) Equal(n NameAndNumberForm) bool
Equal returns a boolean value indicative of whether instance n of NameAndNumberForm matches the receiver.
func (NameAndNumberForm) Identifier ¶
func (nanf NameAndNumberForm) Identifier() string
Identifier returns the string-based nameForm value assigned to the receiver instance.
func (NameAndNumberForm) IsZero ¶
func (nanf NameAndNumberForm) IsZero() bool
IsZero returns a boolean valu indicative of whether the receiver is considered nil.
func (NameAndNumberForm) NumberForm ¶
func (nanf NameAndNumberForm) NumberForm() NumberForm
NumberForm returns the underlying NumberForm value assigned to the receiver instance.
func (NameAndNumberForm) String ¶
func (nanf NameAndNumberForm) String() (val string)
String is a stringer method that returns the properly formatted NameAndNumberForm string value.
type NumberForm ¶
type NumberForm struct {
// contains filtered or unexported fields
}
NumberForm is an unsigned 128-bit number. This type is based on github.com/lukechampine/uint128. It has been incorporated into this package to produce unsigned 128-bit OID numberForm support (i.e.: UUID-based OIDs).
func ParseNumberForm ¶
func ParseNumberForm(v any) (a NumberForm, err error)
ParseNumberForm converts v into an instance of NumberForm, which is returned alongside an error.
Acceptable input types are string, int and uint64. No decimal value, whether string or int, can ever be negative.
Example ¶
// single UUID integer parse example arc, err := ParseNumberForm(`987895962269883002155146617097157934`) if err != nil { fmt.Println(err) return } fmt.Printf("%s\n", arc)
Output: 987895962269883002155146617097157934
func (NumberForm) Compare ¶
func (a NumberForm) Compare(v NumberForm) int
Compare compares a and v and returns:
-1 if a < v 0 if a == v +1 if a > v
func (NumberForm) Compare64 ¶
func (a NumberForm) Compare64(v uint64) int
Compare64 compares a and v and returns:
-1 if a < v 0 if a == v +1 if a > v
func (NumberForm) Equal ¶
func (a NumberForm) Equal(v NumberForm) bool
Equal returns true if a == v.
NumberForm values can be compared directly with ==, but use of the Equals method // is preferred for consistency.
func (NumberForm) Equal64 ¶
func (a NumberForm) Equal64(v uint64) bool
Equal64 returns true if a == v.
func (*NumberForm) Scan ¶
func (a *NumberForm) Scan(s fmt.ScanState, ch rune) error
Scan implements fmt.Scanner, and is only present to allow conversion of an NumberForm into a string value per fmt.Sscan. Users need not execute this method directly.
func (NumberForm) String ¶
func (a NumberForm) String() string
String returns the base-10 representation of a as a string.
func (NumberForm) Valid ¶
func (a NumberForm) Valid() bool
Valid returns a boolean valud indicative of proper instantiation.
type OID ¶
type OID struct {
// contains filtered or unexported fields
}
OID contains an underlying ASN1Notation value, and extends convenient methods allowing interrogation and verification.
func NewOID ¶
NewOID creates an instance of OID and returns it alongside an error.
The correct raw input syntax is the ASN.1 NameAndNumberForm sequence syntax, i.e.:
{ iso(1) identified-organization(3) dod(6) }
Not all NameAndNumberForm values (arcs) require actual names; they can be numbers alone or in the so-called nameAndNumber syntax (name(Number)). For example:
{ iso(1) identified-organization(3) 6 }
... is perfectly valid, but generally NOT recommended when clarity or precision is desired.
Example ¶
// UUID-based (uint128) OID example a := `{joint-iso-itu-t(2) uuid(25) ans(987895962269883002155146617097157934)}` id, err := NewOID(a) if err != nil { fmt.Println(err) return } fmt.Printf("ASN.1 Notation: %s", id.ASN())
Output: ASN.1 Notation: {joint-iso-itu-t(2) uuid(25) ans(987895962269883002155146617097157934)}
func (OID) ASN ¶
func (id OID) ASN() ASN1Notation
ASN returns the underlying ASN1Notation instance found within the receiver.
func (OID) Dot ¶
func (id OID) Dot() DotNotation
Dot returns a DotNotation instance based on the contents of the underlying ASN1Notation instance found within the receiver.
func (*OID) IsZero ¶
IsZero checks the receiver for nilness and returns a boolean indicative of the result.
func (OID) Leaf ¶
func (id OID) Leaf() (nanf NameAndNumberForm)
Leaf returns the leaf-node instance of NameAndNumberForm.
Example ¶
a := `{joint-iso-itu-t(2) uuid(25) ans(987895962269883002155146617097157934)}` id, err := NewOID(a) if err != nil { fmt.Println(err) return } fmt.Printf("Leaf node: %s", id.Leaf())
Output: Leaf node: ans(987895962269883002155146617097157934)
func (OID) Len ¶
Len returns the integer length of all underlying NumberForm values present within the receiver.
func (OID) Parent ¶
func (id OID) Parent() (nanf NameAndNumberForm)
Parent returns the leaf-node's Parent instance of NameAndNumberForm.
Example ¶
a := `{joint-iso-itu-t(2) uuid(25) ans(987895962269883002155146617097157934)}` id, err := NewOID(a) if err != nil { fmt.Println(err) return } fmt.Printf("Leaf node parent: %s", id.Parent())
Output: Leaf node parent: uuid(25)
func (OID) Root ¶
func (id OID) Root() (nanf NameAndNumberForm)
Root returns the root node instance of NameAndNumberForm.
Example ¶
a := `{joint-iso-itu-t(2) uuid(25) ans(987895962269883002155146617097157934)}` id, err := NewOID(a) if err != nil { fmt.Println(err) return } fmt.Printf("Root node: %s", id.Root())
Output: Root node: joint-iso-itu-t(2)