Skip to content

Truly independent web browser

LibCrypto: Remove the unused ASN.1 DER pretty printer

Jelle Raaijmakersd61937497ed0
diff --git a/Libraries/LibCrypto/ASN1/ASN1.cpp b/Libraries/LibCrypto/ASN1/ASN1.cpp
index df3307f405d..6271a9d8f8b 100644
--- a/Libraries/LibCrypto/ASN1/ASN1.cpp
+++ b/Libraries/LibCrypto/ASN1/ASN1.cpp
@@ -91,34 +91,6 @@ StringView kind_name(Kind kind)
return "InvalidKind"sv;
}
-StringView class_name(Class class_)
-{
- switch (class_) {
- case Class::Application:
- return "Application"sv;
- case Class::Context:
- return "Context"sv;
- case Class::Private:
- return "Private"sv;
- case Class::Universal:
- return "Universal"sv;
- }
-
- return "InvalidClass"sv;
-}
-
-StringView type_name(Type type)
-{
- switch (type) {
- case Type::Constructed:
- return "Constructed"sv;
- case Type::Primitive:
- return "Primitive"sv;
- }
-
- return "InvalidType"sv;
-}
-
Optional<UnixDateTime> parse_utc_time(StringView time)
{
// YYMMDDhhmm[ss]Z or YYMMDDhhmm[ss](+|-)hhmm
diff --git a/Libraries/LibCrypto/ASN1/ASN1.h b/Libraries/LibCrypto/ASN1/ASN1.h
index a89f053d63e..8743254dc1a 100644
--- a/Libraries/LibCrypto/ASN1/ASN1.h
+++ b/Libraries/LibCrypto/ASN1/ASN1.h
@@ -72,8 +72,6 @@ struct Tag {
};
StringView kind_name(Kind);
-StringView class_name(Class);
-StringView type_name(Type);
Optional<UnixDateTime> parse_utc_time(StringView);
Optional<UnixDateTime> parse_generalized_time(StringView);
diff --git a/Libraries/LibCrypto/ASN1/DER.cpp b/Libraries/LibCrypto/ASN1/DER.cpp
index b1e2c6fd99e..95366ec3b26 100644
--- a/Libraries/LibCrypto/ASN1/DER.cpp
+++ b/Libraries/LibCrypto/ASN1/DER.cpp
@@ -4,10 +4,8 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
-#include <AK/BitmapView.h>
#include <AK/IntegralMath.h>
#include <AK/Math.h>
-#include <AK/Stream.h>
#include <AK/Try.h>
#include <AK/Utf8View.h>
#include <LibCrypto/ASN1/DER.h>
@@ -433,105 +431,4 @@ ErrorOr<void> Encoder::write_bit_string(BitStringView view, Optional<Class> clas
return write_bytes(view.underlying_bytes());
}
-ErrorOr<void> pretty_print(Decoder& decoder, Stream& stream, int indent)
-{
- while (!decoder.eof()) {
- auto tag = TRY(decoder.peek());
-
- StringBuilder builder;
- for (int i = 0; i < indent; ++i)
- builder.append(' ');
- builder.appendff("<{}> ", class_name(tag.class_));
- if (tag.type == Type::Constructed) {
- builder.appendff("[{}] {} ({})", type_name(tag.type), to_underlying(tag.kind), kind_name(tag.kind));
- TRY(decoder.enter());
-
- builder.append('\n');
- TRY(stream.write_until_depleted(builder.string_view().bytes()));
-
- TRY(pretty_print(decoder, stream, indent + 2));
-
- TRY(decoder.leave());
-
- continue;
- } else {
- if (tag.class_ != Class::Universal)
- builder.appendff("[{}] {} {}", type_name(tag.type), to_underlying(tag.kind), kind_name(tag.kind));
- else
- builder.appendff("[{}] {}", type_name(tag.type), kind_name(tag.kind));
- switch (tag.kind) {
- case Kind::Eol: {
- TRY(decoder.read<ReadonlyBytes>());
- break;
- }
- case Kind::Boolean: {
- auto value = TRY(decoder.read<bool>());
- builder.appendff(" {}", value);
- break;
- }
- case Kind::Integer: {
- auto value = TRY(decoder.read<ReadonlyBytes>());
- builder.append(" 0x"sv);
- for (auto ch : value)
- builder.appendff("{:0>2x}", ch);
- break;
- }
- case Kind::BitString: {
- auto value = TRY(decoder.read<BitmapView>());
- builder.append(" 0b"sv);
- for (size_t i = 0; i < value.size(); ++i)
- builder.append(value.get(i) ? '1' : '0');
- break;
- }
- case Kind::OctetString: {
- auto value = TRY(decoder.read<StringView>());
- builder.append(" 0x"sv);
- for (auto ch : value)
- builder.appendff("{:0>2x}", ch);
- break;
- }
- case Kind::Null: {
- TRY(decoder.read<decltype(nullptr)>());
- break;
- }
- case Kind::ObjectIdentifier: {
- auto value = TRY(decoder.read<ObjectIdentifier>());
- for (auto& id : value)
- builder.appendff(" {}", id);
- break;
- }
- case Kind::UTCTime:
- case Kind::GeneralizedTime:
- case Kind::IA5String:
- case Kind::VisibleString:
- case Kind::BMPString:
- case Kind::PrintableString: {
- auto value = TRY(decoder.read<StringView>());
- builder.append(' ');
- builder.append(value);
- break;
- }
- case Kind::Utf8String: {
- auto value = TRY(decoder.read<Utf8View>());
- builder.append(' ');
- for (auto cp : value)
- builder.append_code_point(cp);
- break;
- }
- case Kind::Sequence:
- case Kind::Set:
- return Error::from_string_literal("ASN1::Decoder: Unexpected Primitive");
- default: {
- dbgln("PrettyPrint error: Unhandled kind {}", to_underlying(tag.kind));
- }
- }
- }
-
- builder.append('\n');
- TRY(stream.write_until_depleted(builder.string_view().bytes()));
- }
-
- return {};
-}
-
}
diff --git a/Libraries/LibCrypto/ASN1/DER.h b/Libraries/LibCrypto/ASN1/DER.h
index bb5c1ed4ca9..246e6791984 100644
--- a/Libraries/LibCrypto/ASN1/DER.h
+++ b/Libraries/LibCrypto/ASN1/DER.h
@@ -322,8 +322,6 @@ private:
Optional<Tag> m_current_tag;
};
-ErrorOr<void> pretty_print(Decoder&, Stream&, int indent = 0);
-
class Encoder {
public:
Encoder()