SubtleCrypto.h (4754B)
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/. */ 6 7 #ifndef mozilla_dom_SubtleCrypto_h 8 #define mozilla_dom_SubtleCrypto_h 9 10 #include "js/TypeDecls.h" 11 #include "mozilla/dom/CryptoKey.h" 12 #include "nsCycleCollectionParticipant.h" 13 #include "nsIGlobalObject.h" 14 #include "nsWrapperCache.h" 15 16 namespace mozilla::dom { 17 18 class ObjectOrString; 19 class Promise; 20 21 typedef ArrayBufferViewOrArrayBuffer CryptoOperationData; 22 23 class SubtleCrypto final : public nsISupports, public nsWrapperCache { 24 ~SubtleCrypto() = default; 25 26 public: 27 NS_DECL_CYCLE_COLLECTING_ISUPPORTS 28 NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(SubtleCrypto) 29 30 public: 31 explicit SubtleCrypto(nsIGlobalObject* aParent); 32 33 nsIGlobalObject* GetParentObject() const { return mParent; } 34 35 virtual JSObject* WrapObject(JSContext* aCx, 36 JS::Handle<JSObject*> aGivenProto) override; 37 38 already_AddRefed<Promise> Encrypt(JSContext* cx, 39 const ObjectOrString& algorithm, 40 CryptoKey& key, 41 const CryptoOperationData& data, 42 ErrorResult& aRv); 43 44 already_AddRefed<Promise> Decrypt(JSContext* cx, 45 const ObjectOrString& algorithm, 46 CryptoKey& key, 47 const CryptoOperationData& data, 48 ErrorResult& aRv); 49 50 already_AddRefed<Promise> Sign(JSContext* cx, const ObjectOrString& algorithm, 51 CryptoKey& key, 52 const CryptoOperationData& data, 53 ErrorResult& aRv); 54 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); 61 62 already_AddRefed<Promise> Digest(JSContext* cx, 63 const ObjectOrString& aAlgorithm, 64 const CryptoOperationData& aData, 65 ErrorResult& aRv); 66 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); 73 74 already_AddRefed<Promise> ExportKey(const nsAString& format, CryptoKey& key, 75 ErrorResult& aRv); 76 77 already_AddRefed<Promise> GenerateKey(JSContext* cx, 78 const ObjectOrString& algorithm, 79 bool extractable, 80 const Sequence<nsString>& keyUsages, 81 ErrorResult& aRv); 82 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); 87 88 already_AddRefed<Promise> DeriveBits(JSContext* cx, 89 const ObjectOrString& algorithm, 90 CryptoKey& baseKey, 91 const Nullable<uint32_t>& length, 92 ErrorResult& aRv); 93 94 already_AddRefed<Promise> WrapKey(JSContext* cx, const nsAString& format, 95 CryptoKey& key, CryptoKey& wrappingKey, 96 const ObjectOrString& wrapAlgorithm, 97 ErrorResult& aRv); 98 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); 105 106 private: 107 nsCOMPtr<nsIGlobalObject> mParent; 108 }; 109 110 } // namespace mozilla::dom 111 112 #endif // mozilla_dom_SubtleCrypto_h