Skip to content

Commit 8273fc2

Browse files
stelar7alimpfard
authored andcommitted
LibCrypto: Add missing ASN1 tag kinds
1 parent 6163f60 commit 8273fc2

File tree

3 files changed

+89
-16
lines changed

3 files changed

+89
-16
lines changed

Userland/Libraries/LibCrypto/ASN1/ASN1.cpp

Lines changed: 54 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,66 @@ DeprecatedString kind_name(Kind kind)
2626
return "Null";
2727
case Kind::ObjectIdentifier:
2828
return "ObjectIdentifier";
29-
case Kind::IA5String:
30-
return "IA5String";
29+
case Kind::ObjectDescriptor:
30+
return "ObjectDescriptor";
31+
case Kind::External:
32+
return "External";
33+
case Kind::Real:
34+
return "Real";
35+
case Kind::Enumerated:
36+
return "Enumerated";
37+
case Kind::EmbeddedPdv:
38+
return "EmbeddedPdv";
39+
case Kind::Utf8String:
40+
return "Utf8String";
41+
case Kind::RelativeOid:
42+
return "RelativeOid";
43+
case Kind::Time:
44+
return "Time";
45+
case Kind::Reserved:
46+
return "Reserved";
47+
case Kind::Sequence:
48+
return "Sequence";
49+
case Kind::Set:
50+
return "Set";
51+
case Kind::NumericString:
52+
return "NumericString";
3153
case Kind::PrintableString:
3254
return "PrintableString";
33-
case Kind::Utf8String:
34-
return "UTF8String";
55+
case Kind::T61String:
56+
return "T61String";
57+
case Kind::VideotexString:
58+
return "VideotexString";
59+
case Kind::IA5String:
60+
return "IA5String";
3561
case Kind::UTCTime:
3662
return "UTCTime";
3763
case Kind::GeneralizedTime:
3864
return "GeneralizedTime";
39-
case Kind::Sequence:
40-
return "Sequence";
41-
case Kind::Set:
42-
return "Set";
65+
case Kind::GraphicString:
66+
return "GraphicString";
67+
case Kind::VisibleString:
68+
return "VisibleString";
69+
case Kind::GeneralString:
70+
return "GeneralString";
71+
case Kind::UniversalString:
72+
return "UniversalString";
73+
case Kind::CharacterString:
74+
return "CharacterString";
75+
case Kind::BMPString:
76+
return "BMPString";
77+
case Kind::Date:
78+
return "Date";
79+
case Kind::TimeOfDay:
80+
return "TimeOfDay";
81+
case Kind::DateTime:
82+
return "DateTime";
83+
case Kind::Duration:
84+
return "Duration";
85+
case Kind::OidIri:
86+
return "OidIri";
87+
case Kind::RelativeOidIri:
88+
return "RelativeOidIri";
4389
}
4490

4591
return "InvalidKind";
@@ -190,5 +236,4 @@ done_parsing:;
190236
// Unceremoniously drop the milliseconds on the floor.
191237
return Core::DateTime::create(year.value(), month.value(), day.value(), hour.value(), minute.value_or(0), seconds.value_or(0));
192238
}
193-
194239
}

Userland/Libraries/LibCrypto/ASN1/ASN1.h

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,45 @@
1212

1313
namespace Crypto::ASN1 {
1414

15+
// ITU-T X.680, section 8, table 1
1516
enum class Kind : u8 {
16-
Eol,
17+
Eol = 0x00,
1718
Boolean = 0x01,
1819
Integer = 0x02,
1920
BitString = 0x03,
2021
OctetString = 0x04,
2122
Null = 0x05,
2223
ObjectIdentifier = 0x06,
23-
IA5String = 0x16,
24-
PrintableString = 0x13,
25-
Utf8String = 0x0c,
26-
UTCTime = 0x017,
27-
GeneralizedTime = 0x018,
24+
ObjectDescriptor = 0x07,
25+
External = 0x08,
26+
Real = 0x09,
27+
Enumerated = 0x0A,
28+
EmbeddedPdv = 0x0B,
29+
Utf8String = 0x0C,
30+
RelativeOid = 0x0D,
31+
Time = 0x0E,
32+
Reserved = 0x0F,
2833
Sequence = 0x10,
2934
Set = 0x11,
30-
// Choice = ??,
35+
NumericString = 0x12,
36+
PrintableString = 0x13,
37+
T61String = 0x14,
38+
VideotexString = 0x15,
39+
IA5String = 0x16,
40+
UTCTime = 0x017,
41+
GeneralizedTime = 0x18,
42+
GraphicString = 0x19,
43+
VisibleString = 0x1A,
44+
GeneralString = 0x1B,
45+
UniversalString = 0x1C,
46+
CharacterString = 0x1D,
47+
BMPString = 0x1E,
48+
Date = 0x1F,
49+
TimeOfDay = 0x20,
50+
DateTime = 0x21,
51+
Duration = 0x22,
52+
OidIri = 0x23,
53+
RelativeOidIri = 0x24,
3154
};
3255

3356
enum class Class : u8 {

Userland/Libraries/LibCrypto/ASN1/DER.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,8 @@ ErrorOr<void> pretty_print(Decoder& decoder, Stream& stream, int indent)
294294
case Kind::UTCTime:
295295
case Kind::GeneralizedTime:
296296
case Kind::IA5String:
297+
case Kind::VisibleString:
298+
case Kind::BMPString:
297299
case Kind::PrintableString: {
298300
auto value = TRY(decoder.read<StringView>());
299301
builder.append(' ');
@@ -310,6 +312,9 @@ ErrorOr<void> pretty_print(Decoder& decoder, Stream& stream, int indent)
310312
case Kind::Sequence:
311313
case Kind::Set:
312314
return Error::from_string_literal("ASN1::Decoder: Unexpected Primitive");
315+
default: {
316+
dbgln("PrettyPrint error: Unhandled kind {}", static_cast<u8>(tag.kind));
317+
}
313318
}
314319
}
315320

0 commit comments

Comments
 (0)