diff options
Diffstat (limited to 'ber/new/class.go')
-rw-r--r-- | ber/new/class.go | 125 |
1 files changed, 125 insertions, 0 deletions
diff --git a/ber/new/class.go b/ber/new/class.go new file mode 100644 index 0000000..7e4bfd3 --- /dev/null +++ b/ber/new/class.go @@ -0,0 +1,125 @@ +package ber + +type Header struct { + Class + Kind + Tag +} + +type Class int + +const ( + classUniversal Class = iota << 6 + classApplication + classContextSpecific + classPrivate + classMask Class = 3 << 6 +) + +var classNames = map[Class]string{ + classUniversal: "Universal", + classApplication: "Application", + classContextSpecific: "Context-specific", + classPrivate: "Private", +} + +func (c Class) String() string { return classNames[c] } + +type Kind int + +const ( + kindPrimitive Kind = iota << 5 + kindConstructed + kindMask Kind = 1 << 5 +) + +var kindNames = map[Kind]string{ + kindPrimitive: "Primitive", + kindConstructed: "Constructed", +} + +func (k Kind) String() string { return kindNames[k] } + +type Tag int + +const ( + tagEOT Tag = iota + tagBoolean + tagInteger + tagBitString + tagOctetString + tagNull + tagObjectIdentifier + tagObjectDescriptor + tagInstanceOf + tagReal + tagEnumerated + tagEmbeddedPDV + tagUTF8String + tagRelativeOID + _ + _ + tagSequence // SequenceOf + tagSet // SetOf + tagNumericString + tagPrintableString + tagTeletexString // T61String + tagVideotexString + tagIA5String + tagUTCTime + tagGeneralizedTime + tagGraphicString + tagVisibleString // ISO646String + tagGeneralString + tagUniversalString + tagCharacterString + tagBMPString + tagMask Tag = (1 << 5) - 1 +) + +var tagNames = map[Tag]string{ + tagEOT: "End-of-Content", + tagBoolean: "Boolean", + tagInteger: "Integer", + tagBitString: "Bit String", + tagOctetString: "Octet String", + tagNull: "Null", + tagObjectIdentifier: "Object Identifier", + tagObjectDescriptor: "Object Descriptor", + tagInstanceOf: "Instance Of", + tagReal: "Real", + tagEnumerated: "Enumerated", + tagEmbeddedPDV: "Embedded PDV", + tagUTF8String: "UTF8 String", + tagRelativeOID: "Relative OID", + tagSequence: "Sequence (Of)", + tagSet: "Set (Of)", + tagNumericString: "Numeric String", + tagPrintableString: "Printable String", + tagTeletexString: "Teletext String", + tagVideotexString: "Videotex String", + tagIA5String: "IA5 String", + tagUTCTime: "UTC Time", + tagGeneralizedTime: "Generalized Time", + tagGraphicString: "Graphic String", + tagVisibleString: "Visible String", + tagGeneralString: "General String", + tagUniversalString: "Universal String", + tagCharacterString: "Character String", + tagBMPString: "BMP String", +} + +func (t Tag) String() string { return tagNames[t] } + +func (s *state) ident() Header { + b, _ := s.ReadByte() + tag := Tag(b) & tagMask + if tag == tagMask { + tag = Tag(s.unmarshalBase128()) + } + return Header{ + Class: Class(b) & classMask, + Kind: Kind(b) & kindMask, + Tag: tag, + } +} |