Documentation ¶
Index ¶
- Constants
- Variables
- func MarshalToFile(val interface{}, path string, mode os.FileMode) error
- type AnyType
- type Assignment
- type AssignmentList
- type BitStringType
- type Boolean
- type BooleanType
- type CharacterStringType
- type ChoiceExtension
- type ChoiceType
- type CodeGenerator
- type ComponentType
- type ComponentTypeList
- type ComponentTypeLists
- type ComponentsOfComponentType
- type Constraint
- type ConstraintSpec
- type ConstraintedType
- type DefinedValue
- type DefinitiveIdentifier
- type DefinitiveObjIdComponent
- type ElementSetSpec
- type Elements
- type EnumeratedType
- type EnumerationItem
- type Exclusions
- type ExtensionAddition
- type ExtensionAdditions
- type GenParams
- type GenType
- type GeneralConstraint
- type GlobalModuleReference
- type IdentifiedIntegerValue
- type Identifier
- type InnerTypeConstraint
- type IntegerRepr
- type IntegerType
- type IntersectionElements
- type Intersections
- type ModuleBody
- type ModuleDefinition
- type ModuleIdentifier
- type ModuleReference
- type MyLexer
- type NamedBit
- type NamedComponentType
- type NamedNumber
- type NamedNumberValue
- type NamedType
- type NullType
- type Number
- type ObjectIdElement
- type ObjectIdentifierType
- type ObjectIdentifierValue
- type OctetStringType
- type RangeEndpoint
- type Real
- type RealType
- type Reference
- type RestrictedStringType
- type SequenceOfType
- type SequenceType
- type SetOfType
- type SetType
- type SingleValue
- type SizeConstraint
- type SubtypeConstraint
- type Symbol
- type SymbolsFromModule
- type Tag
- type TaggedType
- type Type
- type TypeAssignment
- type TypeConstraint
- type TypeReference
- type Unions
- type Value
- type ValueAssignment
- type ValueRange
- type ValueReference
Constants ¶
const ( TAGS_EXPLICIT = iota TAGS_IMPLICIT TAGS_AUTOMATIC )
Consts for ModuleDefinition.TagDefault.
const ( CLASS_CONTEXT_SPECIFIC = iota // when not specified CLASS_UNIVERSAL CLASS_APPLICATION CLASS_PRIVATE )
Tag class constants.
const ( GeneralizedTimeName = "GeneralizedTime" UTCTimeName = "UTCTime" )
Names for useful types.
const ABSENT = 57389
const ABSTRACT_SYNTAX = 57393
const ALL = 57397
const ANY = 57469
const APOSTROPHE = 57382
const APPLICATION = 57401
const ASSIGNMENT = 57357
const AT = 57385
const AUTOMATIC = 57405
const BEGIN = 57409
const BIT = 57413
const BMPString = 57417
const BOOLEAN = 57421
const BSTRING = 57351
const BY = 57425
const CARET = 57388
const CHARACTER = 57429
const CHOICE = 57433
const CLASS = 57437
const CLOSE_CURLY = 57369
const CLOSE_ROUND = 57375
const CLOSE_SQUARE = 57377
const COLON = 57379
const COMMA = 57372
const COMPONENT = 57441
const COMPONENTS = 57445
const CONSTRAINED = 57449
const CONTAINING = 57453
const CSTRING = 57355
const DEFAULT = 57457
const DEFINED = 57470
const DEFINITIONS = 57461
const DOT = 57373
const ELLIPSIS = 57359
const EMBEDDED = 57465
const ENCODED = 57390
const END = 57394
const ENUMERATED = 57398
const EQUALS = 57380
const EXCEPT = 57402
const EXCLAMATION = 57387
const EXPLICIT = 57406
const EXPONENT = 57367
const EXPORTS = 57410
const EXTENSIBILITY = 57414
const EXTERNAL = 57418
const FALSE = 57422
const FROM = 57426
const GREATER = 57371
const GeneralString = 57434
const GeneralizedTime = 57430
const GraphicString = 57438
const HSTRING = 57353
const IA5String = 57442
const IDENTIFIER = 57446
const IMPLICIT = 57450
const IMPLIED = 57454
const IMPORTS = 57458
const INCLUDES = 57462
const INSTANCE = 57466
const INTEGER = 57391
const INTERSECTION = 57395
const ISO646String = 57399
const LEFT_VERSION_BRACKETS = 57360
const LESS = 57370
const MAX = 57403
const MIN = 57407
const MINUS = 57378
const MINUS_INFINITY = 57411
const NEWLINE = 57347
const NULL = 57415
const NUMBER = 57350
const NumericString = 57419
const OBJECT = 57423
const OCTET = 57431
const OF = 57435
const OPEN_CURLY = 57368
const OPEN_ROUND = 57374
const OPEN_SQUARE = 57376
const OPTIONAL = 57439
const ObjectDescriptor = 57427
const PATTERN = 57443
const PDV = 57447
const PIPE = 57386
const PLUS_INFINITY = 57451
const PRESENT = 57455
const PRIVATE = 57463
const PrintableString = 57459
const QUOTATION_MARK = 57381
const RANGE_SEPARATOR = 57358
const REAL = 57467
const RELATIVE_OID = 57392
const RIGHT_VERSION_BRACKETS = 57361
const SEMICOLON = 57384
const SEQUENCE = 57396
const SET = 57400
const SIZE = 57404
const SPACE = 57383
const STRING = 57408
const SYNTAX = 57412
const T61String = 57416
const TAGS = 57420
const TRUE = 57428
const TYPEORMODULEREFERENCE = 57348
const TYPE_IDENTIFIER = 57432
const TeletexString = 57424
const UNION = 57436
const UNIQUE = 57440
const UNIVERSAL = 57444
const UTCTime = 57452
const UTF8String = 57456
const UniversalString = 57448
const VALUEIDENTIFIER = 57349
const VideotexString = 57460
const VisibleString = 57464
const WHITESPACE = 57346
const WITH = 57468
const XMLASN1TYPENAME = 57366
const XMLBSTRING = 57352
const XMLCSTRING = 57356
const XMLHSTRING = 57354
const XML_BOOLEAN_FALSE = 57365
const XML_BOOLEAN_TRUE = 57364
const XML_END_TAG_START = 57362
const XML_SINGLE_START_END = 57363
Variables ¶
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, } )
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 ¶
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.
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.
type DefinitiveIdentifier ¶
type DefinitiveIdentifier []DefinitiveObjIdComponent
DefinitiveIdentifier is fully qualified name of the module.
type DefinitiveObjIdComponent ¶
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 GeneralConstraint ¶
type GeneralConstraint struct{}
GeneralConstraint is not implemented. It is defined by X.682. TODO: implement or remove.
type GlobalModuleReference ¶
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.
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.
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 ¶
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 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.
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.
type OctetStringType ¶
type OctetStringType struct{}
OctetStringType is an ast representation of OCTET STRING type.
type RangeEndpoint ¶
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.
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 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 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.
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.