Backed out changeset 2450366cf7ca (bug 1891629) for causing win msix mochitest failures
[gecko.git] / dom / base / SubtleCrypto.h
bloba4d93420c84055b6a132d449312fdeed6e7cf7c1
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 {
18 class ObjectOrString;
19 class Promise;
21 typedef ArrayBufferViewOrArrayBuffer CryptoOperationData;
23 class SubtleCrypto final : public nsISupports, public nsWrapperCache {
24 ~SubtleCrypto() = default;
26 public:
27 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
28 NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(SubtleCrypto)
30 public:
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,
40 CryptoKey& key,
41 const CryptoOperationData& data,
42 ErrorResult& aRv);
44 already_AddRefed<Promise> Decrypt(JSContext* cx,
45 const ObjectOrString& algorithm,
46 CryptoKey& key,
47 const CryptoOperationData& data,
48 ErrorResult& aRv);
50 already_AddRefed<Promise> Sign(JSContext* cx, const ObjectOrString& algorithm,
51 CryptoKey& key,
52 const CryptoOperationData& data,
53 ErrorResult& aRv);
55 already_AddRefed<Promise> Verify(JSContext* cx,
56 const ObjectOrString& algorithm,
57 CryptoKey& key,
58 const CryptoOperationData& signature,
59 const CryptoOperationData& data,
60 ErrorResult& aRv);
62 already_AddRefed<Promise> Digest(JSContext* cx,
63 const ObjectOrString& aAlgorithm,
64 const CryptoOperationData& aData,
65 ErrorResult& aRv);
67 already_AddRefed<Promise> ImportKey(JSContext* cx, const nsAString& format,
68 JS::Handle<JSObject*> keyData,
69 const ObjectOrString& algorithm,
70 bool extractable,
71 const Sequence<nsString>& keyUsages,
72 ErrorResult& aRv);
74 already_AddRefed<Promise> ExportKey(const nsAString& format, CryptoKey& key,
75 ErrorResult& aRv);
77 already_AddRefed<Promise> GenerateKey(JSContext* cx,
78 const ObjectOrString& algorithm,
79 bool extractable,
80 const Sequence<nsString>& keyUsages,
81 ErrorResult& aRv);
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,
91 ErrorResult& aRv);
93 already_AddRefed<Promise> WrapKey(JSContext* cx, const nsAString& format,
94 CryptoKey& key, CryptoKey& wrappingKey,
95 const ObjectOrString& wrapAlgorithm,
96 ErrorResult& aRv);
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);
105 private:
106 nsCOMPtr<nsIGlobalObject> mParent;
109 } // namespace mozilla::dom
111 #endif // mozilla_dom_SubtleCrypto_h