Coverage Report

Created: 2026-09-26 06:49

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/serenity/Userland/Libraries/LibWeb/Crypto/CryptoBindings.cpp
Line
Count
Source
1
/*
2
 * Copyright (c) 2024, Andrew Kaster <akaster@serenityos.org>
3
 *
4
 * SPDX-License-Identifier: BSD-2-Clause
5
 */
6
7
#include <LibJS/Runtime/Array.h>
8
#include <LibJS/Runtime/Object.h>
9
#include <LibJS/Runtime/Realm.h>
10
#include <LibWeb/Crypto/CryptoBindings.h>
11
12
namespace Web::Bindings {
13
14
JS::ThrowCompletionOr<JS::NonnullGCPtr<JS::Object>> JsonWebKey::to_object(JS::Realm& realm)
15
0
{
16
0
    auto& vm = realm.vm();
17
0
    auto object = JS::Object::create(realm, realm.intrinsics().object_prototype());
18
19
0
    if (kty.has_value())
20
0
        TRY(object->create_data_property("kty", JS::PrimitiveString::create(vm, kty.value())));
21
22
0
    if (use.has_value())
23
0
        TRY(object->create_data_property("use", JS::PrimitiveString::create(vm, use.value())));
24
25
0
    if (key_ops.has_value()) {
26
0
        auto key_ops_array = JS::Array::create_from<String>(realm, key_ops.value().span(), [&](auto& key_usage) -> JS::Value {
27
0
            return JS::PrimitiveString::create(realm.vm(), key_usage);
28
0
        });
29
0
        TRY(object->create_data_property("key_ops", move(key_ops_array)));
30
0
    }
31
32
0
    if (alg.has_value())
33
0
        TRY(object->create_data_property("alg", JS::PrimitiveString::create(vm, alg.value())));
34
35
0
    if (ext.has_value())
36
0
        TRY(object->create_data_property("ext", JS::Value(ext.value())));
37
38
0
    if (crv.has_value())
39
0
        TRY(object->create_data_property("crv", JS::PrimitiveString::create(vm, crv.value())));
40
41
0
    if (x.has_value())
42
0
        TRY(object->create_data_property("x", JS::PrimitiveString::create(vm, x.value())));
43
44
0
    if (y.has_value())
45
0
        TRY(object->create_data_property("y", JS::PrimitiveString::create(vm, y.value())));
46
47
0
    if (d.has_value())
48
0
        TRY(object->create_data_property("d", JS::PrimitiveString::create(vm, d.value())));
49
50
0
    if (n.has_value())
51
0
        TRY(object->create_data_property("n", JS::PrimitiveString::create(vm, n.value())));
52
53
0
    if (e.has_value())
54
0
        TRY(object->create_data_property("e", JS::PrimitiveString::create(vm, e.value())));
55
56
0
    if (p.has_value())
57
0
        TRY(object->create_data_property("p", JS::PrimitiveString::create(vm, p.value())));
58
59
0
    if (q.has_value())
60
0
        TRY(object->create_data_property("q", JS::PrimitiveString::create(vm, q.value())));
61
62
0
    if (dp.has_value())
63
0
        TRY(object->create_data_property("dp", JS::PrimitiveString::create(vm, dp.value())));
64
65
0
    if (dq.has_value())
66
0
        TRY(object->create_data_property("dq", JS::PrimitiveString::create(vm, dq.value())));
67
68
0
    if (qi.has_value())
69
0
        TRY(object->create_data_property("qi", JS::PrimitiveString::create(vm, qi.value())));
70
71
0
    if (oth.has_value()) {
72
0
        TODO();
73
0
    }
74
75
0
    if (k.has_value())
76
0
        TRY(object->create_data_property("k", JS::PrimitiveString::create(vm, k.value())));
77
78
0
    return object;
79
0
}
80
81
}