#include <stddef.h>
#include <stdint.h>
#include <string_view>
#include "base/check_op.h"
#include "base/containers/span.h"
#include "base/strings/string_util.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.h"
#include "third_party/blink/public/platform/web_crypto_key_algorithm.h"
namespace webcrypto {
namespace {
base::Value::Dict BuildTestJwkPublicKey() { … }
base::Value::Dict BuildTestJwkPrivateKey() { … }
void SwapDictMembers(base::Value::Dict& d, const char* a, const char* b) { … }
std::string FlipHexByte(std::string_view hex, size_t index) { … }
blink::WebCryptoAlgorithm RS256Algorithm() { … }
blink::WebCryptoKey ImportJwkRS256OrDie(std::string_view jwk) { … }
blink::WebCryptoKey ImportJwkRS256OrDie(const base::Value::Dict& jwk) { … }
Status ImportJwkRS256MustFail(std::string_view jwk) { … }
Status ImportJwkRS256MustFail(const base::Value::Dict& jwk) { … }
Status ImportSpkiRS256MustFail(std::string_view spki) { … }
Status ImportPkcs8RS256MustFail(std::string_view pkcs8) { … }
std::vector<uint8_t> ExportPkcs8OrDie(blink::WebCryptoKey key) { … }
class WebCryptoRsaSsaTest : public WebCryptoTestBase { … };
TEST_F(WebCryptoRsaSsaTest, ImportExportSpki) { … }
TEST_F(WebCryptoRsaSsaTest, ImportExportPkcs8) { … }
TEST_F(WebCryptoRsaSsaTest, ImportRsaPrivateKeyJwkToPkcs8RoundTrip) { … }
const char kRsa512Jwk_0[] = …;
const char kRsa512Jwk_0_Damaged[] = …;
const char kRsa512Pkcs8_0[] = …;
const char kRsa512Jwk_1[] = …;
const char kRsa512Pkcs8_1[] = …;
TEST_F(WebCryptoRsaSsaTest, ImportMultipleRsaKeysJwk) { … }
TEST_F(WebCryptoRsaSsaTest, ImportCorruptKeyReusedModulus) { … }
TEST_F(WebCryptoRsaSsaTest, GenerateKeyPairRsa) { … }
TEST_F(WebCryptoRsaSsaTest, GenerateKeyPairRsaBadModulusLength) { … }
TEST_F(WebCryptoRsaSsaTest, GenerateKeyPairRsaBadExponent) { … }
TEST_F(WebCryptoRsaSsaTest, SignVerifyFailures) { … }
TEST_F(WebCryptoRsaSsaTest, ImportRsaSsaPublicKeyBadUsage_SPKI) { … }
TEST_F(WebCryptoRsaSsaTest, ImportRsaSsaPublicKeyBadUsage_JWK) { … }
TEST_F(WebCryptoRsaSsaTest, GenerateKeyBadUsages) { … }
TEST_F(WebCryptoRsaSsaTest, GenerateKeyPairIntersectUsages) { … }
TEST_F(WebCryptoRsaSsaTest, GenerateKeyPairEmptyUsages) { … }
TEST_F(WebCryptoRsaSsaTest, ImportKeyEmptyUsages) { … }
TEST_F(WebCryptoRsaSsaTest, ImportExportJwkRsaPublicKey) { … }
TEST_F(WebCryptoRsaSsaTest, ImportJwkRsaFailures) { … }
TEST_F(WebCryptoRsaSsaTest, ImportRsaSsaJwkBadUsageAndData) { … }
TEST_F(WebCryptoRsaSsaTest, ImportValidJwkPrivateKey) { … }
TEST_F(WebCryptoRsaSsaTest, ImportInvalidJwkPrivateKey_SwapPQ) { … }
TEST_F(WebCryptoRsaSsaTest, ImportInvalidJwkPrivateKey_SwapPQDPDQ) { … }
TEST_F(WebCryptoRsaSsaTest, ImportInvalidJwkPrivateKey_MissingMostOptionals) { … }
TEST_F(WebCryptoRsaSsaTest, ImportInvalidJwkPrivateKey_MissingAllOptionals) { … }
TEST_F(WebCryptoRsaSsaTest, ImportInvalidJwkPrivateKey_LeadingZeroesOnE) { … }
TEST_F(WebCryptoRsaSsaTest, ImportInvalidJwkPrivateKey_Base64PaddingInD) { … }
TEST_F(WebCryptoRsaSsaTest, ImportInvalidJwkPrivateKey_Base64UrlInN) { … }
TEST_F(WebCryptoRsaSsaTest, ImportInvalidJwkPrivateKey_Base64UrlInDQ) { … }
TEST_F(WebCryptoRsaSsaTest, ImportInvalidSpki_Empty) { … }
TEST_F(WebCryptoRsaSsaTest, ImportInvalidSpki_BadDER) { … }
TEST_F(WebCryptoRsaSsaTest, ImportInvalidSpki_NotRSA) { … }
TEST_F(WebCryptoRsaSsaTest, ImportInvalidSpki_TrailingData) { … }
TEST_F(WebCryptoRsaSsaTest, ImportInvalidPkcs8_Empty) { … }
TEST_F(WebCryptoRsaSsaTest, ImportInvalidPkcs8_BadDER) { … }
TEST_F(WebCryptoRsaSsaTest, ImportInvalidPkcs8_CRTValuesAreZero) { … }
TEST_F(WebCryptoRsaSsaTest, ImportInvalidPkcs8_NotRSA) { … }
TEST_F(WebCryptoRsaSsaTest, ImportInvalidPkcs8_TrailingData) { … }
TEST_F(WebCryptoRsaSsaTest, ImportInvalidPkcs8_CorruptFields) { … }
}
}