aboutsummaryrefslogtreecommitdiff
path: root/ber/class.go
diff options
context:
space:
mode:
Diffstat (limited to 'ber/class.go')
-rw-r--r--ber/class.go121
1 files changed, 121 insertions, 0 deletions
diff --git a/ber/class.go b/ber/class.go
new file mode 100644
index 0000000..c2e31b6
--- /dev/null
+++ b/ber/class.go
@@ -0,0 +1,121 @@
+package ber
+
+type Class byte
+
+const (
+ Universal Class = iota << 6
+ Application
+ ContextSpecific
+ Private
+)
+
+// 1100 0000
+// C 0
+const ClassMask Class = 3 << 6
+
+var classNames = map[Class]string{
+ Universal: "Universal",
+ Application: "Application",
+ ContextSpecific: "Context-specific",
+ Private: "Private",
+}
+
+func (c Class) String() string { return classNames[c] }
+
+type Identifier byte
+
+const (
+ Primitive Identifier = iota << 5
+ Constructed
+)
+
+// 0010 0000
+// 2 0
+const IdentifierMask Identifier = 1 << 5
+
+var identifierNames = map[Identifier]string{
+ Primitive: "Primitive",
+ Constructed: "Constructed",
+}
+
+func (i Identifier) String() string { return identifierNames[i] }
+
+type Tag byte
+
+const (
+ EOT Tag = iota
+ Boolean
+ Integer
+ BitString
+ OctetString
+ Null
+ ObjectIdentifier
+ ObjectDescriptor
+ InstanceOf
+ Real
+ Enumerated
+ EmbeddedPDV
+ UTF8String
+ RelativeOID
+ _
+ _
+ Sequence // SequenceOf
+ Set // SetOf
+ NumericString
+ PrintableString
+ TeletexString // T61String
+ VideotexString
+ IA5String
+ UTCTime
+ GeneralizedTime
+ GraphicString
+ VisibleString // ISO646String
+ GeneralString
+ UniversalString
+ CharacterString
+ BMPString
+)
+
+// 0001 1111
+// 1 F
+const TagMask Tag = 0x20 - 1
+
+var tagNames = map[Tag]string{
+ EOT: "End-of-Content",
+ Boolean: "Boolean",
+ Integer: "Integer",
+ BitString: "Bit String",
+ OctetString: "Octet String",
+ Null: "Null",
+ ObjectIdentifier: "Object Identifier",
+ ObjectDescriptor: "Object Descriptor",
+ InstanceOf: "Instance Of",
+ Real: "Real",
+ Enumerated: "Enumerated",
+ EmbeddedPDV: "Embedded PDV",
+ UTF8String: "UTF8 String",
+ RelativeOID: "Relative OID",
+ Sequence: "Sequence / Of",
+ Set: "Set / Of",
+ NumericString: "Numeric String",
+ PrintableString: "Printable String",
+ TeletexString: "Teletext String",
+ VideotexString: "Videotex String",
+ IA5String: "IA5 String",
+ UTCTime: "UTC Time",
+ GeneralizedTime: "Generalized Time",
+ GraphicString: "Graphic String",
+ VisibleString: "Visible String",
+ GeneralString: "General String",
+ UniversalString: "Universal String",
+ CharacterString: "Character String",
+ BMPString: "BMP String",
+}
+
+func (t Tag) String() string { return tagNames[t] }
+
+func Ident(b byte) (Class, Identifier, Tag) {
+ return Class(b) & ClassMask,
+ Identifier(b) & IdentifierMask,
+ Tag(b) & TagMask
+}