pen

package module
v0.0.0-...-1f17fbd Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2021 License: GPL-3.0 Imports: 10 Imported by: 0

README

go-penparser

Go IANA Private Enterprise Number (PEN) Parser

GoDoc

Synopsis

Given a syntactically valid user-downloaded IANA PEN file, this package shall populate an abstract object based upon the structure of the Private Enterprise Numbers SMI branch parsed (1.3.6.1.4.1).

See Also

  • IETF RFC 1157
  • IETF RFC 1213

Credit

Jesse Coretta

Documentation

Overview

Package pen parses the user-retrieved IANA Private Enteprise Numbers (PEN) file by path/filename.

Credits

Jesse Coretta (subcon42)

Advisory

You must download the PEN file yourself using your preferred HTTP client. The New() method takes the local filesystem path of that downloaded file (e.g: /tmp/pen.txt).

The URL for the PEN file is below (don't click this URL unless you really mean it, as the file is literally hundreds of thousands of lines long):

http://www.iana.org/assignments/enterprise-numbers/enterprise-numbers

DO NOT MANUALLY EDIT THIS DOWNLOADED FILE, OR YOU WILL SUFFER MANY BIZARRE PROBLEMS.

Keep in mind, this is a very rough and unofficial draft; subject to change without notice!

Usage

Basic usage is described as follows:

func main() {

      // Update this to reference your freshly downloaded
      // IANA PEN file (see ents.URI() in header).
      var file string = `/tmp/pen`

      // Create our *Enterprises object based on
      // data parsed via file
      ents, err := pen.New(file)
      if err != nil {
              fmt.Println(err)
              return
      }

      // Print our header (useful data)
      fmt.Println(ents.DumpHeader())

      //////////////////////////////////////////////////////////
      // Begin our basic demo ...

      fmt.Println(`Results`)

      // Conduct a search for a Node. Note: you have more than
      // one means of searching for Node instances ...
      myNode, ok := ents.FindByOID(asn1.ObjectIdentifier{1, 3, 6, 1, 4, 1, 54399}) // Search by asn1.ObjectIdentifier ...
      //myNode, ok := ents.FindByIRI(`/iso/org/dod/internet/private/enterprise/54399`) // or by string Internationalized Resource Identifier (IRI) path notation ...
      //myNode, ok := ents.FindByOID([]int{1, 3, 6, 1, 4, 1, 54399})                   // or by []int cast of asn1.ObjectIdentifier ...
      //myNode, ok := ents.FindByOID(`1.3.6.1.4.1.54399`)                              // or by stringer of asn1.ObjectIdentifier ...
      //myNode, ok := ents.FindByOID(54399)                                            // or by leaf-node decimal (far-right digit)
      if !ok {
              return // no match!
      }

      // Print our retrieved Node
      fmt.Println(myNode.DumpNode())

      // Alt. search options
      // Find By Email
      //myNode, ok = ents.FindByEmail(`subcon.co.42&gmail.com`)
      //fmt.Printf("Found by email: %t\n", ok)

      // Find By Contact
      //myNode, ok = ents.FindByContact(`Jesse Coretta`)
      //fmt.Printf("Found by contact name: %t\n", ok)

}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Enterprises

type Enterprises struct {
	Nodes       []Node
	SourceURI   *url.URL
	ParseTime   time.Duration
	LastUpdated time.Time
	Title,
	Section string
}

Enterprises represents the entire (parsed) branch of the IANA Private Enterprise Number (PEN) List. This type also contains prefix OID and IRI values, as well as parsing-related data that may be useful to admin responsible for handling regular refreshes.

func New

func New(file string) (ents *Enterprises, err error)

New parses the file specified via input argument as the complete IANA Private Enterprise Numbers List.

If at any point parsing encounters an error, it is returned alongside a likely nil instance of the *Enterprises type. Else, a fully-populated instance of *Enterprises shall be returned alongside a nil error.

Note that you must download the IANA Private Enterprise Numbers List yourself (this package will not do that part for you).

func (Enterprises) Count

func (e Enterprises) Count() int

Count returns the number of Node instances present within the receiver instance of Enterprises.

func (Enterprises) FindByContact

func (e Enterprises) FindByContact(name string) (Node, bool)

FindByContact will conduct a caseless name-based match between each Contact name found within the Enterprises receiver instance and the provided name input argument.

func (Enterprises) FindByEmail

func (e Enterprises) FindByEmail(email string) (Node, bool)

FindByEmail performs a caseless match between the provided email address (email) and each discovered email address within the OID index. For search convenience, it is unnecessary to replace the ampersand (`&`) with the so-called "Commercial At Sign" (`@`), as this is done under-the-hood per email search request.

If found an instance of Node is returned along with an affirmative boolean value; else an empty node and a negative boolean value.

func (Enterprises) FindByIRI

func (e Enterprises) FindByIRI(iri string) (Node, bool)

FindByIRI will conduct a caseless string comparison of all IRI values observed during a looped search, and the provided IRI value (iri).

func (Enterprises) FindByOID

func (e Enterprises) FindByOID(oid interface{}) (Node, bool)

FindByOID will conduct a bonafide ASN.1 ObjectIdentifier match between the provided value and each parsed value found within the Enterprises receiver instance.

func (Enterprises) Header

func (e Enterprises) Header() map[string]map[string]interface{}

Header returns a map[string]map[string]interface{} containing key pieces of information about the data parsed.

func (*Enterprises) URI

func (e *Enterprises) URI() string

type Node

type Node struct {
	Email []string
	Contact,
	Organization string
	Decimal int // aka node number
}

Node represents each distinct occurrence of a given Node entry within the IANA Private Enterprises Numbers List. The number of fields directly matches the number of lines found for each Node (and consequently how many bufio.Scan iterations are conducted per Node during parsing).

As shown on the legend/diagram, IANA describes each field and the leading lengths of subfields:

Decimal
| Organization
| | Contact
| | | Email
| | | |

... which would equate to ...

nodeNum             // Entry Line 1 :: zero (0) leading spaces
__Organization      // Entry Line 2 :: two (2) leading spaces
____Contact         // Entry Line 3 :: four (4) leading spaces
______Email         // Entry Line 4 :: six (6) leading spaces

func (Node) ASN

func (n Node) ASN() string

ASN returns the stringified ASN.1 Path Notation value of the receiver Node.

func (Node) Emails

func (n Node) Emails() (e string)

Emails returns the stringified email address(es) found for the receiver node. An optional boolean value of true will cause indented email address output (helpful for multi- valued entries).

func (Node) IRI

func (n Node) IRI() string

IRI returns the stringified Internationalized Resource Identifier (IRI) value of the receiver Node.

func (Node) Node

func (n Node) Node() map[string]string

Node returns a map[string]string containing key pieces of information regarding the receiver Node instance.

func (Node) OID

func (n Node) OID() string

OID returns the stringified ASN.1 Object Identifier (OID) value of the receiver Node.

Jump to

Keyboard shortcuts

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