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"
16 namespace mozilla::dom
{
21 typedef ArrayBufferViewOrArrayBuffer CryptoOperationData
;
23 class SubtleCrypto final
: public nsISupports
, public nsWrapperCache
{
24 ~SubtleCrypto() = default;
27 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
28 NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(SubtleCrypto
)
31 explicit SubtleCrypto(nsIGlobalObject
* aParent
);
33 nsIGlobalObject
* GetParentObject() const { return mParent
; }
35 virtual JSObject
* WrapObject(JSContext
* aCx
,
36 JS::Handle
<JSObject
*> aGivenProto
) override
;
38 already_AddRefed
<Promise
> Encrypt(JSContext
* cx
,
39 const ObjectOrString
& algorithm
,
41 const CryptoOperationData
& data
,
44 already_AddRefed
<Promise
> Decrypt(JSContext
* cx
,
45 const ObjectOrString
& algorithm
,
47 const CryptoOperationData
& data
,
50 already_AddRefed
<Promise
> Sign(JSContext
* cx
, const ObjectOrString
& algorithm
,
52 const CryptoOperationData
& data
,
55 already_AddRefed
<Promise
> Verify(JSContext
* cx
,
56 const ObjectOrString
& algorithm
,
58 const CryptoOperationData
& signature
,
59 const CryptoOperationData
& data
,
62 already_AddRefed
<Promise
> Digest(JSContext
* cx
,
63 const ObjectOrString
& aAlgorithm
,
64 const CryptoOperationData
& aData
,
67 already_AddRefed
<Promise
> ImportKey(JSContext
* cx
, const nsAString
& format
,
68 JS::Handle
<JSObject
*> keyData
,
69 const ObjectOrString
& algorithm
,
71 const Sequence
<nsString
>& keyUsages
,
74 already_AddRefed
<Promise
> ExportKey(const nsAString
& format
, CryptoKey
& key
,
77 already_AddRefed
<Promise
> GenerateKey(JSContext
* cx
,
78 const ObjectOrString
& algorithm
,
80 const Sequence
<nsString
>& keyUsages
,
83 already_AddRefed
<Promise
> DeriveKey(
84 JSContext
* cx
, const ObjectOrString
& algorithm
, CryptoKey
& baseKey
,
85 const ObjectOrString
& derivedKeyType
, bool extractable
,
86 const Sequence
<nsString
>& keyUsages
, ErrorResult
& aRv
);
88 already_AddRefed
<Promise
> DeriveBits(JSContext
* cx
,
89 const ObjectOrString
& algorithm
,
90 CryptoKey
& baseKey
, uint32_t length
,
93 already_AddRefed
<Promise
> WrapKey(JSContext
* cx
, const nsAString
& format
,
94 CryptoKey
& key
, CryptoKey
& wrappingKey
,
95 const ObjectOrString
& wrapAlgorithm
,
98 already_AddRefed
<Promise
> UnwrapKey(
99 JSContext
* cx
, const nsAString
& format
,
100 const ArrayBufferViewOrArrayBuffer
& wrappedKey
, CryptoKey
& unwrappingKey
,
101 const ObjectOrString
& unwrapAlgorithm
,
102 const ObjectOrString
& unwrappedKeyAlgorithm
, bool extractable
,
103 const Sequence
<nsString
>& keyUsages
, ErrorResult
& aRv
);
106 nsCOMPtr
<nsIGlobalObject
> mParent
;
109 } // namespace mozilla::dom
111 #endif // mozilla_dom_SubtleCrypto_h