2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2014-05-15 14:20:00 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_dom_SubtleCrypto_h
|
|
|
|
#define mozilla_dom_SubtleCrypto_h
|
|
|
|
|
|
|
|
#include "nsCycleCollectionParticipant.h"
|
|
|
|
#include "nsWrapperCache.h"
|
2015-01-09 21:55:44 +03:00
|
|
|
#include "nsIGlobalObject.h"
|
2014-06-24 01:25:13 +04:00
|
|
|
#include "mozilla/dom/CryptoKey.h"
|
2014-05-15 14:20:00 +04:00
|
|
|
#include "js/TypeDecls.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2014-10-01 22:43:26 +04:00
|
|
|
class ObjectOrString;
|
2014-05-15 14:20:00 +04:00
|
|
|
class Promise;
|
|
|
|
|
|
|
|
typedef ArrayBufferViewOrArrayBuffer CryptoOperationData;
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class SubtleCrypto final : public nsISupports, public nsWrapperCache {
|
2020-02-21 13:41:47 +03:00
|
|
|
~SubtleCrypto() = default;
|
2014-06-23 23:56:07 +04:00
|
|
|
|
2014-05-15 14:20:00 +04:00
|
|
|
public:
|
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(SubtleCrypto)
|
|
|
|
|
|
|
|
public:
|
2015-01-09 21:55:44 +03:00
|
|
|
explicit SubtleCrypto(nsIGlobalObject* aParent);
|
2014-05-15 14:20:00 +04:00
|
|
|
|
2015-01-09 21:55:44 +03:00
|
|
|
nsIGlobalObject* GetParentObject() const { return mParent; }
|
2014-05-15 14:20:00 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual JSObject* WrapObject(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) override;
|
2014-05-15 14:20:00 +04:00
|
|
|
|
|
|
|
already_AddRefed<Promise> Encrypt(JSContext* cx,
|
|
|
|
const ObjectOrString& algorithm,
|
2014-06-24 01:25:13 +04:00
|
|
|
CryptoKey& key,
|
2014-07-19 05:31:11 +04:00
|
|
|
const CryptoOperationData& data,
|
|
|
|
ErrorResult& aRv);
|
2014-05-15 14:20:00 +04:00
|
|
|
|
|
|
|
already_AddRefed<Promise> Decrypt(JSContext* cx,
|
|
|
|
const ObjectOrString& algorithm,
|
2014-06-24 01:25:13 +04:00
|
|
|
CryptoKey& key,
|
2014-07-19 05:31:11 +04:00
|
|
|
const CryptoOperationData& data,
|
|
|
|
ErrorResult& aRv);
|
2014-05-15 14:20:00 +04:00
|
|
|
|
|
|
|
already_AddRefed<Promise> Sign(JSContext* cx, const ObjectOrString& algorithm,
|
2014-06-24 01:25:13 +04:00
|
|
|
CryptoKey& key,
|
2014-07-19 05:31:11 +04:00
|
|
|
const CryptoOperationData& data,
|
|
|
|
ErrorResult& aRv);
|
2014-05-15 14:20:00 +04:00
|
|
|
|
|
|
|
already_AddRefed<Promise> Verify(JSContext* cx,
|
|
|
|
const ObjectOrString& algorithm,
|
2014-06-24 01:25:13 +04:00
|
|
|
CryptoKey& key,
|
2014-05-15 14:20:00 +04:00
|
|
|
const CryptoOperationData& signature,
|
2014-07-19 05:31:11 +04:00
|
|
|
const CryptoOperationData& data,
|
|
|
|
ErrorResult& aRv);
|
2014-05-15 14:20:00 +04:00
|
|
|
|
|
|
|
already_AddRefed<Promise> Digest(JSContext* cx,
|
|
|
|
const ObjectOrString& aAlgorithm,
|
2014-07-19 05:31:11 +04:00
|
|
|
const CryptoOperationData& aData,
|
|
|
|
ErrorResult& aRv);
|
2014-05-15 14:20:00 +04:00
|
|
|
|
|
|
|
already_AddRefed<Promise> ImportKey(JSContext* cx, const nsAString& format,
|
2014-07-19 17:25:00 +04:00
|
|
|
JS::Handle<JSObject*> keyData,
|
2014-05-15 14:20:00 +04:00
|
|
|
const ObjectOrString& algorithm,
|
|
|
|
bool extractable,
|
2014-07-19 05:31:11 +04:00
|
|
|
const Sequence<nsString>& keyUsages,
|
|
|
|
ErrorResult& aRv);
|
2014-05-15 14:20:00 +04:00
|
|
|
|
2014-07-19 05:31:11 +04:00
|
|
|
already_AddRefed<Promise> ExportKey(const nsAString& format, CryptoKey& key,
|
|
|
|
ErrorResult& aRv);
|
2014-05-15 14:20:00 +04:00
|
|
|
|
|
|
|
already_AddRefed<Promise> GenerateKey(JSContext* cx,
|
|
|
|
const ObjectOrString& algorithm,
|
|
|
|
bool extractable,
|
2014-07-19 05:31:11 +04:00
|
|
|
const Sequence<nsString>& keyUsages,
|
|
|
|
ErrorResult& aRv);
|
2014-05-15 14:20:00 +04:00
|
|
|
|
|
|
|
already_AddRefed<Promise> DeriveKey(
|
|
|
|
JSContext* cx, const ObjectOrString& algorithm, CryptoKey& baseKey,
|
|
|
|
const ObjectOrString& derivedKeyType, bool extractable,
|
2014-07-19 05:31:11 +04:00
|
|
|
const Sequence<nsString>& keyUsages, ErrorResult& aRv);
|
2014-05-15 14:20:00 +04:00
|
|
|
|
|
|
|
already_AddRefed<Promise> DeriveBits(JSContext* cx,
|
|
|
|
const ObjectOrString& algorithm,
|
2014-06-24 01:25:13 +04:00
|
|
|
CryptoKey& baseKey, uint32_t length,
|
2014-07-19 05:31:11 +04:00
|
|
|
ErrorResult& aRv);
|
2014-05-15 14:20:00 +04:00
|
|
|
|
2014-07-19 17:24:00 +04:00
|
|
|
already_AddRefed<Promise> WrapKey(JSContext* cx, const nsAString& format,
|
|
|
|
CryptoKey& key, CryptoKey& wrappingKey,
|
|
|
|
const ObjectOrString& wrapAlgorithm,
|
|
|
|
ErrorResult& aRv);
|
|
|
|
|
|
|
|
already_AddRefed<Promise> UnwrapKey(
|
|
|
|
JSContext* cx, const nsAString& format,
|
|
|
|
const ArrayBufferViewOrArrayBuffer& wrappedKey, CryptoKey& unwrappingKey,
|
|
|
|
const ObjectOrString& unwrapAlgorithm,
|
|
|
|
const ObjectOrString& unwrappedKeyAlgorithm, bool extractable,
|
|
|
|
const Sequence<nsString>& keyUsages, ErrorResult& aRv);
|
|
|
|
|
2014-05-15 14:20:00 +04:00
|
|
|
private:
|
2015-01-09 21:55:44 +03:00
|
|
|
nsCOMPtr<nsIGlobalObject> mParent;
|
2014-05-15 14:20:00 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_dom_SubtleCrypto_h
|