asn1go

package module
v0.0.0-...-884e30c Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2018 License: Apache-2.0 Imports: 16 Imported by: 0

README

asn1go

Rationale

Currently existing Go libraries for asn1 support are either reflection-based (crypto/asn1) or very low-level (golang.org/x/crypto/cryptobyte). Idea is to provide Protobuf-like experience for working with ASN1 in Golang.

Originally started to back gorberos kerberos wannabe-library.

Architecture

  1. Custom Lexer consumes from bufio.Reader and called by Parser
  2. Parser is built using goyacc based on BNF provided in X.680 standard. As the result, Parser produces ASN1 module AST.
  3. AST is used by Code Generator to produce declarations, serialization, and deserialization code.

Roadmap

  1. Lexer
  • identifiers
  • numbers
  • keywords
  • symbols
  • strings, bit strings, hex strings
  • XML
  1. Parser
  • module definition BNF
  • parse Kerberos (rfc4120)
  • yield AST from parser
  • parse SNMPv1 (rfc1157, rfc1155)
  • parse LDAP (rfc4511)
  • SNMPv2 (rfc3411–3418)
  1. Code Generator
  • declaration generator
  • crypto/asn1 compatible generation mode
  • verify serialization on Kerberos
  • DER serialization generator
  • DER deserialization generator

Documentation

Index

Constants

View Source
const (
	TAGS_EXPLICIT = iota
	TAGS_IMPLICIT
	TAGS_AUTOMATIC
)
View Source
const (
	CLASS_CONTEXT_SPECIFIC = iota // when not specified
	CLASS_UNIVERSAL
	CLASS_APPLICATION
	CLASS_PRIVATE
)
View Source
const (
	GeneralizedTimeName = "GeneralizedTime"
	UTCTimeName         = "UTCTime"
)
View Source
const ABSENT = 57389
View Source
const ABSTRACT_SYNTAX = 57393
View Source
const ALL = 57397
View Source
const APOSTROPHE = 57382
View Source
const APPLICATION = 57401
View Source
const ASSIGNMENT = 57357
View Source
const AT = 57385
View Source
const AUTOMATIC = 57405
View Source
const BEGIN = 57409
View Source
const BIT = 57413
View Source
const BMPString = 57417
View Source
const BOOLEAN = 57421
View Source
const BSTRING = 57351
View Source
const BY = 57425
View Source
const CARET = 57388
View Source
const CHARACTER = 57429
View Source
const CHOICE = 57433
View Source
const CLASS = 57437
View Source
const CLOSE_CURLY = 57369
View Source
const CLOSE_ROUND = 57375
View Source
const CLOSE_SQUARE = 57377
View Source
const COLON = 57379
View Source
const COMMA = 57372
View Source
const COMPONENT = 57441
View Source
const COMPONENTS = 57445
View Source
const CONSTRAINED = 57449
View Source
const CONTAINING = 57453
View Source
const CSTRING = 57355
View Source
const DEFAULT = 57457
View Source
const DEFINITIONS = 57461
View Source
const DOT = 57373
View Source
const ELLIPSIS = 57359
View Source
const EMBEDDED = 57465
View Source
const ENCODED = 57390
View Source
const END = 57394
View Source
const ENUMERATED = 57398
View Source
const EQUALS = 57380
View Source
const EXCEPT = 57402
View Source
const EXCLAMATION = 57387
View Source
const EXPLICIT = 57406
View Source
const EXPONENT = 57367
View Source
const EXPORTS = 57410
View Source
const EXTENSIBILITY = 57414
View Source
const EXTERNAL = 57418
View Source
const FALSE = 57422
View Source
const FROM = 57426
View Source
const GREATER = 57371
View Source
const GeneralString = 57434
View Source
const GeneralizedTime = 57430
View Source
const GraphicString = 57438
View Source
const HSTRING = 57353
View Source
const IA5String = 57442
View Source
const IDENTIFIER = 57446
View Source
const IMPLICIT = 57450
View Source
const IMPLIED = 57454
View Source
const IMPORTS = 57458
View Source
const INCLUDES = 57462
View Source
const INSTANCE = 57466
View Source
const INTEGER = 57391
View Source
const INTERSECTION = 57395
View Source
const ISO646String = 57399
View Source
const LEFT_VERSION_BRACKETS = 57360
View Source
const LESS = 57370
View Source
const MAX = 57403
View Source
const MIN = 57407
View Source
const MINUS = 57378
View Source
const MINUS_INFINITY = 57411
View Source
const NEWLINE = 57347
View Source
const NULL = 57415
View Source
const NUMBER = 57350
View Source
const NumericString = 57419
View Source
const OBJECT = 57423
View Source
const OCTET = 57431
View Source
const OF = 57435
View Source
const OPEN_CURLY = 57368
View Source
const OPEN_ROUND = 57374
View Source
const OPEN_SQUARE = 57376
View Source
const OPTIONAL = 57439
View Source
const ObjectDescriptor = 57427
View Source
const PATTERN = 57443
View Source
const PDV = 57447
View Source
const PIPE = 57386
View Source
const PLUS_INFINITY = 57451
View Source
const PRESENT = 57455
View Source
const PRIVATE = 57463
View Source
const PrintableString = 57459
View Source
const QUOTATION_MARK = 57381
View Source
const RANGE_SEPARATOR = 57358
View Source
const REAL = 57467
View Source
const RELATIVE_OID = 57392
View Source
const RIGHT_VERSION_BRACKETS = 57361
View Source
const SEMICOLON = 57384
View Source
const SEQUENCE = 57396
View Source
const SET = 57400
View Source
const SIZE = 57404
View Source
const SPACE = 57383
View Source
const STRING = 57408
View Source
const SYNTAX = 57412
View Source
const T61String = 57416
View Source
const TAGS = 57420
View Source
const TRUE = 57428
View Source
const TYPEORMODULEREFERENCE = 57348
View Source
const TYPE_IDENTIFIER = 57432
View Source
const TeletexString = 57424
View Source
const UNION = 57436
View Source
const UNIQUE = 57440
View Source
const UNIVERSAL = 57444
View Source
const UTCTime = 57452
View Source
const UTF8String = 57456
View Source
const UniversalString = 57448
View Source
const VALUEIDENTIFIER = 57349
View Source
const VideotexString = 57460
View Source
const VisibleString = 57464
View Source
const WHITESPACE = 57346
View Source
const WITH = 57468
View Source
const XMLASN1TYPENAME = 57366
View Source
const XMLBSTRING = 57352
View Source
const XMLCSTRING = 57356
View Source
const XMLHSTRING = 57354
View Source
const XML_BOOLEAN_FALSE = 57365
View Source
const XML_BOOLEAN_TRUE = 57364
View Source
const XML_END_TAG_START = 57362
View Source
const XML_SINGLE_START_END = 57363

Variables

View Source
var (
	RESERVED_WORDS map[string]int = map[string]int{
		"ABSENT":           ABSENT,
		"ENCODED":          ENCODED,
		"INTEGER":          INTEGER,
		"RELATIVE-OID":     RELATIVE_OID,
		"ABSTRACT-SYNTAX":  ABSTRACT_SYNTAX,
		"END":              END,
		"INTERSECTION":     INTERSECTION,
		"SEQUENCE":         SEQUENCE,
		"ALL":              ALL,
		"ENUMERATED":       ENUMERATED,
		"ISO646String":     ISO646String,
		"SET":              SET,
		"APPLICATION":      APPLICATION,
		"EXCEPT":           EXCEPT,
		"MAX":              MAX,
		"SIZE":             SIZE,
		"AUTOMATIC":        AUTOMATIC,
		"EXPLICIT":         EXPLICIT,
		"MIN":              MIN,
		"STRING":           STRING,
		"BEGIN":            BEGIN,
		"EXPORTS":          EXPORTS,
		"MINUS-INFINITY":   MINUS_INFINITY,
		"SYNTAX":           SYNTAX,
		"BIT":              BIT,
		"EXTENSIBILITY":    EXTENSIBILITY,
		"NULL":             NULL,
		"T61String":        T61String,
		"BMPString":        BMPString,
		"EXTERNAL":         EXTERNAL,
		"NumericString":    NumericString,
		"TAGS":             TAGS,
		"BOOLEAN":          BOOLEAN,
		"FALSE":            FALSE,
		"OBJECT":           OBJECT,
		"TeletexString":    TeletexString,
		"BY":               BY,
		"FROM":             FROM,
		"ObjectDescriptor": ObjectDescriptor,
		"TRUE":             TRUE,
		"CHARACTER":        CHARACTER,
		"GeneralizedTime":  GeneralizedTime,
		"OCTET":            OCTET,
		"TYPE-IDENTIFIER":  TYPE_IDENTIFIER,
		"CHOICE":           CHOICE,
		"GeneralString":    GeneralString,
		"OF":               OF,
		"UNION":            UNION,
		"CLASS":            CLASS,
		"GraphicString":    GraphicString,
		"OPTIONAL":         OPTIONAL,
		"UNIQUE":           UNIQUE,
		"COMPONENT":        COMPONENT,
		"IA5String":        IA5String,
		"PATTERN":          PATTERN,
		"UNIVERSAL":        UNIVERSAL,
		"COMPONENTS":       COMPONENTS,
		"IDENTIFIER":       IDENTIFIER,
		"PDV":              PDV,
		"UniversalString":  UniversalString,
		"CONSTRAINED":      CONSTRAINED,
		"IMPLICIT":         IMPLICIT,
		"PLUS-INFINITY":    PLUS_INFINITY,
		"UTCTime":          UTCTime,
		"CONTAINING":       CONTAINING,
		"IMPLIED":          IMPLIED,
		"PRESENT":          PRESENT,
		"UTF8String":       UTF8String,
		"DEFAULT":          DEFAULT,
		"IMPORTS":          IMPORTS,
		"PrintableString":  PrintableString,
		"VideotexString":   VideotexString,
		"DEFINITIONS":      DEFINITIONS,
		"INCLUDES":         INCLUDES,
		"PRIVATE":          PRIVATE,
		"VisibleString":    VisibleString,
		"EMBEDDED":         EMBEDDED,
		"INSTANCE":         INSTANCE,
		"REAL":             REAL,
		"WITH":             WITH,
	}
)
View Source
var (
	USEFUL_TYPES map[string]Type = map[string]Type{
		GeneralizedTimeName: TaggedType{
			Tag:  Tag{Class: CLASS_UNIVERSAL, ClassNumber: Number(24)},
			Type: RestrictedStringType{VisibleString}},
	}
)

Functions

func MarshalToFile

func MarshalToFile(val interface{}, path string, mode os.FileMode) error

Types

type Assignment

type Assignment interface {
	Reference() Reference
}

type AssignmentList

type AssignmentList []Assignment

func NewAssignmentList

func NewAssignmentList(other ...Assignment) AssignmentList

func (AssignmentList) Append

func (al AssignmentList) Append(other ...Assignment) AssignmentList

func (AssignmentList) Get

func (l AssignmentList) Get(name string) Assignment

func (AssignmentList) GetType

func (l AssignmentList) GetType(name string) *TypeAssignment

func (AssignmentList) GetValue

func (l AssignmentList) GetValue(name string) *ValueAssignment

type AstNode

type AstNode interface{}

type BitStringType

type BitStringType struct {
	NamedBits []NamedBit
}

BIT STRING with optional named bits

func (BitStringType) Zero

func (BitStringType) Zero() interface{}

type Boolean

type Boolean bool

func (Boolean) Type

func (Boolean) Type() Type

type BooleanType

type BooleanType struct{}

boolean

func (BooleanType) Zero

func (BooleanType) Zero() interface{}

type CharacterStringType

type CharacterStringType struct{}

func (CharacterStringType) Zero

func (CharacterStringType) Zero() interface{}

type ChoiceExtension

type ChoiceExtension interface {
	// contains filtered or unexported methods
}

type ChoiceType

type ChoiceType struct {
	AlternativeTypeList []NamedType
	ExtensionTypes      []ChoiceExtension
}

func (ChoiceType) Zero

func (ChoiceType) Zero() interface{}

type CodeGenerator

type CodeGenerator interface {
	Generate(module ModuleDefinition, writer io.Writer) error
}

func NewCodeGenerator

func NewCodeGenerator(params GenParams) CodeGenerator

type ComponentType

type ComponentType interface {
	IsComponentType()
}

type ComponentTypeList

type ComponentTypeList []ComponentType

type ComponentsOfComponentType

type ComponentsOfComponentType struct {
	Type Type
}

reference to other SEQUENCE type to be expanded

func (ComponentsOfComponentType) IsComponentType

func (ComponentsOfComponentType) IsComponentType()

type Constraint

type Constraint struct {
	ConstraintSpec ConstraintSpec
}

func SingleElementConstraint

func SingleElementConstraint(elem Elements) Constraint

type ConstraintSpec

type ConstraintSpec interface {
	IsConstraintSpec()
}

ConstraintSpec can be SubtypeConstraint or GeneralConstraint

type ConstraintedType

type ConstraintedType struct {
	Type       Type
	Constraint Constraint
}

////////////////////////////////////////////// type with constraints

func (ConstraintedType) Zero

func (t ConstraintedType) Zero() interface{}

type DefinedValue

type DefinedValue struct{}

TODO represents value reference

func (DefinedValue) IsObjectIdComponent

func (DefinedValue) IsObjectIdComponent() bool

func (DefinedValue) Type

func (DefinedValue) Type() Type

type DefinitiveIdentifier

type DefinitiveIdentifier []DefinitiveObjIdComponent

type DefinitiveObjIdComponent

type DefinitiveObjIdComponent struct {
	Name string
	Id   int
}

type ElementSetSpec

type ElementSetSpec interface {
	Elements
	IsElementSpec()
}

Union or Exclusion

type Elements

type Elements interface {
	IsElements()
}

Describe elements of Intersections or Exclusions

type Exclusions

type Exclusions struct {
	Elements Elements
}

Exclusion is ElementSetSpec and Elements

func (Exclusions) IsElementSpec

func (Exclusions) IsElementSpec()

func (Exclusions) IsElements

func (Exclusions) IsElements()

type GenParams

type GenParams struct {
	Package string
	Prefix  string
	Type    GenType
}

type GenType

type GenType int
const (
	GEN_DECLARATIONS GenType = iota
)

type GeneralConstraint

type GeneralConstraint struct{}

TODO

func (GeneralConstraint) IsConstraintSpec

func (GeneralConstraint) IsConstraintSpec()

type GlobalModuleReference

type GlobalModuleReference struct {
	Reference          string
	AssignedIdentifier Value
}

type IdentifiedIntegerValue

type IdentifiedIntegerValue struct {
	Name string
	// contains filtered or unexported fields
}

element of integer type referenced by name

func (IdentifiedIntegerValue) Type

func (x IdentifiedIntegerValue) Type() Type

type Identifier

type Identifier string

identifier type

func (Identifier) Name

func (id Identifier) Name() string

type IntegerType

type IntegerType struct {
	NamedNumberList map[string]int
}

integer

func (IntegerType) Zero

func (IntegerType) Zero() interface{}

type IntersectionElements

type IntersectionElements struct {
	Elements   Elements
	Exclusions Exclusions
}

type Intersections

type Intersections []IntersectionElements

part of the Union

type ModuleBody

type ModuleBody struct {
	AssignmentList AssignmentList
	Imports        []SymbolsFromModule
}

type ModuleDefinition

type ModuleDefinition struct {
	ModuleIdentifier     ModuleIdentifier
	TagDefault           int
	ExtensibilityImplied bool
	ModuleBody           ModuleBody
}

func ParseFile

func ParseFile(name string) (*ModuleDefinition, error)

func ParseStream

func ParseStream(reader io.Reader) (*ModuleDefinition, error)

func ParseString

func ParseString(str string) (*ModuleDefinition, error)

type ModuleIdentifier

type ModuleIdentifier struct {
	Reference            string
	DefinitiveIdentifier DefinitiveIdentifier
}

type ModuleReference

type ModuleReference string

module reference

func (ModuleReference) IsSymbol

func (ModuleReference) IsSymbol()

type MyLexer

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

func (*MyLexer) Error

func (lex *MyLexer) Error(e string)

func (*MyLexer) Lex

func (lex *MyLexer) Lex(lval *yySymType) int

type NamedBit

type NamedBit struct {
	Name  Identifier
	Index Value // Number or DefinedValue
}

type NamedComponentType

type NamedComponentType struct {
	NamedType  NamedType
	IsOptional bool
	Default    *Value
}

"regular" named element of SEQUENCE

func (NamedComponentType) IsComponentType

func (NamedComponentType) IsComponentType()

type NamedType

type NamedType struct {
	Identifier Identifier
	Type       Type
}

func (NamedType) Zero

func (t NamedType) Zero() interface{}

type NullType

type NullType struct{}

func (NullType) Zero

func (NullType) Zero() interface{}

type Number

type Number int

number lexem, implements Value

func (Number) IntValue

func (x Number) IntValue() int

func (Number) Type

func (Number) Type() Type

func (Number) UnaryMinus

func (x Number) UnaryMinus() Number

type ObjIdComponents

type ObjIdComponents interface {
	IsObjectIdComponent() bool // fake method for grouping
}

implemented by ObjectIdElement, DefinedValue and ObjectIdentifierValue itself

type ObjectIdElement

type ObjectIdElement struct {
	Name      string
	Id        int
	Reference *DefinedValue // nil if Id is set explicitly
}

func (ObjectIdElement) IsObjectIdComponent

func (ObjectIdElement) IsObjectIdComponent() bool

type ObjectIdentifierType

type ObjectIdentifierType struct{}

object identifier

func (ObjectIdentifierType) Zero

func (ObjectIdentifierType) Zero() interface{}

type ObjectIdentifierValue

type ObjectIdentifierValue []ObjIdComponents

//////////////////////////// OID

func NewObjectIdentifierValue

func NewObjectIdentifierValue(initial ...ObjIdComponents) ObjectIdentifierValue

func (ObjectIdentifierValue) Append

func (ObjectIdentifierValue) IsObjectIdComponent

func (ObjectIdentifierValue) IsObjectIdComponent() bool

func (ObjectIdentifierValue) Type

func (ObjectIdentifierValue) Type() Type

type OctetStringType

type OctetStringType struct{}

func (OctetStringType) Zero

func (OctetStringType) Zero() interface{}

type RangeEndpoint

type RangeEndpoint struct {
	Value  Value
	IsOpen bool // X<..<X
}

func (RangeEndpoint) IsUnspecified

func (e RangeEndpoint) IsUnspecified() bool

IsUnspecified corresponds to MIN or MAX

type Real

type Real float64

real lexem

func (Real) Type

func (x Real) Type() Type

func (Real) UnaryMinus

func (x Real) UnaryMinus() Real

type RealType

type RealType struct{}

real

func (RealType) Zero

func (RealType) Zero() interface{}

type Reference

type Reference interface {
	Name() string
}

type RestrictedStringType

type RestrictedStringType struct {
	LexType int
}

func (RestrictedStringType) Zero

func (RestrictedStringType) Zero() interface{}

type SequenceOfType

type SequenceOfType struct {
	Type Type
}

func (SequenceOfType) Zero

func (SequenceOfType) Zero() interface{}

type SequenceType

type SequenceType struct {
	Components ComponentTypeList
}

TODO Extensions are not supported

func (SequenceType) Zero

func (SequenceType) Zero() interface{}

type SingleValue

type SingleValue struct {
	Value
}

SingleValue is Elements

func (SingleValue) IsElements

func (SingleValue) IsElements()

type SizeConstraint

type SizeConstraint struct {
	Constraint Constraint
}

func (SizeConstraint) IsElements

func (SizeConstraint) IsElements()

type SubtypeConstraint

type SubtypeConstraint []ElementSetSpec

SubtypeConstraint describes list of element sets that can be used in constainted type

func (SubtypeConstraint) IsConstraintSpec

func (SubtypeConstraint) IsConstraintSpec()

type Symbol

type Symbol interface {
	IsSymbol()
}

type SymbolsFromModule

type SymbolsFromModule struct {
	SymbolList []Symbol
	Module     GlobalModuleReference
}

type Tag

type Tag struct {
	Class       int
	ClassNumber Value // either DefinedValue or Number
}

type TaggedType

type TaggedType struct {
	Tag        Tag
	Type       Type
	TagType    int  // one of TAGS_*
	HasTagType bool // true if explicitly set
}

tagged types

func (TaggedType) Zero

func (t TaggedType) Zero() interface{}

type Type

type Type interface {
	Zero() interface{}
}

type TypeAssignment

type TypeAssignment struct {
	TypeReference TypeReference
	Type          Type
}

assigns Type to TypeReference

func (TypeAssignment) Reference

func (v TypeAssignment) Reference() Reference

type TypeConstraint

type TypeConstraint struct {
	Type Type
}

func (TypeConstraint) IsElements

func (TypeConstraint) IsElements()

type TypeReference

type TypeReference string

type reference

func (TypeReference) IsSymbol

func (TypeReference) IsSymbol()

func (TypeReference) Name

func (r TypeReference) Name() string

func (TypeReference) Zero

func (r TypeReference) Zero() interface{}

type Unions

type Unions []Intersections

Unions is ElementSetSpec and Elements

func (Unions) IsElementSpec

func (Unions) IsElementSpec()

func (Unions) IsElements

func (Unions) IsElements()

type Value

type Value interface {
	Type() Type
}

type ValueAssignment

type ValueAssignment struct {
	ValueReference ValueReference
	Type           Type
	Value          Value
}

assigns Value of Type to ValueReference

func (ValueAssignment) Reference

func (v ValueAssignment) Reference() Reference

type ValueRange

type ValueRange struct {
	LowerEndpoint RangeEndpoint
	UpperEndpoint RangeEndpoint
}

ValueRange is Elements

func (ValueRange) IsElements

func (ValueRange) IsElements()

type ValueReference

type ValueReference string

value reference

func (ValueReference) IsSymbol

func (ValueReference) IsSymbol()

func (ValueReference) Name

func (r ValueReference) Name() string

Directories

Path Synopsis
cmd
internal

Jump to

Keyboard shortcuts

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