oid

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2023 License: MIT Imports: 6 Imported by: 0

README

go-oid

Package oid offers a convenient ASN.1 Object Identifier type and associated methods.

ASN.1 Object Identifiers encompass information that goes beyond their dotted representation. This tiny package merely facilitates the handling of ASN.1 NameAndNumberForm values and alternate names that may be associated with a given OID in the wild.

Example

package main
import (
        "log"

        "github.com/JesseCoretta/go-oid"
)

func main() {
        chkerr := func(err error) {
                if err != nil {
                        log.Fatal(err)
                }
        }

        // Test 1
        internet, err := oid.NewObjectIdentifier(`{ iso(1) identified-organization(3) dod(6) internet(1) }`)
        chkerr(err)

        log.SetFlags(0)
        log.Printf("dotNotation: %s\n", internet.ASN1().String())
        log.Printf("ASN.1 Notation: %s\n", internet.String())
        log.Printf("NameAndNumberForm: %s\n", internet.NameAndNumberForm())

        // Test 2
        var sa *oid.ObjectIdentifier
        sa, err = oid.NewObjectIdentifier(`1 3 6 1 5 5 7 3 1`) // legal but less than helpful
        chkerr(err)
        sa.SetAltNames(`serverAuth`)

        log.Printf("dotNotation: %s\n", sa.ASN1().String())
        log.Printf("Alt. Names: %v\n", sa.AltNames())

}

Result

dotNotation: 1.3.6.1
ASN.1 Notation: { iso(1) identified-organization(3) dod(6) internet(1) }
NameAndNumberForm: [internet 1]
dotNotation: 1.3.6.1.5.5.7.3.1
Alt. Names: [serverAuth]

Documentation

Overview

Convenient ASN.1 Object Identifier type and methods.

ASN.1 Object Identifiers often encompass information that goes beyond their dotted representation. This tiny package merely facilitates the handling of ASN.1 NameAndNumberForm values and alternate names that may be associated with a given OID in the wild.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type NameAndNumberForm

type NameAndNumberForm struct {
	// contains filtered or unexported fields
}

func NewNameAndNumberForm

func NewNameAndNumberForm(x any) (nanf *NameAndNumberForm, err error)

func (NameAndNumberForm) Decimal

func (nanf NameAndNumberForm) Decimal() int

func (NameAndNumberForm) Equal

func (NameAndNumberForm) Identifier

func (nanf NameAndNumberForm) Identifier() string

func (NameAndNumberForm) IsZero

func (nanf NameAndNumberForm) IsZero() bool

func (NameAndNumberForm) String

func (nanf NameAndNumberForm) String() (val string)

type ObjectIdentifier

type ObjectIdentifier struct {
	// contains filtered or unexported fields
}

ObjectIdentifier facilitates the storage, and varied representation of, an ASN.1 object identifier in a manner that goes beyond mere dotNotation and may be more convenient than using the asn1.ObjectIdentifier instance.

func NewObjectIdentifier

func NewObjectIdentifier(x any) (o *ObjectIdentifier, err error)

NewObjectIdentifier creates an instance of ObjectIdentifier 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 is desired.

func (ObjectIdentifier) ASN1

func (o ObjectIdentifier) ASN1() (a asn1.ObjectIdentifier)

ASN1 returns a populated instance of asn1.ObjectIdentifier using the contents of the receiver.

func (ObjectIdentifier) AltNames

func (o ObjectIdentifier) AltNames() []string

AltNames returns slices of string values, each representing an alternate name by which the receiver OID may be known in the wild.

func (ObjectIdentifier) Equal

func (o ObjectIdentifier) Equal(x any) bool

Equal returns a boolean indicative of whether the provided type instance effectively matches the receiver.

This method supports asn1.ObjectIdentifier, []int, string and []string type instances for comparison. In the case of string input, a dotNotation match is attempted first, followed by an ASN.1 NameAndNumberForm sequence match and lastly a case folded string match of any alternative names by which the OID may be known.

func (*ObjectIdentifier) IsZero

func (oid *ObjectIdentifier) IsZero() bool

IsZero checks the receiver for nilness and returns a boolean indicative of the result.

func (ObjectIdentifier) NameAndNumberForm

func (o ObjectIdentifier) NameAndNumberForm() (nanf NameAndNumberForm)

func (*ObjectIdentifier) SetAltNames

func (o *ObjectIdentifier) SetAltNames(name ...string)

SetAltNames assigns alternative names by which the receiver may be known in the wild in addition to its "principal" name. Duplicates are filtered out.

One example of an alternate name in the wild is the OID `id-kp-serverAuth(1)` (1.3.6.1.5.5.7.3.1), which is also known simply as 'serverAuth'.

func (ObjectIdentifier) String

func (o ObjectIdentifier) String() (a string)

String returns the ASN.1 NameAndNumberForm sequence stored within the receiver in full, e.g.:

{ iso(1) identified-organization(3) dod(6) }

func (ObjectIdentifier) Valid

func (o ObjectIdentifier) 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 ObjectIdentifierMap

type ObjectIdentifierMap map[string]*ObjectIdentifier

func (ObjectIdentifierMap) Exists

func (o ObjectIdentifierMap) Exists(term any) (exists bool)

func (ObjectIdentifierMap) Get

func (o ObjectIdentifierMap) Get(term any) (*ObjectIdentifier, bool)

func (ObjectIdentifierMap) New

func (o ObjectIdentifierMap) New(key, nanf string) (err error)

func (ObjectIdentifierMap) Set

Jump to

Keyboard shortcuts

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