Documentation ¶
Overview ¶
Package objectid implements ASN.1 Object Identifier types and methods.
Features ¶
- Unsigned 128-bit number form support (allows for expressing registrations found below {joint-iso-itu-t(2) uuid(25)}, per ITU-T Rec. X.667.
- Flexible index support, allowing interrogation through negative indices without the risk of panic
- Convenient Leaf, Parent and Root index alias methods, wherever applicable
- Ge, Gt, Le, Lt, Equal comparison methods for interacting with NumberForm instances
License ¶
The go-objectid package is available under the terms of the MIT license.
For further details, see the LICENSE file within the root of the source repository.
NumberForm Maximum ¶
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 UUID-based [OID]s.
Special Credit ¶
A special thanks to Luke Champine for his excellent Uint128 package (found at https://github.com/lukechampine/uint128), which is incorporated within this package.
Index ¶
- type ASN1Notation
- func (a ASN1Notation) AncestorOf(asn any) (anc bool)
- func (a ASN1Notation) Ancestry() (anc []ASN1Notation)
- func (a ASN1Notation) Index(idx int) (nanf NameAndNumberForm, ok bool)
- func (a ASN1Notation) IsZero() (is bool)
- func (a ASN1Notation) Leaf() NameAndNumberForm
- func (a ASN1Notation) Len() int
- func (a ASN1Notation) NewSubordinate(nanf any) *ASN1Notation
- func (a ASN1Notation) Parent() NameAndNumberForm
- func (a ASN1Notation) Root() NameAndNumberForm
- func (a ASN1Notation) String() string
- func (a ASN1Notation) Valid() (is bool)
- type DotNotation
- func (d DotNotation) AncestorOf(dot any) (is bool)
- func (d DotNotation) Ancestry() (anc []DotNotation)
- func (d DotNotation) Index(idx int) (a NumberForm, ok bool)
- func (d DotNotation) IntSlice() (slice []int, err error)
- func (d *DotNotation) IsZero() (is bool)
- func (d DotNotation) Leaf() NumberForm
- func (d DotNotation) Len() int
- func (d DotNotation) NewSubordinate(nf any) (dot *DotNotation)
- func (d DotNotation) Parent() NumberForm
- func (d DotNotation) Root() NumberForm
- func (d DotNotation) String() (s string)
- func (d DotNotation) Valid() (is bool)
- type NameAndNumberForm
- type NumberForm
- func (a NumberForm) Equal(n any) (is bool)
- func (a NumberForm) Ge(n any) (is bool)
- func (a NumberForm) Gt(n any) (is bool)
- func (a *NumberForm) IsZero() (is bool)
- func (a NumberForm) Le(n any) (is bool)
- func (a NumberForm) Lt(n any) (is bool)
- func (a *NumberForm) Scan(s fmt.ScanState, ch rune) error
- func (a NumberForm) String() string
- func (a NumberForm) Valid() bool
- type OID
- func (id OID) ASN() (a ASN1Notation)
- func (id OID) Dot() (d DotNotation)
- func (id *OID) IsZero() (is bool)
- func (id OID) Leaf() (nanf NameAndNumberForm)
- func (id OID) Len() (i int)
- func (id OID) Parent() (nanf NameAndNumberForm)
- func (id OID) Root() (nanf NameAndNumberForm)
- func (id OID) Valid() (ok bool)
Examples ¶
- ASN1Notation.AncestorOf
- ASN1Notation.Ancestry
- ASN1Notation.Index
- ASN1Notation.IsZero
- ASN1Notation.Leaf
- ASN1Notation.Len
- ASN1Notation.NewSubordinate
- ASN1Notation.Parent
- ASN1Notation.Root
- ASN1Notation.String
- ASN1Notation.Valid
- DotNotation.AncestorOf
- DotNotation.Ancestry
- DotNotation.Index
- DotNotation.IntSlice
- DotNotation.IntSlice (Overflow)
- DotNotation.IsZero
- DotNotation.Leaf
- DotNotation.Len
- DotNotation.NewSubordinate
- DotNotation.Parent
- DotNotation.Root
- DotNotation.String
- DotNotation.Valid
- NameAndNumberForm.Equal
- NameAndNumberForm.Identifier
- NameAndNumberForm.IsZero
- NameAndNumberForm.NumberForm
- NameAndNumberForm.String
- NewASN1Notation
- NewDotNotation
- NewNameAndNumberForm
- NewNumberForm
- NewOID
- NumberForm.Equal
- NumberForm.Ge
- NumberForm.Gt
- NumberForm.Gt (ByString)
- NumberForm.Gt (ByUint64)
- NumberForm.IsZero
- NumberForm.Le
- NumberForm.Lt
- NumberForm.Lt (ByString)
- NumberForm.Lt (ByUint64)
- NumberForm.String
- NumberForm.Valid
- OID.ASN
- OID.Dot
- OID.IsZero
- OID.Leaf
- OID.Len
- OID.Parent
- OID.Root
- OID.Valid
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) AncestorOf ¶
func (a ASN1Notation) AncestorOf(asn any) (anc bool)
AncestorOf returns a Boolean value indicative of whether the receiver is an ancestor of the input value, which can be string or ASN1Notation.
Example ¶
asn, _ := NewASN1Notation(`{iso(1) identified-organization(3) dod(6) internet(1)}`) child, _ := NewASN1Notation(`{iso(1) identified-organization(3) dod(6) internet(1) private(4) enterprise(1)}`) fmt.Printf("%t", asn.AncestorOf(child))
Output: true
func (ASN1Notation) Ancestry ¶
func (a ASN1Notation) Ancestry() (anc []ASN1Notation)
Ancestry returns slices of DotNotation values ordered from leaf node (first) to root node (last).
Empty slices of DotNotation are returned if the dotNotation value within the receiver is less than two (2) NumberForm values in length.
Example ¶
asn, err := NewASN1Notation(`{iso(1) identified-organization(3) dod(6) internet(1) private(4) enterprise(1) 56521 example(999)}`) if err != nil { fmt.Println(err) } anc := asn.Ancestry() fmt.Printf("%s", anc[len(anc)-2])
Output: {iso(1) identified-organization(3)}
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.
Example ¶
aNot, err := NewASN1Notation(`{iso(1) identified-organization(3) dod(6) internet(1) private(4) enterprise(1) 56521 example(999)}`) if err != nil { fmt.Println(err) return } nanf, _ := aNot.Index(1) fmt.Printf("%s", nanf)
Output: identified-organization(3)
func (ASN1Notation) IsZero ¶
func (a ASN1Notation) IsZero() (is bool)
IsZero returns a Boolean indicative of whether the receiver is unset.
Example ¶
var aNot ASN1Notation fmt.Printf("Is Zero: %t", aNot.IsZero())
Output: Is Zero: true
func (ASN1Notation) Leaf ¶
func (a ASN1Notation) Leaf() NameAndNumberForm
Leaf returns the leaf node (-1) string value from the receiver.
Example ¶
aNot, err := NewASN1Notation(`{iso(1) identified-organization(3) dod(6) internet(1) private(4) enterprise(1) 56521 example(999)}`) if err != nil { fmt.Println(err) return } fmt.Printf("%s", aNot.Leaf())
Output: example(999)
func (ASN1Notation) Len ¶
func (a ASN1Notation) Len() int
Len returns the integer length of the receiver.
Example ¶
aNot, err := NewASN1Notation(`{iso(1) identified-organization(3) dod(6) internet(1) private(4) enterprise(1) 56521 example(999)}`) if err != nil { fmt.Println(err) return } fmt.Printf("Length: %d", aNot.Len())
Output: Length: 8
func (ASN1Notation) NewSubordinate ¶
func (a ASN1Notation) NewSubordinate(nanf any) *ASN1Notation
NewSubordinate returns a new instance of ASN1Notation based upon the contents of the receiver as well as the input NameAndNumberForm subordinate value. This creates a fully-qualified child ASN1Notation value of the receiver.
Example ¶
asn, err := NewASN1Notation(`{iso(1) identified-organization(3) dod(6) internet(1) private(4) enterprise(1) 56521 example(999)}`) if err != nil { fmt.Println(err) } fmt.Printf("%s", asn.NewSubordinate(`friedChicken(5)`))
Output: {iso(1) identified-organization(3) dod(6) internet(1) private(4) enterprise(1) 56521 example(999) friedChicken(5)}
func (ASN1Notation) Parent ¶
func (a ASN1Notation) Parent() NameAndNumberForm
Parent returns the leaf node's parent (-2) string value from the receiver.
Example ¶
aNot, err := NewASN1Notation(`{iso(1) identified-organization(3) dod(6) internet(1) private(4) enterprise(1) 56521 example(999)}`) if err != nil { fmt.Println(err) return } fmt.Printf("%s", aNot.Parent())
Output: 56521
func (ASN1Notation) Root ¶
func (a ASN1Notation) Root() NameAndNumberForm
Root returns the root node (0) string value from the receiver.
Example ¶
aNot, err := NewASN1Notation(`{iso(1) identified-organization(3) dod(6) internet(1) private(4) enterprise(1) 56521 example(999)}`) if err != nil { fmt.Println(err) return } fmt.Printf("%s", aNot.Root())
Output: iso(1)
func (ASN1Notation) String ¶
func (a ASN1Notation) String() string
String is a stringer method that returns a properly formatted ASN.1 string value.
Example ¶
aNot, err := NewASN1Notation(`{iso(1) identified-organization(3) dod(6) internet(1) private(4) enterprise(1) 56521 example(999)}`) if err != nil { fmt.Println(err) return } fmt.Printf("%s", aNot)
Output: {iso(1) identified-organization(3) dod(6) internet(1) private(4) enterprise(1) 56521 example(999)}
func (ASN1Notation) Valid ¶
func (a ASN1Notation) Valid() (is bool)
Valid returns a Boolean value indicative of whether the receiver's length is greater than or equal to one (1) slice member.
Example ¶
var aNot ASN1Notation fmt.Printf("Is Valid: %t", aNot.Valid())
Output: Is Valid: false
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) AncestorOf ¶
func (d DotNotation) AncestorOf(dot any) (is bool)
AncestorOf returns a Boolean value indicative of whether the receiver is an ancestor of the input value, which can be string or DotNotation.
Example ¶
dot, _ := NewDotNotation(`1.3.6`) child, _ := NewDotNotation(`2.1.0.1`) fmt.Printf("%t", dot.AncestorOf(child))
Output: false
func (DotNotation) Ancestry ¶
func (d DotNotation) Ancestry() (anc []DotNotation)
Ancestry returns slices of DotNotation values ordered from leaf node (first) to root node (last).
Empty slices of DotNotation are returned if the dot notation value within the receiver is less than two (2) NumberForm values in length.
Example ¶
dot, err := NewDotNotation(`1.3.6.1.4.1.56521`) if err != nil { fmt.Println(err) } anc := dot.Ancestry() fmt.Printf("%s", anc[len(anc)-2])
Output: 1.3
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.
Example ¶
dot, err := NewDotNotation(`1.3.6.1.4.1.56521.999.5`) if err != nil { fmt.Println(err) return } arc, _ := dot.Index(1) fmt.Printf("%s", arc)
Output: 3
func (DotNotation) IntSlice ¶
func (d DotNotation) IntSlice() (slice []int, err error)
IntSlice returns slices of integer values and an error. The integer values are based upon the contents of the receiver. Note that if any single arc number overflows int, a zero slice is returned.
Successful output can be cast as an instance of encoding/asn1.ObjectIdentifier, if desired.
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) IsZero ¶
func (d *DotNotation) IsZero() (is bool)
IsZero returns a Boolean indicative of whether the receiver is unset.
Example ¶
var dot DotNotation fmt.Printf("Is Zero: %t", dot.IsZero())
Output: Is Zero: true
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) Len ¶
func (d DotNotation) Len() int
Example ¶
dot, err := NewDotNotation(`1.3.6.1.4.1.56521.999.5`) if err != nil { fmt.Println(err) return } fmt.Printf("Length: %d", dot.Len())
Output: Length: 9
func (DotNotation) NewSubordinate ¶
func (d DotNotation) NewSubordinate(nf any) (dot *DotNotation)
NewSubordinate returns a new instance of DotNotation based upon the contents of the receiver as well as the input NumberForm subordinate value. This creates a fully-qualified child DotNotation value of the receiver.
Example ¶
dot, err := NewDotNotation(`1.3.6.1.4.1.56521.999`) if err != nil { fmt.Println(err) } fmt.Printf("%s", dot.NewSubordinate(5))
Output: 1.3.6.1.4.1.56521.999.5
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() (s string)
String is a stringer method that returns the dot notation form of the receiver (e.g.: "1.3.6.1").
Example ¶
dot, err := NewDotNotation(`1.3.6.1.4.1.56521.999.5`) if err != nil { fmt.Println(err) return } fmt.Printf("%s", dot)
Output: 1.3.6.1.4.1.56521.999.5
func (DotNotation) Valid ¶
func (d DotNotation) Valid() (is bool)
Valid returns a Boolean value indicative of the following:
• Receiver's length is greater than or equal to one (1) slice member, and ... • The first slice in the receiver contains a decimal value that is less than three (3)
Example ¶
var dot DotNotation fmt.Printf("Is Valid: %t", dot.Valid())
Output: Is Valid: false
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). Permitted input types are string, uint64 and (non-negative) int.
Example ¶
nanf, err := NewNameAndNumberForm(`enterprise(1)`) if err != nil { fmt.Println(err) return } fmt.Printf("%s", nanf)
Output: enterprise(1)
func (NameAndNumberForm) Equal ¶
func (nanf NameAndNumberForm) Equal(n any) (is bool)
Equal returns a Boolean value indicative of whether instance n of NameAndNumberForm matches the receiver.
Example ¶
var nanf1, nanf2 *NameAndNumberForm var err error if nanf1, err = NewNameAndNumberForm(`enterprise(1)`); err != nil { fmt.Println(err) return } // bogus if nanf2, err = NewNameAndNumberForm(`enterprise(10)`); err != nil { fmt.Println(err) return } fmt.Printf("Equal: %t", nanf1.Equal(nanf2))
Output: Equal: false
func (NameAndNumberForm) Identifier ¶
func (nanf NameAndNumberForm) Identifier() string
Identifier returns the string-based nameForm value assigned to the receiver instance.
Example ¶
nanf, err := NewNameAndNumberForm(`enterprise(1)`) if err != nil { fmt.Println(err) return } fmt.Printf("%s", nanf.Identifier())
Output: enterprise
func (NameAndNumberForm) IsZero ¶
func (nanf NameAndNumberForm) IsZero() bool
IsZero returns a Boolean valu indicative of whether the receiver is considered nil.
Example ¶
nanf, err := NewNameAndNumberForm(`enterprise(1)`) if err != nil { fmt.Println(err) return } fmt.Printf("Zero: %t", nanf.IsZero())
Output: Zero: false
func (NameAndNumberForm) NumberForm ¶
func (nanf NameAndNumberForm) NumberForm() NumberForm
NumberForm returns the underlying NumberForm value assigned to the receiver instance.
Example ¶
nanf, err := NewNameAndNumberForm(`enterprise(1)`) if err != nil { fmt.Println(err) return } fmt.Printf("%s", nanf.NumberForm())
Output: 1
func (NameAndNumberForm) String ¶
func (nanf NameAndNumberForm) String() (val string)
String is a stringer method that returns the properly formatted NameAndNumberForm string value.
Example ¶
nanf, err := NewNameAndNumberForm(`enterprise(1)`) if err != nil { fmt.Println(err) return } fmt.Printf("%s", nanf)
Output: enterprise(1)
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 [OID]s).
func NewNumberForm ¶
func NewNumberForm(v any) (a NumberForm, err error)
NewNumberForm 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 := NewNumberForm(`987895962269883002155146617097157934`) if err != nil { fmt.Println(err) return } fmt.Printf("%s", arc)
Output: 987895962269883002155146617097157934
func (NumberForm) Equal ¶
func (a NumberForm) Equal(n any) (is bool)
Equal returns a boolean value indicative of whether the receiver is equal to the value provided. Valid input types are string, uint64, int and NumberForm.
Any input that represents a negative number guarantees a false return.
Example ¶
nf1, _ := NewNumberForm(4658) nf2, _ := NewNumberForm(4657) fmt.Printf("Instances are equal: %t", nf1.Equal(nf2))
Output: Instances are equal: false
func (NumberForm) Ge ¶
func (a NumberForm) Ge(n any) (is bool)
Ge returns a boolean value indicative of whether the receiver is greater than or equal to the value provided. Valid input types are string, uint64, int and NumberForm. This method is merely a convenient wrapper to an ORed call of the NumberForm.Gt and NumberForm.Equal methods.
Any input that represents a negative number guarantees a false return.
Example ¶
nf, _ := NewNumberForm(4658) oth, _ := NewNumberForm(4501) fmt.Printf("%s >= %s: %t", nf, oth, nf.Ge(oth))
Output: 4658 >= 4501: true
func (NumberForm) Gt ¶
func (a NumberForm) Gt(n any) (is bool)
Gt returns a boolean value indicative of whether the receiver is greater than the value provided. Valid input types are string, uint64, int and NumberForm.
Any input that represents a negative number guarantees a false return.
Example ¶
nf, _ := NewNumberForm(4658) oth, _ := NewNumberForm(4501) fmt.Printf("%s > %s: %t", nf, oth, nf.Gt(oth))
Output: 4658 > 4501: true
Example (ByString) ¶
nf, _ := NewNumberForm(`4658`) oth := `4501` fmt.Printf("%s > %s: %t", nf, oth, nf.Gt(oth))
Output: 4658 > 4501: true
Example (ByUint64) ¶
nf, _ := NewNumberForm(uint64(4658)) oth := uint64(4501) fmt.Printf("%s > %d: %t", nf, oth, nf.Gt(oth))
Output: 4658 > 4501: true
func (*NumberForm) IsZero ¶
func (a *NumberForm) IsZero() (is bool)
IsZero returns a Boolean value indicative of whether the receiver instance is nil, or unset.
Example ¶
var nf NumberForm fmt.Printf("Zero: %t", nf.IsZero())
Output: Zero: true
func (NumberForm) Le ¶
func (a NumberForm) Le(n any) (is bool)
Le returns a boolean value indicative of whether the receiver is less than or equal to the value provided. Valid input types are string, uint64, int and NumberForm. This method is merely a convenient wrapper to an ORed call of the NumberForm.Lt and NumberForm.Equal methods.
Any input that represents a negative number guarantees a false return.
Example ¶
nf, _ := NewNumberForm(4658) oth, _ := NewNumberForm(4501) fmt.Printf("%s =< %s: %t", nf, oth, nf.Le(oth))
Output: 4658 =< 4501: false
func (NumberForm) Lt ¶
func (a NumberForm) Lt(n any) (is bool)
Lt returns a boolean value indicative of whether the receiver is less than the value provided. Valid input types are string, uint64, int and NumberForm.
Any input that represents a negative number guarantees a false return.
Example ¶
nf, _ := NewNumberForm(4658) oth, _ := NewNumberForm(4501) fmt.Printf("%s < %s: %t", nf, oth, nf.Lt(oth))
Output: 4658 < 4501: false
Example (ByString) ¶
nf, _ := NewNumberForm(`4658`) oth := `4501` fmt.Printf("%s < %s: %t", nf, oth, nf.Lt(oth))
Output: 4658 < 4501: false
Example (ByUint64) ¶
nf, _ := NewNumberForm(uint64(4658)) oth := uint64(4501) fmt.Printf("%s < %d: %t", nf, oth, nf.Lt(oth))
Output: 4658 < 4501: false
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 string representation of the receiver instance.
Example ¶
nf, _ := NewNumberForm(4658) fmt.Printf("%s", nf)
Output: 4658
func (NumberForm) Valid ¶
func (a NumberForm) Valid() bool
Valid returns a Boolean value indicative of proper initialization.
Example ¶
nf, _ := NewNumberForm(4658) fmt.Printf("Valid: %t", nf.Valid())
Output: Valid: true
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() (a ASN1Notation)
ASN returns the underlying ASN1Notation instance found within the receiver.
Example ¶
raw := `{iso(1) identified-organization(3) dod(6) internet(1) private(4) enterprise(1) 56521 example(999)}` id, err := NewOID(raw) if err != nil { fmt.Println(err) return } fmt.Printf("%s", id.ASN())
Output: {iso(1) identified-organization(3) dod(6) internet(1) private(4) enterprise(1) 56521 example(999)}
func (OID) Dot ¶
func (id OID) Dot() (d DotNotation)
Dot returns a DotNotation instance based on the contents of the underlying ASN1Notation instance found within the receiver.
Example ¶
raw := `{iso(1) identified-organization(3) dod(6) internet(1) private(4) enterprise(1) 56521 example(999)}` id, err := NewOID(raw) if err != nil { fmt.Println(err) return } fmt.Printf("%s", id.Dot())
Output: 1.3.6.1.4.1.56521.999
func (*OID) IsZero ¶
IsZero checks the receiver for nilness and returns a Boolean indicative of the result.
Example ¶
var z OID fmt.Printf("Zero: %t", z.IsZero())
Output: Zero: true
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.
Example ¶
raw := `{iso(1) identified-organization(3) dod(6) internet(1) private(4) enterprise(1) 56521 example(999)}` id, err := NewOID(raw) if err != nil { fmt.Println(err) return } fmt.Printf("%d", id.Len())
Output: 8
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)