1 /*
2 * Copyright (c) 2002-2025 Gargoyle Software Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 * https://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 package org.htmlunit.javascript.host.crypto;
16
17 import org.htmlunit.corejs.javascript.NativePromise;
18 import org.htmlunit.javascript.HtmlUnitScriptable;
19 import org.htmlunit.javascript.JavaScriptEngine;
20 import org.htmlunit.javascript.configuration.JsxClass;
21 import org.htmlunit.javascript.configuration.JsxConstructor;
22 import org.htmlunit.javascript.configuration.JsxFunction;
23 import org.htmlunit.javascript.host.dom.DOMException;
24
25 /**
26 * A JavaScript object for {@code SubtleCrypto}.
27 *
28 * @author Ahmed Ashour
29 * @author Ronald Brill
30 * @author Atsushi Nakagawa
31 */
32 @JsxClass
33 public class SubtleCrypto extends HtmlUnitScriptable {
34
35 /**
36 * Creates an instance.
37 */
38 @JsxConstructor
39 public void jsConstructor() {
40 throw JavaScriptEngine.typeErrorIllegalConstructor();
41 }
42
43 private NativePromise notImplemented() {
44 return setupRejectedPromise(() ->
45 new DOMException("Operation is not supported", DOMException.NOT_SUPPORTED_ERR));
46 }
47
48 /**
49 * Not yet implemented.
50 *
51 * @return a Promise which will be fulfilled with the encrypted data (also known as "ciphertext")
52 */
53 @JsxFunction
54 public NativePromise encrypt() {
55 return notImplemented();
56 }
57
58 /**
59 * Not yet implemented.
60 *
61 * @return a Promise which will be fulfilled with the decrypted data (also known as "plaintext")
62 */
63 @JsxFunction
64 public NativePromise decrypt() {
65 return notImplemented();
66 }
67
68 /**
69 * Not yet implemented.
70 *
71 * @return a Promise which will be fulfilled with the signature
72 */
73 @JsxFunction
74 public NativePromise sign() {
75 return notImplemented();
76 }
77
78 /**
79 * Not yet implemented.
80 *
81 * @return a Promise which will be fulfilled with a boolean value indicating whether the signature is valid
82 */
83 @JsxFunction
84 public NativePromise verify() {
85 return notImplemented();
86 }
87
88 /**
89 * Not yet implemented.
90 *
91 * @return a Promise which will be fulfilled with the digest
92 */
93 @JsxFunction
94 public NativePromise digest() {
95 return notImplemented();
96 }
97
98 /**
99 * Not yet implemented.
100 *
101 * @return a new key (for symmetric algorithms) or key pair (for public-key algorithms)
102 */
103 @JsxFunction
104 public NativePromise generateKey() {
105 return notImplemented();
106 }
107
108 /**
109 * Not yet implemented.
110 *
111 * @return a Promise which will be fulfilled with a CryptoKey object representing the new key
112 */
113 @JsxFunction
114 public NativePromise deriveKey() {
115 return notImplemented();
116 }
117
118 /**
119 * Not yet implemented.
120 *
121 * @return a Promise which will be fulfilled with an ArrayBuffer containing the derived bits
122 */
123 @JsxFunction
124 public NativePromise deriveBits() {
125 return notImplemented();
126 }
127
128 /**
129 * Not yet implemented.
130 *
131 * @return a CryptoKey object that you can use in the Web Crypto API
132 */
133 @JsxFunction
134 public NativePromise importKey() {
135 return notImplemented();
136 }
137
138 /**
139 * Not yet implemented.
140 *
141 * @return the key in an external, portable format
142 */
143 @JsxFunction
144 public NativePromise exportKey() {
145 return notImplemented();
146 }
147
148 /**
149 * Not yet implemented.
150 *
151 * @return a Promise that fulfills with an ArrayBuffer containing the encrypted exported key
152 */
153 @JsxFunction
154 public NativePromise wrapKey() {
155 return notImplemented();
156 }
157
158 /**
159 * Not yet implemented.
160 *
161 * @return a Promise that fulfills with the unwrapped key as a CryptoKey object
162 */
163 @JsxFunction
164 public NativePromise unwrapKey() {
165 return notImplemented();
166 }
167 }