CryptoAlgorithmSHA384.cpp [plain text]
#include "config.h"
#include "CryptoAlgorithmSHA384.h"
#if ENABLE(SUBTLE_CRYPTO)
#include "ExceptionCode.h"
#include "ScriptExecutionContext.h"
#include <pal/crypto/CryptoDigest.h>
namespace WebCore {
Ref<CryptoAlgorithm> CryptoAlgorithmSHA384::create()
{
return adoptRef(*new CryptoAlgorithmSHA384);
}
CryptoAlgorithmIdentifier CryptoAlgorithmSHA384::identifier() const
{
return s_identifier;
}
void CryptoAlgorithmSHA384::digest(Vector<uint8_t>&& message, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
{
auto digest = PAL::CryptoDigest::create(PAL::CryptoDigest::Algorithm::SHA_384);
if (!digest) {
exceptionCallback(OperationError);
return;
}
context.ref();
workQueue.dispatch([digest = WTFMove(digest), message = WTFMove(message), callback = WTFMove(callback), &context]() mutable {
digest->addBytes(message.data(), message.size());
auto result = digest->computeHash();
context.postTask([callback = WTFMove(callback), result = WTFMove(result)](ScriptExecutionContext& context) {
callback(result);
context.deref();
});
});
}
ExceptionOr<void> CryptoAlgorithmSHA384::digest(const CryptoAlgorithmParametersDeprecated&, const CryptoOperationData& data, VectorCallback&& callback, VoidCallback&& failureCallback)
{
auto digest = PAL::CryptoDigest::create(PAL::CryptoDigest::Algorithm::SHA_384);
if (!digest) {
failureCallback();
return { };
}
digest->addBytes(data.first, data.second);
callback(digest->computeHash());
return { };
}
}
#endif // ENABLE(SUBTLE_CRYPTO)