1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_dom_SubtleCrypto_h
8 #define mozilla_dom_SubtleCrypto_h
10 #include "nsCycleCollectionParticipant.h"
11 #include "nsWrapperCache.h"
12 #include "nsIGlobalObject.h"
13 #include "mozilla/dom/CryptoKey.h"
14 #include "js/TypeDecls.h"
22 typedef ArrayBufferViewOrArrayBuffer CryptoOperationData
;
24 class SubtleCrypto final
: public nsISupports
, public nsWrapperCache
{
25 ~SubtleCrypto() = default;
28 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
29 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(SubtleCrypto
)
32 explicit SubtleCrypto(nsIGlobalObject
* aParent
);
34 nsIGlobalObject
* GetParentObject() const { return mParent
; }
36 virtual JSObject
* WrapObject(JSContext
* aCx
,
37 JS::Handle
<JSObject
*> aGivenProto
) override
;
39 already_AddRefed
<Promise
> Encrypt(JSContext
* cx
,
40 const ObjectOrString
& algorithm
,
42 const CryptoOperationData
& data
,
45 already_AddRefed
<Promise
> Decrypt(JSContext
* cx
,
46 const ObjectOrString
& algorithm
,
48 const CryptoOperationData
& data
,
51 already_AddRefed
<Promise
> Sign(JSContext
* cx
, const ObjectOrString
& algorithm
,
53 const CryptoOperationData
& data
,
56 already_AddRefed
<Promise
> Verify(JSContext
* cx
,
57 const ObjectOrString
& algorithm
,
59 const CryptoOperationData
& signature
,
60 const CryptoOperationData
& data
,
63 already_AddRefed
<Promise
> Digest(JSContext
* cx
,
64 const ObjectOrString
& aAlgorithm
,
65 const CryptoOperationData
& aData
,
68 already_AddRefed
<Promise
> ImportKey(JSContext
* cx
, const nsAString
& format
,
69 JS::Handle
<JSObject
*> keyData
,
70 const ObjectOrString
& algorithm
,
72 const Sequence
<nsString
>& keyUsages
,
75 already_AddRefed
<Promise
> ExportKey(const nsAString
& format
, CryptoKey
& key
,
78 already_AddRefed
<Promise
> GenerateKey(JSContext
* cx
,
79 const ObjectOrString
& algorithm
,
81 const Sequence
<nsString
>& keyUsages
,
84 already_AddRefed
<Promise
> DeriveKey(
85 JSContext
* cx
, const ObjectOrString
& algorithm
, CryptoKey
& baseKey
,
86 const ObjectOrString
& derivedKeyType
, bool extractable
,
87 const Sequence
<nsString
>& keyUsages
, ErrorResult
& aRv
);
89 already_AddRefed
<Promise
> DeriveBits(JSContext
* cx
,
90 const ObjectOrString
& algorithm
,
91 CryptoKey
& baseKey
, uint32_t length
,
94 already_AddRefed
<Promise
> WrapKey(JSContext
* cx
, const nsAString
& format
,
95 CryptoKey
& key
, CryptoKey
& wrappingKey
,
96 const ObjectOrString
& wrapAlgorithm
,
99 already_AddRefed
<Promise
> UnwrapKey(
100 JSContext
* cx
, const nsAString
& format
,
101 const ArrayBufferViewOrArrayBuffer
& wrappedKey
, CryptoKey
& unwrappingKey
,
102 const ObjectOrString
& unwrapAlgorithm
,
103 const ObjectOrString
& unwrappedKeyAlgorithm
, bool extractable
,
104 const Sequence
<nsString
>& keyUsages
, ErrorResult
& aRv
);
107 nsCOMPtr
<nsIGlobalObject
> mParent
;
111 } // namespace mozilla
113 #endif // mozilla_dom_SubtleCrypto_h