/src/serenity/Userland/Libraries/LibCrypto/ASN1/DER.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright (c) 2020, Ali Mohammad Pur <mpfard@serenityos.org> |
3 | | * |
4 | | * SPDX-License-Identifier: BSD-2-Clause |
5 | | */ |
6 | | |
7 | | #pragma once |
8 | | |
9 | | #include <AK/BitmapView.h> |
10 | | #include <AK/Result.h> |
11 | | #include <AK/Types.h> |
12 | | #include <LibCrypto/ASN1/ASN1.h> |
13 | | #include <LibCrypto/BigInt/UnsignedBigInteger.h> |
14 | | |
15 | | namespace Crypto::ASN1 { |
16 | | |
17 | | class BitStringView { |
18 | | public: |
19 | | BitStringView(ReadonlyBytes data, size_t unused_bits) |
20 | 1.43k | : m_data(data) |
21 | 1.43k | , m_unused_bits(unused_bits) |
22 | 1.43k | { |
23 | 1.43k | } |
24 | | |
25 | | ErrorOr<ReadonlyBytes> raw_bytes() const |
26 | 1.80k | { |
27 | 1.80k | if (m_unused_bits != 0) |
28 | 21 | return Error::from_string_literal("ASN1::Decoder: BitStringView contains unexpected partial bytes"); |
29 | 1.78k | return m_data; |
30 | 1.80k | } |
31 | | |
32 | | bool get(size_t index) const |
33 | 300 | { |
34 | 300 | if (index >= 8 * m_data.size() - m_unused_bits) |
35 | 224 | return false; |
36 | 76 | return 0 != (m_data[index / 8] & (1u << (7 - (index % 8)))); |
37 | 300 | } |
38 | | |
39 | 0 | size_t unused_bits() const { return m_unused_bits; } |
40 | 0 | size_t byte_length() const { return m_data.size(); } |
41 | | |
42 | 0 | ReadonlyBytes underlying_bytes() const { return m_data; } |
43 | | |
44 | | // FIXME: Improve me! I am naive! |
45 | | bool operator==(BitStringView const& other) const |
46 | 0 | { |
47 | 0 | for (size_t bit_index = 0; bit_index < 8 * m_data.size() - m_unused_bits; ++bit_index) { |
48 | 0 | if (get(bit_index) != other.get(bit_index)) |
49 | 0 | return false; |
50 | 0 | } |
51 | 0 | return true; |
52 | 0 | } |
53 | | |
54 | | private: |
55 | | ReadonlyBytes m_data; |
56 | | size_t m_unused_bits; |
57 | | }; |
58 | | |
59 | | class Decoder { |
60 | | public: |
61 | | Decoder(ReadonlyBytes data) |
62 | 10.0k | { |
63 | 10.0k | m_stack.append(data); |
64 | 10.0k | } |
65 | | |
66 | | // Read a tag without consuming it (and its data). |
67 | | ErrorOr<Tag> peek(); |
68 | | |
69 | | bool eof() const; |
70 | | |
71 | | template<typename ValueType> |
72 | | struct TaggedValue { |
73 | | Tag tag; |
74 | | ValueType value; |
75 | | }; |
76 | | |
77 | | ErrorOr<void> rewrite_tag(Kind kind) |
78 | 393 | { |
79 | 393 | if (m_stack.is_empty()) |
80 | 0 | return Error::from_string_literal("Nothing on stack to rewrite"); |
81 | | |
82 | 393 | if (eof()) |
83 | 3 | return Error::from_string_literal("Stream is empty"); |
84 | | |
85 | 390 | if (m_current_tag.has_value()) { |
86 | 390 | m_current_tag->kind = kind; |
87 | 390 | return {}; |
88 | 390 | } |
89 | | |
90 | 0 | auto tag = TRY(read_tag()); |
91 | 0 | m_current_tag = tag; |
92 | 0 | m_current_tag->kind = kind; |
93 | 0 | return {}; |
94 | 0 | } |
95 | | |
96 | | ErrorOr<void> drop() |
97 | 22 | { |
98 | 22 | if (m_stack.is_empty()) |
99 | 0 | return Error::from_string_literal("ASN1::Decoder: Trying to drop using an empty stack"); |
100 | | |
101 | 22 | if (eof()) |
102 | 2 | return Error::from_string_literal("ASN1::Decoder: Trying to drop using a decoder that is EOF"); |
103 | | |
104 | 20 | auto previous_position = m_stack; |
105 | | |
106 | 20 | auto tag_or_error = peek(); |
107 | 20 | if (tag_or_error.is_error()) { |
108 | 0 | m_stack = move(previous_position); |
109 | 0 | return tag_or_error.release_error(); |
110 | 0 | } |
111 | | |
112 | 20 | auto length_or_error = read_length(); |
113 | 20 | if (length_or_error.is_error()) { |
114 | 3 | m_stack = move(previous_position); |
115 | 3 | return length_or_error.release_error(); |
116 | 3 | } |
117 | | |
118 | 17 | auto length = length_or_error.value(); |
119 | | |
120 | 17 | auto bytes_result = read_bytes(length); |
121 | 17 | if (bytes_result.is_error()) { |
122 | 4 | m_stack = move(previous_position); |
123 | 4 | return bytes_result.release_error(); |
124 | 4 | } |
125 | | |
126 | 13 | m_current_tag.clear(); |
127 | 13 | return {}; |
128 | 17 | } |
129 | | |
130 | | template<typename ValueType> |
131 | | ErrorOr<ValueType> read(Optional<Class> class_override = {}, Optional<Kind> kind_override = {}) |
132 | 72.2k | { |
133 | 72.2k | if (m_stack.is_empty()) |
134 | 0 | return Error::from_string_literal("ASN1::Decoder: Trying to read using an empty stack"); |
135 | | |
136 | 72.2k | if (eof()) |
137 | 895 | return Error::from_string_literal("ASN1::Decoder: Trying to read using a decoder that is EOF"); |
138 | | |
139 | 71.3k | auto previous_position = m_stack; |
140 | | |
141 | 71.3k | auto tag_or_error = peek(); |
142 | 71.3k | if (tag_or_error.is_error()) { |
143 | 109 | m_stack = move(previous_position); |
144 | 109 | return tag_or_error.release_error(); |
145 | 109 | } |
146 | | |
147 | 71.2k | auto length_or_error = read_length(); |
148 | 71.2k | if (length_or_error.is_error()) { |
149 | 346 | m_stack = move(previous_position); |
150 | 346 | return length_or_error.release_error(); |
151 | 346 | } |
152 | | |
153 | 70.9k | auto tag = tag_or_error.value(); |
154 | 70.9k | auto length = length_or_error.value(); |
155 | | |
156 | 70.9k | auto value_or_error = read_value<ValueType>(class_override.value_or(tag.class_), kind_override.value_or(tag.kind), length); |
157 | 70.9k | if (value_or_error.is_error()) { |
158 | 3.68k | m_stack = move(previous_position); |
159 | 3.68k | return value_or_error.release_error(); |
160 | 3.68k | } |
161 | | |
162 | 67.2k | m_current_tag.clear(); |
163 | | |
164 | 67.2k | return value_or_error.release_value(); |
165 | 70.9k | } AK::ErrorOr<AK::Vector<int, 0ul>, AK::Error> Crypto::ASN1::Decoder::read<AK::Vector<int, 0ul> >(AK::Optional<Crypto::ASN1::Class>, AK::Optional<Crypto::ASN1::Kind>) Line | Count | Source | 132 | 16.1k | { | 133 | 16.1k | if (m_stack.is_empty()) | 134 | 0 | return Error::from_string_literal("ASN1::Decoder: Trying to read using an empty stack"); | 135 | | | 136 | 16.1k | if (eof()) | 137 | 103 | return Error::from_string_literal("ASN1::Decoder: Trying to read using a decoder that is EOF"); | 138 | | | 139 | 16.0k | auto previous_position = m_stack; | 140 | | | 141 | 16.0k | auto tag_or_error = peek(); | 142 | 16.0k | if (tag_or_error.is_error()) { | 143 | 8 | m_stack = move(previous_position); | 144 | 8 | return tag_or_error.release_error(); | 145 | 8 | } | 146 | | | 147 | 16.0k | auto length_or_error = read_length(); | 148 | 16.0k | if (length_or_error.is_error()) { | 149 | 43 | m_stack = move(previous_position); | 150 | 43 | return length_or_error.release_error(); | 151 | 43 | } | 152 | | | 153 | 15.9k | auto tag = tag_or_error.value(); | 154 | 15.9k | auto length = length_or_error.value(); | 155 | | | 156 | 15.9k | auto value_or_error = read_value<ValueType>(class_override.value_or(tag.class_), kind_override.value_or(tag.kind), length); | 157 | 15.9k | if (value_or_error.is_error()) { | 158 | 200 | m_stack = move(previous_position); | 159 | 200 | return value_or_error.release_error(); | 160 | 200 | } | 161 | | | 162 | 15.7k | m_current_tag.clear(); | 163 | | | 164 | 15.7k | return value_or_error.release_value(); | 165 | 15.9k | } |
AK::ErrorOr<Crypto::UnsignedBigInteger, AK::Error> Crypto::ASN1::Decoder::read<Crypto::UnsignedBigInteger>(AK::Optional<Crypto::ASN1::Class>, AK::Optional<Crypto::ASN1::Kind>) Line | Count | Source | 132 | 13.4k | { | 133 | 13.4k | if (m_stack.is_empty()) | 134 | 0 | return Error::from_string_literal("ASN1::Decoder: Trying to read using an empty stack"); | 135 | | | 136 | 13.4k | if (eof()) | 137 | 777 | return Error::from_string_literal("ASN1::Decoder: Trying to read using a decoder that is EOF"); | 138 | | | 139 | 12.6k | auto previous_position = m_stack; | 140 | | | 141 | 12.6k | auto tag_or_error = peek(); | 142 | 12.6k | if (tag_or_error.is_error()) { | 143 | 94 | m_stack = move(previous_position); | 144 | 94 | return tag_or_error.release_error(); | 145 | 94 | } | 146 | | | 147 | 12.5k | auto length_or_error = read_length(); | 148 | 12.5k | if (length_or_error.is_error()) { | 149 | 284 | m_stack = move(previous_position); | 150 | 284 | return length_or_error.release_error(); | 151 | 284 | } | 152 | | | 153 | 12.2k | auto tag = tag_or_error.value(); | 154 | 12.2k | auto length = length_or_error.value(); | 155 | | | 156 | 12.2k | auto value_or_error = read_value<ValueType>(class_override.value_or(tag.class_), kind_override.value_or(tag.kind), length); | 157 | 12.2k | if (value_or_error.is_error()) { | 158 | 3.20k | m_stack = move(previous_position); | 159 | 3.20k | return value_or_error.release_error(); | 160 | 3.20k | } | 161 | | | 162 | 9.05k | m_current_tag.clear(); | 163 | | | 164 | 9.05k | return value_or_error.release_value(); | 165 | 12.2k | } |
AK::ErrorOr<AK::StringView, AK::Error> Crypto::ASN1::Decoder::read<AK::StringView>(AK::Optional<Crypto::ASN1::Class>, AK::Optional<Crypto::ASN1::Kind>) Line | Count | Source | 132 | 38.7k | { | 133 | 38.7k | if (m_stack.is_empty()) | 134 | 0 | return Error::from_string_literal("ASN1::Decoder: Trying to read using an empty stack"); | 135 | | | 136 | 38.7k | if (eof()) | 137 | 6 | return Error::from_string_literal("ASN1::Decoder: Trying to read using a decoder that is EOF"); | 138 | | | 139 | 38.6k | auto previous_position = m_stack; | 140 | | | 141 | 38.6k | auto tag_or_error = peek(); | 142 | 38.6k | if (tag_or_error.is_error()) { | 143 | 3 | m_stack = move(previous_position); | 144 | 3 | return tag_or_error.release_error(); | 145 | 3 | } | 146 | | | 147 | 38.6k | auto length_or_error = read_length(); | 148 | 38.6k | if (length_or_error.is_error()) { | 149 | 11 | m_stack = move(previous_position); | 150 | 11 | return length_or_error.release_error(); | 151 | 11 | } | 152 | | | 153 | 38.6k | auto tag = tag_or_error.value(); | 154 | 38.6k | auto length = length_or_error.value(); | 155 | | | 156 | 38.6k | auto value_or_error = read_value<ValueType>(class_override.value_or(tag.class_), kind_override.value_or(tag.kind), length); | 157 | 38.6k | if (value_or_error.is_error()) { | 158 | 94 | m_stack = move(previous_position); | 159 | 94 | return value_or_error.release_error(); | 160 | 94 | } | 161 | | | 162 | 38.5k | m_current_tag.clear(); | 163 | | | 164 | 38.5k | return value_or_error.release_value(); | 165 | 38.6k | } |
AK::ErrorOr<AK::BitmapView, AK::Error> Crypto::ASN1::Decoder::read<AK::BitmapView>(AK::Optional<Crypto::ASN1::Class>, AK::Optional<Crypto::ASN1::Kind>) Line | Count | Source | 132 | 145 | { | 133 | 145 | if (m_stack.is_empty()) | 134 | 0 | return Error::from_string_literal("ASN1::Decoder: Trying to read using an empty stack"); | 135 | | | 136 | 145 | if (eof()) | 137 | 2 | return Error::from_string_literal("ASN1::Decoder: Trying to read using a decoder that is EOF"); | 138 | | | 139 | 143 | auto previous_position = m_stack; | 140 | | | 141 | 143 | auto tag_or_error = peek(); | 142 | 143 | if (tag_or_error.is_error()) { | 143 | 2 | m_stack = move(previous_position); | 144 | 2 | return tag_or_error.release_error(); | 145 | 2 | } | 146 | | | 147 | 141 | auto length_or_error = read_length(); | 148 | 141 | if (length_or_error.is_error()) { | 149 | 2 | m_stack = move(previous_position); | 150 | 2 | return length_or_error.release_error(); | 151 | 2 | } | 152 | | | 153 | 139 | auto tag = tag_or_error.value(); | 154 | 139 | auto length = length_or_error.value(); | 155 | | | 156 | 139 | auto value_or_error = read_value<ValueType>(class_override.value_or(tag.class_), kind_override.value_or(tag.kind), length); | 157 | 139 | if (value_or_error.is_error()) { | 158 | 139 | m_stack = move(previous_position); | 159 | 139 | return value_or_error.release_error(); | 160 | 139 | } | 161 | | | 162 | 0 | m_current_tag.clear(); | 163 | |
| 164 | 0 | return value_or_error.release_value(); | 165 | 139 | } |
Unexecuted instantiation: AK::ErrorOr<AK::Span<unsigned char const>, AK::Error> Crypto::ASN1::Decoder::read<AK::Span<unsigned char const> >(AK::Optional<Crypto::ASN1::Class>, AK::Optional<Crypto::ASN1::Kind>) AK::ErrorOr<bool, AK::Error> Crypto::ASN1::Decoder::read<bool>(AK::Optional<Crypto::ASN1::Class>, AK::Optional<Crypto::ASN1::Kind>) Line | Count | Source | 132 | 406 | { | 133 | 406 | if (m_stack.is_empty()) | 134 | 0 | return Error::from_string_literal("ASN1::Decoder: Trying to read using an empty stack"); | 135 | | | 136 | 406 | if (eof()) | 137 | 1 | return Error::from_string_literal("ASN1::Decoder: Trying to read using a decoder that is EOF"); | 138 | | | 139 | 405 | auto previous_position = m_stack; | 140 | | | 141 | 405 | auto tag_or_error = peek(); | 142 | 405 | if (tag_or_error.is_error()) { | 143 | 0 | m_stack = move(previous_position); | 144 | 0 | return tag_or_error.release_error(); | 145 | 0 | } | 146 | | | 147 | 405 | auto length_or_error = read_length(); | 148 | 405 | if (length_or_error.is_error()) { | 149 | 1 | m_stack = move(previous_position); | 150 | 1 | return length_or_error.release_error(); | 151 | 1 | } | 152 | | | 153 | 404 | auto tag = tag_or_error.value(); | 154 | 404 | auto length = length_or_error.value(); | 155 | | | 156 | 404 | auto value_or_error = read_value<ValueType>(class_override.value_or(tag.class_), kind_override.value_or(tag.kind), length); | 157 | 404 | if (value_or_error.is_error()) { | 158 | 5 | m_stack = move(previous_position); | 159 | 5 | return value_or_error.release_error(); | 160 | 5 | } | 161 | | | 162 | 399 | m_current_tag.clear(); | 163 | | | 164 | 399 | return value_or_error.release_value(); | 165 | 404 | } |
Unexecuted instantiation: AK::ErrorOr<decltype(nullptr), AK::Error> Crypto::ASN1::Decoder::read<decltype(nullptr)>(AK::Optional<Crypto::ASN1::Class>, AK::Optional<Crypto::ASN1::Kind>) Unexecuted instantiation: AK::ErrorOr<AK::Utf8View, AK::Error> Crypto::ASN1::Decoder::read<AK::Utf8View>(AK::Optional<Crypto::ASN1::Class>, AK::Optional<Crypto::ASN1::Kind>) AK::ErrorOr<void*, AK::Error> Crypto::ASN1::Decoder::read<void*>(AK::Optional<Crypto::ASN1::Class>, AK::Optional<Crypto::ASN1::Kind>) Line | Count | Source | 132 | 2.11k | { | 133 | 2.11k | if (m_stack.is_empty()) | 134 | 0 | return Error::from_string_literal("ASN1::Decoder: Trying to read using an empty stack"); | 135 | | | 136 | 2.11k | if (eof()) | 137 | 2 | return Error::from_string_literal("ASN1::Decoder: Trying to read using a decoder that is EOF"); | 138 | | | 139 | 2.11k | auto previous_position = m_stack; | 140 | | | 141 | 2.11k | auto tag_or_error = peek(); | 142 | 2.11k | if (tag_or_error.is_error()) { | 143 | 1 | m_stack = move(previous_position); | 144 | 1 | return tag_or_error.release_error(); | 145 | 1 | } | 146 | | | 147 | 2.11k | auto length_or_error = read_length(); | 148 | 2.11k | if (length_or_error.is_error()) { | 149 | 2 | m_stack = move(previous_position); | 150 | 2 | return length_or_error.release_error(); | 151 | 2 | } | 152 | | | 153 | 2.11k | auto tag = tag_or_error.value(); | 154 | 2.11k | auto length = length_or_error.value(); | 155 | | | 156 | 2.11k | auto value_or_error = read_value<ValueType>(class_override.value_or(tag.class_), kind_override.value_or(tag.kind), length); | 157 | 2.11k | if (value_or_error.is_error()) { | 158 | 13 | m_stack = move(previous_position); | 159 | 13 | return value_or_error.release_error(); | 160 | 13 | } | 161 | | | 162 | 2.09k | m_current_tag.clear(); | 163 | | | 164 | 2.09k | return value_or_error.release_value(); | 165 | 2.11k | } |
AK::ErrorOr<Crypto::ASN1::BitStringView, AK::Error> Crypto::ASN1::Decoder::read<Crypto::ASN1::BitStringView>(AK::Optional<Crypto::ASN1::Class>, AK::Optional<Crypto::ASN1::Kind>) Line | Count | Source | 132 | 1.35k | { | 133 | 1.35k | if (m_stack.is_empty()) | 134 | 0 | return Error::from_string_literal("ASN1::Decoder: Trying to read using an empty stack"); | 135 | | | 136 | 1.35k | if (eof()) | 137 | 4 | return Error::from_string_literal("ASN1::Decoder: Trying to read using a decoder that is EOF"); | 138 | | | 139 | 1.35k | auto previous_position = m_stack; | 140 | | | 141 | 1.35k | auto tag_or_error = peek(); | 142 | 1.35k | if (tag_or_error.is_error()) { | 143 | 1 | m_stack = move(previous_position); | 144 | 1 | return tag_or_error.release_error(); | 145 | 1 | } | 146 | | | 147 | 1.35k | auto length_or_error = read_length(); | 148 | 1.35k | if (length_or_error.is_error()) { | 149 | 3 | m_stack = move(previous_position); | 150 | 3 | return length_or_error.release_error(); | 151 | 3 | } | 152 | | | 153 | 1.34k | auto tag = tag_or_error.value(); | 154 | 1.34k | auto length = length_or_error.value(); | 155 | | | 156 | 1.34k | auto value_or_error = read_value<ValueType>(class_override.value_or(tag.class_), kind_override.value_or(tag.kind), length); | 157 | 1.34k | if (value_or_error.is_error()) { | 158 | 20 | m_stack = move(previous_position); | 159 | 20 | return value_or_error.release_error(); | 160 | 20 | } | 161 | | | 162 | 1.32k | m_current_tag.clear(); | 163 | | | 164 | 1.32k | return value_or_error.release_value(); | 165 | 1.34k | } |
|
166 | | |
167 | | ErrorOr<void> enter(); |
168 | | ErrorOr<void> leave(); |
169 | | |
170 | | ErrorOr<ReadonlyBytes> peek_entry_bytes(); |
171 | | |
172 | | private: |
173 | | template<typename ValueType, typename DecodedType> |
174 | | ErrorOr<ValueType> with_type_check(DecodedType&& value) |
175 | 772 | { |
176 | | if constexpr (requires { ValueType { value }; }) |
177 | 231 | return ValueType { value }; |
178 | | |
179 | 0 | return Error::from_string_literal("ASN1::Decoder: Trying to decode a value from an incompatible type"); |
180 | 772 | } AK::ErrorOr<AK::Vector<int, 0ul>, AK::Error> Crypto::ASN1::Decoder::with_type_check<AK::Vector<int, 0ul>, AK::Span<unsigned char const>&>(AK::Span<unsigned char const>&) Line | Count | Source | 175 | 42 | { | 176 | | if constexpr (requires { ValueType { value }; }) | 177 | | return ValueType { value }; | 178 | | | 179 | 42 | return Error::from_string_literal("ASN1::Decoder: Trying to decode a value from an incompatible type"); | 180 | 42 | } |
AK::ErrorOr<AK::Vector<int, 0ul>, AK::Error> Crypto::ASN1::Decoder::with_type_check<AK::Vector<int, 0ul>, AK::StringView>(AK::StringView&&) Line | Count | Source | 175 | 2 | { | 176 | | if constexpr (requires { ValueType { value }; }) | 177 | | return ValueType { value }; | 178 | | | 179 | 2 | return Error::from_string_literal("ASN1::Decoder: Trying to decode a value from an incompatible type"); | 180 | 2 | } |
AK::ErrorOr<Crypto::UnsignedBigInteger, AK::Error> Crypto::ASN1::Decoder::with_type_check<Crypto::UnsignedBigInteger, AK::Span<unsigned char const>&>(AK::Span<unsigned char const>&) Line | Count | Source | 175 | 428 | { | 176 | | if constexpr (requires { ValueType { value }; }) | 177 | | return ValueType { value }; | 178 | | | 179 | 428 | return Error::from_string_literal("ASN1::Decoder: Trying to decode a value from an incompatible type"); | 180 | 428 | } |
AK::ErrorOr<Crypto::UnsignedBigInteger, AK::Error> Crypto::ASN1::Decoder::with_type_check<Crypto::UnsignedBigInteger, AK::StringView>(AK::StringView&&) Line | Count | Source | 175 | 45 | { | 176 | | if constexpr (requires { ValueType { value }; }) | 177 | | return ValueType { value }; | 178 | | | 179 | 45 | return Error::from_string_literal("ASN1::Decoder: Trying to decode a value from an incompatible type"); | 180 | 45 | } |
AK::ErrorOr<AK::StringView, AK::Error> Crypto::ASN1::Decoder::with_type_check<AK::StringView, AK::Span<unsigned char const>&>(AK::Span<unsigned char const>&) Line | Count | Source | 175 | 202 | { | 176 | | if constexpr (requires { ValueType { value }; }) | 177 | 202 | return ValueType { value }; | 178 | | | 179 | 0 | return Error::from_string_literal("ASN1::Decoder: Trying to decode a value from an incompatible type"); | 180 | 202 | } |
AK::ErrorOr<AK::StringView, AK::Error> Crypto::ASN1::Decoder::with_type_check<AK::StringView, AK::StringView>(AK::StringView&&) Line | Count | Source | 175 | 29 | { | 176 | | if constexpr (requires { ValueType { value }; }) | 177 | 29 | return ValueType { value }; | 178 | | | 179 | 0 | return Error::from_string_literal("ASN1::Decoder: Trying to decode a value from an incompatible type"); | 180 | 29 | } |
AK::ErrorOr<AK::BitmapView, AK::Error> Crypto::ASN1::Decoder::with_type_check<AK::BitmapView, AK::Span<unsigned char const>&>(AK::Span<unsigned char const>&) Line | Count | Source | 175 | 22 | { | 176 | | if constexpr (requires { ValueType { value }; }) | 177 | | return ValueType { value }; | 178 | | | 179 | 22 | return Error::from_string_literal("ASN1::Decoder: Trying to decode a value from an incompatible type"); | 180 | 22 | } |
AK::ErrorOr<AK::BitmapView, AK::Error> Crypto::ASN1::Decoder::with_type_check<AK::BitmapView, AK::StringView>(AK::StringView&&) Line | Count | Source | 175 | 2 | { | 176 | | if constexpr (requires { ValueType { value }; }) | 177 | | return ValueType { value }; | 178 | | | 179 | 2 | return Error::from_string_literal("ASN1::Decoder: Trying to decode a value from an incompatible type"); | 180 | 2 | } |
Unexecuted instantiation: AK::ErrorOr<bool, AK::Error> Crypto::ASN1::Decoder::with_type_check<bool, AK::Span<unsigned char const>&>(AK::Span<unsigned char const>&) Unexecuted instantiation: AK::ErrorOr<bool, AK::Error> Crypto::ASN1::Decoder::with_type_check<bool, AK::StringView>(AK::StringView&&) Unexecuted instantiation: AK::ErrorOr<decltype(nullptr), AK::Error> Crypto::ASN1::Decoder::with_type_check<decltype(nullptr), AK::Span<unsigned char const>&>(AK::Span<unsigned char const>&) Unexecuted instantiation: AK::ErrorOr<decltype(nullptr), AK::Error> Crypto::ASN1::Decoder::with_type_check<decltype(nullptr), AK::StringView>(AK::StringView&&) Unexecuted instantiation: AK::ErrorOr<AK::Utf8View, AK::Error> Crypto::ASN1::Decoder::with_type_check<AK::Utf8View, AK::Span<unsigned char const>&>(AK::Span<unsigned char const>&) Unexecuted instantiation: AK::ErrorOr<AK::Utf8View, AK::Error> Crypto::ASN1::Decoder::with_type_check<AK::Utf8View, AK::StringView>(AK::StringView&&) Unexecuted instantiation: AK::ErrorOr<void*, AK::Error> Crypto::ASN1::Decoder::with_type_check<void*, AK::Span<unsigned char const>&>(AK::Span<unsigned char const>&) Unexecuted instantiation: AK::ErrorOr<void*, AK::Error> Crypto::ASN1::Decoder::with_type_check<void*, AK::StringView>(AK::StringView&&) Unexecuted instantiation: AK::ErrorOr<Crypto::ASN1::BitStringView, AK::Error> Crypto::ASN1::Decoder::with_type_check<Crypto::ASN1::BitStringView, AK::Span<unsigned char const>&>(AK::Span<unsigned char const>&) Unexecuted instantiation: AK::ErrorOr<Crypto::ASN1::BitStringView, AK::Error> Crypto::ASN1::Decoder::with_type_check<Crypto::ASN1::BitStringView, AK::StringView>(AK::StringView&&) |
181 | | |
182 | | template<typename ValueType, typename DecodedType> |
183 | | ErrorOr<ValueType> with_type_check(ErrorOr<DecodedType>&& value_or_error) |
184 | 69.2k | { |
185 | 69.2k | if (value_or_error.is_error()) |
186 | 1.46k | return value_or_error.release_error(); |
187 | | |
188 | 67.8k | if constexpr (IsSame<ValueType, bool> && !IsSame<DecodedType, bool>) { |
189 | 0 | return Error::from_string_literal("ASN1::Decoder: Trying to decode a boolean from a non-boolean type"); |
190 | 67.8k | } else { |
191 | 67.8k | auto&& value = value_or_error.value(); |
192 | | if constexpr (requires { ValueType { value }; }) |
193 | 67.0k | return ValueType { value }; |
194 | 67.8k | } |
195 | | |
196 | 0 | return Error::from_string_literal("ASN1::Decoder: Trying to decode a value from an incompatible type"); |
197 | 69.2k | } AK::ErrorOr<AK::Vector<int, 0ul>, AK::Error> Crypto::ASN1::Decoder::with_type_check<AK::Vector<int, 0ul>, bool>(AK::ErrorOr<bool, AK::Error>&&) Line | Count | Source | 184 | 10 | { | 185 | 10 | if (value_or_error.is_error()) | 186 | 7 | return value_or_error.release_error(); | 187 | | | 188 | | if constexpr (IsSame<ValueType, bool> && !IsSame<DecodedType, bool>) { | 189 | | return Error::from_string_literal("ASN1::Decoder: Trying to decode a boolean from a non-boolean type"); | 190 | 3 | } else { | 191 | 3 | auto&& value = value_or_error.value(); | 192 | | if constexpr (requires { ValueType { value }; }) | 193 | 3 | return ValueType { value }; | 194 | 3 | } | 195 | | | 196 | 0 | return Error::from_string_literal("ASN1::Decoder: Trying to decode a value from an incompatible type"); | 197 | 10 | } |
AK::ErrorOr<AK::Vector<int, 0ul>, AK::Error> Crypto::ASN1::Decoder::with_type_check<AK::Vector<int, 0ul>, Crypto::UnsignedBigInteger>(AK::ErrorOr<Crypto::UnsignedBigInteger, AK::Error>&&) Line | Count | Source | 184 | 28 | { | 185 | 28 | if (value_or_error.is_error()) | 186 | 7 | return value_or_error.release_error(); | 187 | | | 188 | | if constexpr (IsSame<ValueType, bool> && !IsSame<DecodedType, bool>) { | 189 | | return Error::from_string_literal("ASN1::Decoder: Trying to decode a boolean from a non-boolean type"); | 190 | 21 | } else { | 191 | 21 | auto&& value = value_or_error.value(); | 192 | | if constexpr (requires { ValueType { value }; }) | 193 | | return ValueType { value }; | 194 | 21 | } | 195 | | | 196 | 21 | return Error::from_string_literal("ASN1::Decoder: Trying to decode a value from an incompatible type"); | 197 | 28 | } |
AK::ErrorOr<AK::Vector<int, 0ul>, AK::Error> Crypto::ASN1::Decoder::with_type_check<AK::Vector<int, 0ul>, AK::StringView>(AK::ErrorOr<AK::StringView, AK::Error>&&) Line | Count | Source | 184 | 28 | { | 185 | 28 | if (value_or_error.is_error()) | 186 | 10 | return value_or_error.release_error(); | 187 | | | 188 | | if constexpr (IsSame<ValueType, bool> && !IsSame<DecodedType, bool>) { | 189 | | return Error::from_string_literal("ASN1::Decoder: Trying to decode a boolean from a non-boolean type"); | 190 | 18 | } else { | 191 | 18 | auto&& value = value_or_error.value(); | 192 | | if constexpr (requires { ValueType { value }; }) | 193 | | return ValueType { value }; | 194 | 18 | } | 195 | | | 196 | 18 | return Error::from_string_literal("ASN1::Decoder: Trying to decode a value from an incompatible type"); | 197 | 28 | } |
AK::ErrorOr<AK::Vector<int, 0ul>, AK::Error> Crypto::ASN1::Decoder::with_type_check<AK::Vector<int, 0ul>, decltype(nullptr)>(AK::ErrorOr<decltype(nullptr), AK::Error>&&) Line | Count | Source | 184 | 10 | { | 185 | 10 | if (value_or_error.is_error()) | 186 | 5 | return value_or_error.release_error(); | 187 | | | 188 | | if constexpr (IsSame<ValueType, bool> && !IsSame<DecodedType, bool>) { | 189 | | return Error::from_string_literal("ASN1::Decoder: Trying to decode a boolean from a non-boolean type"); | 190 | 5 | } else { | 191 | 5 | auto&& value = value_or_error.value(); | 192 | | if constexpr (requires { ValueType { value }; }) | 193 | | return ValueType { value }; | 194 | 5 | } | 195 | | | 196 | 5 | return Error::from_string_literal("ASN1::Decoder: Trying to decode a value from an incompatible type"); | 197 | 10 | } |
AK::ErrorOr<AK::Vector<int, 0ul>, AK::Error> Crypto::ASN1::Decoder::with_type_check<AK::Vector<int, 0ul>, AK::Vector<int, 0ul> >(AK::ErrorOr<AK::Vector<int, 0ul>, AK::Error>&&) Line | Count | Source | 184 | 15.8k | { | 185 | 15.8k | if (value_or_error.is_error()) | 186 | 47 | return value_or_error.release_error(); | 187 | | | 188 | | if constexpr (IsSame<ValueType, bool> && !IsSame<DecodedType, bool>) { | 189 | | return Error::from_string_literal("ASN1::Decoder: Trying to decode a boolean from a non-boolean type"); | 190 | 15.7k | } else { | 191 | 15.7k | auto&& value = value_or_error.value(); | 192 | | if constexpr (requires { ValueType { value }; }) | 193 | 15.7k | return ValueType { value }; | 194 | 15.7k | } | 195 | | | 196 | 0 | return Error::from_string_literal("ASN1::Decoder: Trying to decode a value from an incompatible type"); | 197 | 15.8k | } |
AK::ErrorOr<AK::Vector<int, 0ul>, AK::Error> Crypto::ASN1::Decoder::with_type_check<AK::Vector<int, 0ul>, Crypto::ASN1::BitStringView>(AK::ErrorOr<Crypto::ASN1::BitStringView, AK::Error>&&) Line | Count | Source | 184 | 9 | { | 185 | 9 | if (value_or_error.is_error()) | 186 | 6 | return value_or_error.release_error(); | 187 | | | 188 | | if constexpr (IsSame<ValueType, bool> && !IsSame<DecodedType, bool>) { | 189 | | return Error::from_string_literal("ASN1::Decoder: Trying to decode a boolean from a non-boolean type"); | 190 | 3 | } else { | 191 | 3 | auto&& value = value_or_error.value(); | 192 | | if constexpr (requires { ValueType { value }; }) | 193 | | return ValueType { value }; | 194 | 3 | } | 195 | | | 196 | 3 | return Error::from_string_literal("ASN1::Decoder: Trying to decode a value from an incompatible type"); | 197 | 9 | } |
AK::ErrorOr<Crypto::UnsignedBigInteger, AK::Error> Crypto::ASN1::Decoder::with_type_check<Crypto::UnsignedBigInteger, bool>(AK::ErrorOr<bool, AK::Error>&&) Line | Count | Source | 184 | 2.03k | { | 185 | 2.03k | if (value_or_error.is_error()) | 186 | 146 | return value_or_error.release_error(); | 187 | | | 188 | | if constexpr (IsSame<ValueType, bool> && !IsSame<DecodedType, bool>) { | 189 | | return Error::from_string_literal("ASN1::Decoder: Trying to decode a boolean from a non-boolean type"); | 190 | 1.89k | } else { | 191 | 1.89k | auto&& value = value_or_error.value(); | 192 | | if constexpr (requires { ValueType { value }; }) | 193 | 1.89k | return ValueType { value }; | 194 | 1.89k | } | 195 | | | 196 | 0 | return Error::from_string_literal("ASN1::Decoder: Trying to decode a value from an incompatible type"); | 197 | 2.03k | } |
AK::ErrorOr<Crypto::UnsignedBigInteger, AK::Error> Crypto::ASN1::Decoder::with_type_check<Crypto::UnsignedBigInteger, Crypto::UnsignedBigInteger>(AK::ErrorOr<Crypto::UnsignedBigInteger, AK::Error>&&) Line | Count | Source | 184 | 7.45k | { | 185 | 7.45k | if (value_or_error.is_error()) | 186 | 287 | return value_or_error.release_error(); | 187 | | | 188 | | if constexpr (IsSame<ValueType, bool> && !IsSame<DecodedType, bool>) { | 189 | | return Error::from_string_literal("ASN1::Decoder: Trying to decode a boolean from a non-boolean type"); | 190 | 7.16k | } else { | 191 | 7.16k | auto&& value = value_or_error.value(); | 192 | | if constexpr (requires { ValueType { value }; }) | 193 | 7.16k | return ValueType { value }; | 194 | 7.16k | } | 195 | | | 196 | 0 | return Error::from_string_literal("ASN1::Decoder: Trying to decode a value from an incompatible type"); | 197 | 7.45k | } |
AK::ErrorOr<Crypto::UnsignedBigInteger, AK::Error> Crypto::ASN1::Decoder::with_type_check<Crypto::UnsignedBigInteger, AK::StringView>(AK::ErrorOr<AK::StringView, AK::Error>&&) Line | Count | Source | 184 | 781 | { | 185 | 781 | if (value_or_error.is_error()) | 186 | 450 | return value_or_error.release_error(); | 187 | | | 188 | | if constexpr (IsSame<ValueType, bool> && !IsSame<DecodedType, bool>) { | 189 | | return Error::from_string_literal("ASN1::Decoder: Trying to decode a boolean from a non-boolean type"); | 190 | 331 | } else { | 191 | 331 | auto&& value = value_or_error.value(); | 192 | | if constexpr (requires { ValueType { value }; }) | 193 | | return ValueType { value }; | 194 | 331 | } | 195 | | | 196 | 331 | return Error::from_string_literal("ASN1::Decoder: Trying to decode a value from an incompatible type"); | 197 | 781 | } |
AK::ErrorOr<Crypto::UnsignedBigInteger, AK::Error> Crypto::ASN1::Decoder::with_type_check<Crypto::UnsignedBigInteger, decltype(nullptr)>(AK::ErrorOr<decltype(nullptr), AK::Error>&&) Line | Count | Source | 184 | 90 | { | 185 | 90 | if (value_or_error.is_error()) | 186 | 69 | return value_or_error.release_error(); | 187 | | | 188 | | if constexpr (IsSame<ValueType, bool> && !IsSame<DecodedType, bool>) { | 189 | | return Error::from_string_literal("ASN1::Decoder: Trying to decode a boolean from a non-boolean type"); | 190 | 21 | } else { | 191 | 21 | auto&& value = value_or_error.value(); | 192 | | if constexpr (requires { ValueType { value }; }) | 193 | | return ValueType { value }; | 194 | 21 | } | 195 | | | 196 | 21 | return Error::from_string_literal("ASN1::Decoder: Trying to decode a value from an incompatible type"); | 197 | 90 | } |
AK::ErrorOr<Crypto::UnsignedBigInteger, AK::Error> Crypto::ASN1::Decoder::with_type_check<Crypto::UnsignedBigInteger, AK::Vector<int, 0ul> >(AK::ErrorOr<AK::Vector<int, 0ul>, AK::Error>&&) Line | Count | Source | 184 | 526 | { | 185 | 526 | if (value_or_error.is_error()) | 186 | 246 | return value_or_error.release_error(); | 187 | | | 188 | | if constexpr (IsSame<ValueType, bool> && !IsSame<DecodedType, bool>) { | 189 | | return Error::from_string_literal("ASN1::Decoder: Trying to decode a boolean from a non-boolean type"); | 190 | 280 | } else { | 191 | 280 | auto&& value = value_or_error.value(); | 192 | | if constexpr (requires { ValueType { value }; }) | 193 | | return ValueType { value }; | 194 | 280 | } | 195 | | | 196 | 280 | return Error::from_string_literal("ASN1::Decoder: Trying to decode a value from an incompatible type"); | 197 | 526 | } |
AK::ErrorOr<Crypto::UnsignedBigInteger, AK::Error> Crypto::ASN1::Decoder::with_type_check<Crypto::UnsignedBigInteger, Crypto::ASN1::BitStringView>(AK::ErrorOr<Crypto::ASN1::BitStringView, AK::Error>&&) Line | Count | Source | 184 | 174 | { | 185 | 174 | if (value_or_error.is_error()) | 186 | 75 | return value_or_error.release_error(); | 187 | | | 188 | | if constexpr (IsSame<ValueType, bool> && !IsSame<DecodedType, bool>) { | 189 | | return Error::from_string_literal("ASN1::Decoder: Trying to decode a boolean from a non-boolean type"); | 190 | 99 | } else { | 191 | 99 | auto&& value = value_or_error.value(); | 192 | | if constexpr (requires { ValueType { value }; }) | 193 | | return ValueType { value }; | 194 | 99 | } | 195 | | | 196 | 99 | return Error::from_string_literal("ASN1::Decoder: Trying to decode a value from an incompatible type"); | 197 | 174 | } |
AK::ErrorOr<AK::StringView, AK::Error> Crypto::ASN1::Decoder::with_type_check<AK::StringView, bool>(AK::ErrorOr<bool, AK::Error>&&) Line | Count | Source | 184 | 4 | { | 185 | 4 | if (value_or_error.is_error()) | 186 | 2 | return value_or_error.release_error(); | 187 | | | 188 | | if constexpr (IsSame<ValueType, bool> && !IsSame<DecodedType, bool>) { | 189 | | return Error::from_string_literal("ASN1::Decoder: Trying to decode a boolean from a non-boolean type"); | 190 | 2 | } else { | 191 | 2 | auto&& value = value_or_error.value(); | 192 | | if constexpr (requires { ValueType { value }; }) | 193 | | return ValueType { value }; | 194 | 2 | } | 195 | | | 196 | 2 | return Error::from_string_literal("ASN1::Decoder: Trying to decode a value from an incompatible type"); | 197 | 4 | } |
AK::ErrorOr<AK::StringView, AK::Error> Crypto::ASN1::Decoder::with_type_check<AK::StringView, Crypto::UnsignedBigInteger>(AK::ErrorOr<Crypto::UnsignedBigInteger, AK::Error>&&) Line | Count | Source | 184 | 6 | { | 185 | 6 | if (value_or_error.is_error()) | 186 | 2 | return value_or_error.release_error(); | 187 | | | 188 | | if constexpr (IsSame<ValueType, bool> && !IsSame<DecodedType, bool>) { | 189 | | return Error::from_string_literal("ASN1::Decoder: Trying to decode a boolean from a non-boolean type"); | 190 | 4 | } else { | 191 | 4 | auto&& value = value_or_error.value(); | 192 | | if constexpr (requires { ValueType { value }; }) | 193 | | return ValueType { value }; | 194 | 4 | } | 195 | | | 196 | 4 | return Error::from_string_literal("ASN1::Decoder: Trying to decode a value from an incompatible type"); | 197 | 6 | } |
AK::ErrorOr<AK::StringView, AK::Error> Crypto::ASN1::Decoder::with_type_check<AK::StringView, AK::StringView>(AK::ErrorOr<AK::StringView, AK::Error>&&) Line | Count | Source | 184 | 38.4k | { | 185 | 38.4k | if (value_or_error.is_error()) | 186 | 52 | return value_or_error.release_error(); | 187 | | | 188 | | if constexpr (IsSame<ValueType, bool> && !IsSame<DecodedType, bool>) { | 189 | | return Error::from_string_literal("ASN1::Decoder: Trying to decode a boolean from a non-boolean type"); | 190 | 38.3k | } else { | 191 | 38.3k | auto&& value = value_or_error.value(); | 192 | | if constexpr (requires { ValueType { value }; }) | 193 | 38.3k | return ValueType { value }; | 194 | 38.3k | } | 195 | | | 196 | 0 | return Error::from_string_literal("ASN1::Decoder: Trying to decode a value from an incompatible type"); | 197 | 38.4k | } |
AK::ErrorOr<AK::StringView, AK::Error> Crypto::ASN1::Decoder::with_type_check<AK::StringView, decltype(nullptr)>(AK::ErrorOr<decltype(nullptr), AK::Error>&&) Line | Count | Source | 184 | 4 | { | 185 | 4 | if (value_or_error.is_error()) | 186 | 2 | return value_or_error.release_error(); | 187 | | | 188 | | if constexpr (IsSame<ValueType, bool> && !IsSame<DecodedType, bool>) { | 189 | | return Error::from_string_literal("ASN1::Decoder: Trying to decode a boolean from a non-boolean type"); | 190 | 2 | } else { | 191 | 2 | auto&& value = value_or_error.value(); | 192 | | if constexpr (requires { ValueType { value }; }) | 193 | | return ValueType { value }; | 194 | 2 | } | 195 | | | 196 | 2 | return Error::from_string_literal("ASN1::Decoder: Trying to decode a value from an incompatible type"); | 197 | 4 | } |
AK::ErrorOr<AK::StringView, AK::Error> Crypto::ASN1::Decoder::with_type_check<AK::StringView, AK::Vector<int, 0ul> >(AK::ErrorOr<AK::Vector<int, 0ul>, AK::Error>&&) Line | Count | Source | 184 | 4 | { | 185 | 4 | if (value_or_error.is_error()) | 186 | 2 | return value_or_error.release_error(); | 187 | | | 188 | | if constexpr (IsSame<ValueType, bool> && !IsSame<DecodedType, bool>) { | 189 | | return Error::from_string_literal("ASN1::Decoder: Trying to decode a boolean from a non-boolean type"); | 190 | 2 | } else { | 191 | 2 | auto&& value = value_or_error.value(); | 192 | | if constexpr (requires { ValueType { value }; }) | 193 | | return ValueType { value }; | 194 | 2 | } | 195 | | | 196 | 2 | return Error::from_string_literal("ASN1::Decoder: Trying to decode a value from an incompatible type"); | 197 | 4 | } |
AK::ErrorOr<AK::StringView, AK::Error> Crypto::ASN1::Decoder::with_type_check<AK::StringView, Crypto::ASN1::BitStringView>(AK::ErrorOr<Crypto::ASN1::BitStringView, AK::Error>&&) Line | Count | Source | 184 | 4 | { | 185 | 4 | if (value_or_error.is_error()) | 186 | 2 | return value_or_error.release_error(); | 187 | | | 188 | | if constexpr (IsSame<ValueType, bool> && !IsSame<DecodedType, bool>) { | 189 | | return Error::from_string_literal("ASN1::Decoder: Trying to decode a boolean from a non-boolean type"); | 190 | 2 | } else { | 191 | 2 | auto&& value = value_or_error.value(); | 192 | | if constexpr (requires { ValueType { value }; }) | 193 | | return ValueType { value }; | 194 | 2 | } | 195 | | | 196 | 2 | return Error::from_string_literal("ASN1::Decoder: Trying to decode a value from an incompatible type"); | 197 | 4 | } |
AK::ErrorOr<AK::BitmapView, AK::Error> Crypto::ASN1::Decoder::with_type_check<AK::BitmapView, bool>(AK::ErrorOr<bool, AK::Error>&&) Line | Count | Source | 184 | 10 | { | 185 | 10 | if (value_or_error.is_error()) | 186 | 7 | return value_or_error.release_error(); | 187 | | | 188 | | if constexpr (IsSame<ValueType, bool> && !IsSame<DecodedType, bool>) { | 189 | | return Error::from_string_literal("ASN1::Decoder: Trying to decode a boolean from a non-boolean type"); | 190 | 3 | } else { | 191 | 3 | auto&& value = value_or_error.value(); | 192 | | if constexpr (requires { ValueType { value }; }) | 193 | | return ValueType { value }; | 194 | 3 | } | 195 | | | 196 | 3 | return Error::from_string_literal("ASN1::Decoder: Trying to decode a value from an incompatible type"); | 197 | 10 | } |
AK::ErrorOr<AK::BitmapView, AK::Error> Crypto::ASN1::Decoder::with_type_check<AK::BitmapView, Crypto::UnsignedBigInteger>(AK::ErrorOr<Crypto::UnsignedBigInteger, AK::Error>&&) Line | Count | Source | 184 | 6 | { | 185 | 6 | if (value_or_error.is_error()) | 186 | 2 | return value_or_error.release_error(); | 187 | | | 188 | | if constexpr (IsSame<ValueType, bool> && !IsSame<DecodedType, bool>) { | 189 | | return Error::from_string_literal("ASN1::Decoder: Trying to decode a boolean from a non-boolean type"); | 190 | 4 | } else { | 191 | 4 | auto&& value = value_or_error.value(); | 192 | | if constexpr (requires { ValueType { value }; }) | 193 | | return ValueType { value }; | 194 | 4 | } | 195 | | | 196 | 4 | return Error::from_string_literal("ASN1::Decoder: Trying to decode a value from an incompatible type"); | 197 | 6 | } |
AK::ErrorOr<AK::BitmapView, AK::Error> Crypto::ASN1::Decoder::with_type_check<AK::BitmapView, AK::StringView>(AK::ErrorOr<AK::StringView, AK::Error>&&) Line | Count | Source | 184 | 11 | { | 185 | 11 | if (value_or_error.is_error()) | 186 | 2 | return value_or_error.release_error(); | 187 | | | 188 | | if constexpr (IsSame<ValueType, bool> && !IsSame<DecodedType, bool>) { | 189 | | return Error::from_string_literal("ASN1::Decoder: Trying to decode a boolean from a non-boolean type"); | 190 | 9 | } else { | 191 | 9 | auto&& value = value_or_error.value(); | 192 | | if constexpr (requires { ValueType { value }; }) | 193 | | return ValueType { value }; | 194 | 9 | } | 195 | | | 196 | 9 | return Error::from_string_literal("ASN1::Decoder: Trying to decode a value from an incompatible type"); | 197 | 11 | } |
AK::ErrorOr<AK::BitmapView, AK::Error> Crypto::ASN1::Decoder::with_type_check<AK::BitmapView, decltype(nullptr)>(AK::ErrorOr<decltype(nullptr), AK::Error>&&) Line | Count | Source | 184 | 4 | { | 185 | 4 | if (value_or_error.is_error()) | 186 | 2 | return value_or_error.release_error(); | 187 | | | 188 | | if constexpr (IsSame<ValueType, bool> && !IsSame<DecodedType, bool>) { | 189 | | return Error::from_string_literal("ASN1::Decoder: Trying to decode a boolean from a non-boolean type"); | 190 | 2 | } else { | 191 | 2 | auto&& value = value_or_error.value(); | 192 | | if constexpr (requires { ValueType { value }; }) | 193 | | return ValueType { value }; | 194 | 2 | } | 195 | | | 196 | 2 | return Error::from_string_literal("ASN1::Decoder: Trying to decode a value from an incompatible type"); | 197 | 4 | } |
AK::ErrorOr<AK::BitmapView, AK::Error> Crypto::ASN1::Decoder::with_type_check<AK::BitmapView, AK::Vector<int, 0ul> >(AK::ErrorOr<AK::Vector<int, 0ul>, AK::Error>&&) Line | Count | Source | 184 | 7 | { | 185 | 7 | if (value_or_error.is_error()) | 186 | 4 | return value_or_error.release_error(); | 187 | | | 188 | | if constexpr (IsSame<ValueType, bool> && !IsSame<DecodedType, bool>) { | 189 | | return Error::from_string_literal("ASN1::Decoder: Trying to decode a boolean from a non-boolean type"); | 190 | 3 | } else { | 191 | 3 | auto&& value = value_or_error.value(); | 192 | | if constexpr (requires { ValueType { value }; }) | 193 | | return ValueType { value }; | 194 | 3 | } | 195 | | | 196 | 3 | return Error::from_string_literal("ASN1::Decoder: Trying to decode a value from an incompatible type"); | 197 | 7 | } |
AK::ErrorOr<AK::BitmapView, AK::Error> Crypto::ASN1::Decoder::with_type_check<AK::BitmapView, Crypto::ASN1::BitStringView>(AK::ErrorOr<Crypto::ASN1::BitStringView, AK::Error>&&) Line | Count | Source | 184 | 7 | { | 185 | 7 | if (value_or_error.is_error()) | 186 | 5 | return value_or_error.release_error(); | 187 | | | 188 | | if constexpr (IsSame<ValueType, bool> && !IsSame<DecodedType, bool>) { | 189 | | return Error::from_string_literal("ASN1::Decoder: Trying to decode a boolean from a non-boolean type"); | 190 | 2 | } else { | 191 | 2 | auto&& value = value_or_error.value(); | 192 | | if constexpr (requires { ValueType { value }; }) | 193 | | return ValueType { value }; | 194 | 2 | } | 195 | | | 196 | 2 | return Error::from_string_literal("ASN1::Decoder: Trying to decode a value from an incompatible type"); | 197 | 7 | } |
AK::ErrorOr<bool, AK::Error> Crypto::ASN1::Decoder::with_type_check<bool, bool>(AK::ErrorOr<bool, AK::Error>&&) Line | Count | Source | 184 | 403 | { | 185 | 403 | if (value_or_error.is_error()) | 186 | 4 | return value_or_error.release_error(); | 187 | | | 188 | | if constexpr (IsSame<ValueType, bool> && !IsSame<DecodedType, bool>) { | 189 | | return Error::from_string_literal("ASN1::Decoder: Trying to decode a boolean from a non-boolean type"); | 190 | 399 | } else { | 191 | 399 | auto&& value = value_or_error.value(); | 192 | | if constexpr (requires { ValueType { value }; }) | 193 | 399 | return ValueType { value }; | 194 | 399 | } | 195 | | | 196 | 0 | return Error::from_string_literal("ASN1::Decoder: Trying to decode a value from an incompatible type"); | 197 | 403 | } |
Unexecuted instantiation: AK::ErrorOr<bool, AK::Error> Crypto::ASN1::Decoder::with_type_check<bool, Crypto::UnsignedBigInteger>(AK::ErrorOr<Crypto::UnsignedBigInteger, AK::Error>&&) Unexecuted instantiation: AK::ErrorOr<bool, AK::Error> Crypto::ASN1::Decoder::with_type_check<bool, AK::StringView>(AK::ErrorOr<AK::StringView, AK::Error>&&) Unexecuted instantiation: AK::ErrorOr<bool, AK::Error> Crypto::ASN1::Decoder::with_type_check<bool, decltype(nullptr)>(AK::ErrorOr<decltype(nullptr), AK::Error>&&) Unexecuted instantiation: AK::ErrorOr<bool, AK::Error> Crypto::ASN1::Decoder::with_type_check<bool, AK::Vector<int, 0ul> >(AK::ErrorOr<AK::Vector<int, 0ul>, AK::Error>&&) Unexecuted instantiation: AK::ErrorOr<bool, AK::Error> Crypto::ASN1::Decoder::with_type_check<bool, Crypto::ASN1::BitStringView>(AK::ErrorOr<Crypto::ASN1::BitStringView, AK::Error>&&) Unexecuted instantiation: AK::ErrorOr<decltype(nullptr), AK::Error> Crypto::ASN1::Decoder::with_type_check<decltype(nullptr), bool>(AK::ErrorOr<bool, AK::Error>&&) Unexecuted instantiation: AK::ErrorOr<decltype(nullptr), AK::Error> Crypto::ASN1::Decoder::with_type_check<decltype(nullptr), Crypto::UnsignedBigInteger>(AK::ErrorOr<Crypto::UnsignedBigInteger, AK::Error>&&) Unexecuted instantiation: AK::ErrorOr<decltype(nullptr), AK::Error> Crypto::ASN1::Decoder::with_type_check<decltype(nullptr), AK::StringView>(AK::ErrorOr<AK::StringView, AK::Error>&&) Unexecuted instantiation: AK::ErrorOr<decltype(nullptr), AK::Error> Crypto::ASN1::Decoder::with_type_check<decltype(nullptr), decltype(nullptr)>(AK::ErrorOr<decltype(nullptr), AK::Error>&&) Unexecuted instantiation: AK::ErrorOr<decltype(nullptr), AK::Error> Crypto::ASN1::Decoder::with_type_check<decltype(nullptr), AK::Vector<int, 0ul> >(AK::ErrorOr<AK::Vector<int, 0ul>, AK::Error>&&) Unexecuted instantiation: AK::ErrorOr<decltype(nullptr), AK::Error> Crypto::ASN1::Decoder::with_type_check<decltype(nullptr), Crypto::ASN1::BitStringView>(AK::ErrorOr<Crypto::ASN1::BitStringView, AK::Error>&&) Unexecuted instantiation: AK::ErrorOr<AK::Utf8View, AK::Error> Crypto::ASN1::Decoder::with_type_check<AK::Utf8View, bool>(AK::ErrorOr<bool, AK::Error>&&) Unexecuted instantiation: AK::ErrorOr<AK::Utf8View, AK::Error> Crypto::ASN1::Decoder::with_type_check<AK::Utf8View, Crypto::UnsignedBigInteger>(AK::ErrorOr<Crypto::UnsignedBigInteger, AK::Error>&&) Unexecuted instantiation: AK::ErrorOr<AK::Utf8View, AK::Error> Crypto::ASN1::Decoder::with_type_check<AK::Utf8View, AK::StringView>(AK::ErrorOr<AK::StringView, AK::Error>&&) Unexecuted instantiation: AK::ErrorOr<AK::Utf8View, AK::Error> Crypto::ASN1::Decoder::with_type_check<AK::Utf8View, decltype(nullptr)>(AK::ErrorOr<decltype(nullptr), AK::Error>&&) Unexecuted instantiation: AK::ErrorOr<AK::Utf8View, AK::Error> Crypto::ASN1::Decoder::with_type_check<AK::Utf8View, AK::Vector<int, 0ul> >(AK::ErrorOr<AK::Vector<int, 0ul>, AK::Error>&&) Unexecuted instantiation: AK::ErrorOr<AK::Utf8View, AK::Error> Crypto::ASN1::Decoder::with_type_check<AK::Utf8View, Crypto::ASN1::BitStringView>(AK::ErrorOr<Crypto::ASN1::BitStringView, AK::Error>&&) Unexecuted instantiation: AK::ErrorOr<void*, AK::Error> Crypto::ASN1::Decoder::with_type_check<void*, bool>(AK::ErrorOr<bool, AK::Error>&&) Unexecuted instantiation: AK::ErrorOr<void*, AK::Error> Crypto::ASN1::Decoder::with_type_check<void*, Crypto::UnsignedBigInteger>(AK::ErrorOr<Crypto::UnsignedBigInteger, AK::Error>&&) Unexecuted instantiation: AK::ErrorOr<void*, AK::Error> Crypto::ASN1::Decoder::with_type_check<void*, AK::StringView>(AK::ErrorOr<AK::StringView, AK::Error>&&) AK::ErrorOr<void*, AK::Error> Crypto::ASN1::Decoder::with_type_check<void*, decltype(nullptr)>(AK::ErrorOr<decltype(nullptr), AK::Error>&&) Line | Count | Source | 184 | 2.10k | { | 185 | 2.10k | if (value_or_error.is_error()) | 186 | 7 | return value_or_error.release_error(); | 187 | | | 188 | | if constexpr (IsSame<ValueType, bool> && !IsSame<DecodedType, bool>) { | 189 | | return Error::from_string_literal("ASN1::Decoder: Trying to decode a boolean from a non-boolean type"); | 190 | 2.09k | } else { | 191 | 2.09k | auto&& value = value_or_error.value(); | 192 | | if constexpr (requires { ValueType { value }; }) | 193 | 2.09k | return ValueType { value }; | 194 | 2.09k | } | 195 | | | 196 | 0 | return Error::from_string_literal("ASN1::Decoder: Trying to decode a value from an incompatible type"); | 197 | 2.10k | } |
Unexecuted instantiation: AK::ErrorOr<void*, AK::Error> Crypto::ASN1::Decoder::with_type_check<void*, AK::Vector<int, 0ul> >(AK::ErrorOr<AK::Vector<int, 0ul>, AK::Error>&&) Unexecuted instantiation: AK::ErrorOr<void*, AK::Error> Crypto::ASN1::Decoder::with_type_check<void*, Crypto::ASN1::BitStringView>(AK::ErrorOr<Crypto::ASN1::BitStringView, AK::Error>&&) Unexecuted instantiation: AK::ErrorOr<Crypto::ASN1::BitStringView, AK::Error> Crypto::ASN1::Decoder::with_type_check<Crypto::ASN1::BitStringView, bool>(AK::ErrorOr<bool, AK::Error>&&) Unexecuted instantiation: AK::ErrorOr<Crypto::ASN1::BitStringView, AK::Error> Crypto::ASN1::Decoder::with_type_check<Crypto::ASN1::BitStringView, Crypto::UnsignedBigInteger>(AK::ErrorOr<Crypto::UnsignedBigInteger, AK::Error>&&) Unexecuted instantiation: AK::ErrorOr<Crypto::ASN1::BitStringView, AK::Error> Crypto::ASN1::Decoder::with_type_check<Crypto::ASN1::BitStringView, AK::StringView>(AK::ErrorOr<AK::StringView, AK::Error>&&) Unexecuted instantiation: AK::ErrorOr<Crypto::ASN1::BitStringView, AK::Error> Crypto::ASN1::Decoder::with_type_check<Crypto::ASN1::BitStringView, decltype(nullptr)>(AK::ErrorOr<decltype(nullptr), AK::Error>&&) Unexecuted instantiation: AK::ErrorOr<Crypto::ASN1::BitStringView, AK::Error> Crypto::ASN1::Decoder::with_type_check<Crypto::ASN1::BitStringView, AK::Vector<int, 0ul> >(AK::ErrorOr<AK::Vector<int, 0ul>, AK::Error>&&) AK::ErrorOr<Crypto::ASN1::BitStringView, AK::Error> Crypto::ASN1::Decoder::with_type_check<Crypto::ASN1::BitStringView, Crypto::ASN1::BitStringView>(AK::ErrorOr<Crypto::ASN1::BitStringView, AK::Error>&&) Line | Count | Source | 184 | 1.34k | { | 185 | 1.34k | if (value_or_error.is_error()) | 186 | 13 | return value_or_error.release_error(); | 187 | | | 188 | | if constexpr (IsSame<ValueType, bool> && !IsSame<DecodedType, bool>) { | 189 | | return Error::from_string_literal("ASN1::Decoder: Trying to decode a boolean from a non-boolean type"); | 190 | 1.32k | } else { | 191 | 1.32k | auto&& value = value_or_error.value(); | 192 | | if constexpr (requires { ValueType { value }; }) | 193 | 1.32k | return ValueType { value }; | 194 | 1.32k | } | 195 | | | 196 | 0 | return Error::from_string_literal("ASN1::Decoder: Trying to decode a value from an incompatible type"); | 197 | 1.34k | } |
|
198 | | |
199 | | template<typename ValueType> |
200 | | ErrorOr<ValueType> read_value(Class klass, Kind kind, size_t length) |
201 | 70.9k | { |
202 | 70.9k | auto data = TRY(read_bytes(length)); |
203 | | |
204 | 0 | if constexpr (IsSame<ValueType, ReadonlyBytes>) { |
205 | 0 | return data; |
206 | 70.0k | } else { |
207 | 70.0k | if (klass != Class::Universal) |
208 | 192 | return with_type_check<ValueType>(data); |
209 | | |
210 | 69.8k | if (kind == Kind::Boolean) |
211 | 2.46k | return with_type_check<ValueType>(decode_boolean(data)); |
212 | | |
213 | 67.4k | if (kind == Kind::Integer) |
214 | 7.49k | return with_type_check<ValueType>(decode_arbitrary_sized_integer(data)); |
215 | | |
216 | 59.9k | if (kind == Kind::OctetString) |
217 | 4.92k | return with_type_check<ValueType>(decode_octet_string(data)); |
218 | | |
219 | 54.9k | if (kind == Kind::Null) |
220 | 2.21k | return with_type_check<ValueType>(decode_null(data)); |
221 | | |
222 | 52.7k | if (kind == Kind::ObjectIdentifier) |
223 | 16.3k | return with_type_check<ValueType>(decode_object_identifier(data)); |
224 | | |
225 | 36.4k | if (kind == Kind::PrintableString || kind == Kind::IA5String || kind == Kind::UTCTime) |
226 | 34.3k | return with_type_check<ValueType>(decode_printable_string(data)); |
227 | | |
228 | 2.11k | if (kind == Kind::Utf8String) |
229 | 78 | return with_type_check<ValueType>(StringView { data.data(), data.size() }); |
230 | | |
231 | 2.03k | if (kind == Kind::BitString) |
232 | 1.53k | return with_type_check<ValueType>(decode_bit_string(data)); |
233 | | |
234 | 502 | return with_type_check<ValueType>(data); |
235 | 2.03k | } |
236 | 70.0k | } AK::ErrorOr<AK::Vector<int, 0ul>, AK::Error> Crypto::ASN1::Decoder::read_value<AK::Vector<int, 0ul> >(Crypto::ASN1::Class, Crypto::ASN1::Kind, unsigned long) Line | Count | Source | 201 | 15.9k | { | 202 | 15.9k | auto data = TRY(read_bytes(length)); | 203 | | | 204 | | if constexpr (IsSame<ValueType, ReadonlyBytes>) { | 205 | | return data; | 206 | 15.9k | } else { | 207 | 15.9k | if (klass != Class::Universal) | 208 | 5 | return with_type_check<ValueType>(data); | 209 | | | 210 | 15.9k | if (kind == Kind::Boolean) | 211 | 10 | return with_type_check<ValueType>(decode_boolean(data)); | 212 | | | 213 | 15.9k | if (kind == Kind::Integer) | 214 | 28 | return with_type_check<ValueType>(decode_arbitrary_sized_integer(data)); | 215 | | | 216 | 15.9k | if (kind == Kind::OctetString) | 217 | 8 | return with_type_check<ValueType>(decode_octet_string(data)); | 218 | | | 219 | 15.8k | if (kind == Kind::Null) | 220 | 10 | return with_type_check<ValueType>(decode_null(data)); | 221 | | | 222 | 15.8k | if (kind == Kind::ObjectIdentifier) | 223 | 15.8k | return with_type_check<ValueType>(decode_object_identifier(data)); | 224 | | | 225 | 68 | if (kind == Kind::PrintableString || kind == Kind::IA5String || kind == Kind::UTCTime) | 226 | 20 | return with_type_check<ValueType>(decode_printable_string(data)); | 227 | | | 228 | 48 | if (kind == Kind::Utf8String) | 229 | 2 | return with_type_check<ValueType>(StringView { data.data(), data.size() }); | 230 | | | 231 | 46 | if (kind == Kind::BitString) | 232 | 9 | return with_type_check<ValueType>(decode_bit_string(data)); | 233 | | | 234 | 37 | return with_type_check<ValueType>(data); | 235 | 46 | } | 236 | 15.9k | } |
AK::ErrorOr<Crypto::UnsignedBigInteger, AK::Error> Crypto::ASN1::Decoder::read_value<Crypto::UnsignedBigInteger>(Crypto::ASN1::Class, Crypto::ASN1::Kind, unsigned long) Line | Count | Source | 201 | 12.2k | { | 202 | 12.2k | auto data = TRY(read_bytes(length)); | 203 | | | 204 | | if constexpr (IsSame<ValueType, ReadonlyBytes>) { | 205 | | return data; | 206 | 11.5k | } else { | 207 | 11.5k | if (klass != Class::Universal) | 208 | 93 | return with_type_check<ValueType>(data); | 209 | | | 210 | 11.4k | if (kind == Kind::Boolean) | 211 | 2.03k | return with_type_check<ValueType>(decode_boolean(data)); | 212 | | | 213 | 9.40k | if (kind == Kind::Integer) | 214 | 7.45k | return with_type_check<ValueType>(decode_arbitrary_sized_integer(data)); | 215 | | | 216 | 1.95k | if (kind == Kind::OctetString) | 217 | 43 | return with_type_check<ValueType>(decode_octet_string(data)); | 218 | | | 219 | 1.90k | if (kind == Kind::Null) | 220 | 90 | return with_type_check<ValueType>(decode_null(data)); | 221 | | | 222 | 1.81k | if (kind == Kind::ObjectIdentifier) | 223 | 526 | return with_type_check<ValueType>(decode_object_identifier(data)); | 224 | | | 225 | 1.29k | if (kind == Kind::PrintableString || kind == Kind::IA5String || kind == Kind::UTCTime) | 226 | 738 | return with_type_check<ValueType>(decode_printable_string(data)); | 227 | | | 228 | 554 | if (kind == Kind::Utf8String) | 229 | 45 | return with_type_check<ValueType>(StringView { data.data(), data.size() }); | 230 | | | 231 | 509 | if (kind == Kind::BitString) | 232 | 174 | return with_type_check<ValueType>(decode_bit_string(data)); | 233 | | | 234 | 335 | return with_type_check<ValueType>(data); | 235 | 509 | } | 236 | 11.5k | } |
AK::ErrorOr<AK::StringView, AK::Error> Crypto::ASN1::Decoder::read_value<AK::StringView>(Crypto::ASN1::Class, Crypto::ASN1::Kind, unsigned long) Line | Count | Source | 201 | 38.6k | { | 202 | 38.6k | auto data = TRY(read_bytes(length)); | 203 | | | 204 | | if constexpr (IsSame<ValueType, ReadonlyBytes>) { | 205 | | return data; | 206 | 38.6k | } else { | 207 | 38.6k | if (klass != Class::Universal) | 208 | 91 | return with_type_check<ValueType>(data); | 209 | | | 210 | 38.5k | if (kind == Kind::Boolean) | 211 | 4 | return with_type_check<ValueType>(decode_boolean(data)); | 212 | | | 213 | 38.5k | if (kind == Kind::Integer) | 214 | 6 | return with_type_check<ValueType>(decode_arbitrary_sized_integer(data)); | 215 | | | 216 | 38.5k | if (kind == Kind::OctetString) | 217 | 4.87k | return with_type_check<ValueType>(decode_octet_string(data)); | 218 | | | 219 | 33.6k | if (kind == Kind::Null) | 220 | 4 | return with_type_check<ValueType>(decode_null(data)); | 221 | | | 222 | 33.6k | if (kind == Kind::ObjectIdentifier) | 223 | 4 | return with_type_check<ValueType>(decode_object_identifier(data)); | 224 | | | 225 | 33.6k | if (kind == Kind::PrintableString || kind == Kind::IA5String || kind == Kind::UTCTime) | 226 | 33.5k | return with_type_check<ValueType>(decode_printable_string(data)); | 227 | | | 228 | 144 | if (kind == Kind::Utf8String) | 229 | 29 | return with_type_check<ValueType>(StringView { data.data(), data.size() }); | 230 | | | 231 | 115 | if (kind == Kind::BitString) | 232 | 4 | return with_type_check<ValueType>(decode_bit_string(data)); | 233 | | | 234 | 111 | return with_type_check<ValueType>(data); | 235 | 115 | } | 236 | 38.6k | } |
AK::ErrorOr<AK::BitmapView, AK::Error> Crypto::ASN1::Decoder::read_value<AK::BitmapView>(Crypto::ASN1::Class, Crypto::ASN1::Kind, unsigned long) Line | Count | Source | 201 | 139 | { | 202 | 139 | auto data = TRY(read_bytes(length)); | 203 | | | 204 | | if constexpr (IsSame<ValueType, ReadonlyBytes>) { | 205 | | return data; | 206 | 69 | } else { | 207 | 69 | if (klass != Class::Universal) | 208 | 3 | return with_type_check<ValueType>(data); | 209 | | | 210 | 66 | if (kind == Kind::Boolean) | 211 | 10 | return with_type_check<ValueType>(decode_boolean(data)); | 212 | | | 213 | 56 | if (kind == Kind::Integer) | 214 | 6 | return with_type_check<ValueType>(decode_arbitrary_sized_integer(data)); | 215 | | | 216 | 50 | if (kind == Kind::OctetString) | 217 | 2 | return with_type_check<ValueType>(decode_octet_string(data)); | 218 | | | 219 | 48 | if (kind == Kind::Null) | 220 | 4 | return with_type_check<ValueType>(decode_null(data)); | 221 | | | 222 | 44 | if (kind == Kind::ObjectIdentifier) | 223 | 7 | return with_type_check<ValueType>(decode_object_identifier(data)); | 224 | | | 225 | 37 | if (kind == Kind::PrintableString || kind == Kind::IA5String || kind == Kind::UTCTime) | 226 | 9 | return with_type_check<ValueType>(decode_printable_string(data)); | 227 | | | 228 | 28 | if (kind == Kind::Utf8String) | 229 | 2 | return with_type_check<ValueType>(StringView { data.data(), data.size() }); | 230 | | | 231 | 26 | if (kind == Kind::BitString) | 232 | 7 | return with_type_check<ValueType>(decode_bit_string(data)); | 233 | | | 234 | 19 | return with_type_check<ValueType>(data); | 235 | 26 | } | 236 | 69 | } |
Unexecuted instantiation: AK::ErrorOr<AK::Span<unsigned char const>, AK::Error> Crypto::ASN1::Decoder::read_value<AK::Span<unsigned char const> >(Crypto::ASN1::Class, Crypto::ASN1::Kind, unsigned long) AK::ErrorOr<bool, AK::Error> Crypto::ASN1::Decoder::read_value<bool>(Crypto::ASN1::Class, Crypto::ASN1::Kind, unsigned long) Line | Count | Source | 201 | 404 | { | 202 | 404 | auto data = TRY(read_bytes(length)); | 203 | | | 204 | | if constexpr (IsSame<ValueType, ReadonlyBytes>) { | 205 | | return data; | 206 | 403 | } else { | 207 | 403 | if (klass != Class::Universal) | 208 | 0 | return with_type_check<ValueType>(data); | 209 | | | 210 | 403 | if (kind == Kind::Boolean) | 211 | 403 | return with_type_check<ValueType>(decode_boolean(data)); | 212 | | | 213 | 0 | if (kind == Kind::Integer) | 214 | 0 | return with_type_check<ValueType>(decode_arbitrary_sized_integer(data)); | 215 | | | 216 | 0 | if (kind == Kind::OctetString) | 217 | 0 | return with_type_check<ValueType>(decode_octet_string(data)); | 218 | | | 219 | 0 | if (kind == Kind::Null) | 220 | 0 | return with_type_check<ValueType>(decode_null(data)); | 221 | | | 222 | 0 | if (kind == Kind::ObjectIdentifier) | 223 | 0 | return with_type_check<ValueType>(decode_object_identifier(data)); | 224 | | | 225 | 0 | if (kind == Kind::PrintableString || kind == Kind::IA5String || kind == Kind::UTCTime) | 226 | 0 | return with_type_check<ValueType>(decode_printable_string(data)); | 227 | | | 228 | 0 | if (kind == Kind::Utf8String) | 229 | 0 | return with_type_check<ValueType>(StringView { data.data(), data.size() }); | 230 | | | 231 | 0 | if (kind == Kind::BitString) | 232 | 0 | return with_type_check<ValueType>(decode_bit_string(data)); | 233 | | | 234 | 0 | return with_type_check<ValueType>(data); | 235 | 0 | } | 236 | 403 | } |
Unexecuted instantiation: AK::ErrorOr<decltype(nullptr), AK::Error> Crypto::ASN1::Decoder::read_value<decltype(nullptr)>(Crypto::ASN1::Class, Crypto::ASN1::Kind, unsigned long) Unexecuted instantiation: AK::ErrorOr<AK::Utf8View, AK::Error> Crypto::ASN1::Decoder::read_value<AK::Utf8View>(Crypto::ASN1::Class, Crypto::ASN1::Kind, unsigned long) AK::ErrorOr<void*, AK::Error> Crypto::ASN1::Decoder::read_value<void*>(Crypto::ASN1::Class, Crypto::ASN1::Kind, unsigned long) Line | Count | Source | 201 | 2.11k | { | 202 | 2.11k | auto data = TRY(read_bytes(length)); | 203 | | | 204 | | if constexpr (IsSame<ValueType, ReadonlyBytes>) { | 205 | | return data; | 206 | 2.10k | } else { | 207 | 2.10k | if (klass != Class::Universal) | 208 | 0 | return with_type_check<ValueType>(data); | 209 | | | 210 | 2.10k | if (kind == Kind::Boolean) | 211 | 0 | return with_type_check<ValueType>(decode_boolean(data)); | 212 | | | 213 | 2.10k | if (kind == Kind::Integer) | 214 | 0 | return with_type_check<ValueType>(decode_arbitrary_sized_integer(data)); | 215 | | | 216 | 2.10k | if (kind == Kind::OctetString) | 217 | 0 | return with_type_check<ValueType>(decode_octet_string(data)); | 218 | | | 219 | 2.10k | if (kind == Kind::Null) | 220 | 2.10k | return with_type_check<ValueType>(decode_null(data)); | 221 | | | 222 | 0 | if (kind == Kind::ObjectIdentifier) | 223 | 0 | return with_type_check<ValueType>(decode_object_identifier(data)); | 224 | | | 225 | 0 | if (kind == Kind::PrintableString || kind == Kind::IA5String || kind == Kind::UTCTime) | 226 | 0 | return with_type_check<ValueType>(decode_printable_string(data)); | 227 | | | 228 | 0 | if (kind == Kind::Utf8String) | 229 | 0 | return with_type_check<ValueType>(StringView { data.data(), data.size() }); | 230 | | | 231 | 0 | if (kind == Kind::BitString) | 232 | 0 | return with_type_check<ValueType>(decode_bit_string(data)); | 233 | | | 234 | 0 | return with_type_check<ValueType>(data); | 235 | 0 | } | 236 | 2.10k | } |
AK::ErrorOr<Crypto::ASN1::BitStringView, AK::Error> Crypto::ASN1::Decoder::read_value<Crypto::ASN1::BitStringView>(Crypto::ASN1::Class, Crypto::ASN1::Kind, unsigned long) Line | Count | Source | 201 | 1.34k | { | 202 | 1.34k | auto data = TRY(read_bytes(length)); | 203 | | | 204 | | if constexpr (IsSame<ValueType, ReadonlyBytes>) { | 205 | | return data; | 206 | 1.34k | } else { | 207 | 1.34k | if (klass != Class::Universal) | 208 | 0 | return with_type_check<ValueType>(data); | 209 | | | 210 | 1.34k | if (kind == Kind::Boolean) | 211 | 0 | return with_type_check<ValueType>(decode_boolean(data)); | 212 | | | 213 | 1.34k | if (kind == Kind::Integer) | 214 | 0 | return with_type_check<ValueType>(decode_arbitrary_sized_integer(data)); | 215 | | | 216 | 1.34k | if (kind == Kind::OctetString) | 217 | 0 | return with_type_check<ValueType>(decode_octet_string(data)); | 218 | | | 219 | 1.34k | if (kind == Kind::Null) | 220 | 0 | return with_type_check<ValueType>(decode_null(data)); | 221 | | | 222 | 1.34k | if (kind == Kind::ObjectIdentifier) | 223 | 0 | return with_type_check<ValueType>(decode_object_identifier(data)); | 224 | | | 225 | 1.34k | if (kind == Kind::PrintableString || kind == Kind::IA5String || kind == Kind::UTCTime) | 226 | 0 | return with_type_check<ValueType>(decode_printable_string(data)); | 227 | | | 228 | 1.34k | if (kind == Kind::Utf8String) | 229 | 0 | return with_type_check<ValueType>(StringView { data.data(), data.size() }); | 230 | | | 231 | 1.34k | if (kind == Kind::BitString) | 232 | 1.34k | return with_type_check<ValueType>(decode_bit_string(data)); | 233 | | | 234 | 0 | return with_type_check<ValueType>(data); | 235 | 1.34k | } | 236 | 1.34k | } |
|
237 | | |
238 | | ErrorOr<Tag> read_tag(); |
239 | | ErrorOr<size_t> read_length(); |
240 | | ErrorOr<u8> read_byte(); |
241 | | ErrorOr<ReadonlyBytes> read_bytes(size_t length); |
242 | | |
243 | | static ErrorOr<bool> decode_boolean(ReadonlyBytes); |
244 | | static ErrorOr<UnsignedBigInteger> decode_arbitrary_sized_integer(ReadonlyBytes); |
245 | | static ErrorOr<StringView> decode_octet_string(ReadonlyBytes); |
246 | | static ErrorOr<nullptr_t> decode_null(ReadonlyBytes); |
247 | | static ErrorOr<Vector<int>> decode_object_identifier(ReadonlyBytes); |
248 | | static ErrorOr<StringView> decode_printable_string(ReadonlyBytes); |
249 | | static ErrorOr<BitStringView> decode_bit_string(ReadonlyBytes); |
250 | | |
251 | | Vector<ReadonlyBytes> m_stack; |
252 | | Optional<Tag> m_current_tag; |
253 | | }; |
254 | | |
255 | | ErrorOr<void> pretty_print(Decoder&, Stream&, int indent = 0); |
256 | | |
257 | | class Encoder { |
258 | | public: |
259 | | Encoder() |
260 | 0 | { |
261 | 0 | m_buffer_stack.empend(); |
262 | 0 | } |
263 | | |
264 | 0 | ReadonlyBytes active_bytes() const { return m_buffer_stack.last().bytes(); } |
265 | | ByteBuffer finish() |
266 | 0 | { |
267 | 0 | VERIFY(m_buffer_stack.size() == 1); |
268 | 0 | return m_buffer_stack.take_last(); |
269 | 0 | } Unexecuted instantiation: Crypto::ASN1::Encoder::finish() Unexecuted instantiation: Crypto::ASN1::Encoder::finish() |
270 | | |
271 | | template<typename ValueType> |
272 | | ErrorOr<void> write(ValueType const& value, Optional<Class> class_override = {}, Optional<Kind> kind_override = {}) |
273 | 0 | { |
274 | | if constexpr (IsSame<ValueType, bool>) { |
275 | | return write_boolean(value, class_override, kind_override); |
276 | 0 | } else if constexpr (IsSame<ValueType, UnsignedBigInteger> || (IsIntegral<ValueType> && IsUnsigned<ValueType>)) { |
277 | 0 | return write_arbitrary_sized_integer(value, class_override, kind_override); |
278 | | } else if constexpr (IsOneOf<ValueType, StringView, String, ByteString>) { |
279 | | return write_printable_string(value, class_override, kind_override); |
280 | 0 | } else if constexpr (IsOneOf<ValueType, ReadonlyBytes, ByteBuffer>) { |
281 | 0 | return write_octet_string(value, class_override, kind_override); |
282 | 0 | } else if constexpr (IsSame<ValueType, nullptr_t>) { |
283 | 0 | return write_null(class_override, kind_override); |
284 | 0 | } else if constexpr (IsOneOf<ValueType, Vector<int>, Span<int const>, Span<int>>) { |
285 | 0 | return write_object_identifier(value, class_override, kind_override); |
286 | 0 | } else if constexpr (IsSame<ValueType, BitStringView>) { |
287 | 0 | return write_bit_string(value, class_override, kind_override); |
288 | | } else { |
289 | | dbgln("Unsupported type: {}", __PRETTY_FUNCTION__); |
290 | | return Error::from_string_literal("ASN1::Encoder: Trying to encode a value of an unsupported type"); |
291 | | } |
292 | 0 | } Unexecuted instantiation: AK::ErrorOr<void, AK::Error> Crypto::ASN1::Encoder::write<AK::Span<int> >(AK::Span<int> const&, AK::Optional<Crypto::ASN1::Class>, AK::Optional<Crypto::ASN1::Kind>) Unexecuted instantiation: AK::ErrorOr<void, AK::Error> Crypto::ASN1::Encoder::write<decltype(nullptr)>(decltype(nullptr) const&, AK::Optional<Crypto::ASN1::Class>, AK::Optional<Crypto::ASN1::Kind>) Unexecuted instantiation: AK::ErrorOr<void, AK::Error> Crypto::ASN1::Encoder::write<Crypto::UnsignedBigInteger>(Crypto::UnsignedBigInteger const&, AK::Optional<Crypto::ASN1::Class>, AK::Optional<Crypto::ASN1::Kind>) Unexecuted instantiation: AK::ErrorOr<void, AK::Error> Crypto::ASN1::Encoder::write<Crypto::ASN1::BitStringView>(Crypto::ASN1::BitStringView const&, AK::Optional<Crypto::ASN1::Class>, AK::Optional<Crypto::ASN1::Kind>) Unexecuted instantiation: AK::ErrorOr<void, AK::Error> Crypto::ASN1::Encoder::write<unsigned int>(unsigned int const&, AK::Optional<Crypto::ASN1::Class>, AK::Optional<Crypto::ASN1::Kind>) Unexecuted instantiation: AK::ErrorOr<void, AK::Error> Crypto::ASN1::Encoder::write<AK::Detail::ByteBuffer<32ul> >(AK::Detail::ByteBuffer<32ul> const&, AK::Optional<Crypto::ASN1::Class>, AK::Optional<Crypto::ASN1::Kind>) |
293 | | |
294 | | template<typename Fn> |
295 | | ErrorOr<void> write_constructed(Class class_, Kind kind, Fn&& fn) |
296 | 0 | { |
297 | 0 | return write_constructed(bit_cast<u8>(class_), bit_cast<u8>(kind), forward<Fn>(fn)); |
298 | 0 | } Unexecuted instantiation: _ZN6Crypto4ASN17Encoder17write_constructedIZNS_2PK31wrap_in_subject_public_key_infoINS3_12RSAPublicKeyINS_18UnsignedBigIntegerEEEEEN2AK7ErrorOrINS8_6Detail10ByteBufferILm32EEENS8_5ErrorEEET_NS8_4SpanIiEEQrQSF__XcldtfL0p_13export_as_derEEEUlvE_EENS9_IvSD_EENS0_5ClassENS0_4KindEOSF_ Unexecuted instantiation: _ZN6Crypto4ASN17Encoder17write_constructedIZZNS_2PK31wrap_in_subject_public_key_infoINS3_12RSAPublicKeyINS_18UnsignedBigIntegerEEEEEN2AK7ErrorOrINS8_6Detail10ByteBufferILm32EEENS8_5ErrorEEET_NS8_4SpanIiEEQrQSF__XcldtfL1p_13export_as_derEEENKUlvE_clEvEUlvE_EENS9_IvSD_EENS0_5ClassENS0_4KindEOSF_ Unexecuted instantiation: AK::ErrorOr<void, Crypto::PK::RSAPublicKey<Crypto::UnsignedBigInteger>::export_as_der() const::{lambda()#1}::Error> Crypto::ASN1::Encoder::write_constructed<Crypto::PK::RSAPublicKey<Crypto::UnsignedBigInteger>::export_as_der() const::{lambda()#1}>(Crypto::ASN1::Class, Crypto::ASN1::Kind, Crypto::PK::RSAPublicKey<Crypto::UnsignedBigInteger>::export_as_der() const::{lambda()#1}&&) Unexecuted instantiation: _ZN6Crypto4ASN17Encoder17write_constructedIZNS_2PK24wrap_in_private_key_infoINS3_13RSAPrivateKeyINS_18UnsignedBigIntegerEEEEEN2AK7ErrorOrINS8_6Detail10ByteBufferILm32EEENS8_5ErrorEEET_NS8_4SpanIiEEQrQSF__XcldtfL0p_13export_as_derEEEUlvE_EENS9_IvSD_EENS0_5ClassENS0_4KindEOSF_ Unexecuted instantiation: _ZN6Crypto4ASN17Encoder17write_constructedIZZNS_2PK24wrap_in_private_key_infoINS3_13RSAPrivateKeyINS_18UnsignedBigIntegerEEEEEN2AK7ErrorOrINS8_6Detail10ByteBufferILm32EEENS8_5ErrorEEET_NS8_4SpanIiEEQrQSF__XcldtfL1p_13export_as_derEEENKUlvE_clEvEUlvE_EENS9_IvSD_EENS0_5ClassENS0_4KindEOSF_ Unexecuted instantiation: AK::ErrorOr<void, Crypto::PK::RSAPrivateKey<Crypto::UnsignedBigInteger>::export_as_der() const::{lambda()#1}::Error> Crypto::ASN1::Encoder::write_constructed<Crypto::PK::RSAPrivateKey<Crypto::UnsignedBigInteger>::export_as_der() const::{lambda()#1}>(Crypto::ASN1::Class, Crypto::ASN1::Kind, Crypto::PK::RSAPrivateKey<Crypto::UnsignedBigInteger>::export_as_der() const::{lambda()#1}&&) Unexecuted instantiation: CryptoAlgorithms.cpp:AK::ErrorOr<void, AK::Error> Crypto::ASN1::Encoder::write_constructed<Web::Crypto::ECDSA::verify(Web::Crypto::AlgorithmParams const&, JS::NonnullGCPtr<Web::Crypto::CryptoKey>, AK::Detail::ByteBuffer<32ul> const&, AK::Detail::ByteBuffer<32ul> const&)::$_2>(Crypto::ASN1::Class, Crypto::ASN1::Kind, Web::Crypto::ECDSA::verify(Web::Crypto::AlgorithmParams const&, JS::NonnullGCPtr<Web::Crypto::CryptoKey>, AK::Detail::ByteBuffer<32ul> const&, AK::Detail::ByteBuffer<32ul> const&)::$_2&&) |
299 | | |
300 | | template<typename Fn> |
301 | | ErrorOr<void> write_constructed(u8 class_, u8 kind, Fn&& fn) |
302 | 0 | { |
303 | 0 | m_buffer_stack.empend(); |
304 | 0 | using ResultType = decltype(fn()); |
305 | 0 | if constexpr (IsSpecializationOf<ResultType, ErrorOr>) { |
306 | 0 | TRY(fn()); |
307 | 0 | } else { |
308 | 0 | fn(); |
309 | 0 | } |
310 | 0 | auto buffer = m_buffer_stack.take_last(); |
311 | |
|
312 | 0 | TRY(write_tag(bit_cast<Class>(class_), Type::Constructed, bit_cast<Kind>(kind))); |
313 | 0 | TRY(write_length(buffer.size())); |
314 | 0 | TRY(write_bytes(buffer.bytes())); |
315 | | |
316 | 0 | return {}; |
317 | 0 | } Unexecuted instantiation: _ZN6Crypto4ASN17Encoder17write_constructedIZNS_2PK31wrap_in_subject_public_key_infoINS3_12RSAPublicKeyINS_18UnsignedBigIntegerEEEEEN2AK7ErrorOrINS8_6Detail10ByteBufferILm32EEENS8_5ErrorEEET_NS8_4SpanIiEEQrQSF__XcldtfL0p_13export_as_derEEEUlvE_EENS9_IvSD_EEhhOSF_ Unexecuted instantiation: _ZN6Crypto4ASN17Encoder17write_constructedIZZNS_2PK31wrap_in_subject_public_key_infoINS3_12RSAPublicKeyINS_18UnsignedBigIntegerEEEEEN2AK7ErrorOrINS8_6Detail10ByteBufferILm32EEENS8_5ErrorEEET_NS8_4SpanIiEEQrQSF__XcldtfL1p_13export_as_derEEENKUlvE_clEvEUlvE_EENS9_IvSD_EEhhOSF_ Unexecuted instantiation: AK::ErrorOr<void, Crypto::PK::RSAPublicKey<Crypto::UnsignedBigInteger>::export_as_der() const::{lambda()#1}::Error> Crypto::ASN1::Encoder::write_constructed<Crypto::PK::RSAPublicKey<Crypto::UnsignedBigInteger>::export_as_der() const::{lambda()#1}>(unsigned char, unsigned char, Crypto::PK::RSAPublicKey<Crypto::UnsignedBigInteger>::export_as_der() const::{lambda()#1}&&) Unexecuted instantiation: _ZN6Crypto4ASN17Encoder17write_constructedIZNS_2PK24wrap_in_private_key_infoINS3_13RSAPrivateKeyINS_18UnsignedBigIntegerEEEEEN2AK7ErrorOrINS8_6Detail10ByteBufferILm32EEENS8_5ErrorEEET_NS8_4SpanIiEEQrQSF__XcldtfL0p_13export_as_derEEEUlvE_EENS9_IvSD_EEhhOSF_ Unexecuted instantiation: _ZN6Crypto4ASN17Encoder17write_constructedIZZNS_2PK24wrap_in_private_key_infoINS3_13RSAPrivateKeyINS_18UnsignedBigIntegerEEEEEN2AK7ErrorOrINS8_6Detail10ByteBufferILm32EEENS8_5ErrorEEET_NS8_4SpanIiEEQrQSF__XcldtfL1p_13export_as_derEEENKUlvE_clEvEUlvE_EENS9_IvSD_EEhhOSF_ Unexecuted instantiation: AK::ErrorOr<void, Crypto::PK::RSAPrivateKey<Crypto::UnsignedBigInteger>::export_as_der() const::{lambda()#1}::Error> Crypto::ASN1::Encoder::write_constructed<Crypto::PK::RSAPrivateKey<Crypto::UnsignedBigInteger>::export_as_der() const::{lambda()#1}>(unsigned char, unsigned char, Crypto::PK::RSAPrivateKey<Crypto::UnsignedBigInteger>::export_as_der() const::{lambda()#1}&&) Unexecuted instantiation: CryptoAlgorithms.cpp:AK::ErrorOr<void, AK::Error> Crypto::ASN1::Encoder::write_constructed<Web::Crypto::ECDSA::verify(Web::Crypto::AlgorithmParams const&, JS::NonnullGCPtr<Web::Crypto::CryptoKey>, AK::Detail::ByteBuffer<32ul> const&, AK::Detail::ByteBuffer<32ul> const&)::$_2>(unsigned char, unsigned char, Web::Crypto::ECDSA::verify(Web::Crypto::AlgorithmParams const&, JS::NonnullGCPtr<Web::Crypto::CryptoKey>, AK::Detail::ByteBuffer<32ul> const&, AK::Detail::ByteBuffer<32ul> const&)::$_2&&) |
318 | | |
319 | | private: |
320 | | ErrorOr<void> write_tag(Class, Type, Kind); |
321 | | ErrorOr<void> write_length(size_t); |
322 | | ErrorOr<void> write_bytes(ReadonlyBytes); |
323 | | ErrorOr<void> write_byte(u8); |
324 | | |
325 | | ErrorOr<void> write_boolean(bool, Optional<Class>, Optional<Kind>); |
326 | | ErrorOr<void> write_arbitrary_sized_integer(UnsignedBigInteger const&, Optional<Class>, Optional<Kind>); |
327 | | ErrorOr<void> write_printable_string(StringView, Optional<Class>, Optional<Kind>); |
328 | | ErrorOr<void> write_octet_string(ReadonlyBytes, Optional<Class>, Optional<Kind>); |
329 | | ErrorOr<void> write_null(Optional<Class>, Optional<Kind>); |
330 | | ErrorOr<void> write_object_identifier(Span<int const>, Optional<Class>, Optional<Kind>); |
331 | | ErrorOr<void> write_bit_string(BitStringView, Optional<Class>, Optional<Kind>); |
332 | | |
333 | | Vector<ByteBuffer> m_buffer_stack; |
334 | | }; |
335 | | |
336 | | } |