Coverage Report

Created: 2026-02-14 08:01

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/serenity/Userland/Libraries/LibCrypto/ASN1/DER.h
Line
Count
Source
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.70k
        : m_data(data)
21
1.70k
        , m_unused_bits(unused_bits)
22
1.70k
    {
23
1.70k
    }
24
25
    ErrorOr<ReadonlyBytes> raw_bytes() const
26
2.09k
    {
27
2.09k
        if (m_unused_bits != 0)
28
26
            return Error::from_string_literal("ASN1::Decoder: BitStringView contains unexpected partial bytes");
29
2.07k
        return m_data;
30
2.09k
    }
31
32
    bool get(size_t index) const
33
327
    {
34
327
        if (index >= 8 * m_data.size() - m_unused_bits)
35
246
            return false;
36
81
        return 0 != (m_data[index / 8] & (1u << (7 - (index % 8))));
37
327
    }
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.3k
    {
63
10.3k
        m_stack.append(data);
64
10.3k
    }
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
481
    {
79
481
        if (m_stack.is_empty())
80
0
            return Error::from_string_literal("Nothing on stack to rewrite");
81
82
481
        if (eof())
83
7
            return Error::from_string_literal("Stream is empty");
84
85
474
        if (m_current_tag.has_value()) {
86
474
            m_current_tag->kind = kind;
87
474
            return {};
88
474
        }
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
1
            return Error::from_string_literal("ASN1::Decoder: Trying to drop using a decoder that is EOF");
103
104
21
        auto previous_position = m_stack;
105
106
21
        auto tag_or_error = peek();
107
21
        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
21
        auto length_or_error = read_length();
113
21
        if (length_or_error.is_error()) {
114
2
            m_stack = move(previous_position);
115
2
            return length_or_error.release_error();
116
2
        }
117
118
19
        auto length = length_or_error.value();
119
120
19
        auto bytes_result = read_bytes(length);
121
19
        if (bytes_result.is_error()) {
122
5
            m_stack = move(previous_position);
123
5
            return bytes_result.release_error();
124
5
        }
125
126
14
        m_current_tag.clear();
127
14
        return {};
128
19
    }
129
130
    template<typename ValueType>
131
    ErrorOr<ValueType> read(Optional<Class> class_override = {}, Optional<Kind> kind_override = {})
132
79.2k
    {
133
79.2k
        if (m_stack.is_empty())
134
0
            return Error::from_string_literal("ASN1::Decoder: Trying to read using an empty stack");
135
136
79.2k
        if (eof())
137
888
            return Error::from_string_literal("ASN1::Decoder: Trying to read using a decoder that is EOF");
138
139
78.3k
        auto previous_position = m_stack;
140
141
78.3k
        auto tag_or_error = peek();
142
78.3k
        if (tag_or_error.is_error()) {
143
122
            m_stack = move(previous_position);
144
122
            return tag_or_error.release_error();
145
122
        }
146
147
78.1k
        auto length_or_error = read_length();
148
78.1k
        if (length_or_error.is_error()) {
149
434
            m_stack = move(previous_position);
150
434
            return length_or_error.release_error();
151
434
        }
152
153
77.7k
        auto tag = tag_or_error.value();
154
77.7k
        auto length = length_or_error.value();
155
156
77.7k
        auto value_or_error = read_value<ValueType>(class_override.value_or(tag.class_), kind_override.value_or(tag.kind), length);
157
77.7k
        if (value_or_error.is_error()) {
158
3.94k
            m_stack = move(previous_position);
159
3.94k
            return value_or_error.release_error();
160
3.94k
        }
161
162
73.8k
        m_current_tag.clear();
163
164
73.8k
        return value_or_error.release_value();
165
77.7k
    }
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.9k
    {
133
16.9k
        if (m_stack.is_empty())
134
0
            return Error::from_string_literal("ASN1::Decoder: Trying to read using an empty stack");
135
136
16.9k
        if (eof())
137
109
            return Error::from_string_literal("ASN1::Decoder: Trying to read using a decoder that is EOF");
138
139
16.8k
        auto previous_position = m_stack;
140
141
16.8k
        auto tag_or_error = peek();
142
16.8k
        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.8k
        auto length_or_error = read_length();
148
16.8k
        if (length_or_error.is_error()) {
149
63
            m_stack = move(previous_position);
150
63
            return length_or_error.release_error();
151
63
        }
152
153
16.8k
        auto tag = tag_or_error.value();
154
16.8k
        auto length = length_or_error.value();
155
156
16.8k
        auto value_or_error = read_value<ValueType>(class_override.value_or(tag.class_), kind_override.value_or(tag.kind), length);
157
16.8k
        if (value_or_error.is_error()) {
158
196
            m_stack = move(previous_position);
159
196
            return value_or_error.release_error();
160
196
        }
161
162
16.6k
        m_current_tag.clear();
163
164
16.6k
        return value_or_error.release_value();
165
16.8k
    }
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
14.9k
    {
133
14.9k
        if (m_stack.is_empty())
134
0
            return Error::from_string_literal("ASN1::Decoder: Trying to read using an empty stack");
135
136
14.9k
        if (eof())
137
764
            return Error::from_string_literal("ASN1::Decoder: Trying to read using a decoder that is EOF");
138
139
14.1k
        auto previous_position = m_stack;
140
141
14.1k
        auto tag_or_error = peek();
142
14.1k
        if (tag_or_error.is_error()) {
143
107
            m_stack = move(previous_position);
144
107
            return tag_or_error.release_error();
145
107
        }
146
147
14.0k
        auto length_or_error = read_length();
148
14.0k
        if (length_or_error.is_error()) {
149
354
            m_stack = move(previous_position);
150
354
            return length_or_error.release_error();
151
354
        }
152
153
13.7k
        auto tag = tag_or_error.value();
154
13.7k
        auto length = length_or_error.value();
155
156
13.7k
        auto value_or_error = read_value<ValueType>(class_override.value_or(tag.class_), kind_override.value_or(tag.kind), length);
157
13.7k
        if (value_or_error.is_error()) {
158
3.46k
            m_stack = move(previous_position);
159
3.46k
            return value_or_error.release_error();
160
3.46k
        }
161
162
10.2k
        m_current_tag.clear();
163
164
10.2k
        return value_or_error.release_value();
165
13.7k
    }
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
42.8k
    {
133
42.8k
        if (m_stack.is_empty())
134
0
            return Error::from_string_literal("ASN1::Decoder: Trying to read using an empty stack");
135
136
42.8k
        if (eof())
137
7
            return Error::from_string_literal("ASN1::Decoder: Trying to read using a decoder that is EOF");
138
139
42.8k
        auto previous_position = m_stack;
140
141
42.8k
        auto tag_or_error = peek();
142
42.8k
        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
42.8k
        auto length_or_error = read_length();
148
42.8k
        if (length_or_error.is_error()) {
149
8
            m_stack = move(previous_position);
150
8
            return length_or_error.release_error();
151
8
        }
152
153
42.8k
        auto tag = tag_or_error.value();
154
42.8k
        auto length = length_or_error.value();
155
156
42.8k
        auto value_or_error = read_value<ValueType>(class_override.value_or(tag.class_), kind_override.value_or(tag.kind), length);
157
42.8k
        if (value_or_error.is_error()) {
158
100
            m_stack = move(previous_position);
159
100
            return value_or_error.release_error();
160
100
        }
161
162
42.7k
        m_current_tag.clear();
163
164
42.7k
        return value_or_error.release_value();
165
42.8k
    }
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
154
    {
133
154
        if (m_stack.is_empty())
134
0
            return Error::from_string_literal("ASN1::Decoder: Trying to read using an empty stack");
135
136
154
        if (eof())
137
2
            return Error::from_string_literal("ASN1::Decoder: Trying to read using a decoder that is EOF");
138
139
152
        auto previous_position = m_stack;
140
141
152
        auto tag_or_error = peek();
142
152
        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
150
        auto length_or_error = read_length();
148
150
        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
148
        auto tag = tag_or_error.value();
154
148
        auto length = length_or_error.value();
155
156
148
        auto value_or_error = read_value<ValueType>(class_override.value_or(tag.class_), kind_override.value_or(tag.kind), length);
157
148
        if (value_or_error.is_error()) {
158
148
            m_stack = move(previous_position);
159
148
            return value_or_error.release_error();
160
148
        }
161
162
0
        m_current_tag.clear();
163
164
0
        return value_or_error.release_value();
165
148
    }
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
435
    {
133
435
        if (m_stack.is_empty())
134
0
            return Error::from_string_literal("ASN1::Decoder: Trying to read using an empty stack");
135
136
435
        if (eof())
137
1
            return Error::from_string_literal("ASN1::Decoder: Trying to read using a decoder that is EOF");
138
139
434
        auto previous_position = m_stack;
140
141
434
        auto tag_or_error = peek();
142
434
        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
434
        auto length_or_error = read_length();
148
434
        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
432
        auto tag = tag_or_error.value();
154
432
        auto length = length_or_error.value();
155
156
432
        auto value_or_error = read_value<ValueType>(class_override.value_or(tag.class_), kind_override.value_or(tag.kind), length);
157
432
        if (value_or_error.is_error()) {
158
3
            m_stack = move(previous_position);
159
3
            return value_or_error.release_error();
160
3
        }
161
162
429
        m_current_tag.clear();
163
164
429
        return value_or_error.release_value();
165
432
    }
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.26k
    {
133
2.26k
        if (m_stack.is_empty())
134
0
            return Error::from_string_literal("ASN1::Decoder: Trying to read using an empty stack");
135
136
2.26k
        if (eof())
137
1
            return Error::from_string_literal("ASN1::Decoder: Trying to read using a decoder that is EOF");
138
139
2.26k
        auto previous_position = m_stack;
140
141
2.26k
        auto tag_or_error = peek();
142
2.26k
        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.26k
        auto length_or_error = read_length();
148
2.26k
        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.25k
        auto tag = tag_or_error.value();
154
2.25k
        auto length = length_or_error.value();
155
156
2.25k
        auto value_or_error = read_value<ValueType>(class_override.value_or(tag.class_), kind_override.value_or(tag.kind), length);
157
2.25k
        if (value_or_error.is_error()) {
158
11
            m_stack = move(previous_position);
159
11
            return value_or_error.release_error();
160
11
        }
161
162
2.24k
        m_current_tag.clear();
163
164
2.24k
        return value_or_error.release_value();
165
2.25k
    }
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.60k
    {
133
1.60k
        if (m_stack.is_empty())
134
0
            return Error::from_string_literal("ASN1::Decoder: Trying to read using an empty stack");
135
136
1.60k
        if (eof())
137
4
            return Error::from_string_literal("ASN1::Decoder: Trying to read using a decoder that is EOF");
138
139
1.60k
        auto previous_position = m_stack;
140
141
1.60k
        auto tag_or_error = peek();
142
1.60k
        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.60k
        auto length_or_error = read_length();
148
1.60k
        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.59k
        auto tag = tag_or_error.value();
154
1.59k
        auto length = length_or_error.value();
155
156
1.59k
        auto value_or_error = read_value<ValueType>(class_override.value_or(tag.class_), kind_override.value_or(tag.kind), length);
157
1.59k
        if (value_or_error.is_error()) {
158
26
            m_stack = move(previous_position);
159
26
            return value_or_error.release_error();
160
26
        }
161
162
1.57k
        m_current_tag.clear();
163
164
1.57k
        return value_or_error.release_value();
165
1.59k
    }
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
863
    {
176
        if constexpr (requires { ValueType { value }; })
177
246
            return ValueType { value };
178
179
0
        return Error::from_string_literal("ASN1::Decoder: Trying to decode a value from an incompatible type");
180
863
    }
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
38
    {
176
        if constexpr (requires { ValueType { value }; })
177
            return ValueType { value };
178
179
38
        return Error::from_string_literal("ASN1::Decoder: Trying to decode a value from an incompatible type");
180
38
    }
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
10
    {
176
        if constexpr (requires { ValueType { value }; })
177
            return ValueType { value };
178
179
10
        return Error::from_string_literal("ASN1::Decoder: Trying to decode a value from an incompatible type");
180
10
    }
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
496
    {
176
        if constexpr (requires { ValueType { value }; })
177
            return ValueType { value };
178
179
496
        return Error::from_string_literal("ASN1::Decoder: Trying to decode a value from an incompatible type");
180
496
    }
AK::ErrorOr<Crypto::UnsignedBigInteger, AK::Error> Crypto::ASN1::Decoder::with_type_check<Crypto::UnsignedBigInteger, AK::StringView>(AK::StringView&&)
Line
Count
Source
175
40
    {
176
        if constexpr (requires { ValueType { value }; })
177
            return ValueType { value };
178
179
40
        return Error::from_string_literal("ASN1::Decoder: Trying to decode a value from an incompatible type");
180
40
    }
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
216
    {
176
        if constexpr (requires { ValueType { value }; })
177
216
            return ValueType { value };
178
179
0
        return Error::from_string_literal("ASN1::Decoder: Trying to decode a value from an incompatible type");
180
216
    }
AK::ErrorOr<AK::StringView, AK::Error> Crypto::ASN1::Decoder::with_type_check<AK::StringView, AK::StringView>(AK::StringView&&)
Line
Count
Source
175
30
    {
176
        if constexpr (requires { ValueType { value }; })
177
30
            return ValueType { value };
178
179
0
        return Error::from_string_literal("ASN1::Decoder: Trying to decode a value from an incompatible type");
180
30
    }
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
31
    {
176
        if constexpr (requires { ValueType { value }; })
177
            return ValueType { value };
178
179
31
        return Error::from_string_literal("ASN1::Decoder: Trying to decode a value from an incompatible type");
180
31
    }
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
75.9k
    {
185
75.9k
        if (value_or_error.is_error())
186
1.47k
            return value_or_error.release_error();
187
188
74.4k
        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
74.4k
        } else {
191
74.4k
            auto&& value = value_or_error.value();
192
            if constexpr (requires { ValueType { value }; })
193
73.5k
                return ValueType { value };
194
74.4k
        }
195
196
0
        return Error::from_string_literal("ASN1::Decoder: Trying to decode a value from an incompatible type");
197
75.9k
    }
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
9
    {
185
9
        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
        } else {
191
2
            auto&& value = value_or_error.value();
192
            if constexpr (requires { ValueType { value }; })
193
2
                return ValueType { value };
194
2
        }
195
196
0
        return Error::from_string_literal("ASN1::Decoder: Trying to decode a value from an incompatible type");
197
9
    }
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
25
    {
185
25
        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
19
        } else {
191
19
            auto&& value = value_or_error.value();
192
            if constexpr (requires { ValueType { value }; })
193
                return ValueType { value };
194
19
        }
195
196
19
        return Error::from_string_literal("ASN1::Decoder: Trying to decode a value from an incompatible type");
197
25
    }
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
19
    {
185
19
        if (value_or_error.is_error())
186
8
            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
11
        } else {
191
11
            auto&& value = value_or_error.value();
192
            if constexpr (requires { ValueType { value }; })
193
                return ValueType { value };
194
11
        }
195
196
11
        return Error::from_string_literal("ASN1::Decoder: Trying to decode a value from an incompatible type");
197
19
    }
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
12
    {
185
12
        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
7
        } else {
191
7
            auto&& value = value_or_error.value();
192
            if constexpr (requires { ValueType { value }; })
193
                return ValueType { value };
194
7
        }
195
196
7
        return Error::from_string_literal("ASN1::Decoder: Trying to decode a value from an incompatible type");
197
12
    }
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
16.6k
    {
185
16.6k
        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
16.6k
        } else {
191
16.6k
            auto&& value = value_or_error.value();
192
            if constexpr (requires { ValueType { value }; })
193
16.6k
                return ValueType { value };
194
16.6k
        }
195
196
0
        return Error::from_string_literal("ASN1::Decoder: Trying to decode a value from an incompatible type");
197
16.6k
    }
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
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<Crypto::UnsignedBigInteger, AK::Error> Crypto::ASN1::Decoder::with_type_check<Crypto::UnsignedBigInteger, bool>(AK::ErrorOr<bool, AK::Error>&&)
Line
Count
Source
184
2.41k
    {
185
2.41k
        if (value_or_error.is_error())
186
132
            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.28k
        } else {
191
2.28k
            auto&& value = value_or_error.value();
192
            if constexpr (requires { ValueType { value }; })
193
2.28k
                return ValueType { value };
194
2.28k
        }
195
196
0
        return Error::from_string_literal("ASN1::Decoder: Trying to decode a value from an incompatible type");
197
2.41k
    }
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
8.29k
    {
185
8.29k
        if (value_or_error.is_error())
186
338
            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.95k
        } else {
191
7.95k
            auto&& value = value_or_error.value();
192
            if constexpr (requires { ValueType { value }; })
193
7.95k
                return ValueType { value };
194
7.95k
        }
195
196
0
        return Error::from_string_literal("ASN1::Decoder: Trying to decode a value from an incompatible type");
197
8.29k
    }
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
794
    {
185
794
        if (value_or_error.is_error())
186
440
            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
354
        } else {
191
354
            auto&& value = value_or_error.value();
192
            if constexpr (requires { ValueType { value }; })
193
                return ValueType { value };
194
354
        }
195
196
354
        return Error::from_string_literal("ASN1::Decoder: Trying to decode a value from an incompatible type");
197
794
    }
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
93
    {
185
93
        if (value_or_error.is_error())
186
61
            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
32
        } else {
191
32
            auto&& value = value_or_error.value();
192
            if constexpr (requires { ValueType { value }; })
193
                return ValueType { value };
194
32
        }
195
196
32
        return Error::from_string_literal("ASN1::Decoder: Trying to decode a value from an incompatible type");
197
93
    }
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
549
    {
185
549
        if (value_or_error.is_error())
186
253
            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
296
        } else {
191
296
            auto&& value = value_or_error.value();
192
            if constexpr (requires { ValueType { value }; })
193
                return ValueType { value };
194
296
        }
195
196
296
        return Error::from_string_literal("ASN1::Decoder: Trying to decode a value from an incompatible type");
197
549
    }
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
197
    {
185
197
        if (value_or_error.is_error())
186
74
            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
123
        } else {
191
123
            auto&& value = value_or_error.value();
192
            if constexpr (requires { ValueType { value }; })
193
                return ValueType { value };
194
123
        }
195
196
123
        return Error::from_string_literal("ASN1::Decoder: Trying to decode a value from an incompatible type");
197
197
    }
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
42.5k
    {
185
42.5k
        if (value_or_error.is_error())
186
56
            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
42.4k
        } else {
191
42.4k
            auto&& value = value_or_error.value();
192
            if constexpr (requires { ValueType { value }; })
193
42.4k
                return ValueType { value };
194
42.4k
        }
195
196
0
        return Error::from_string_literal("ASN1::Decoder: Trying to decode a value from an incompatible type");
197
42.5k
    }
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
6
    {
185
6
        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
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
6
    }
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
12
    {
185
12
        if (value_or_error.is_error())
186
3
            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
12
    }
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
431
    {
185
431
        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
429
        } else {
191
429
            auto&& value = value_or_error.value();
192
            if constexpr (requires { ValueType { value }; })
193
429
                return ValueType { value };
194
429
        }
195
196
0
        return Error::from_string_literal("ASN1::Decoder: Trying to decode a value from an incompatible type");
197
431
    }
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.25k
    {
185
2.25k
        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
2.24k
        } else {
191
2.24k
            auto&& value = value_or_error.value();
192
            if constexpr (requires { ValueType { value }; })
193
2.24k
                return ValueType { value };
194
2.24k
        }
195
196
0
        return Error::from_string_literal("ASN1::Decoder: Trying to decode a value from an incompatible type");
197
2.25k
    }
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.57k
    {
185
1.57k
        if (value_or_error.is_error())
186
8
            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.57k
        } else {
191
1.57k
            auto&& value = value_or_error.value();
192
            if constexpr (requires { ValueType { value }; })
193
1.57k
                return ValueType { value };
194
1.57k
        }
195
196
0
        return Error::from_string_literal("ASN1::Decoder: Trying to decode a value from an incompatible type");
197
1.57k
    }
198
199
    template<typename ValueType>
200
    ErrorOr<ValueType> read_value(Class klass, Kind kind, size_t length)
201
77.7k
    {
202
77.7k
        auto data = TRY(read_bytes(length));
203
204
76.7k
        if constexpr (IsSame<ValueType, ReadonlyBytes>) {
205
0
            return data;
206
76.7k
        } else {
207
76.7k
            if (klass != Class::Universal)
208
218
                return with_type_check<ValueType>(data);
209
210
76.5k
            if (kind == Kind::Boolean)
211
2.86k
                return with_type_check<ValueType>(decode_boolean(data));
212
213
73.7k
            if (kind == Kind::Integer)
214
8.33k
                return with_type_check<ValueType>(decode_arbitrary_sized_integer(data));
215
216
65.3k
            if (kind == Kind::OctetString)
217
5.39k
                return with_type_check<ValueType>(decode_octet_string(data));
218
219
59.9k
            if (kind == Kind::Null)
220
2.36k
                return with_type_check<ValueType>(decode_null(data));
221
222
57.6k
            if (kind == Kind::ObjectIdentifier)
223
17.2k
                return with_type_check<ValueType>(decode_object_identifier(data));
224
225
40.3k
            if (kind == Kind::PrintableString || kind == Kind::IA5String || kind == Kind::UTCTime)
226
37.9k
                return with_type_check<ValueType>(decode_printable_string(data));
227
228
2.43k
            if (kind == Kind::Utf8String)
229
82
                return with_type_check<ValueType>(StringView { data.data(), data.size() });
230
231
2.35k
            if (kind == Kind::BitString)
232
1.79k
                return with_type_check<ValueType>(decode_bit_string(data));
233
234
563
            return with_type_check<ValueType>(data);
235
2.35k
        }
236
76.7k
    }
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
16.8k
    {
202
16.8k
        auto data = TRY(read_bytes(length));
203
204
        if constexpr (IsSame<ValueType, ReadonlyBytes>) {
205
            return data;
206
16.7k
        } else {
207
16.7k
            if (klass != Class::Universal)
208
5
                return with_type_check<ValueType>(data);
209
210
16.7k
            if (kind == Kind::Boolean)
211
9
                return with_type_check<ValueType>(decode_boolean(data));
212
213
16.7k
            if (kind == Kind::Integer)
214
25
                return with_type_check<ValueType>(decode_arbitrary_sized_integer(data));
215
216
16.7k
            if (kind == Kind::OctetString)
217
5
                return with_type_check<ValueType>(decode_octet_string(data));
218
219
16.7k
            if (kind == Kind::Null)
220
12
                return with_type_check<ValueType>(decode_null(data));
221
222
16.7k
            if (kind == Kind::ObjectIdentifier)
223
16.6k
                return with_type_check<ValueType>(decode_object_identifier(data));
224
225
64
            if (kind == Kind::PrintableString || kind == Kind::IA5String || kind == Kind::UTCTime)
226
14
                return with_type_check<ValueType>(decode_printable_string(data));
227
228
50
            if (kind == Kind::Utf8String)
229
10
                return with_type_check<ValueType>(StringView { data.data(), data.size() });
230
231
40
            if (kind == Kind::BitString)
232
7
                return with_type_check<ValueType>(decode_bit_string(data));
233
234
33
            return with_type_check<ValueType>(data);
235
40
        }
236
16.7k
    }
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
13.7k
    {
202
13.7k
        auto data = TRY(read_bytes(length));
203
204
        if constexpr (IsSame<ValueType, ReadonlyBytes>) {
205
            return data;
206
12.8k
        } else {
207
12.8k
            if (klass != Class::Universal)
208
100
                return with_type_check<ValueType>(data);
209
210
12.7k
            if (kind == Kind::Boolean)
211
2.41k
                return with_type_check<ValueType>(decode_boolean(data));
212
213
10.3k
            if (kind == Kind::Integer)
214
8.29k
                return with_type_check<ValueType>(decode_arbitrary_sized_integer(data));
215
216
2.06k
            if (kind == Kind::OctetString)
217
45
                return with_type_check<ValueType>(decode_octet_string(data));
218
219
2.02k
            if (kind == Kind::Null)
220
93
                return with_type_check<ValueType>(decode_null(data));
221
222
1.93k
            if (kind == Kind::ObjectIdentifier)
223
549
                return with_type_check<ValueType>(decode_object_identifier(data));
224
225
1.38k
            if (kind == Kind::PrintableString || kind == Kind::IA5String || kind == Kind::UTCTime)
226
749
                return with_type_check<ValueType>(decode_printable_string(data));
227
228
633
            if (kind == Kind::Utf8String)
229
40
                return with_type_check<ValueType>(StringView { data.data(), data.size() });
230
231
593
            if (kind == Kind::BitString)
232
197
                return with_type_check<ValueType>(decode_bit_string(data));
233
234
396
            return with_type_check<ValueType>(data);
235
593
        }
236
12.8k
    }
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
42.8k
    {
202
42.8k
        auto data = TRY(read_bytes(length));
203
204
        if constexpr (IsSame<ValueType, ReadonlyBytes>) {
205
            return data;
206
42.7k
        } else {
207
42.7k
            if (klass != Class::Universal)
208
108
                return with_type_check<ValueType>(data);
209
210
42.6k
            if (kind == Kind::Boolean)
211
4
                return with_type_check<ValueType>(decode_boolean(data));
212
213
42.6k
            if (kind == Kind::Integer)
214
6
                return with_type_check<ValueType>(decode_arbitrary_sized_integer(data));
215
216
42.6k
            if (kind == Kind::OctetString)
217
5.34k
                return with_type_check<ValueType>(decode_octet_string(data));
218
219
37.3k
            if (kind == Kind::Null)
220
4
                return with_type_check<ValueType>(decode_null(data));
221
222
37.3k
            if (kind == Kind::ObjectIdentifier)
223
4
                return with_type_check<ValueType>(decode_object_identifier(data));
224
225
37.3k
            if (kind == Kind::PrintableString || kind == Kind::IA5String || kind == Kind::UTCTime)
226
37.1k
                return with_type_check<ValueType>(decode_printable_string(data));
227
228
142
            if (kind == Kind::Utf8String)
229
30
                return with_type_check<ValueType>(StringView { data.data(), data.size() });
230
231
112
            if (kind == Kind::BitString)
232
4
                return with_type_check<ValueType>(decode_bit_string(data));
233
234
108
            return with_type_check<ValueType>(data);
235
112
        }
236
42.7k
    }
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
148
    {
202
148
        auto data = TRY(read_bytes(length));
203
204
        if constexpr (IsSame<ValueType, ReadonlyBytes>) {
205
            return data;
206
75
        } else {
207
75
            if (klass != Class::Universal)
208
5
                return with_type_check<ValueType>(data);
209
210
70
            if (kind == Kind::Boolean)
211
6
                return with_type_check<ValueType>(decode_boolean(data));
212
213
64
            if (kind == Kind::Integer)
214
6
                return with_type_check<ValueType>(decode_arbitrary_sized_integer(data));
215
216
58
            if (kind == Kind::OctetString)
217
2
                return with_type_check<ValueType>(decode_octet_string(data));
218
219
56
            if (kind == Kind::Null)
220
4
                return with_type_check<ValueType>(decode_null(data));
221
222
52
            if (kind == Kind::ObjectIdentifier)
223
7
                return with_type_check<ValueType>(decode_object_identifier(data));
224
225
45
            if (kind == Kind::PrintableString || kind == Kind::IA5String || kind == Kind::UTCTime)
226
10
                return with_type_check<ValueType>(decode_printable_string(data));
227
228
35
            if (kind == Kind::Utf8String)
229
2
                return with_type_check<ValueType>(StringView { data.data(), data.size() });
230
231
33
            if (kind == Kind::BitString)
232
7
                return with_type_check<ValueType>(decode_bit_string(data));
233
234
26
            return with_type_check<ValueType>(data);
235
33
        }
236
75
    }
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
432
    {
202
432
        auto data = TRY(read_bytes(length));
203
204
        if constexpr (IsSame<ValueType, ReadonlyBytes>) {
205
            return data;
206
431
        } else {
207
431
            if (klass != Class::Universal)
208
0
                return with_type_check<ValueType>(data);
209
210
431
            if (kind == Kind::Boolean)
211
431
                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
431
    }
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.25k
    {
202
2.25k
        auto data = TRY(read_bytes(length));
203
204
        if constexpr (IsSame<ValueType, ReadonlyBytes>) {
205
            return data;
206
2.25k
        } else {
207
2.25k
            if (klass != Class::Universal)
208
0
                return with_type_check<ValueType>(data);
209
210
2.25k
            if (kind == Kind::Boolean)
211
0
                return with_type_check<ValueType>(decode_boolean(data));
212
213
2.25k
            if (kind == Kind::Integer)
214
0
                return with_type_check<ValueType>(decode_arbitrary_sized_integer(data));
215
216
2.25k
            if (kind == Kind::OctetString)
217
0
                return with_type_check<ValueType>(decode_octet_string(data));
218
219
2.25k
            if (kind == Kind::Null)
220
2.25k
                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.25k
    }
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.59k
    {
202
1.59k
        auto data = TRY(read_bytes(length));
203
204
        if constexpr (IsSame<ValueType, ReadonlyBytes>) {
205
            return data;
206
1.57k
        } else {
207
1.57k
            if (klass != Class::Universal)
208
0
                return with_type_check<ValueType>(data);
209
210
1.57k
            if (kind == Kind::Boolean)
211
0
                return with_type_check<ValueType>(decode_boolean(data));
212
213
1.57k
            if (kind == Kind::Integer)
214
0
                return with_type_check<ValueType>(decode_arbitrary_sized_integer(data));
215
216
1.57k
            if (kind == Kind::OctetString)
217
0
                return with_type_check<ValueType>(decode_octet_string(data));
218
219
1.57k
            if (kind == Kind::Null)
220
0
                return with_type_check<ValueType>(decode_null(data));
221
222
1.57k
            if (kind == Kind::ObjectIdentifier)
223
0
                return with_type_check<ValueType>(decode_object_identifier(data));
224
225
1.57k
            if (kind == Kind::PrintableString || kind == Kind::IA5String || kind == Kind::UTCTime)
226
0
                return with_type_check<ValueType>(decode_printable_string(data));
227
228
1.57k
            if (kind == Kind::Utf8String)
229
0
                return with_type_check<ValueType>(StringView { data.data(), data.size() });
230
231
1.57k
            if (kind == Kind::BitString)
232
1.57k
                return with_type_check<ValueType>(decode_bit_string(data));
233
234
0
            return with_type_check<ValueType>(data);
235
1.57k
        }
236
1.57k
    }
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, AK::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, AK::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, AK::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, AK::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
}