ASN1.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * Copyright (c) 2020, Ali Mohammad Pur <mpfard@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/Types.h>
  8. #include <LibCore/DateTime.h>
  9. #include <LibCrypto/BigInt/UnsignedBigInteger.h>
  10. namespace Crypto::ASN1 {
  11. // ITU-T X.680, section 8, table 1
  12. enum class Kind : u8 {
  13. Eol = 0x00,
  14. Boolean = 0x01,
  15. Integer = 0x02,
  16. BitString = 0x03,
  17. OctetString = 0x04,
  18. Null = 0x05,
  19. ObjectIdentifier = 0x06,
  20. ObjectDescriptor = 0x07,
  21. External = 0x08,
  22. Real = 0x09,
  23. Enumerated = 0x0A,
  24. EmbeddedPdv = 0x0B,
  25. Utf8String = 0x0C,
  26. RelativeOid = 0x0D,
  27. Time = 0x0E,
  28. Reserved = 0x0F,
  29. Sequence = 0x10,
  30. Set = 0x11,
  31. NumericString = 0x12,
  32. PrintableString = 0x13,
  33. T61String = 0x14,
  34. VideotexString = 0x15,
  35. IA5String = 0x16,
  36. UTCTime = 0x017,
  37. GeneralizedTime = 0x18,
  38. GraphicString = 0x19,
  39. VisibleString = 0x1A,
  40. GeneralString = 0x1B,
  41. UniversalString = 0x1C,
  42. CharacterString = 0x1D,
  43. BMPString = 0x1E,
  44. Date = 0x1F,
  45. TimeOfDay = 0x20,
  46. DateTime = 0x21,
  47. Duration = 0x22,
  48. OidIri = 0x23,
  49. RelativeOidIri = 0x24,
  50. };
  51. enum class Class : u8 {
  52. Universal = 0,
  53. Application = 0x40,
  54. Context = 0x80,
  55. Private = 0xc0,
  56. };
  57. enum class Type : u8 {
  58. Primitive = 0,
  59. Constructed = 0x20,
  60. };
  61. struct Tag {
  62. Kind kind;
  63. Class class_;
  64. Type type;
  65. };
  66. ByteString kind_name(Kind);
  67. ByteString class_name(Class);
  68. ByteString type_name(Type);
  69. Optional<Core::DateTime> parse_utc_time(StringView);
  70. Optional<Core::DateTime> parse_generalized_time(StringView);
  71. }