asn1.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // Copyright 2017 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. // Package asn1 contains supporting types for parsing and building ASN.1
  5. // messages with the cryptobyte package.
  6. package asn1 // import "golang.org/x/crypto/cryptobyte/asn1"
  7. // Tag represents an ASN.1 identifier octet, consisting of a tag number
  8. // (indicating a type) and class (such as context-specific or constructed).
  9. //
  10. // Methods in the cryptobyte package only support the low-tag-number form, i.e.
  11. // a single identifier octet with bits 7-8 encoding the class and bits 1-6
  12. // encoding the tag number.
  13. type Tag uint8
  14. const (
  15. classConstructed = 0x20
  16. classContextSpecific = 0x80
  17. )
  18. // Constructed returns t with the constructed class bit set.
  19. func (t Tag) Constructed() Tag { return t | classConstructed }
  20. // ContextSpecific returns t with the context-specific class bit set.
  21. func (t Tag) ContextSpecific() Tag { return t | classContextSpecific }
  22. // The following is a list of standard tag and class combinations.
  23. const (
  24. BOOLEAN = Tag(1)
  25. INTEGER = Tag(2)
  26. BIT_STRING = Tag(3)
  27. OCTET_STRING = Tag(4)
  28. NULL = Tag(5)
  29. OBJECT_IDENTIFIER = Tag(6)
  30. ENUM = Tag(10)
  31. UTF8String = Tag(12)
  32. SEQUENCE = Tag(16 | classConstructed)
  33. SET = Tag(17 | classConstructed)
  34. PrintableString = Tag(19)
  35. T61String = Tag(20)
  36. IA5String = Tag(22)
  37. UTCTime = Tag(23)
  38. GeneralizedTime = Tag(24)
  39. GeneralString = Tag(27)
  40. )