#include "third_party/blink/renderer/modules/crypto/subtle_crypto.h"
#include "base/check_deref.h"
#include "base/task/single_thread_task_runner.h"
#include "third_party/blink/public/platform/platform.h"
#include "third_party/blink/public/platform/task_type.h"
#include "third_party/blink/public/platform/web_crypto.h"
#include "third_party/blink/public/platform/web_crypto_algorithm.h"
#include "third_party/blink/public/platform/web_crypto_algorithm_params.h"
#include "third_party/blink/public/web/web_crypto_histograms.h"
#include "third_party/blink/renderer/bindings/core/v8/dictionary.h"
#include "third_party/blink/renderer/bindings/core/v8/script_promise_resolver.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_json_web_key.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_union_arraybuffer_arraybufferview_jsonwebkey.h"
#include "third_party/blink/renderer/core/execution_context/execution_context.h"
#include "third_party/blink/renderer/core/typed_arrays/dom_array_buffer.h"
#include "third_party/blink/renderer/core/typed_arrays/dom_array_buffer_view.h"
#include "third_party/blink/renderer/core/typed_arrays/dom_array_piece.h"
#include "third_party/blink/renderer/modules/crypto/crypto_key.h"
#include "third_party/blink/renderer/modules/crypto/crypto_result_impl.h"
#include "third_party/blink/renderer/modules/crypto/crypto_utilities.h"
#include "third_party/blink/renderer/modules/crypto/normalize_algorithm.h"
#include "third_party/blink/renderer/platform/json/json_values.h"
namespace blink {
namespace {
bool ParseJsonWebKey(const JsonWebKey& key, WebVector<uint8_t>& json_utf8) { … }
}
SubtleCrypto::SubtleCrypto() = default;
ScriptPromise<IDLAny> SubtleCrypto::encrypt(
ScriptState* script_state,
const V8AlgorithmIdentifier* raw_algorithm,
CryptoKey* key,
const V8BufferSource* raw_data,
ExceptionState& exception_state) { … }
ScriptPromise<IDLAny> SubtleCrypto::decrypt(
ScriptState* script_state,
const V8AlgorithmIdentifier* raw_algorithm,
CryptoKey* key,
const V8BufferSource* raw_data,
ExceptionState& exception_state) { … }
ScriptPromise<IDLAny> SubtleCrypto::sign(
ScriptState* script_state,
const V8AlgorithmIdentifier* raw_algorithm,
CryptoKey* key,
const V8BufferSource* raw_data,
ExceptionState& exception_state) { … }
ScriptPromise<IDLAny> SubtleCrypto::verifySignature(
ScriptState* script_state,
const V8AlgorithmIdentifier* raw_algorithm,
CryptoKey* key,
const V8BufferSource* raw_signature,
const V8BufferSource* raw_data,
ExceptionState& exception_state) { … }
ScriptPromise<IDLAny> SubtleCrypto::digest(
ScriptState* script_state,
const V8AlgorithmIdentifier* raw_algorithm,
const V8BufferSource* raw_data,
ExceptionState& exception_state) { … }
ScriptPromise<IDLAny> SubtleCrypto::generateKey(
ScriptState* script_state,
const V8AlgorithmIdentifier* raw_algorithm,
bool extractable,
const Vector<String>& raw_key_usages,
ExceptionState& exception_state) { … }
ScriptPromise<CryptoKey> SubtleCrypto::importKey(
ScriptState* script_state,
const String& raw_format,
const V8UnionBufferSourceOrJsonWebKey* raw_key_data,
const V8AlgorithmIdentifier* raw_algorithm,
bool extractable,
const Vector<String>& raw_key_usages,
ExceptionState& exception_state) { … }
ScriptPromise<IDLAny> SubtleCrypto::exportKey(ScriptState* script_state,
const String& raw_format,
CryptoKey* key,
ExceptionState& exception_state) { … }
ScriptPromise<IDLAny> SubtleCrypto::wrapKey(
ScriptState* script_state,
const String& raw_format,
CryptoKey* key,
CryptoKey* wrapping_key,
const V8AlgorithmIdentifier* raw_wrap_algorithm,
ExceptionState& exception_state) { … }
ScriptPromise<CryptoKey> SubtleCrypto::unwrapKey(
ScriptState* script_state,
const String& raw_format,
const V8BufferSource* raw_wrapped_key,
CryptoKey* unwrapping_key,
const V8AlgorithmIdentifier* raw_unwrap_algorithm,
const V8AlgorithmIdentifier* raw_unwrapped_key_algorithm,
bool extractable,
const Vector<String>& raw_key_usages,
ExceptionState& exception_state) { … }
ScriptPromise<DOMArrayBuffer> SubtleCrypto::deriveBits(
ScriptState* script_state,
const V8AlgorithmIdentifier* raw_algorithm,
CryptoKey* base_key,
std::optional<unsigned> length_bits,
ExceptionState& exception_state) { … }
ScriptPromise<IDLAny> SubtleCrypto::deriveKey(
ScriptState* script_state,
const V8AlgorithmIdentifier* raw_algorithm,
CryptoKey* base_key,
const V8AlgorithmIdentifier* raw_derived_key_type,
bool extractable,
const Vector<String>& raw_key_usages,
ExceptionState& exception_state) { … }
}