Bug 1861467 - [wpt-sync] Update web-platform-tests to eedf737ce39c512d0ca3471f988972e...
[gecko.git] / dom / webidl / SubtleCrypto.webidl
blob6c7842b1f245efdb42fe416711a716a342307e64
1 /* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
4  * You can obtain one at http://mozilla.org/MPL/2.0/.
5  *
6  * The origin of this IDL file is
7  * http://www.w3.org/TR/WebCryptoAPI/
8  */
10 typedef DOMString KeyType;
11 typedef DOMString KeyUsage;
12 typedef DOMString NamedCurve;
13 typedef Uint8Array BigInteger;
15 /***** Algorithm dictionaries *****/
17 dictionary Algorithm {
18   required DOMString name;
21 [GenerateInit]
22 dictionary AesCbcParams : Algorithm {
23   required BufferSource iv;
26 [GenerateInit]
27 dictionary AesCtrParams : Algorithm {
28   required BufferSource counter;
29   required [EnforceRange] octet length;
32 [GenerateInit]
33 dictionary AesGcmParams : Algorithm {
34   required BufferSource iv;
35   BufferSource additionalData;
36   [EnforceRange] octet tagLength;
39 dictionary HmacImportParams : Algorithm {
40   required AlgorithmIdentifier hash;
43 [GenerateInit]
44 dictionary Pbkdf2Params : Algorithm {
45   required BufferSource salt;
46   required [EnforceRange] unsigned long iterations;
47   required AlgorithmIdentifier hash;
50 [GenerateInit]
51 dictionary RsaHashedImportParams {
52   required AlgorithmIdentifier hash;
55 dictionary AesKeyGenParams : Algorithm {
56   required [EnforceRange] unsigned short length;
59 [GenerateInit]
60 dictionary HmacKeyGenParams : Algorithm {
61   required AlgorithmIdentifier hash;
62   [EnforceRange] unsigned long length;
65 [GenerateInit]
66 dictionary RsaHashedKeyGenParams : Algorithm {
67   required [EnforceRange] unsigned long modulusLength;
68   required BigInteger publicExponent;
69   required AlgorithmIdentifier hash;
72 [GenerateInit]
73 dictionary RsaOaepParams : Algorithm {
74   BufferSource label;
77 [GenerateInit]
78 dictionary RsaPssParams : Algorithm {
79   required [EnforceRange] unsigned long saltLength;
82 [GenerateInit]
83 dictionary EcKeyGenParams : Algorithm {
84   required NamedCurve namedCurve;
87 [GenerateInit]
88 dictionary AesDerivedKeyParams : Algorithm {
89   required [EnforceRange] unsigned long length;
92 [GenerateInit]
93 dictionary HmacDerivedKeyParams : HmacImportParams {
94   [EnforceRange] unsigned long length;
97 [GenerateInit]
98 dictionary EcdhKeyDeriveParams : Algorithm {
99   required CryptoKey public;
102 [GenerateInit]
103 dictionary DhImportKeyParams : Algorithm {
104   required BigInteger prime;
105   required BigInteger generator;
108 [GenerateInit]
109 dictionary EcdsaParams : Algorithm {
110   required AlgorithmIdentifier hash;
113 [GenerateInit]
114 dictionary EcKeyImportParams : Algorithm {
115   NamedCurve namedCurve;
118 [GenerateInit]
119 dictionary HkdfParams : Algorithm {
120   required AlgorithmIdentifier hash;
121   required BufferSource salt;
122   required BufferSource info;
125 /***** JWK *****/
127 dictionary RsaOtherPrimesInfo {
128   // The following fields are defined in Section 6.3.2.7 of JSON Web Algorithms
129   required DOMString r;
130   required DOMString d;
131   required DOMString t;
134 [GenerateInitFromJSON, GenerateToJSON]
135 dictionary JsonWebKey {
136   // The following fields are defined in Section 3.1 of JSON Web Key
137   required DOMString kty;
138   DOMString use;
139   sequence<DOMString> key_ops;
140   DOMString alg;
142   // The following fields are defined in JSON Web Key Parameters Registration
143   boolean ext;
145   // The following fields are defined in Section 6 of JSON Web Algorithms
146   DOMString crv;
147   DOMString x;
148   DOMString y;
149   DOMString d;
150   DOMString n;
151   DOMString e;
152   DOMString p;
153   DOMString q;
154   DOMString dp;
155   DOMString dq;
156   DOMString qi;
157   sequence<RsaOtherPrimesInfo> oth;
158   DOMString k;
162 /***** The Main API *****/
164 [Serializable,
165  SecureContext,
166  Exposed=(Window,Worker)]
167 interface CryptoKey {
168   readonly attribute KeyType type;
169   readonly attribute boolean extractable;
170   [Cached, Constant, Throws] readonly attribute object algorithm;
171   [Cached, Constant, Frozen] readonly attribute sequence<KeyUsage> usages;
174 [GenerateConversionToJS]
175 dictionary CryptoKeyPair {
176   required CryptoKey publicKey;
177   required CryptoKey privateKey;
180 typedef DOMString KeyFormat;
181 typedef (object or DOMString) AlgorithmIdentifier;
183 [Exposed=(Window,Worker),
184  SecureContext]
185 interface SubtleCrypto {
186   [NewObject]
187   Promise<any> encrypt(AlgorithmIdentifier algorithm,
188                        CryptoKey key,
189                        BufferSource data);
190   [NewObject]
191   Promise<any> decrypt(AlgorithmIdentifier algorithm,
192                        CryptoKey key,
193                        BufferSource data);
194   [NewObject]
195   Promise<any> sign(AlgorithmIdentifier algorithm,
196                      CryptoKey key,
197                      BufferSource data);
198   [NewObject]
199   Promise<any> verify(AlgorithmIdentifier algorithm,
200                       CryptoKey key,
201                       BufferSource signature,
202                       BufferSource data);
203   [NewObject]
204   Promise<any> digest(AlgorithmIdentifier algorithm,
205                       BufferSource data);
207   [NewObject]
208   Promise<any> generateKey(AlgorithmIdentifier algorithm,
209                            boolean extractable,
210                            sequence<KeyUsage> keyUsages );
211   [NewObject]
212   Promise<any> deriveKey(AlgorithmIdentifier algorithm,
213                          CryptoKey baseKey,
214                          AlgorithmIdentifier derivedKeyType,
215                          boolean extractable,
216                          sequence<KeyUsage> keyUsages );
217   [NewObject]
218   Promise<any> deriveBits(AlgorithmIdentifier algorithm,
219                           CryptoKey baseKey,
220                           unsigned long length);
222   [NewObject]
223   Promise<any> importKey(KeyFormat format,
224                          object keyData,
225                          AlgorithmIdentifier algorithm,
226                          boolean extractable,
227                          sequence<KeyUsage> keyUsages );
228   [NewObject]
229   Promise<any> exportKey(KeyFormat format, CryptoKey key);
231   [NewObject]
232   Promise<any> wrapKey(KeyFormat format,
233                        CryptoKey key,
234                        CryptoKey wrappingKey,
235                        AlgorithmIdentifier wrapAlgorithm);
237   [NewObject]
238   Promise<any> unwrapKey(KeyFormat format,
239                          BufferSource wrappedKey,
240                          CryptoKey unwrappingKey,
241                          AlgorithmIdentifier unwrapAlgorithm,
242                          AlgorithmIdentifier unwrappedKeyAlgorithm,
243                          boolean extractable,
244                          sequence<KeyUsage> keyUsages );