#ifndef COMPONENTS_WEBCRYPTO_ALGORITHMS_TEST_HELPERS_H_
#define COMPONENTS_WEBCRYPTO_ALGORITHMS_TEST_HELPERS_H_
#include <stdint.h>
#include <memory>
#include <optional>
#include <ostream>
#include <string>
#include <string_view>
#include <vector>
#include "base/strings/string_number_conversions.h"
#include "base/values.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/platform/web_crypto_algorithm.h"
#include "third_party/blink/public/platform/web_crypto_key.h"
#define EXPECT_BYTES_EQ(expected, actual) …
#define EXPECT_BYTES_EQ_HEX(expected_hex, actual_bytes) …
namespace blink {
class WebCryptoAlgorithm;
}
namespace webcrypto {
class WebCryptoTestBase : public testing::Test { … };
class Status;
void PrintTo(const Status& status, ::std::ostream* os);
bool operator==(const Status& a, const Status& b);
bool operator!=(const Status& a, const Status& b);
std::string StatusToString(const Status& status);
blink::WebCryptoAlgorithm CreateRsaHashedKeyGenAlgorithm(
blink::WebCryptoAlgorithmId algorithm_id,
const blink::WebCryptoAlgorithmId hash_id,
unsigned int modulus_length,
const std::vector<uint8_t>& public_exponent);
std::vector<uint8_t> Corrupted(const std::vector<uint8_t>& input);
std::vector<uint8_t> HexStringToBytes(std::string_view hex);
std::vector<uint8_t> MakeJsonVector(const base::ValueView& value);
base::Value::List ReadJsonTestFileAsList(const char* test_file_name);
std::vector<uint8_t> GetBytesFromHexString(const base::Value::Dict& dict,
std::string_view property_name);
blink::WebCryptoAlgorithm GetDigestAlgorithm(const base::Value::Dict& dict,
const char* property_name);
bool CopiesExist(const std::vector<std::vector<uint8_t>>& bufs);
blink::WebCryptoAlgorithm CreateAesKeyGenAlgorithm(
blink::WebCryptoAlgorithmId aes_alg_id,
uint16_t length);
extern const unsigned int kModulusLengthBits;
extern const char* const kPublicKeySpkiDerHex;
extern const char* const kPrivateKeyPkcs8DerHex;
extern const char* const kPublicKeyModulusHex;
extern const char* const kPublicKeyExponentHex;
blink::WebCryptoKey ImportSecretKeyFromRaw(
const std::vector<uint8_t>& key_raw,
const blink::WebCryptoAlgorithm& algorithm,
blink::WebCryptoKeyUsageMask usage);
void ImportRsaKeyPair(const std::vector<uint8_t>& spki_der,
const std::vector<uint8_t>& pkcs8_der,
const blink::WebCryptoAlgorithm& algorithm,
bool extractable,
blink::WebCryptoKeyUsageMask public_key_usages,
blink::WebCryptoKeyUsageMask private_key_usages,
blink::WebCryptoKey* public_key,
blink::WebCryptoKey* private_key);
Status ImportKeyJwkFromDict(const base::ValueView& dict,
const blink::WebCryptoAlgorithm& algorithm,
bool extractable,
blink::WebCryptoKeyUsageMask usages,
blink::WebCryptoKey* key);
std::optional<base::Value::Dict> GetJwkDictionary(
const std::vector<uint8_t>& json);
::testing::AssertionResult VerifyJwk(
const base::Value::Dict& dict,
std::string_view kty_expected,
std::string_view alg_expected,
blink::WebCryptoKeyUsageMask use_mask_expected);
::testing::AssertionResult VerifySecretJwk(
const std::vector<uint8_t>& json,
std::string_view alg_expected,
std::string_view k_expected_hex,
blink::WebCryptoKeyUsageMask use_mask_expected);
::testing::AssertionResult VerifyPublicJwk(
const std::vector<uint8_t>& json,
std::string_view alg_expected,
std::string_view n_expected_hex,
std::string_view e_expected_hex,
blink::WebCryptoKeyUsageMask use_mask_expected);
void ImportExportJwkSymmetricKey(
int key_len_bits,
const blink::WebCryptoAlgorithm& import_algorithm,
blink::WebCryptoKeyUsageMask usages,
std::string_view jwk_alg);
Status GenerateSecretKey(const blink::WebCryptoAlgorithm& algorithm,
bool extractable,
blink::WebCryptoKeyUsageMask usages,
blink::WebCryptoKey* key);
Status GenerateKeyPair(const blink::WebCryptoAlgorithm& algorithm,
bool extractable,
blink::WebCryptoKeyUsageMask usages,
blink::WebCryptoKey* public_key,
blink::WebCryptoKey* private_key);
blink::WebCryptoKeyFormat GetKeyFormatFromJsonTestCase(
const base::Value::Dict& test);
std::vector<uint8_t> GetKeyDataFromJsonTestCase(
const base::Value::Dict& test,
blink::WebCryptoKeyFormat key_format);
blink::WebCryptoNamedCurve GetCurveNameFromDictionary(
const base::Value::Dict& dict);
blink::WebCryptoNamedCurve CurveNameToCurve(std::string_view name);
blink::WebCryptoAlgorithm CreateHmacImportAlgorithm(
blink::WebCryptoAlgorithmId hash_id,
unsigned int length_bits);
blink::WebCryptoAlgorithm CreateHmacImportAlgorithmNoLength(
blink::WebCryptoAlgorithmId hash_id);
blink::WebCryptoAlgorithm CreateAlgorithm(blink::WebCryptoAlgorithmId id);
blink::WebCryptoAlgorithm CreateRsaHashedImportAlgorithm(
blink::WebCryptoAlgorithmId id,
blink::WebCryptoAlgorithmId hash_id);
blink::WebCryptoAlgorithm CreateEcImportAlgorithm(
blink::WebCryptoAlgorithmId id,
blink::WebCryptoNamedCurve named_curve);
}
#endif