ExceptionOr<void> CryptoAlgorithmHMAC::platformSign(const CryptoAlgorithmHmacParamsDeprecated& parameters, const CryptoKeyHMAC& key, const CryptoOperationData& data, VectorCallback&& callback, VoidCallback&&)
{
    auto algorithm = commonCryptoHMACAlgorithm(parameters.hash);
    if (!algorithm)
        return Exception { NOT_SUPPORTED_ERR };
    callback(calculateSignature(*algorithm, key.key(), data));
    return { };
}
void CryptoAlgorithmHMAC::platformSign(const CryptoAlgorithmHmacParams& parameters, const CryptoKeyHMAC& key, const CryptoOperationData& data, VectorCallback&& callback, VoidCallback&&, ExceptionCode& ec)
{
    CCHmacAlgorithm algorithm;
    if (!getCommonCryptoHMACAlgorithm(parameters.hash, algorithm)) {
        ec = NOT_SUPPORTED_ERR;
        return;
    }

    Vector<uint8_t> signature = calculateSignature(algorithm, key.key(), data);

    callback(signature);
}
void CryptoAlgorithmHMAC::platformVerify(const CryptoAlgorithmHmacParams& parameters, const CryptoKeyHMAC& key, const CryptoOperationData& expectedSignature, const CryptoOperationData& data, BoolCallback&& callback, VoidCallback&&, ExceptionCode& ec)
{
    CCHmacAlgorithm algorithm;
    if (!getCommonCryptoHMACAlgorithm(parameters.hash, algorithm)) {
        ec = NOT_SUPPORTED_ERR;
        return;
    }

    Vector<uint8_t> signature = calculateSignature(algorithm, key.key(), data);

    // Using a constant time comparison to prevent timing attacks.
    bool result = signature.size() == expectedSignature.second && !constantTimeMemcmp(signature.data(), expectedSignature.first, signature.size());

    callback(result);
}
ExceptionOr<void> CryptoAlgorithmHMAC::platformVerify(const CryptoAlgorithmHmacParamsDeprecated& parameters, const CryptoKeyHMAC& key, const CryptoOperationData& expectedSignature, const CryptoOperationData& data, BoolCallback&& callback, VoidCallback&&)
{
    auto algorithm = commonCryptoHMACAlgorithm(parameters.hash);
    if (!algorithm)
        return Exception { NOT_SUPPORTED_ERR };

    auto signature = calculateSignature(*algorithm, key.key(), data);

    // Using a constant time comparison to prevent timing attacks.
    bool result = signature.size() == expectedSignature.second && !constantTimeMemcmp(signature.data(), expectedSignature.first, signature.size());

    callback(result);

    return { };
}