#ifndef CryptoAlgorithm_h
#define CryptoAlgorithm_h
#include "CryptoAlgorithmIdentifier.h"
#include "CryptoKeyUsage.h"
#include <functional>
#include <wtf/Noncopyable.h>
#include <wtf/RefCounted.h>
#include <wtf/Vector.h>
#if ENABLE(SUBTLE_CRYPTO)
namespace WebCore {
typedef int ExceptionCode;
class CryptoAlgorithmParameters;
class CryptoKey;
class CryptoKeyPair;
class CryptoKeyData;
typedef std::pair<const uint8_t*, size_t> CryptoOperationData;
class CryptoAlgorithm : public RefCounted<CryptoAlgorithm> {
WTF_MAKE_NONCOPYABLE(CryptoAlgorithm)
public:
virtual ~CryptoAlgorithm();
virtual CryptoAlgorithmIdentifier identifier() const = 0;
typedef std::function<void(bool)> BoolCallback;
typedef std::function<void(CryptoKey&)> KeyCallback;
typedef std::function<void(CryptoKey*, CryptoKeyPair*)> KeyOrKeyPairCallback;
typedef std::function<void(const Vector<uint8_t>&)> VectorCallback;
typedef std::function<void()> VoidCallback;
virtual void encrypt(const CryptoAlgorithmParameters&, const CryptoKey&, const CryptoOperationData&, VectorCallback&&, VoidCallback&& failureCallback, ExceptionCode&);
virtual void decrypt(const CryptoAlgorithmParameters&, const CryptoKey&, const CryptoOperationData&, VectorCallback&&, VoidCallback&& failureCallback, ExceptionCode&);
virtual void sign(const CryptoAlgorithmParameters&, const CryptoKey&, const CryptoOperationData&, VectorCallback&&, VoidCallback&& failureCallback, ExceptionCode&);
virtual void verify(const CryptoAlgorithmParameters&, const CryptoKey&, const CryptoOperationData& signature, const CryptoOperationData& data, BoolCallback&&, VoidCallback&& failureCallback, ExceptionCode&);
virtual void digest(const CryptoAlgorithmParameters&, const CryptoOperationData&, VectorCallback&&, VoidCallback&& failureCallback, ExceptionCode&);
virtual void generateKey(const CryptoAlgorithmParameters&, bool extractable, CryptoKeyUsage, KeyOrKeyPairCallback&&, VoidCallback&& failureCallback, ExceptionCode&);
virtual void deriveKey(const CryptoAlgorithmParameters&, const CryptoKey& baseKey, CryptoAlgorithm* derivedKeyType, bool extractable, CryptoKeyUsage, KeyCallback&&, VoidCallback&& failureCallback, ExceptionCode&);
virtual void deriveBits(const CryptoAlgorithmParameters&, const CryptoKey& baseKey, unsigned long length, VectorCallback&&, VoidCallback&& failureCallback, ExceptionCode&);
virtual void importKey(const CryptoAlgorithmParameters&, const CryptoKeyData&, bool extractable, CryptoKeyUsage, KeyCallback&&, VoidCallback&& failureCallback, ExceptionCode&);
virtual void encryptForWrapKey(const CryptoAlgorithmParameters&, const CryptoKey&, const CryptoOperationData&, VectorCallback&&, VoidCallback&& failureCallback, ExceptionCode&);
virtual void decryptForUnwrapKey(const CryptoAlgorithmParameters&, const CryptoKey&, const CryptoOperationData&, VectorCallback&&, VoidCallback&& failureCallback, ExceptionCode&);
protected:
CryptoAlgorithm();
};
}
#endif // ENABLE(SUBTLE_CRYPTO)
#endif // CryptoAlgorithm_h