asn1go

package module
v0.0.0-...-94bc7ed Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2022 License: Apache-2.0 Imports: 16 Imported by: 1

README

asn1go

Rationale

Built-in 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.

Note: currently provided code generator implementation creates definitions to be used with crypto/asn1, so all its limitations (no real CHOICE support) apply for this project as well.

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.

Supported features

Feature categories
Feature Parsing Codegen
Exports Syntax only No
Imports Yes No
Type assignments Yes Yes
Value assignments Yes Partial [^f1]
XML No
Objects No
Parameterization No

[^f1]: Only literal values are supported, referenced values are not implemented.

Types
Type Parsing Codegen
BIT STRING Yes Yes; named bits not translated
BOOLEAN Yes Yes
CHARACTER STRING Yes Yes
CHOICE Yes Yes; common demoninator type is used
Embedded PDV No
External No
ENUMERATED Yes [^t4] Yes; alternative values not translated
Instance Of No
INTEGER Yes Yes
NULL Yes
Object Class No
Object Identifier Yes
OCTET STRING Yes Yes
REAL Yes Yes
Relative OID No
SEQUENCE Yes [^t1] Yes
SEQUENCE OF Yes Yes
SET Yes [^t1] Yes
SET OF Yes Yes
ANY Yes [^t2] Yes
Tagged types Yes Yes [^t3]
Constrained types Partial Partial; generates wrapped type

[^t1]: With ASN.1 syntax limitations: two component type lists, exceptions and extension addition groups are not supported, extensions are not exposed in generated Go code. [^t2]: Not defined in the latest ASN.1 standard. [^t3]: Used by encoding/asn1 only in SEQUENCE and SET fields. CHOICE with tagged alternatives is represented as RawValue. [^t4]: With ASN.1 syntax limitations: explicit extensibility and non-literal values are not supported.

Values
Value Parsing Codegen
BOOLEAN Yes Yes
INTEGER Yes Yes
OID Yes No
Real Yes Yes
Referenced No
Object class fields No
BIT STRING No
Other No

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); no codegen, depends on CHOICE
  • parse LDAP (rfc4511, partially - required minor modifications); no codegen, depends on CHOICE
  • parse X.509 (rfc 5280) - depends on ANY
  • SNMPv2 (rfc3411–3418)
  1. Code Generator
  • declaration generator
  • crypto/asn1 compatible generation mode
  • verify serialization on Kerberos
  • DER serialization generator
  • DER deserialization generator
  1. Supported ASN features
  • SET type
  • ANY type (1988 standard) - mapped to interface{}
  • CHOICE type - mapped to interface{}, or asn1.RawValue if selections are tagged
  • Extensions in SEQUENCE, SET, CHOICE
  • Add more as found

Adding features

Real-world ASN.1 descriptions from RFC documents are used to gauge completeness of the implementation. Standard itself is pretty huge, so features are added as needed.

Typically, this requires:

  1. Modifying asn1.y to uncomment unsupported branches of syntax notation, and add missing declarations. Refer to goyacc documentation for .y syntax notation.
  2. Extending ast.go with necessary fields and types.
  3. Modifying codegen.go to produce corresponding Go declarations. Note that not all ASN declarations can be mapped to crypto/asn1.

For example, refer to CHOICE implementation.

Documentation

Index

Constants

View Source
const (
	TAGS_EXPLICIT = iota
	TAGS_IMPLICIT
	TAGS_AUTOMATIC
)

Consts for ModuleDefinition.TagDefault.

View Source
const (
	CLASS_CONTEXT_SPECIFIC = iota // when not specified
	CLASS_UNIVERSAL
	CLASS_APPLICATION
	CLASS_PRIVATE
)

Tag class constants.

View Source
const (
	GeneralizedTimeName = "GeneralizedTime"
	UTCTimeName         = "UTCTime"
)

Names for useful types.

View Source
const ABSENT = 57389
View Source
const ABSTRACT_SYNTAX = 57393
View Source
const ALL = 57397
View Source
const ANY = 57469
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 DEFINED = 57470
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,
		"ANY":              ANY,
		"DEFINED":          DEFINED,
	}
)
View Source
var (
	// USEFUL_TYPES are defined in X.680, section 41.
	// These are built-in types that behave like type assignments that are always in scope.
	// TODO: clarify why UTCTimeName is missing here.
	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 AnyType

type AnyType struct {
	// Identifier is set if IDENTIFIED BY is provided.
	Identifier Identifier
}

AnyType is an ast representation of ANY type. It is NOT defined in X.680, but added for compatibility with older ASN definitions, e.g. X.509. See X.208, section 27.

type Assignment

type Assignment interface {
	Reference() Reference
}

Assignment is interface for Assignment nodes. Only TypeAssignment and ValueAssignment are supported. Other assignment types (value sets, xml values, objects) are not implemented.

type AssignmentList

type AssignmentList []Assignment

AssignmentList holds assignments in module body.

func (AssignmentList) Get

func (l AssignmentList) Get(name string) Assignment

Get finds Assignment by defined reference name, or returns nil if not found.

func (AssignmentList) GetType

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

GetType returns TypeAssignment by name, or nil if not found.

func (AssignmentList) GetValue

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

GetValue returns ValueAssignment by name, or nil if not found.

type BitStringType

type BitStringType struct {
	NamedBits []NamedBit
}

BitStringType is an ast representation of BIT STRING type.

type Boolean

type Boolean bool

Boolean is a bool value. It is named BooleanValue in BNF. See X.680, section 17.3.

func (Boolean) Type

func (Boolean) Type() Type

Type implements Value.

type BooleanType

type BooleanType struct{}

BooleanType is an ast representation of BOOLEAN type.

type CharacterStringType

type CharacterStringType struct{}

CharacterStringType is an ast representation of CHARACTER STRING type. It is defined as UnrestrictedCharacterStringType in BNF.

type ChoiceExtension

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

ChoiceExtension is a type for choice extensions. Only NamedType is implemented, ExtensionAdditionAlternativesGroup is not supported.

type ChoiceType

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

ChoiceType is an ast representation of CHOICE type. It is partially implemented, exceptions are ignored.

type CodeGenerator

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

CodeGenerator is an interface for code generation from ASN.1 modules.

func NewCodeGenerator

func NewCodeGenerator(params GenParams) CodeGenerator

NewCodeGenerator creates a new code generator from provided params.

type ComponentType

type ComponentType interface {
	ExtensionAddition
	// contains filtered or unexported methods
}

ComponentType is a component type of SEQUENCE or SET. It can be used in ExtensionAddition context, so types implementing it must implement both.

type ComponentTypeList

type ComponentTypeList []ComponentType

ComponentTypeList is a list of ComponentType.

type ComponentTypeLists

type ComponentTypeLists struct {
	Components         ComponentTypeList
	ExtensionAdditions ExtensionAdditions
	TrailingComponents ComponentTypeList
}

ComponentTypeLists is not used in AST directly but is used in parser for intermediate representation.

type ComponentsOfComponentType

type ComponentsOfComponentType struct {
	Type Type
}

ComponentsOfComponentType is content of COMPONENTS OF clause.

type Constraint

type Constraint struct {
	ConstraintSpec ConstraintSpec
}

Constraint is a constraint applied to a type.

func SingleElementConstraint

func SingleElementConstraint(elem Elements) Constraint

SingleElementConstraint is a Constraint of single intersection elements.

type ConstraintSpec

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

ConstraintSpec can be SubtypeConstraint or GeneralConstraint. GeneralConstraint is not implemented.

type ConstraintedType

type ConstraintedType struct {
	Type       Type
	Constraint Constraint
}

ConstraintedType is a type with constraints applied. General constraints are not implemented in parser, and exception spec is not preserved in AST.

type DefinedValue

type DefinedValue struct {
	// ModuleName, if non-empty, specifies module where value was defined.
	ModuleName ModuleReference
	// ValueName is name of the value.
	// It should always be provided.
	ValueName ValueReference
}

DefinedValue represents value reference.

func (DefinedValue) Type

func (DefinedValue) Type() Type

Type implements Value.

type DefinitiveIdentifier

type DefinitiveIdentifier []DefinitiveObjIdComponent

DefinitiveIdentifier is fully qualified name of the module.

type DefinitiveObjIdComponent

type DefinitiveObjIdComponent struct {
	Name string
	Id   int
}

DefinitiveObjIdComponent is part of DefinitiveIdentifier.

type ElementSetSpec

type ElementSetSpec interface {
	Elements
	// contains filtered or unexported methods
}

ElementSetSpec is element of the SubtypeConstraint.

type Elements

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

Elements is one of subtype elements (values, type constraints, etc).

type EnumeratedType

type EnumeratedType struct {
	// Alternatives of the enumeration.
	RootEnumeration       []EnumerationItem
	AdditionalEnumeration []EnumerationItem
}

EnumeratedType is an ast representation of ENUMERATED type. TODO: implement enumerations properly.

type EnumerationItem

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

EnumerationItem is interface for items. It can be NamedNumber of Identifier.

type Exclusions

type Exclusions struct {
	Elements Elements
}

Exclusions are Elements excluded from IntersectionElements.

type ExtensionAddition

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

ExtensionAddition is a single element of extension addition.

type ExtensionAdditions

type ExtensionAdditions []ExtensionAddition

ExtensionAdditions is a list of extension additions in SET or SEQUENCE.

type GenParams

type GenParams struct {
	// Package is go package name.
	// If not specified, ASN.1 module name will be used to derive go module name.
	Package string
	// Type is a type of code generation to run.
	// TODO: deprecate in favor of separate New methods.
	Type GenType
	// IntegerRepr controls how INTEGER type is expressed in generated go code.
	IntegerRepr IntegerRepr
}

GenParams is code generator configuration.

type GenType

type GenType int

GenType is code generator type.

const (
	// GEN_DECLARATIONS is code generator that is
	GEN_DECLARATIONS GenType = iota
)

type GeneralConstraint

type GeneralConstraint struct{}

GeneralConstraint is not implemented. It is defined by X.682. TODO: implement or remove.

type GlobalModuleReference

type GlobalModuleReference struct {
	Reference          string
	AssignedIdentifier Value
}

GlobalModuleReference fully qualifies module from which symbols are imported.

type IdentifiedIntegerValue

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

IdentifiedIntegerValue is named value defined for the type. TODO: use of these in assignments is not implemented.

func (IdentifiedIntegerValue) Type

func (x IdentifiedIntegerValue) Type() Type

Type implements Value.

type Identifier

type Identifier string

Identifier is a non-referential identifier. This is a lexical construct, named `identifier` in the doc. See X.680, section 11.3.

func (Identifier) Name

func (id Identifier) Name() string

Name returns name of the reference.

type InnerTypeConstraint

type InnerTypeConstraint struct{}

InnerTypeConstraint is WITH COMPONENT constraint. Contents are not represented in parsed AST and are ignored.

type IntegerRepr

type IntegerRepr string

IntegerRepr is enum controlling how INTEGER is represented.

const (
	IntegerReprInt64  IntegerRepr = "int64"
	IntegerReprBigInt IntegerRepr = "big.Int"
)

IntegerRepr modes supported.

type IntegerType

type IntegerType struct {
	NamedNumberList []NamedNumber
}

IntegerType is an ast representation of INTEGER type.

type IntersectionElements

type IntersectionElements struct {
	Elements   Elements
	Exclusions Exclusions
}

IntersectionElements is part of Intersections.

type Intersections

type Intersections []IntersectionElements

Intersections is a part of SubtypeConstraint.

type ModuleBody

type ModuleBody struct {
	AssignmentList AssignmentList
	Imports        []SymbolsFromModule
}

ModuleBody holds module body. TODO: implement Exports.

type ModuleDefinition

type ModuleDefinition struct {
	ModuleIdentifier ModuleIdentifier
	// TagDefault is default tagging behavior, one of TAGS_ constants.
	TagDefault           int
	ExtensibilityImplied bool
	ModuleBody           ModuleBody
}

ModuleDefinition represents ASN.1 ModuleName. This and all other AST types are named according to their BNF in X.680 document, if not specified otherwise. See: X.680, section 12.

func ParseFile

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

ParseFile parses ASN.1 definition file into ASN.1 AST.

func ParseStream

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

ParseStream reads text of ASN.1 definitions from provided reader and parses it into ASN.1 AST.

func ParseString

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

ParseString parses string containing ASN.1 definitions into ASN.1 AST.

type ModuleIdentifier

type ModuleIdentifier struct {
	Reference            string
	DefinitiveIdentifier DefinitiveIdentifier
}

ModuleIdentifier is root of ASN.1 module.

type ModuleReference

type ModuleReference string

ModuleReference refers to a module. This is lexical construct, named `modulereference` in the doc. See X.680, section 11.5.

type MyLexer

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

MyLexer is an ASN.1 lexer that is producing lexems for the generated goyacc parser.

func (*MyLexer) Error

func (lex *MyLexer) Error(e string)

Error implements yyLexer, and is used by the parser to communicate errors.

func (*MyLexer) Lex

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

Lex implements yyLexer. It is reading runes from the bufReader, stores some state in lval if needed, and returns token type. If syntax error was detected, it saves it in err, and returns -1, which is understood by goyacc as end of input.

type NamedBit

type NamedBit struct {
	Name Identifier
	// Index is index of the bit.
	// Will have Number or DefinedValue type.
	Index Value
}

NamedBit is a named bit in BIT STRING.

type NamedComponentType

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

NamedComponentType is an entry in a SEQUENCE definition.

type NamedNumber

type NamedNumber struct {
	Name  Identifier
	Value NamedNumberValue
}

NamedNumber is number with name. It is mainly used as Enumerated and Integer definitions.

type NamedNumberValue

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

NamedNumberValue signifies that value can be a value of named number.

type NamedType

type NamedType struct {
	Identifier Identifier
	Type       Type
}

NamedType is a identifier-type tuple. It's used as element in SequenceType, SetType, ChoiceType and some other types.

type NullType

type NullType struct{}

NullType is an ast representation of NULL type.

type Number

type Number int

Number is an integer value. This is a lexical construct, named `number` in the doc. See X.680, section 11.8.

func (Number) IntValue

func (x Number) IntValue() int

IntValue returns value of the number.

func (Number) Type

func (Number) Type() Type

Type implements Value.

func (Number) UnaryMinus

func (x Number) UnaryMinus() Number

UnaryMinus returns negated Number.

type ObjectIdElement

type ObjectIdElement struct {
	// Name is non-empty in name-and-number form.
	Name string
	// ID is set in Number or NameAndNumber form, if number is specified as number literal.
	ID int
	// Reference is set in NameAndNumber form, when number is provided as DefinedValue.
	// NameForm is always parsed as Reference.
	Reference *DefinedValue
}

ObjectIdElement is object id element in name, number or name and number form.

type ObjectIdentifierType

type ObjectIdentifierType struct{}

ObjectIdentifierType is an ast representation of OBJECT IDENTIFIER type.

type ObjectIdentifierValue

type ObjectIdentifierValue []ObjectIdElement

ObjectIdentifierValue is a value of OBJECT IDENTIFIER type.

func (ObjectIdentifierValue) Type

func (ObjectIdentifierValue) Type() Type

Type implements Value.

type OctetStringType

type OctetStringType struct{}

OctetStringType is an ast representation of OCTET STRING type.

type RangeEndpoint

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

RangeEndpoint is left or right side of the ValueRange.

func (RangeEndpoint) IsUnspecified

func (e RangeEndpoint) IsUnspecified() bool

IsUnspecified corresponds to MIN or MAX of the range.

type Real

type Real float64

Real is a floating point value. This is a lexical construct, named `realnumber` in the doc. See X.680, section 11.9.

func (Real) Type

func (x Real) Type() Type

Type implements Value.

func (Real) UnaryMinus

func (x Real) UnaryMinus() Real

UnaryMinus returns negated value.

type RealType

type RealType struct{}

RealType is an ast representation of REAL type.

type Reference

type Reference interface {
	Name() string
}

Reference is an interface for a reference. There are different reference types depending on a referent.

type RestrictedStringType

type RestrictedStringType struct {
	// LexType is a lexem value for restricted string (e.g. IA5String).
	LexType int
}

RestrictedStringType is a type for strings with restricted character set. It is defined as RestrictedCharacterStringType in BNF. See X.680, section 36.1.

type SequenceOfType

type SequenceOfType struct {
	Type Type
}

SequenceOfType is an ast representation of SEQUENCE OF type.

type SequenceType

type SequenceType struct {
	Components         ComponentTypeList
	ExtensionAdditions ExtensionAdditions
}

SequenceType is an ast representation of SEQUENCE type. TODO: Exceptions are not supported.

type SetOfType

type SetOfType struct {
	Type Type
}

SetOfType is an ast representation of SET OF type.

type SetType

type SetType struct {
	Components         ComponentTypeList
	ExtensionAdditions ExtensionAdditions
}

SetType is an ast representation of SEQUENCE type. TODO: Extensions are not supported.

type SingleValue

type SingleValue struct {
	Value
}

SingleValue is included or excluded value.

type SizeConstraint

type SizeConstraint struct {
	Constraint Constraint
}

SizeConstraint is a SIZE constraint expressed by another Constraint.

type SubtypeConstraint

type SubtypeConstraint []ElementSetSpec

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

type Symbol

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

Symbol is exported or imported symbol. Only References are supported, ParameterizedReference is not implemented.

type SymbolsFromModule

type SymbolsFromModule struct {
	SymbolList []Symbol
	Module     GlobalModuleReference
}

SymbolsFromModule holds imports from particular module.

type Tag

type Tag struct {
	// Class is a tag class, one of CLASS_ constants.
	// E.g. UNIVERSAL, APPLICATION.
	Class int
	// ClassNumber is a tag value.
	// Will hold DefinedValue or Number.
	ClassNumber Value
}

Tag is a tag value.

type TaggedType

type TaggedType struct {
	// Tag assigned to a type.
	Tag Tag
	// Type that is being tagged.
	Type Type
	// TagType is one of TAGS_ constants.
	// E.g. IMPLICIT, EXPLICIT.
	TagType int
	// HasTagType is set to true if TagType was explicitly specified in module syntax.
	// Otherwise, TagType would hold module default.
	HasTagType bool // true if explicitly set
}

TaggedType is a tagged type.

type Type

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

Type is a builtin, referenced or constrained type.

type TypeAssignment

type TypeAssignment struct {
	TypeReference TypeReference
	Type          Type
}

TypeAssignment defines TypeReference of specified Type.

func (TypeAssignment) Reference

func (v TypeAssignment) Reference() Reference

Reference implements Assignment.

type TypeConstraint

type TypeConstraint struct {
	Type Type
}

TypeConstraint is a type constraint.

type TypeReference

type TypeReference string

TypeReference refers to a type defined in same module or imported from different module. This is lexical construct, named `typereference` in the doc. See X.680, section 11.2.

func (TypeReference) Name

func (r TypeReference) Name() string

Name implements Reference.

type Unions

type Unions []Intersections

Unions is ElementSetSpec and Elements

type Value

type Value interface {
	Type() Type
}

Value is interface for values.

type ValueAssignment

type ValueAssignment struct {
	ValueReference ValueReference
	Type           Type
	Value          Value
}

ValueAssignment defines ValueReference of Type with given Value.

func (ValueAssignment) Reference

func (v ValueAssignment) Reference() Reference

Reference implements Assignment.

type ValueRange

type ValueRange struct {
	LowerEndpoint RangeEndpoint
	UpperEndpoint RangeEndpoint
}

ValueRange is included or excluded range.

type ValueReference

type ValueReference string

ValueReference refers to a value defined in same module or imported from different module. This is lexical construct, named `valuereference` in the doc. See X.680, section 11.2.

func (ValueReference) Name

func (r ValueReference) Name() string

Name implements Reference.

Directories

Path Synopsis
cmd
asn1go
Binary asn1go generates go code from ASN.1 definitions.
Binary asn1go generates go code from ASN.1 definitions.
internal

Jump to

Keyboard shortcuts

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