CryptoAlgorithmPBKDF2.cpp [plain text]
#include "config.h"
#include "CryptoAlgorithmPBKDF2.h"
#if ENABLE(SUBTLE_CRYPTO)
#include "CryptoAlgorithmParameters.h"
#include "CryptoKeyRaw.h"
#include "ExceptionCode.h"
namespace WebCore {
Ref<CryptoAlgorithm> CryptoAlgorithmPBKDF2::create()
{
return adoptRef(*new CryptoAlgorithmPBKDF2);
}
CryptoAlgorithmIdentifier CryptoAlgorithmPBKDF2::identifier() const
{
return s_identifier;
}
void CryptoAlgorithmPBKDF2::deriveBits(std::unique_ptr<CryptoAlgorithmParameters>&& parameters, Ref<CryptoKey>&& baseKey, size_t length, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
{
if (!length || length % 8) {
exceptionCallback(OperationError);
return;
}
platformDeriveBits(WTFMove(parameters), WTFMove(baseKey), length, WTFMove(callback), WTFMove(exceptionCallback), context, workQueue);
}
void CryptoAlgorithmPBKDF2::importKey(SubtleCrypto::KeyFormat format, KeyData&& data, const std::unique_ptr<CryptoAlgorithmParameters>&& parameters, bool extractable, CryptoKeyUsageBitmap usages, KeyCallback&& callback, ExceptionCallback&& exceptionCallback)
{
if (format != SubtleCrypto::KeyFormat::Raw) {
exceptionCallback(NOT_SUPPORTED_ERR);
return;
}
if (usages & (CryptoKeyUsageEncrypt | CryptoKeyUsageDecrypt | CryptoKeyUsageSign | CryptoKeyUsageVerify | CryptoKeyUsageWrapKey | CryptoKeyUsageUnwrapKey)) {
exceptionCallback(SYNTAX_ERR);
return;
}
if (extractable) {
exceptionCallback(SYNTAX_ERR);
return;
}
callback(CryptoKeyRaw::create(parameters->identifier, WTFMove(WTF::get<Vector<uint8_t>>(data)), usages));
}
ExceptionOr<size_t> CryptoAlgorithmPBKDF2::getKeyLength(const CryptoAlgorithmParameters&)
{
return 0;
}
}
#endif // ENABLE(SUBTLE_CRYPTO)