#pragma once
#include "CryptoAlgorithmIdentifier.h"
#include "CryptoKeyFormat.h"
#include "CryptoKeyPair.h"
#include "CryptoKeyUsage.h"
#include "ExceptionOr.h"
#include "JsonWebKey.h"
#include "SubtleCrypto.h"
#include <wtf/Function.h>
#include <wtf/ThreadSafeRefCounted.h>
#include <wtf/Variant.h>
#include <wtf/Vector.h>
#include <wtf/WorkQueue.h>
#if ENABLE(WEB_CRYPTO)
namespace WebCore {
class CryptoAlgorithmParameters;
class CryptoKey;
class ScriptExecutionContext;
using KeyData = Variant<Vector<uint8_t>, JsonWebKey>;
using KeyOrKeyPair = Variant<RefPtr<CryptoKey>, CryptoKeyPair>;
class CryptoAlgorithm : public ThreadSafeRefCounted<CryptoAlgorithm> {
public:
virtual ~CryptoAlgorithm() = default;
virtual CryptoAlgorithmIdentifier identifier() const = 0;
using BoolCallback = WTF::Function<void(bool)>;
using KeyCallback = WTF::Function<void(CryptoKey&)>;
using KeyOrKeyPairCallback = WTF::Function<void(KeyOrKeyPair&&)>;
using VectorCallback = WTF::Function<void(const Vector<uint8_t>&)>;
using VoidCallback = WTF::Function<void()>;
using ExceptionCallback = WTF::Function<void(ExceptionCode)>;
using KeyDataCallback = WTF::Function<void(CryptoKeyFormat, KeyData&&)>;
virtual void encrypt(const CryptoAlgorithmParameters&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&);
virtual void decrypt(const CryptoAlgorithmParameters&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&);
virtual void sign(const CryptoAlgorithmParameters&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&);
virtual void verify(const CryptoAlgorithmParameters&, Ref<CryptoKey>&&, Vector<uint8_t>&& signature, Vector<uint8_t>&&, BoolCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&);
virtual void digest(Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&);
virtual void generateKey(const CryptoAlgorithmParameters&, bool extractable, CryptoKeyUsageBitmap, KeyOrKeyPairCallback&&, ExceptionCallback&&, ScriptExecutionContext&);
virtual void deriveBits(const CryptoAlgorithmParameters&, Ref<CryptoKey>&&, size_t length, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&);
virtual void importKey(CryptoKeyFormat, KeyData&&, const CryptoAlgorithmParameters&, bool extractable, CryptoKeyUsageBitmap, KeyCallback&&, ExceptionCallback&&);
virtual void exportKey(CryptoKeyFormat, Ref<CryptoKey>&&, KeyDataCallback&&, ExceptionCallback&&);
virtual void wrapKey(Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&);
virtual void unwrapKey(Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&);
virtual ExceptionOr<size_t> getKeyLength(const CryptoAlgorithmParameters&);
static void dispatchOperationInWorkQueue(WorkQueue&, ScriptExecutionContext&, VectorCallback&&, ExceptionCallback&&, WTF::Function<ExceptionOr<Vector<uint8_t>>()>&&);
static void dispatchOperationInWorkQueue(WorkQueue&, ScriptExecutionContext&, BoolCallback&&, ExceptionCallback&&, WTF::Function<ExceptionOr<bool>()>&&);
};
}
#endif // ENABLE(WEB_CRYPTO)