#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include <limits.h>
#include <stddef.h>
#include <stdint.h>
#include <memory>
#include <utility>
#include "base/check.h"
#include "base/containers/contains.h"
#include "base/containers/flat_set.h"
#include "base/containers/span.h"
#include "base/values.h"
#include "components/webcrypto/algorithm_dispatch.h"
#include "components/webcrypto/algorithms/test_helpers.h"
#include "components/webcrypto/status.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/platform/web_crypto_algorithm_params.h"
#include "third_party/blink/public/platform/web_crypto_key_algorithm.h"
namespace webcrypto {
namespace {
blink::WebCryptoAlgorithm CreateHmacKeyGenAlgorithm(
blink::WebCryptoAlgorithmId hash_id,
unsigned int key_length_bits) { … }
blink::WebCryptoAlgorithm CreateHmacImportAlgorithmWithLength(
blink::WebCryptoAlgorithmId hash_id,
unsigned int length_bits) { … }
blink::WebCryptoKey GenerateHmacKey(blink::WebCryptoAlgorithmId hash,
size_t key_length_bits) { … }
class WebCryptoHmacTest : public WebCryptoTestBase { … };
struct HmacKnownAnswer { … };
const HmacKnownAnswer kHmacKnownAnswers[] = …;
blink::WebCryptoKey HmacKeyFromHexBytes(blink::WebCryptoAlgorithmId hash,
const char* key) { … }
std::vector<uint8_t> BytesFromHmacKey(blink::WebCryptoKey key) { … }
std::vector<uint8_t> HmacSign(blink::WebCryptoKey key,
const std::vector<uint8_t>& message) { … }
bool HmacVerify(blink::WebCryptoKey key,
const std::vector<uint8_t>& message,
const std::vector<uint8_t>& hmac) { … }
TEST_F(WebCryptoHmacTest, KnownAnswers) { … }
TEST_F(WebCryptoHmacTest, GeneratedKeysHaveExpectedProperties) { … }
TEST_F(WebCryptoHmacTest, GeneratedKeysAreRandomIsh) { … }
TEST_F(WebCryptoHmacTest, GeneratedKeysDefaultToBlockSize) { … }
TEST_F(WebCryptoHmacTest, Generating1BitKeyWorks) { … }
TEST_F(WebCryptoHmacTest, GenerateKeyEmptyUsage) { … }
TEST_F(WebCryptoHmacTest, ImportKeyEmptyUsage) { … }
TEST_F(WebCryptoHmacTest, ImportKeyJwkKeyOpsSignVerify) { … }
TEST_F(WebCryptoHmacTest, ImportKeyJwkUseInconsisteWithKeyOps) { … }
TEST_F(WebCryptoHmacTest, ImportKeyJwkUseSig) { … }
TEST_F(WebCryptoHmacTest, ImportJwkInputConsistency) { … }
TEST_F(WebCryptoHmacTest, ImportJwkHappy) { … }
TEST_F(WebCryptoHmacTest, ImportExportJwk) { … }
TEST_F(WebCryptoHmacTest, ExportJwkEmptyKey) { … }
TEST_F(WebCryptoHmacTest, ImportRawEmptyKey) { … }
TEST_F(WebCryptoHmacTest, ImportRawKeyWithZeroLength) { … }
TEST_F(WebCryptoHmacTest, ImportRawKeyTooLarge) { … }
TEST_F(WebCryptoHmacTest, ImportRawKeyLengthTooLarge) { … }
TEST_F(WebCryptoHmacTest, ImportRawKeyLengthTooSmall) { … }
TEST_F(WebCryptoHmacTest, ImportRawKeyTruncation) { … }
TEST_F(WebCryptoHmacTest, ImportJwkKeyTruncation) { … }
}
}