Commit 7b9591ab authored by eroman's avatar eroman Committed by Commit bot

Cleanup: Use default constructor for WebCryptoKey rather than createNull() factory method.

BUG=425251

Review URL: https://codereview.chromium.org/670433005

Cr-Commit-Position: refs/heads/master@{#300507}
parent 17d3d939
...@@ -10,11 +10,7 @@ namespace content { ...@@ -10,11 +10,7 @@ namespace content {
namespace webcrypto { namespace webcrypto {
GenerateKeyResult::GenerateKeyResult() GenerateKeyResult::GenerateKeyResult() : type_(TYPE_NULL) {
: type_(TYPE_NULL),
secret_key_(blink::WebCryptoKey::createNull()),
public_key_(blink::WebCryptoKey::createNull()),
private_key_(blink::WebCryptoKey::createNull()) {
} }
GenerateKeyResult::Type GenerateKeyResult::type() const { GenerateKeyResult::Type GenerateKeyResult::type() const {
......
...@@ -284,8 +284,8 @@ Status RsaHashedAlgorithm::GenerateKey( ...@@ -284,8 +284,8 @@ Status RsaHashedAlgorithm::GenerateKey(
return Status::OperationError(); return Status::OperationError();
} }
blink::WebCryptoKey public_key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey public_key;
blink::WebCryptoKey private_key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey private_key;
// Note that extractable is unconditionally set to true. This is because per // Note that extractable is unconditionally set to true. This is because per
// the WebCrypto spec generated public keys are always public. // the WebCrypto spec generated public keys are always public.
......
...@@ -110,7 +110,7 @@ TEST(WebCryptoAesCbcTest, KeyTooSmall) { ...@@ -110,7 +110,7 @@ TEST(WebCryptoAesCbcTest, KeyTooSmall) {
std::vector<uint8_t> key_raw(1); std::vector<uint8_t> key_raw(1);
std::vector<uint8_t> iv(16); std::vector<uint8_t> iv(16);
blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey key;
EXPECT_EQ(Status::ErrorImportAesKeyLength(), EXPECT_EQ(Status::ErrorImportAesKeyLength(),
ImportKey(blink::WebCryptoKeyFormatRaw, ImportKey(blink::WebCryptoKeyFormatRaw,
CryptoData(key_raw), CryptoData(key_raw),
...@@ -134,7 +134,7 @@ TEST(WebCryptoAesCbcTest, ExportKeyUnsupportedFormat) { ...@@ -134,7 +134,7 @@ TEST(WebCryptoAesCbcTest, ExportKeyUnsupportedFormat) {
} }
TEST(WebCryptoAesCbcTest, ImportKeyUnsupportedFormat) { TEST(WebCryptoAesCbcTest, ImportKeyUnsupportedFormat) {
blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey key;
ASSERT_EQ(Status::ErrorUnsupportedImportKeyFormat(), ASSERT_EQ(Status::ErrorUnsupportedImportKeyFormat(),
ImportKey(blink::WebCryptoKeyFormatSpki, ImportKey(blink::WebCryptoKeyFormatSpki,
CryptoData(HexStringToBytes(kPublicKeySpkiDerHex)), CryptoData(HexStringToBytes(kPublicKeySpkiDerHex)),
...@@ -254,7 +254,7 @@ TEST(WebCryptoAesCbcTest, GenerateKeyIsRandom) { ...@@ -254,7 +254,7 @@ TEST(WebCryptoAesCbcTest, GenerateKeyIsRandom) {
const unsigned short kKeyLength[] = {128, 256}; const unsigned short kKeyLength[] = {128, 256};
for (size_t key_length_i = 0; key_length_i < arraysize(kKeyLength); for (size_t key_length_i = 0; key_length_i < arraysize(kKeyLength);
++key_length_i) { ++key_length_i) {
blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey key;
std::vector<std::vector<uint8_t> > keys; std::vector<std::vector<uint8_t> > keys;
std::vector<uint8_t> key_bytes; std::vector<uint8_t> key_bytes;
...@@ -283,7 +283,7 @@ TEST(WebCryptoAesCbcTest, GenerateKeyIsRandom) { ...@@ -283,7 +283,7 @@ TEST(WebCryptoAesCbcTest, GenerateKeyIsRandom) {
TEST(WebCryptoAesCbcTest, GenerateKeyBadLength) { TEST(WebCryptoAesCbcTest, GenerateKeyBadLength) {
const unsigned short kKeyLen[] = {0, 127, 257}; const unsigned short kKeyLen[] = {0, 127, 257};
blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey key;
for (size_t i = 0; i < arraysize(kKeyLen); ++i) { for (size_t i = 0; i < arraysize(kKeyLen); ++i) {
SCOPED_TRACE(i); SCOPED_TRACE(i);
EXPECT_EQ(Status::ErrorGenerateKeyLength(), EXPECT_EQ(Status::ErrorGenerateKeyLength(),
...@@ -294,7 +294,7 @@ TEST(WebCryptoAesCbcTest, GenerateKeyBadLength) { ...@@ -294,7 +294,7 @@ TEST(WebCryptoAesCbcTest, GenerateKeyBadLength) {
// If key_ops is specified but empty, no key usages are allowed for the key. // If key_ops is specified but empty, no key usages are allowed for the key.
TEST(WebCryptoAesCbcTest, ImportKeyJwkEmptyKeyOps) { TEST(WebCryptoAesCbcTest, ImportKeyJwkEmptyKeyOps) {
blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey key;
base::DictionaryValue dict; base::DictionaryValue dict;
dict.SetString("kty", "oct"); dict.SetString("kty", "oct");
dict.SetBoolean("ext", false); dict.SetBoolean("ext", false);
...@@ -332,7 +332,7 @@ TEST(WebCryptoAesCbcTest, ImportKeyJwkEmptyKeyOps) { ...@@ -332,7 +332,7 @@ TEST(WebCryptoAesCbcTest, ImportKeyJwkEmptyKeyOps) {
// If key_ops is missing, then any key usages can be specified. // If key_ops is missing, then any key usages can be specified.
TEST(WebCryptoAesCbcTest, ImportKeyJwkNoKeyOps) { TEST(WebCryptoAesCbcTest, ImportKeyJwkNoKeyOps) {
blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey key;
base::DictionaryValue dict; base::DictionaryValue dict;
dict.SetString("kty", "oct"); dict.SetString("kty", "oct");
dict.SetString("k", "GADWrMRHwQfoNaXU5fZvTg=="); dict.SetString("k", "GADWrMRHwQfoNaXU5fZvTg==");
...@@ -358,7 +358,7 @@ TEST(WebCryptoAesCbcTest, ImportKeyJwkNoKeyOps) { ...@@ -358,7 +358,7 @@ TEST(WebCryptoAesCbcTest, ImportKeyJwkNoKeyOps) {
} }
TEST(WebCryptoAesCbcTest, ImportKeyJwkKeyOpsEncryptDecrypt) { TEST(WebCryptoAesCbcTest, ImportKeyJwkKeyOpsEncryptDecrypt) {
blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey key;
base::DictionaryValue dict; base::DictionaryValue dict;
dict.SetString("kty", "oct"); dict.SetString("kty", "oct");
dict.SetString("k", "GADWrMRHwQfoNaXU5fZvTg=="); dict.SetString("k", "GADWrMRHwQfoNaXU5fZvTg==");
...@@ -404,7 +404,7 @@ TEST(WebCryptoAesCbcTest, ImportKeyJwkKeyOpsEncryptDecrypt) { ...@@ -404,7 +404,7 @@ TEST(WebCryptoAesCbcTest, ImportKeyJwkKeyOpsEncryptDecrypt) {
// Test failure if input usage is NOT a strict subset of the JWK usage. // Test failure if input usage is NOT a strict subset of the JWK usage.
TEST(WebCryptoAesCbcTest, ImportKeyJwkKeyOpsNotSuperset) { TEST(WebCryptoAesCbcTest, ImportKeyJwkKeyOpsNotSuperset) {
blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey key;
base::DictionaryValue dict; base::DictionaryValue dict;
dict.SetString("kty", "oct"); dict.SetString("kty", "oct");
dict.SetString("k", "GADWrMRHwQfoNaXU5fZvTg=="); dict.SetString("k", "GADWrMRHwQfoNaXU5fZvTg==");
...@@ -424,7 +424,7 @@ TEST(WebCryptoAesCbcTest, ImportKeyJwkKeyOpsNotSuperset) { ...@@ -424,7 +424,7 @@ TEST(WebCryptoAesCbcTest, ImportKeyJwkKeyOpsNotSuperset) {
} }
TEST(WebCryptoAesCbcTest, ImportKeyJwkUseEnc) { TEST(WebCryptoAesCbcTest, ImportKeyJwkUseEnc) {
blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey key;
base::DictionaryValue dict; base::DictionaryValue dict;
dict.SetString("kty", "oct"); dict.SetString("kty", "oct");
dict.SetString("k", "GADWrMRHwQfoNaXU5fZvTg=="); dict.SetString("k", "GADWrMRHwQfoNaXU5fZvTg==");
...@@ -449,7 +449,7 @@ TEST(WebCryptoAesCbcTest, ImportKeyJwkUseEnc) { ...@@ -449,7 +449,7 @@ TEST(WebCryptoAesCbcTest, ImportKeyJwkUseEnc) {
} }
TEST(WebCryptoAesCbcTest, ImportJwkInvalidJson) { TEST(WebCryptoAesCbcTest, ImportJwkInvalidJson) {
blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey key;
// Fail on empty JSON. // Fail on empty JSON.
EXPECT_EQ(Status::ErrorImportEmptyKeyData(), EXPECT_EQ(Status::ErrorImportEmptyKeyData(),
ImportKey(blink::WebCryptoKeyFormatJwk, ImportKey(blink::WebCryptoKeyFormatJwk,
...@@ -476,7 +476,7 @@ TEST(WebCryptoAesCbcTest, ImportJwkInvalidJson) { ...@@ -476,7 +476,7 @@ TEST(WebCryptoAesCbcTest, ImportJwkInvalidJson) {
// Fail on JWK alg present but incorrect (expecting A128CBC). // Fail on JWK alg present but incorrect (expecting A128CBC).
TEST(WebCryptoAesCbcTest, ImportJwkIncorrectAlg) { TEST(WebCryptoAesCbcTest, ImportJwkIncorrectAlg) {
blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey key;
base::DictionaryValue dict; base::DictionaryValue dict;
dict.SetString("kty", "oct"); dict.SetString("kty", "oct");
...@@ -494,7 +494,7 @@ TEST(WebCryptoAesCbcTest, ImportJwkIncorrectAlg) { ...@@ -494,7 +494,7 @@ TEST(WebCryptoAesCbcTest, ImportJwkIncorrectAlg) {
// Fail on invalid kty. // Fail on invalid kty.
TEST(WebCryptoAesCbcTest, ImportJwkInvalidKty) { TEST(WebCryptoAesCbcTest, ImportJwkInvalidKty) {
blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey key;
base::DictionaryValue dict; base::DictionaryValue dict;
dict.SetString("kty", "foo"); dict.SetString("kty", "foo");
...@@ -510,7 +510,7 @@ TEST(WebCryptoAesCbcTest, ImportJwkInvalidKty) { ...@@ -510,7 +510,7 @@ TEST(WebCryptoAesCbcTest, ImportJwkInvalidKty) {
// Fail on missing kty. // Fail on missing kty.
TEST(WebCryptoAesCbcTest, ImportJwkMissingKty) { TEST(WebCryptoAesCbcTest, ImportJwkMissingKty) {
blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey key;
base::DictionaryValue dict; base::DictionaryValue dict;
dict.SetString("k", "GADWrMRHwQfoNaXU5fZvTg=="); dict.SetString("k", "GADWrMRHwQfoNaXU5fZvTg==");
...@@ -525,7 +525,7 @@ TEST(WebCryptoAesCbcTest, ImportJwkMissingKty) { ...@@ -525,7 +525,7 @@ TEST(WebCryptoAesCbcTest, ImportJwkMissingKty) {
// Fail on kty wrong type. // Fail on kty wrong type.
TEST(WebCryptoAesCbcTest, ImportJwkKtyWrongType) { TEST(WebCryptoAesCbcTest, ImportJwkKtyWrongType) {
blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey key;
base::DictionaryValue dict; base::DictionaryValue dict;
dict.SetDouble("kty", 0.1); dict.SetDouble("kty", 0.1);
...@@ -542,7 +542,7 @@ TEST(WebCryptoAesCbcTest, ImportJwkKtyWrongType) { ...@@ -542,7 +542,7 @@ TEST(WebCryptoAesCbcTest, ImportJwkKtyWrongType) {
// Fail on invalid use. // Fail on invalid use.
TEST(WebCryptoAesCbcTest, ImportJwkUnrecognizedUse) { TEST(WebCryptoAesCbcTest, ImportJwkUnrecognizedUse) {
blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey key;
base::DictionaryValue dict; base::DictionaryValue dict;
dict.SetString("kty", "oct"); dict.SetString("kty", "oct");
...@@ -560,7 +560,7 @@ TEST(WebCryptoAesCbcTest, ImportJwkUnrecognizedUse) { ...@@ -560,7 +560,7 @@ TEST(WebCryptoAesCbcTest, ImportJwkUnrecognizedUse) {
// Fail on invalid use (wrong type). // Fail on invalid use (wrong type).
TEST(WebCryptoAesCbcTest, ImportJwkUseWrongType) { TEST(WebCryptoAesCbcTest, ImportJwkUseWrongType) {
blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey key;
base::DictionaryValue dict; base::DictionaryValue dict;
dict.SetString("kty", "oct"); dict.SetString("kty", "oct");
...@@ -578,7 +578,7 @@ TEST(WebCryptoAesCbcTest, ImportJwkUseWrongType) { ...@@ -578,7 +578,7 @@ TEST(WebCryptoAesCbcTest, ImportJwkUseWrongType) {
// Fail on invalid extractable (wrong type). // Fail on invalid extractable (wrong type).
TEST(WebCryptoAesCbcTest, ImportJwkExtWrongType) { TEST(WebCryptoAesCbcTest, ImportJwkExtWrongType) {
blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey key;
base::DictionaryValue dict; base::DictionaryValue dict;
dict.SetString("kty", "oct"); dict.SetString("kty", "oct");
...@@ -596,7 +596,7 @@ TEST(WebCryptoAesCbcTest, ImportJwkExtWrongType) { ...@@ -596,7 +596,7 @@ TEST(WebCryptoAesCbcTest, ImportJwkExtWrongType) {
// Fail on invalid key_ops (wrong type). // Fail on invalid key_ops (wrong type).
TEST(WebCryptoAesCbcTest, ImportJwkKeyOpsWrongType) { TEST(WebCryptoAesCbcTest, ImportJwkKeyOpsWrongType) {
blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey key;
base::DictionaryValue dict; base::DictionaryValue dict;
dict.SetString("kty", "oct"); dict.SetString("kty", "oct");
...@@ -615,7 +615,7 @@ TEST(WebCryptoAesCbcTest, ImportJwkKeyOpsWrongType) { ...@@ -615,7 +615,7 @@ TEST(WebCryptoAesCbcTest, ImportJwkKeyOpsWrongType) {
// Fail on inconsistent key_ops - asking for "encrypt" however JWK contains // Fail on inconsistent key_ops - asking for "encrypt" however JWK contains
// only "foo". // only "foo".
TEST(WebCryptoAesCbcTest, ImportJwkKeyOpsLacksUsages) { TEST(WebCryptoAesCbcTest, ImportJwkKeyOpsLacksUsages) {
blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey key;
base::DictionaryValue dict; base::DictionaryValue dict;
dict.SetString("kty", "oct"); dict.SetString("kty", "oct");
...@@ -636,7 +636,7 @@ TEST(WebCryptoAesCbcTest, ImportJwkKeyOpsLacksUsages) { ...@@ -636,7 +636,7 @@ TEST(WebCryptoAesCbcTest, ImportJwkKeyOpsLacksUsages) {
// Import a JWK with unrecognized values for "key_ops". // Import a JWK with unrecognized values for "key_ops".
TEST(WebCryptoAesCbcTest, ImportJwkUnrecognizedKeyOps) { TEST(WebCryptoAesCbcTest, ImportJwkUnrecognizedKeyOps) {
blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey key;
blink::WebCryptoAlgorithm algorithm = blink::WebCryptoAlgorithm algorithm =
CreateAlgorithm(blink::WebCryptoAlgorithmIdAesCbc); CreateAlgorithm(blink::WebCryptoAlgorithmIdAesCbc);
blink::WebCryptoKeyUsageMask usage_mask = blink::WebCryptoKeyUsageEncrypt; blink::WebCryptoKeyUsageMask usage_mask = blink::WebCryptoKeyUsageEncrypt;
...@@ -660,7 +660,7 @@ TEST(WebCryptoAesCbcTest, ImportJwkUnrecognizedKeyOps) { ...@@ -660,7 +660,7 @@ TEST(WebCryptoAesCbcTest, ImportJwkUnrecognizedKeyOps) {
// Import a JWK with a value in key_ops array that is not a string. // Import a JWK with a value in key_ops array that is not a string.
TEST(WebCryptoAesCbcTest, ImportJwkNonStringKeyOp) { TEST(WebCryptoAesCbcTest, ImportJwkNonStringKeyOp) {
blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey key;
blink::WebCryptoAlgorithm algorithm = blink::WebCryptoAlgorithm algorithm =
CreateAlgorithm(blink::WebCryptoAlgorithmIdAesCbc); CreateAlgorithm(blink::WebCryptoAlgorithmIdAesCbc);
blink::WebCryptoKeyUsageMask usage_mask = blink::WebCryptoKeyUsageEncrypt; blink::WebCryptoKeyUsageMask usage_mask = blink::WebCryptoKeyUsageEncrypt;
...@@ -682,7 +682,7 @@ TEST(WebCryptoAesCbcTest, ImportJwkNonStringKeyOp) { ...@@ -682,7 +682,7 @@ TEST(WebCryptoAesCbcTest, ImportJwkNonStringKeyOp) {
// Fail on missing k. // Fail on missing k.
TEST(WebCryptoAesCbcTest, ImportJwkMissingK) { TEST(WebCryptoAesCbcTest, ImportJwkMissingK) {
blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey key;
base::DictionaryValue dict; base::DictionaryValue dict;
dict.SetString("kty", "oct"); dict.SetString("kty", "oct");
...@@ -698,7 +698,7 @@ TEST(WebCryptoAesCbcTest, ImportJwkMissingK) { ...@@ -698,7 +698,7 @@ TEST(WebCryptoAesCbcTest, ImportJwkMissingK) {
// Fail on bad b64 encoding for k. // Fail on bad b64 encoding for k.
TEST(WebCryptoAesCbcTest, ImportJwkBadB64ForK) { TEST(WebCryptoAesCbcTest, ImportJwkBadB64ForK) {
blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey key;
base::DictionaryValue dict; base::DictionaryValue dict;
dict.SetString("kty", "oct"); dict.SetString("kty", "oct");
...@@ -714,7 +714,7 @@ TEST(WebCryptoAesCbcTest, ImportJwkBadB64ForK) { ...@@ -714,7 +714,7 @@ TEST(WebCryptoAesCbcTest, ImportJwkBadB64ForK) {
// Fail on empty k. // Fail on empty k.
TEST(WebCryptoAesCbcTest, ImportJwkEmptyK) { TEST(WebCryptoAesCbcTest, ImportJwkEmptyK) {
blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey key;
base::DictionaryValue dict; base::DictionaryValue dict;
dict.SetString("kty", "oct"); dict.SetString("kty", "oct");
...@@ -731,7 +731,7 @@ TEST(WebCryptoAesCbcTest, ImportJwkEmptyK) { ...@@ -731,7 +731,7 @@ TEST(WebCryptoAesCbcTest, ImportJwkEmptyK) {
// Fail on empty k (with alg specified). // Fail on empty k (with alg specified).
TEST(WebCryptoAesCbcTest, ImportJwkEmptyK2) { TEST(WebCryptoAesCbcTest, ImportJwkEmptyK2) {
blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey key;
base::DictionaryValue dict; base::DictionaryValue dict;
dict.SetString("kty", "oct"); dict.SetString("kty", "oct");
...@@ -750,7 +750,7 @@ TEST(WebCryptoAesCbcTest, ImportJwkEmptyK2) { ...@@ -750,7 +750,7 @@ TEST(WebCryptoAesCbcTest, ImportJwkEmptyK2) {
// Fail on k actual length (120 bits) inconsistent with the embedded JWK alg // Fail on k actual length (120 bits) inconsistent with the embedded JWK alg
// value (128) for an AES key. // value (128) for an AES key.
TEST(WebCryptoAesCbcTest, ImportJwkInconsistentKLength) { TEST(WebCryptoAesCbcTest, ImportJwkInconsistentKLength) {
blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey key;
base::DictionaryValue dict; base::DictionaryValue dict;
dict.SetString("kty", "oct"); dict.SetString("kty", "oct");
...@@ -768,7 +768,7 @@ TEST(WebCryptoAesCbcTest, ImportJwkInconsistentKLength) { ...@@ -768,7 +768,7 @@ TEST(WebCryptoAesCbcTest, ImportJwkInconsistentKLength) {
// Fail on k actual length (192 bits) inconsistent with the embedded JWK alg // Fail on k actual length (192 bits) inconsistent with the embedded JWK alg
// value (128) for an AES key. // value (128) for an AES key.
TEST(WebCryptoAesCbcTest, ImportJwkInconsistentKLength2) { TEST(WebCryptoAesCbcTest, ImportJwkInconsistentKLength2) {
blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey key;
base::DictionaryValue dict; base::DictionaryValue dict;
dict.SetString("kty", "oct"); dict.SetString("kty", "oct");
...@@ -810,7 +810,7 @@ TEST(WebCryptoAesCbcTest, ImportExportJwk) { ...@@ -810,7 +810,7 @@ TEST(WebCryptoAesCbcTest, ImportExportJwk) {
// AES 192-bit is not allowed: http://crbug.com/381829 // AES 192-bit is not allowed: http://crbug.com/381829
TEST(WebCryptoAesCbcTest, ImportAesCbc192Raw) { TEST(WebCryptoAesCbcTest, ImportAesCbc192Raw) {
std::vector<uint8_t> key_raw(24, 0); std::vector<uint8_t> key_raw(24, 0);
blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey key;
Status status = ImportKey(blink::WebCryptoKeyFormatRaw, Status status = ImportKey(blink::WebCryptoKeyFormatRaw,
CryptoData(key_raw), CryptoData(key_raw),
CreateAlgorithm(blink::WebCryptoAlgorithmIdAesCbc), CreateAlgorithm(blink::WebCryptoAlgorithmIdAesCbc),
...@@ -822,7 +822,7 @@ TEST(WebCryptoAesCbcTest, ImportAesCbc192Raw) { ...@@ -822,7 +822,7 @@ TEST(WebCryptoAesCbcTest, ImportAesCbc192Raw) {
// AES 192-bit is not allowed: http://crbug.com/381829 // AES 192-bit is not allowed: http://crbug.com/381829
TEST(WebCryptoAesCbcTest, ImportAesCbc192Jwk) { TEST(WebCryptoAesCbcTest, ImportAesCbc192Jwk) {
blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey key;
base::DictionaryValue dict; base::DictionaryValue dict;
dict.SetString("kty", "oct"); dict.SetString("kty", "oct");
...@@ -840,7 +840,7 @@ TEST(WebCryptoAesCbcTest, ImportAesCbc192Jwk) { ...@@ -840,7 +840,7 @@ TEST(WebCryptoAesCbcTest, ImportAesCbc192Jwk) {
// AES 192-bit is not allowed: http://crbug.com/381829 // AES 192-bit is not allowed: http://crbug.com/381829
TEST(WebCryptoAesCbcTest, GenerateAesCbc192) { TEST(WebCryptoAesCbcTest, GenerateAesCbc192) {
blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey key;
Status status = GenerateSecretKey(CreateAesCbcKeyGenAlgorithm(192), Status status = GenerateSecretKey(CreateAesCbcKeyGenAlgorithm(192),
true, true,
blink::WebCryptoKeyUsageEncrypt, blink::WebCryptoKeyUsageEncrypt,
...@@ -859,7 +859,7 @@ TEST(WebCryptoAesCbcTest, UnwrapAesCbc192) { ...@@ -859,7 +859,7 @@ TEST(WebCryptoAesCbcTest, UnwrapAesCbc192) {
CreateAlgorithm(blink::WebCryptoAlgorithmIdAesKw), CreateAlgorithm(blink::WebCryptoAlgorithmIdAesKw),
blink::WebCryptoKeyUsageUnwrapKey); blink::WebCryptoKeyUsageUnwrapKey);
blink::WebCryptoKey unwrapped_key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey unwrapped_key;
ASSERT_EQ(Status::ErrorAes192BitUnsupported(), ASSERT_EQ(Status::ErrorAes192BitUnsupported(),
UnwrapKey(blink::WebCryptoKeyFormatRaw, UnwrapKey(blink::WebCryptoKeyFormatRaw,
CryptoData(wrapped_key), CryptoData(wrapped_key),
...@@ -890,7 +890,7 @@ TEST(WebCryptoAesCbcTest, ImportKeyBadUsage_Raw) { ...@@ -890,7 +890,7 @@ TEST(WebCryptoAesCbcTest, ImportKeyBadUsage_Raw) {
for (size_t i = 0; i < arraysize(bad_usages); ++i) { for (size_t i = 0; i < arraysize(bad_usages); ++i) {
SCOPED_TRACE(i); SCOPED_TRACE(i);
blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey key;
ASSERT_EQ(Status::ErrorCreateKeyBadUsages(), ASSERT_EQ(Status::ErrorCreateKeyBadUsages(),
ImportKey(blink::WebCryptoKeyFormatRaw, ImportKey(blink::WebCryptoKeyFormatRaw,
CryptoData(key_bytes), CryptoData(key_bytes),
...@@ -912,7 +912,7 @@ TEST(WebCryptoAesCbcTest, GenerateKeyBadUsages) { ...@@ -912,7 +912,7 @@ TEST(WebCryptoAesCbcTest, GenerateKeyBadUsages) {
for (size_t i = 0; i < arraysize(bad_usages); ++i) { for (size_t i = 0; i < arraysize(bad_usages); ++i) {
SCOPED_TRACE(i); SCOPED_TRACE(i);
blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey key;
ASSERT_EQ(Status::ErrorCreateKeyBadUsages(), ASSERT_EQ(Status::ErrorCreateKeyBadUsages(),
GenerateSecretKey( GenerateSecretKey(
...@@ -928,7 +928,7 @@ TEST(WebCryptoAesCbcTest, WrapUnwrapRoundtripSpkiPkcs8) { ...@@ -928,7 +928,7 @@ TEST(WebCryptoAesCbcTest, WrapUnwrapRoundtripSpkiPkcs8) {
return; return;
// Generate the wrapping key. // Generate the wrapping key.
blink::WebCryptoKey wrapping_key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey wrapping_key;
ASSERT_EQ(Status::Success(), ASSERT_EQ(Status::Success(),
GenerateSecretKey(CreateAesCbcKeyGenAlgorithm(128), GenerateSecretKey(CreateAesCbcKeyGenAlgorithm(128),
true, true,
...@@ -940,8 +940,8 @@ TEST(WebCryptoAesCbcTest, WrapUnwrapRoundtripSpkiPkcs8) { ...@@ -940,8 +940,8 @@ TEST(WebCryptoAesCbcTest, WrapUnwrapRoundtripSpkiPkcs8) {
const unsigned int modulus_length = 256; const unsigned int modulus_length = 256;
const std::vector<uint8_t> public_exponent = HexStringToBytes("010001"); const std::vector<uint8_t> public_exponent = HexStringToBytes("010001");
blink::WebCryptoKey public_key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey public_key;
blink::WebCryptoKey private_key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey private_key;
ASSERT_EQ(Status::Success(), ASSERT_EQ(Status::Success(),
GenerateKeyPair(CreateRsaHashedKeyGenAlgorithm( GenerateKeyPair(CreateRsaHashedKeyGenAlgorithm(
blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5,
...@@ -990,7 +990,7 @@ TEST(WebCryptoAesCbcTest, WrapUnwrapRoundtripSpkiPkcs8) { ...@@ -990,7 +990,7 @@ TEST(WebCryptoAesCbcTest, WrapUnwrapRoundtripSpkiPkcs8) {
CreateRsaHashedImportAlgorithm(blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, CreateRsaHashedImportAlgorithm(blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5,
blink::WebCryptoAlgorithmIdSha256); blink::WebCryptoAlgorithmIdSha256);
blink::WebCryptoKey unwrapped_public_key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey unwrapped_public_key;
ASSERT_EQ(Status::Success(), ASSERT_EQ(Status::Success(),
UnwrapKey(blink::WebCryptoKeyFormatSpki, UnwrapKey(blink::WebCryptoKeyFormatSpki,
...@@ -1002,7 +1002,7 @@ TEST(WebCryptoAesCbcTest, WrapUnwrapRoundtripSpkiPkcs8) { ...@@ -1002,7 +1002,7 @@ TEST(WebCryptoAesCbcTest, WrapUnwrapRoundtripSpkiPkcs8) {
0, 0,
&unwrapped_public_key)); &unwrapped_public_key));
blink::WebCryptoKey unwrapped_private_key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey unwrapped_private_key;
ASSERT_EQ(Status::Success(), ASSERT_EQ(Status::Success(),
UnwrapKey(blink::WebCryptoKeyFormatPkcs8, UnwrapKey(blink::WebCryptoKeyFormatPkcs8,
......
...@@ -109,7 +109,7 @@ TEST(WebCryptoAesGcmTest, GenerateKeyBadLength) { ...@@ -109,7 +109,7 @@ TEST(WebCryptoAesGcmTest, GenerateKeyBadLength) {
} }
const unsigned short kKeyLen[] = {0, 127, 257}; const unsigned short kKeyLen[] = {0, 127, 257};
blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey key;
for (size_t i = 0; i < arraysize(kKeyLen); ++i) { for (size_t i = 0; i < arraysize(kKeyLen); ++i) {
SCOPED_TRACE(i); SCOPED_TRACE(i);
EXPECT_EQ(Status::ErrorGenerateKeyLength(), EXPECT_EQ(Status::ErrorGenerateKeyLength(),
......
...@@ -25,7 +25,7 @@ blink::WebCryptoAlgorithm CreateAesKwKeyGenAlgorithm( ...@@ -25,7 +25,7 @@ blink::WebCryptoAlgorithm CreateAesKwKeyGenAlgorithm(
TEST(WebCryptoAesKwTest, GenerateKeyBadLength) { TEST(WebCryptoAesKwTest, GenerateKeyBadLength) {
const unsigned short kKeyLen[] = {0, 127, 257}; const unsigned short kKeyLen[] = {0, 127, 257};
blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey key;
for (size_t i = 0; i < arraysize(kKeyLen); ++i) { for (size_t i = 0; i < arraysize(kKeyLen); ++i) {
SCOPED_TRACE(i); SCOPED_TRACE(i);
EXPECT_EQ(Status::ErrorGenerateKeyLength(), EXPECT_EQ(Status::ErrorGenerateKeyLength(),
...@@ -35,7 +35,7 @@ TEST(WebCryptoAesKwTest, GenerateKeyBadLength) { ...@@ -35,7 +35,7 @@ TEST(WebCryptoAesKwTest, GenerateKeyBadLength) {
} }
TEST(WebCryptoAesKwTest, ImportKeyJwkKeyOpsWrapUnwrap) { TEST(WebCryptoAesKwTest, ImportKeyJwkKeyOpsWrapUnwrap) {
blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey key;
base::DictionaryValue dict; base::DictionaryValue dict;
dict.SetString("kty", "oct"); dict.SetString("kty", "oct");
dict.SetString("k", "GADWrMRHwQfoNaXU5fZvTg=="); dict.SetString("k", "GADWrMRHwQfoNaXU5fZvTg==");
...@@ -87,7 +87,7 @@ TEST(WebCryptoAesKwTest, ImportExportJwk) { ...@@ -87,7 +87,7 @@ TEST(WebCryptoAesKwTest, ImportExportJwk) {
} }
TEST(WebCryptoAesKwTest, AesKwKeyImport) { TEST(WebCryptoAesKwTest, AesKwKeyImport) {
blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey key;
blink::WebCryptoAlgorithm algorithm = blink::WebCryptoAlgorithm algorithm =
CreateAlgorithm(blink::WebCryptoAlgorithmIdAesKw); CreateAlgorithm(blink::WebCryptoAlgorithmIdAesKw);
...@@ -180,7 +180,7 @@ TEST(WebCryptoAesKwTest, UnwrapFailures) { ...@@ -180,7 +180,7 @@ TEST(WebCryptoAesKwTest, UnwrapFailures) {
const std::vector<uint8_t> test_ciphertext = const std::vector<uint8_t> test_ciphertext =
GetBytesFromHexString(test, "ciphertext"); GetBytesFromHexString(test, "ciphertext");
blink::WebCryptoKey unwrapped_key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey unwrapped_key;
// Using a wrapping algorithm that does not match the wrapping key algorithm // Using a wrapping algorithm that does not match the wrapping key algorithm
// should fail. // should fail.
...@@ -237,7 +237,7 @@ TEST(WebCryptoAesKwTest, AesKwRawSymkeyWrapUnwrapKnownAnswer) { ...@@ -237,7 +237,7 @@ TEST(WebCryptoAesKwTest, AesKwRawSymkeyWrapUnwrapKnownAnswer) {
EXPECT_BYTES_EQ(test_ciphertext, wrapped_key); EXPECT_BYTES_EQ(test_ciphertext, wrapped_key);
// Unwrap the known ciphertext to get a new test_key. // Unwrap the known ciphertext to get a new test_key.
blink::WebCryptoKey unwrapped_key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey unwrapped_key;
ASSERT_EQ( ASSERT_EQ(
Status::Success(), Status::Success(),
UnwrapKey(blink::WebCryptoKeyFormatRaw, UnwrapKey(blink::WebCryptoKeyFormatRaw,
...@@ -282,7 +282,7 @@ TEST(WebCryptoAesKwTest, AesKwRawSymkeyUnwrapSignVerifyHmac) { ...@@ -282,7 +282,7 @@ TEST(WebCryptoAesKwTest, AesKwRawSymkeyUnwrapSignVerifyHmac) {
test_kek, wrapping_algorithm, blink::WebCryptoKeyUsageUnwrapKey); test_kek, wrapping_algorithm, blink::WebCryptoKeyUsageUnwrapKey);
// Unwrap the known ciphertext. // Unwrap the known ciphertext.
blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey key;
ASSERT_EQ( ASSERT_EQ(
Status::Success(), Status::Success(),
UnwrapKey(blink::WebCryptoKeyFormatRaw, UnwrapKey(blink::WebCryptoKeyFormatRaw,
...@@ -349,7 +349,7 @@ TEST(WebCryptoAesKwTest, AesKwRawSymkeyWrapUnwrapErrors) { ...@@ -349,7 +349,7 @@ TEST(WebCryptoAesKwTest, AesKwRawSymkeyWrapUnwrapErrors) {
// Unwrap with wrapped data too small must fail. // Unwrap with wrapped data too small must fail.
const std::vector<uint8_t> small_data(test_ciphertext.begin(), const std::vector<uint8_t> small_data(test_ciphertext.begin(),
test_ciphertext.begin() + 23); test_ciphertext.begin() + 23);
blink::WebCryptoKey unwrapped_key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey unwrapped_key;
EXPECT_EQ(Status::ErrorDataTooSmall(), EXPECT_EQ(Status::ErrorDataTooSmall(),
UnwrapKey(blink::WebCryptoKeyFormatRaw, UnwrapKey(blink::WebCryptoKeyFormatRaw,
CryptoData(small_data), CryptoData(small_data),
...@@ -395,7 +395,7 @@ TEST(WebCryptoAesKwTest, AesKwRawSymkeyUnwrapCorruptData) { ...@@ -395,7 +395,7 @@ TEST(WebCryptoAesKwTest, AesKwRawSymkeyUnwrapCorruptData) {
// Unwrap of a corrupted version of the known ciphertext should fail, due to // Unwrap of a corrupted version of the known ciphertext should fail, due to
// AES-KW's built-in integrity check. // AES-KW's built-in integrity check.
blink::WebCryptoKey unwrapped_key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey unwrapped_key;
EXPECT_EQ(Status::OperationError(), EXPECT_EQ(Status::OperationError(),
UnwrapKey(blink::WebCryptoKeyFormatRaw, UnwrapKey(blink::WebCryptoKeyFormatRaw,
CryptoData(Corrupted(test_ciphertext)), CryptoData(Corrupted(test_ciphertext)),
...@@ -432,7 +432,7 @@ TEST(WebCryptoAesKwTest, AesKwJwkSymkeyUnwrapKnownData) { ...@@ -432,7 +432,7 @@ TEST(WebCryptoAesKwTest, AesKwJwkSymkeyUnwrapKnownData) {
wrapping_key_data, wrapping_algorithm, blink::WebCryptoKeyUsageUnwrapKey); wrapping_key_data, wrapping_algorithm, blink::WebCryptoKeyUsageUnwrapKey);
// Unwrap the known wrapped key data to produce a new key // Unwrap the known wrapped key data to produce a new key
blink::WebCryptoKey unwrapped_key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey unwrapped_key;
ASSERT_EQ( ASSERT_EQ(
Status::Success(), Status::Success(),
UnwrapKey(blink::WebCryptoKeyFormatJwk, UnwrapKey(blink::WebCryptoKeyFormatJwk,
...@@ -483,7 +483,7 @@ TEST(WebCryptoAesKwTest, ImportKeyBadUsage_Raw) { ...@@ -483,7 +483,7 @@ TEST(WebCryptoAesKwTest, ImportKeyBadUsage_Raw) {
for (size_t i = 0; i < arraysize(bad_usages); ++i) { for (size_t i = 0; i < arraysize(bad_usages); ++i) {
SCOPED_TRACE(i); SCOPED_TRACE(i);
blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey key;
ASSERT_EQ(Status::ErrorCreateKeyBadUsages(), ASSERT_EQ(Status::ErrorCreateKeyBadUsages(),
ImportKey(blink::WebCryptoKeyFormatRaw, ImportKey(blink::WebCryptoKeyFormatRaw,
CryptoData(key_bytes), CryptoData(key_bytes),
...@@ -510,7 +510,7 @@ TEST(WebCryptoAesKwTest, UnwrapHmacKeyBadUsage_JWK) { ...@@ -510,7 +510,7 @@ TEST(WebCryptoAesKwTest, UnwrapHmacKeyBadUsage_JWK) {
}; };
// Import the wrapping key. // Import the wrapping key.
blink::WebCryptoKey wrapping_key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey wrapping_key;
ASSERT_EQ(Status::Success(), ASSERT_EQ(Status::Success(),
ImportKey(blink::WebCryptoKeyFormatRaw, ImportKey(blink::WebCryptoKeyFormatRaw,
CryptoData(std::vector<uint8_t>(16)), CryptoData(std::vector<uint8_t>(16)),
...@@ -529,7 +529,7 @@ TEST(WebCryptoAesKwTest, UnwrapHmacKeyBadUsage_JWK) { ...@@ -529,7 +529,7 @@ TEST(WebCryptoAesKwTest, UnwrapHmacKeyBadUsage_JWK) {
for (size_t i = 0; i < arraysize(bad_usages); ++i) { for (size_t i = 0; i < arraysize(bad_usages); ++i) {
SCOPED_TRACE(i); SCOPED_TRACE(i);
blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey key;
ASSERT_EQ( ASSERT_EQ(
Status::ErrorCreateKeyBadUsages(), Status::ErrorCreateKeyBadUsages(),
...@@ -560,7 +560,7 @@ TEST(WebCryptoAesKwTest, UnwrapRsaSsaPublicKeyBadUsage_JWK) { ...@@ -560,7 +560,7 @@ TEST(WebCryptoAesKwTest, UnwrapRsaSsaPublicKeyBadUsage_JWK) {
}; };
// Import the wrapping key. // Import the wrapping key.
blink::WebCryptoKey wrapping_key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey wrapping_key;
ASSERT_EQ(Status::Success(), ASSERT_EQ(Status::Success(),
ImportKey(blink::WebCryptoKeyFormatRaw, ImportKey(blink::WebCryptoKeyFormatRaw,
CryptoData(std::vector<uint8_t>(16)), CryptoData(std::vector<uint8_t>(16)),
...@@ -584,7 +584,7 @@ TEST(WebCryptoAesKwTest, UnwrapRsaSsaPublicKeyBadUsage_JWK) { ...@@ -584,7 +584,7 @@ TEST(WebCryptoAesKwTest, UnwrapRsaSsaPublicKeyBadUsage_JWK) {
for (size_t i = 0; i < arraysize(bad_usages); ++i) { for (size_t i = 0; i < arraysize(bad_usages); ++i) {
SCOPED_TRACE(i); SCOPED_TRACE(i);
blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey key;
ASSERT_EQ(Status::ErrorCreateKeyBadUsages(), ASSERT_EQ(Status::ErrorCreateKeyBadUsages(),
UnwrapKey(blink::WebCryptoKeyFormatJwk, UnwrapKey(blink::WebCryptoKeyFormatJwk,
......
...@@ -118,7 +118,7 @@ TEST(WebCryptoHmacTest, GenerateKeyIsRandom) { ...@@ -118,7 +118,7 @@ TEST(WebCryptoHmacTest, GenerateKeyIsRandom) {
std::vector<std::vector<uint8_t> > keys; std::vector<std::vector<uint8_t> > keys;
for (int i = 0; i < 16; ++i) { for (int i = 0; i < 16; ++i) {
std::vector<uint8_t> key_bytes; std::vector<uint8_t> key_bytes;
blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey key;
blink::WebCryptoAlgorithm algorithm = blink::WebCryptoAlgorithm algorithm =
CreateHmacKeyGenAlgorithm(blink::WebCryptoAlgorithmIdSha1, 512); CreateHmacKeyGenAlgorithm(blink::WebCryptoAlgorithmIdSha1, 512);
ASSERT_EQ(Status::Success(), GenerateSecretKey(algorithm, true, 0, &key)); ASSERT_EQ(Status::Success(), GenerateSecretKey(algorithm, true, 0, &key));
...@@ -143,7 +143,7 @@ TEST(WebCryptoHmacTest, GenerateKeyIsRandom) { ...@@ -143,7 +143,7 @@ TEST(WebCryptoHmacTest, GenerateKeyIsRandom) {
// If the key length is not provided, then the block size is used. // If the key length is not provided, then the block size is used.
TEST(WebCryptoHmacTest, GenerateKeyNoLengthSha1) { TEST(WebCryptoHmacTest, GenerateKeyNoLengthSha1) {
blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey key;
blink::WebCryptoAlgorithm algorithm = blink::WebCryptoAlgorithm algorithm =
CreateHmacKeyGenAlgorithm(blink::WebCryptoAlgorithmIdSha1, 0); CreateHmacKeyGenAlgorithm(blink::WebCryptoAlgorithmIdSha1, 0);
ASSERT_EQ(Status::Success(), GenerateSecretKey(algorithm, true, 0, &key)); ASSERT_EQ(Status::Success(), GenerateSecretKey(algorithm, true, 0, &key));
...@@ -161,7 +161,7 @@ TEST(WebCryptoHmacTest, GenerateKeyNoLengthSha1) { ...@@ -161,7 +161,7 @@ TEST(WebCryptoHmacTest, GenerateKeyNoLengthSha1) {
// If the key length is not provided, then the block size is used. // If the key length is not provided, then the block size is used.
TEST(WebCryptoHmacTest, GenerateKeyNoLengthSha512) { TEST(WebCryptoHmacTest, GenerateKeyNoLengthSha512) {
blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey key;
blink::WebCryptoAlgorithm algorithm = blink::WebCryptoAlgorithm algorithm =
CreateHmacKeyGenAlgorithm(blink::WebCryptoAlgorithmIdSha512, 0); CreateHmacKeyGenAlgorithm(blink::WebCryptoAlgorithmIdSha512, 0);
ASSERT_EQ(Status::Success(), GenerateSecretKey(algorithm, true, 0, &key)); ASSERT_EQ(Status::Success(), GenerateSecretKey(algorithm, true, 0, &key));
...@@ -176,7 +176,7 @@ TEST(WebCryptoHmacTest, GenerateKeyNoLengthSha512) { ...@@ -176,7 +176,7 @@ TEST(WebCryptoHmacTest, GenerateKeyNoLengthSha512) {
} }
TEST(WebCryptoHmacTest, ImportKeyJwkKeyOpsSignVerify) { TEST(WebCryptoHmacTest, ImportKeyJwkKeyOpsSignVerify) {
blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey key;
base::DictionaryValue dict; base::DictionaryValue dict;
dict.SetString("kty", "oct"); dict.SetString("kty", "oct");
dict.SetString("k", "GADWrMRHwQfoNaXU5fZvTg=="); dict.SetString("k", "GADWrMRHwQfoNaXU5fZvTg==");
...@@ -210,7 +210,7 @@ TEST(WebCryptoHmacTest, ImportKeyJwkKeyOpsSignVerify) { ...@@ -210,7 +210,7 @@ TEST(WebCryptoHmacTest, ImportKeyJwkKeyOpsSignVerify) {
// Test 'use' inconsistent with 'key_ops'. // Test 'use' inconsistent with 'key_ops'.
TEST(WebCryptoHmacTest, ImportKeyJwkUseInconsisteWithKeyOps) { TEST(WebCryptoHmacTest, ImportKeyJwkUseInconsisteWithKeyOps) {
blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey key;
base::DictionaryValue dict; base::DictionaryValue dict;
dict.SetString("kty", "oct"); dict.SetString("kty", "oct");
dict.SetString("k", "GADWrMRHwQfoNaXU5fZvTg=="); dict.SetString("k", "GADWrMRHwQfoNaXU5fZvTg==");
...@@ -233,7 +233,7 @@ TEST(WebCryptoHmacTest, ImportKeyJwkUseInconsisteWithKeyOps) { ...@@ -233,7 +233,7 @@ TEST(WebCryptoHmacTest, ImportKeyJwkUseInconsisteWithKeyOps) {
// Test JWK composite 'sig' use // Test JWK composite 'sig' use
TEST(WebCryptoHmacTest, ImportKeyJwkUseSig) { TEST(WebCryptoHmacTest, ImportKeyJwkUseSig) {
blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey key;
base::DictionaryValue dict; base::DictionaryValue dict;
dict.SetString("kty", "oct"); dict.SetString("kty", "oct");
dict.SetString("k", "GADWrMRHwQfoNaXU5fZvTg=="); dict.SetString("k", "GADWrMRHwQfoNaXU5fZvTg==");
...@@ -256,7 +256,7 @@ TEST(WebCryptoHmacTest, ImportJwkInputConsistency) { ...@@ -256,7 +256,7 @@ TEST(WebCryptoHmacTest, ImportJwkInputConsistency) {
// inconsistent with the input value, the operation must fail. // inconsistent with the input value, the operation must fail.
// Consistency rules when JWK value is not present: Inputs should be used. // Consistency rules when JWK value is not present: Inputs should be used.
blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey key;
bool extractable = false; bool extractable = false;
blink::WebCryptoAlgorithm algorithm = blink::WebCryptoAlgorithm algorithm =
CreateHmacImportAlgorithm(blink::WebCryptoAlgorithmIdSha256); CreateHmacImportAlgorithm(blink::WebCryptoAlgorithmIdSha256);
...@@ -408,7 +408,7 @@ TEST(WebCryptoHmacTest, ImportJwkHappy) { ...@@ -408,7 +408,7 @@ TEST(WebCryptoHmacTest, ImportJwkHappy) {
// This test verifies the happy path of JWK import, including the application // This test verifies the happy path of JWK import, including the application
// of the imported key material. // of the imported key material.
blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey key;
bool extractable = false; bool extractable = false;
blink::WebCryptoAlgorithm algorithm = blink::WebCryptoAlgorithm algorithm =
CreateHmacImportAlgorithm(blink::WebCryptoAlgorithmIdSha256); CreateHmacImportAlgorithm(blink::WebCryptoAlgorithmIdSha256);
...@@ -488,7 +488,7 @@ TEST(WebCryptoHmacTest, ExportJwkEmptyKey) { ...@@ -488,7 +488,7 @@ TEST(WebCryptoHmacTest, ExportJwkEmptyKey) {
CreateHmacImportAlgorithm(blink::WebCryptoAlgorithmIdSha1); CreateHmacImportAlgorithm(blink::WebCryptoAlgorithmIdSha1);
blink::WebCryptoKeyUsageMask usages = blink::WebCryptoKeyUsageSign; blink::WebCryptoKeyUsageMask usages = blink::WebCryptoKeyUsageSign;
blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey key;
// Import a zero-byte HMAC key. // Import a zero-byte HMAC key.
const char key_data_hex[] = ""; const char key_data_hex[] = "";
...@@ -527,7 +527,7 @@ TEST(WebCryptoHmacTest, ExportJwkEmptyKey) { ...@@ -527,7 +527,7 @@ TEST(WebCryptoHmacTest, ExportJwkEmptyKey) {
TEST(WebCryptoHmacTest, ImportRawKeyTooLarge) { TEST(WebCryptoHmacTest, ImportRawKeyTooLarge) {
CryptoData big_data(NULL, UINT_MAX); // Invalid data of big length. CryptoData big_data(NULL, UINT_MAX); // Invalid data of big length.
blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey key;
EXPECT_EQ( EXPECT_EQ(
Status::ErrorDataTooLarge(), Status::ErrorDataTooLarge(),
ImportKey(blink::WebCryptoKeyFormatRaw, ImportKey(blink::WebCryptoKeyFormatRaw,
......
...@@ -47,7 +47,7 @@ TEST(WebCryptoRsaOaepTest, ImportPkcs8WithRsaEncryption) { ...@@ -47,7 +47,7 @@ TEST(WebCryptoRsaOaepTest, ImportPkcs8WithRsaEncryption) {
return; return;
} }
blink::WebCryptoKey private_key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey private_key;
ASSERT_EQ(Status::Success(), ASSERT_EQ(Status::Success(),
ImportKey(blink::WebCryptoKeyFormatPkcs8, ImportKey(blink::WebCryptoKeyFormatPkcs8,
CryptoData(HexStringToBytes(kPrivateKeyPkcs8DerHex)), CryptoData(HexStringToBytes(kPrivateKeyPkcs8DerHex)),
...@@ -67,7 +67,7 @@ TEST(WebCryptoRsaOaepTest, ImportPublicJwkWithNoAlg) { ...@@ -67,7 +67,7 @@ TEST(WebCryptoRsaOaepTest, ImportPublicJwkWithNoAlg) {
scoped_ptr<base::DictionaryValue> jwk(CreatePublicKeyJwkDict()); scoped_ptr<base::DictionaryValue> jwk(CreatePublicKeyJwkDict());
blink::WebCryptoKey public_key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey public_key;
ASSERT_EQ(Status::Success(), ASSERT_EQ(Status::Success(),
ImportKeyJwkFromDict(*jwk.get(), ImportKeyJwkFromDict(*jwk.get(),
CreateRsaHashedImportAlgorithm( CreateRsaHashedImportAlgorithm(
...@@ -87,7 +87,7 @@ TEST(WebCryptoRsaOaepTest, ImportPublicJwkWithMatchingAlg) { ...@@ -87,7 +87,7 @@ TEST(WebCryptoRsaOaepTest, ImportPublicJwkWithMatchingAlg) {
scoped_ptr<base::DictionaryValue> jwk(CreatePublicKeyJwkDict()); scoped_ptr<base::DictionaryValue> jwk(CreatePublicKeyJwkDict());
jwk->SetString("alg", "RSA-OAEP"); jwk->SetString("alg", "RSA-OAEP");
blink::WebCryptoKey public_key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey public_key;
ASSERT_EQ(Status::Success(), ASSERT_EQ(Status::Success(),
ImportKeyJwkFromDict(*jwk.get(), ImportKeyJwkFromDict(*jwk.get(),
CreateRsaHashedImportAlgorithm( CreateRsaHashedImportAlgorithm(
...@@ -107,7 +107,7 @@ TEST(WebCryptoRsaOaepTest, ImportPublicJwkWithMismatchedAlgFails) { ...@@ -107,7 +107,7 @@ TEST(WebCryptoRsaOaepTest, ImportPublicJwkWithMismatchedAlgFails) {
scoped_ptr<base::DictionaryValue> jwk(CreatePublicKeyJwkDict()); scoped_ptr<base::DictionaryValue> jwk(CreatePublicKeyJwkDict());
jwk->SetString("alg", "RSA-OAEP-512"); jwk->SetString("alg", "RSA-OAEP-512");
blink::WebCryptoKey public_key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey public_key;
ASSERT_EQ(Status::ErrorJwkAlgorithmInconsistent(), ASSERT_EQ(Status::ErrorJwkAlgorithmInconsistent(),
ImportKeyJwkFromDict(*jwk.get(), ImportKeyJwkFromDict(*jwk.get(),
CreateRsaHashedImportAlgorithm( CreateRsaHashedImportAlgorithm(
...@@ -128,7 +128,7 @@ TEST(WebCryptoRsaOaepTest, ImportPublicJwkWithMismatchedTypeFails) { ...@@ -128,7 +128,7 @@ TEST(WebCryptoRsaOaepTest, ImportPublicJwkWithMismatchedTypeFails) {
jwk->SetString("kty", "oct"); jwk->SetString("kty", "oct");
jwk->SetString("alg", "RSA-OAEP"); jwk->SetString("alg", "RSA-OAEP");
blink::WebCryptoKey public_key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey public_key;
ASSERT_EQ(Status::ErrorJwkUnexpectedKty("RSA"), ASSERT_EQ(Status::ErrorJwkUnexpectedKty("RSA"),
ImportKeyJwkFromDict(*jwk.get(), ImportKeyJwkFromDict(*jwk.get(),
CreateRsaHashedImportAlgorithm( CreateRsaHashedImportAlgorithm(
...@@ -160,7 +160,7 @@ TEST(WebCryptoRsaOaepTest, ExportPublicJwk) { ...@@ -160,7 +160,7 @@ TEST(WebCryptoRsaOaepTest, ExportPublicJwk) {
jwk->SetString("alg", test_data.expected_jwk_alg); jwk->SetString("alg", test_data.expected_jwk_alg);
// Import the key in a known-good format // Import the key in a known-good format
blink::WebCryptoKey public_key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey public_key;
ASSERT_EQ(Status::Success(), ASSERT_EQ(Status::Success(),
ImportKeyJwkFromDict( ImportKeyJwkFromDict(
*jwk.get(), *jwk.get(),
...@@ -210,8 +210,8 @@ TEST(WebCryptoRsaOaepTest, EncryptDecryptKnownAnswerTest) { ...@@ -210,8 +210,8 @@ TEST(WebCryptoRsaOaepTest, EncryptDecryptKnownAnswerTest) {
blink::WebCryptoAlgorithm import_algorithm = CreateRsaHashedImportAlgorithm( blink::WebCryptoAlgorithm import_algorithm = CreateRsaHashedImportAlgorithm(
blink::WebCryptoAlgorithmIdRsaOaep, digest_algorithm.id()); blink::WebCryptoAlgorithmIdRsaOaep, digest_algorithm.id());
blink::WebCryptoKey public_key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey public_key;
blink::WebCryptoKey private_key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey private_key;
ASSERT_NO_FATAL_FAILURE(ImportRsaKeyPair(public_key_der, ASSERT_NO_FATAL_FAILURE(ImportRsaKeyPair(public_key_der,
private_key_der, private_key_der,
...@@ -256,7 +256,7 @@ TEST(WebCryptoRsaOaepTest, EncryptWithLargeMessageFails) { ...@@ -256,7 +256,7 @@ TEST(WebCryptoRsaOaepTest, EncryptWithLargeMessageFails) {
scoped_ptr<base::DictionaryValue> jwk(CreatePublicKeyJwkDict()); scoped_ptr<base::DictionaryValue> jwk(CreatePublicKeyJwkDict());
blink::WebCryptoKey public_key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey public_key;
ASSERT_EQ(Status::Success(), ASSERT_EQ(Status::Success(),
ImportKeyJwkFromDict(*jwk.get(), ImportKeyJwkFromDict(*jwk.get(),
CreateRsaHashedImportAlgorithm( CreateRsaHashedImportAlgorithm(
...@@ -323,7 +323,7 @@ TEST(WebCryptoRsaOaepTest, EncryptWithLargeDigestFails) { ...@@ -323,7 +323,7 @@ TEST(WebCryptoRsaOaepTest, EncryptWithLargeDigestFails) {
scoped_ptr<base::DictionaryValue> jwk(CreatePublicKeyJwkDict()); scoped_ptr<base::DictionaryValue> jwk(CreatePublicKeyJwkDict());
blink::WebCryptoKey public_key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey public_key;
ASSERT_EQ(Status::Success(), ASSERT_EQ(Status::Success(),
ImportKeyJwkFromDict(*jwk.get(), ImportKeyJwkFromDict(*jwk.get(),
CreateRsaHashedImportAlgorithm( CreateRsaHashedImportAlgorithm(
...@@ -353,7 +353,7 @@ TEST(WebCryptoRsaOaepTest, DecryptWithLargeMessageFails) { ...@@ -353,7 +353,7 @@ TEST(WebCryptoRsaOaepTest, DecryptWithLargeMessageFails) {
return; return;
} }
blink::WebCryptoKey private_key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey private_key;
ASSERT_EQ(Status::Success(), ASSERT_EQ(Status::Success(),
ImportKey(blink::WebCryptoKeyFormatPkcs8, ImportKey(blink::WebCryptoKeyFormatPkcs8,
CryptoData(HexStringToBytes(kPrivateKeyPkcs8DerHex)), CryptoData(HexStringToBytes(kPrivateKeyPkcs8DerHex)),
...@@ -387,8 +387,8 @@ TEST(WebCryptoRsaOaepTest, WrapUnwrapRawKey) { ...@@ -387,8 +387,8 @@ TEST(WebCryptoRsaOaepTest, WrapUnwrapRawKey) {
blink::WebCryptoAlgorithm import_algorithm = CreateRsaHashedImportAlgorithm( blink::WebCryptoAlgorithm import_algorithm = CreateRsaHashedImportAlgorithm(
blink::WebCryptoAlgorithmIdRsaOaep, blink::WebCryptoAlgorithmIdSha1); blink::WebCryptoAlgorithmIdRsaOaep, blink::WebCryptoAlgorithmIdSha1);
blink::WebCryptoKey public_key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey public_key;
blink::WebCryptoKey private_key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey private_key;
ASSERT_NO_FATAL_FAILURE(ImportRsaKeyPair( ASSERT_NO_FATAL_FAILURE(ImportRsaKeyPair(
HexStringToBytes(kPublicKeySpkiDerHex), HexStringToBytes(kPublicKeySpkiDerHex),
...@@ -432,7 +432,7 @@ TEST(WebCryptoRsaOaepTest, WrapUnwrapRawKey) { ...@@ -432,7 +432,7 @@ TEST(WebCryptoRsaOaepTest, WrapUnwrapRawKey) {
EXPECT_BYTES_EQ_HEX(key_hex, decrypted_key); EXPECT_BYTES_EQ_HEX(key_hex, decrypted_key);
// Now attempt to unwrap the key, which should also decrypt the data. // Now attempt to unwrap the key, which should also decrypt the data.
blink::WebCryptoKey unwrapped_key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey unwrapped_key;
ASSERT_EQ(Status::Success(), ASSERT_EQ(Status::Success(),
UnwrapKey(blink::WebCryptoKeyFormatRaw, UnwrapKey(blink::WebCryptoKeyFormatRaw,
CryptoData(wrapped_key), CryptoData(wrapped_key),
...@@ -505,8 +505,8 @@ TEST(WebCryptoRsaOaepTest, WrapUnwrapJwkSymKey) { ...@@ -505,8 +505,8 @@ TEST(WebCryptoRsaOaepTest, WrapUnwrapJwkSymKey) {
"37f3e1972c45a477e66db95c9609bb27f862700ef93379930786cf751b"; "37f3e1972c45a477e66db95c9609bb27f862700ef93379930786cf751b";
blink::WebCryptoAlgorithm import_algorithm = CreateRsaHashedImportAlgorithm( blink::WebCryptoAlgorithm import_algorithm = CreateRsaHashedImportAlgorithm(
blink::WebCryptoAlgorithmIdRsaOaep, blink::WebCryptoAlgorithmIdSha1); blink::WebCryptoAlgorithmIdRsaOaep, blink::WebCryptoAlgorithmIdSha1);
blink::WebCryptoKey public_key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey public_key;
blink::WebCryptoKey private_key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey private_key;
ASSERT_NO_FATAL_FAILURE(ImportRsaKeyPair( ASSERT_NO_FATAL_FAILURE(ImportRsaKeyPair(
HexStringToBytes(kPublicKey2048SpkiDerHex), HexStringToBytes(kPublicKey2048SpkiDerHex),
...@@ -551,7 +551,7 @@ TEST(WebCryptoRsaOaepTest, WrapUnwrapJwkSymKey) { ...@@ -551,7 +551,7 @@ TEST(WebCryptoRsaOaepTest, WrapUnwrapJwkSymKey) {
decrypted_jwk, "A128CBC", key_hex, blink::WebCryptoKeyUsageEncrypt)); decrypted_jwk, "A128CBC", key_hex, blink::WebCryptoKeyUsageEncrypt));
// Now attempt to unwrap the key, which should also decrypt the data. // Now attempt to unwrap the key, which should also decrypt the data.
blink::WebCryptoKey unwrapped_key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey unwrapped_key;
ASSERT_EQ(Status::Success(), ASSERT_EQ(Status::Success(),
UnwrapKey(blink::WebCryptoKeyFormatJwk, UnwrapKey(blink::WebCryptoKeyFormatJwk,
CryptoData(wrapped_key), CryptoData(wrapped_key),
...@@ -598,7 +598,7 @@ TEST(WebCryptoRsaOaepTest, ImportExportJwkRsaPublicKey) { ...@@ -598,7 +598,7 @@ TEST(WebCryptoRsaOaepTest, ImportExportJwkRsaPublicKey) {
test.hash); test.hash);
// Import the spki to create a public key // Import the spki to create a public key
blink::WebCryptoKey public_key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey public_key;
ASSERT_EQ(Status::Success(), ASSERT_EQ(Status::Success(),
ImportKey(blink::WebCryptoKeyFormatSpki, ImportKey(blink::WebCryptoKeyFormatSpki,
CryptoData(HexStringToBytes(kPublicKeySpkiDerHex)), CryptoData(HexStringToBytes(kPublicKeySpkiDerHex)),
...@@ -618,7 +618,7 @@ TEST(WebCryptoRsaOaepTest, ImportExportJwkRsaPublicKey) { ...@@ -618,7 +618,7 @@ TEST(WebCryptoRsaOaepTest, ImportExportJwkRsaPublicKey) {
test.usage)); test.usage));
// Import the JWK back in to create a new key // Import the JWK back in to create a new key
blink::WebCryptoKey public_key2 = blink::WebCryptoKey::createNull(); blink::WebCryptoKey public_key2;
ASSERT_EQ(Status::Success(), ASSERT_EQ(Status::Success(),
ImportKey(blink::WebCryptoKeyFormatJwk, ImportKey(blink::WebCryptoKeyFormatJwk,
CryptoData(jwk), CryptoData(jwk),
......
...@@ -38,7 +38,7 @@ void RestoreJwkRsaDictionary(base::DictionaryValue* dict) { ...@@ -38,7 +38,7 @@ void RestoreJwkRsaDictionary(base::DictionaryValue* dict) {
TEST(WebCryptoRsaSsaTest, ImportExportSpki) { TEST(WebCryptoRsaSsaTest, ImportExportSpki) {
// Passing case: Import a valid RSA key in SPKI format. // Passing case: Import a valid RSA key in SPKI format.
blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey key;
ASSERT_EQ(Status::Success(), ASSERT_EQ(Status::Success(),
ImportKey(blink::WebCryptoKeyFormatSpki, ImportKey(blink::WebCryptoKeyFormatSpki,
CryptoData(HexStringToBytes(kPublicKeySpkiDerHex)), CryptoData(HexStringToBytes(kPublicKeySpkiDerHex)),
...@@ -127,7 +127,7 @@ TEST(WebCryptoRsaSsaTest, ImportExportPkcs8) { ...@@ -127,7 +127,7 @@ TEST(WebCryptoRsaSsaTest, ImportExportPkcs8) {
return; return;
// Passing case: Import a valid RSA key in PKCS#8 format. // Passing case: Import a valid RSA key in PKCS#8 format.
blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey key;
ASSERT_EQ(Status::Success(), ASSERT_EQ(Status::Success(),
ImportKey(blink::WebCryptoKeyFormatPkcs8, ImportKey(blink::WebCryptoKeyFormatPkcs8,
CryptoData(HexStringToBytes(kPrivateKeyPkcs8DerHex)), CryptoData(HexStringToBytes(kPrivateKeyPkcs8DerHex)),
...@@ -226,7 +226,7 @@ TEST(WebCryptoRsaSsaTest, ImportInvalidPkcs8) { ...@@ -226,7 +226,7 @@ TEST(WebCryptoRsaSsaTest, ImportInvalidPkcs8) {
HexStringToBytes(kPrivateKeyPkcs8DerHex); HexStringToBytes(kPrivateKeyPkcs8DerHex);
corrupted_data[i] = ~corrupted_data[i]; corrupted_data[i] = ~corrupted_data[i];
blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey key;
EXPECT_EQ(Status::DataError(), EXPECT_EQ(Status::DataError(),
ImportKey(blink::WebCryptoKeyFormatPkcs8, ImportKey(blink::WebCryptoKeyFormatPkcs8,
CryptoData(corrupted_data), CryptoData(corrupted_data),
...@@ -247,7 +247,7 @@ TEST(WebCryptoRsaSsaTest, ImportRsaPrivateKeyJwkToPkcs8RoundTrip) { ...@@ -247,7 +247,7 @@ TEST(WebCryptoRsaSsaTest, ImportRsaPrivateKeyJwkToPkcs8RoundTrip) {
if (!SupportsRsaPrivateKeyImport()) if (!SupportsRsaPrivateKeyImport())
return; return;
blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey key;
ASSERT_EQ(Status::Success(), ASSERT_EQ(Status::Success(),
ImportKey(blink::WebCryptoKeyFormatPkcs8, ImportKey(blink::WebCryptoKeyFormatPkcs8,
CryptoData(HexStringToBytes(kPrivateKeyPkcs8DerHex)), CryptoData(HexStringToBytes(kPrivateKeyPkcs8DerHex)),
...@@ -341,7 +341,7 @@ TEST(WebCryptoRsaSsaTest, ImportMultipleRSAPrivateKeysJwk) { ...@@ -341,7 +341,7 @@ TEST(WebCryptoRsaSsaTest, ImportMultipleRSAPrivateKeysJwk) {
int modulus_length_bits = 0; int modulus_length_bits = 0;
ASSERT_TRUE(key_values->GetInteger("modulusLength", &modulus_length_bits)); ASSERT_TRUE(key_values->GetInteger("modulusLength", &modulus_length_bits));
blink::WebCryptoKey private_key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey private_key;
// Import the key from JWK. // Import the key from JWK.
ASSERT_EQ( ASSERT_EQ(
...@@ -389,7 +389,7 @@ TEST(WebCryptoRsaSsaTest, ImportJwkExistingModulusAndInvalid) { ...@@ -389,7 +389,7 @@ TEST(WebCryptoRsaSsaTest, ImportJwkExistingModulusAndInvalid) {
base::DictionaryValue* key1_jwk; base::DictionaryValue* key1_jwk;
ASSERT_TRUE(key1_props->GetDictionary("jwk", &key1_jwk)); ASSERT_TRUE(key1_props->GetDictionary("jwk", &key1_jwk));
blink::WebCryptoKey key1 = blink::WebCryptoKey::createNull(); blink::WebCryptoKey key1;
ASSERT_EQ(Status::Success(), ASSERT_EQ(Status::Success(),
ImportKeyJwkFromDict(*key1_jwk, ImportKeyJwkFromDict(*key1_jwk,
CreateRsaHashedImportAlgorithm( CreateRsaHashedImportAlgorithm(
...@@ -413,7 +413,7 @@ TEST(WebCryptoRsaSsaTest, ImportJwkExistingModulusAndInvalid) { ...@@ -413,7 +413,7 @@ TEST(WebCryptoRsaSsaTest, ImportJwkExistingModulusAndInvalid) {
// This should fail, as the n,e,d parameters are not consistent. It MUST NOT // This should fail, as the n,e,d parameters are not consistent. It MUST NOT
// somehow return the key created earlier. // somehow return the key created earlier.
blink::WebCryptoKey key2 = blink::WebCryptoKey::createNull(); blink::WebCryptoKey key2;
ASSERT_EQ(Status::OperationError(), ASSERT_EQ(Status::OperationError(),
ImportKeyJwkFromDict(*key2_jwk, ImportKeyJwkFromDict(*key2_jwk,
CreateRsaHashedImportAlgorithm( CreateRsaHashedImportAlgorithm(
...@@ -432,7 +432,7 @@ TEST(WebCryptoRsaSsaTest, ImportJwkExistingModulusAndInvalid) { ...@@ -432,7 +432,7 @@ TEST(WebCryptoRsaSsaTest, ImportJwkExistingModulusAndInvalid) {
// This fails because JWA says that producers must include either ALL optional // This fails because JWA says that producers must include either ALL optional
// parameters or NONE. // parameters or NONE.
TEST(WebCryptoRsaSsaTest, ImportRsaPrivateKeyJwkMissingOptionalParams) { TEST(WebCryptoRsaSsaTest, ImportRsaPrivateKeyJwkMissingOptionalParams) {
blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey key;
base::DictionaryValue dict; base::DictionaryValue dict;
dict.SetString("kty", "RSA"); dict.SetString("kty", "RSA");
...@@ -475,7 +475,7 @@ TEST(WebCryptoRsaSsaTest, ImportRsaPrivateKeyJwkIncorrectOptionalEmpty) { ...@@ -475,7 +475,7 @@ TEST(WebCryptoRsaSsaTest, ImportRsaPrivateKeyJwkIncorrectOptionalEmpty) {
if (!SupportsRsaPrivateKeyImport()) if (!SupportsRsaPrivateKeyImport())
return; return;
blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey key;
base::DictionaryValue dict; base::DictionaryValue dict;
dict.SetString("kty", "RSA"); dict.SetString("kty", "RSA");
...@@ -515,7 +515,7 @@ TEST(WebCryptoRsaSsaTest, ImportJwkRsaNonMinimalExponent) { ...@@ -515,7 +515,7 @@ TEST(WebCryptoRsaSsaTest, ImportJwkRsaNonMinimalExponent) {
"p0LGxjD1M8jMcvYq6DPEC_JYQumEu3i9v5fAEH1VvbZi9cTg-rmEXLUUjvc5LdOq_5OuHmtm" "p0LGxjD1M8jMcvYq6DPEC_JYQumEu3i9v5fAEH1VvbZi9cTg-rmEXLUUjvc5LdOq_5OuHmtm"
"e7PUJHYW1PW6ENTP0ibeiNOfFvs"); "e7PUJHYW1PW6ENTP0ibeiNOfFvs");
blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey key;
EXPECT_EQ(Status::ErrorJwkBigIntegerHasLeadingZero("e"), EXPECT_EQ(Status::ErrorJwkBigIntegerHasLeadingZero("e"),
ImportKeyJwkFromDict(dict, ImportKeyJwkFromDict(dict,
...@@ -540,8 +540,8 @@ TEST(WebCryptoRsaSsaTest, GenerateKeyPairRsa) { ...@@ -540,8 +540,8 @@ TEST(WebCryptoRsaSsaTest, GenerateKeyPairRsa) {
public_exponent); public_exponent);
bool extractable = true; bool extractable = true;
const blink::WebCryptoKeyUsageMask usage_mask = 0; const blink::WebCryptoKeyUsageMask usage_mask = 0;
blink::WebCryptoKey public_key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey public_key;
blink::WebCryptoKey private_key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey private_key;
EXPECT_EQ(Status::Success(), EXPECT_EQ(Status::Success(),
GenerateKeyPair( GenerateKeyPair(
...@@ -732,8 +732,8 @@ TEST(WebCryptoRsaSsaTest, GenerateKeyPairRsaBadModulusLength) { ...@@ -732,8 +732,8 @@ TEST(WebCryptoRsaSsaTest, GenerateKeyPairRsaBadModulusLength) {
public_exponent); public_exponent);
bool extractable = true; bool extractable = true;
const blink::WebCryptoKeyUsageMask usage_mask = 0; const blink::WebCryptoKeyUsageMask usage_mask = 0;
blink::WebCryptoKey public_key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey public_key;
blink::WebCryptoKey private_key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey private_key;
EXPECT_EQ( EXPECT_EQ(
Status::ErrorGenerateRsaUnsupportedModulus(), Status::ErrorGenerateRsaUnsupportedModulus(),
...@@ -763,8 +763,8 @@ TEST(WebCryptoRsaSsaTest, GenerateKeyPairRsaBadExponent) { ...@@ -763,8 +763,8 @@ TEST(WebCryptoRsaSsaTest, GenerateKeyPairRsaBadExponent) {
modulus_length, modulus_length,
HexStringToBytes(kPublicExponents[i])); HexStringToBytes(kPublicExponents[i]));
blink::WebCryptoKey public_key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey public_key;
blink::WebCryptoKey private_key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey private_key;
EXPECT_EQ(Status::ErrorGenerateKeyPublicExponent(), EXPECT_EQ(Status::ErrorGenerateKeyPublicExponent(),
GenerateKeyPair(algorithm, true, 0, &public_key, &private_key)); GenerateKeyPair(algorithm, true, 0, &public_key, &private_key));
...@@ -779,8 +779,8 @@ TEST(WebCryptoRsaSsaTest, SignVerifyFailures) { ...@@ -779,8 +779,8 @@ TEST(WebCryptoRsaSsaTest, SignVerifyFailures) {
blink::WebCryptoAlgorithm import_algorithm = blink::WebCryptoAlgorithm import_algorithm =
CreateRsaHashedImportAlgorithm(blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, CreateRsaHashedImportAlgorithm(blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5,
blink::WebCryptoAlgorithmIdSha1); blink::WebCryptoAlgorithmIdSha1);
blink::WebCryptoKey public_key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey public_key;
blink::WebCryptoKey private_key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey private_key;
ASSERT_NO_FATAL_FAILURE( ASSERT_NO_FATAL_FAILURE(
ImportRsaKeyPair(HexStringToBytes(kPublicKeySpkiDerHex), ImportRsaKeyPair(HexStringToBytes(kPublicKeySpkiDerHex),
HexStringToBytes(kPrivateKeyPkcs8DerHex), HexStringToBytes(kPrivateKeyPkcs8DerHex),
...@@ -872,7 +872,7 @@ TEST(WebCryptoRsaSsaTest, SignVerifyFailures) { ...@@ -872,7 +872,7 @@ TEST(WebCryptoRsaSsaTest, SignVerifyFailures) {
CryptoData(data), CryptoData(data),
&signature)); &signature));
blink::WebCryptoKey public_key_256 = blink::WebCryptoKey::createNull(); blink::WebCryptoKey public_key_256;
EXPECT_EQ(Status::Success(), EXPECT_EQ(Status::Success(),
ImportKey(blink::WebCryptoKeyFormatSpki, ImportKey(blink::WebCryptoKeyFormatSpki,
CryptoData(HexStringToBytes(kPublicKeySpkiDerHex)), CryptoData(HexStringToBytes(kPublicKeySpkiDerHex)),
...@@ -914,8 +914,8 @@ TEST(WebCryptoRsaSsaTest, SignVerifyKnownAnswer) { ...@@ -914,8 +914,8 @@ TEST(WebCryptoRsaSsaTest, SignVerifyKnownAnswer) {
blink::WebCryptoAlgorithm import_algorithm = blink::WebCryptoAlgorithm import_algorithm =
CreateRsaHashedImportAlgorithm(blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, CreateRsaHashedImportAlgorithm(blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5,
blink::WebCryptoAlgorithmIdSha1); blink::WebCryptoAlgorithmIdSha1);
blink::WebCryptoKey public_key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey public_key;
blink::WebCryptoKey private_key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey private_key;
ASSERT_NO_FATAL_FAILURE( ASSERT_NO_FATAL_FAILURE(
ImportRsaKeyPair(HexStringToBytes(kPublicKeySpkiDerHex), ImportRsaKeyPair(HexStringToBytes(kPublicKeySpkiDerHex),
HexStringToBytes(kPrivateKeyPkcs8DerHex), HexStringToBytes(kPrivateKeyPkcs8DerHex),
...@@ -976,7 +976,7 @@ TEST(WebCryptoRsaSsaTest, ImportRsaSsaPublicKeyBadUsage_SPKI) { ...@@ -976,7 +976,7 @@ TEST(WebCryptoRsaSsaTest, ImportRsaSsaPublicKeyBadUsage_SPKI) {
for (size_t i = 0; i < arraysize(bad_usages); ++i) { for (size_t i = 0; i < arraysize(bad_usages); ++i) {
SCOPED_TRACE(i); SCOPED_TRACE(i);
blink::WebCryptoKey public_key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey public_key;
ASSERT_EQ(Status::ErrorCreateKeyBadUsages(), ASSERT_EQ(Status::ErrorCreateKeyBadUsages(),
ImportKey(blink::WebCryptoKeyFormatSpki, ImportKey(blink::WebCryptoKeyFormatSpki,
CryptoData(HexStringToBytes(kPublicKeySpkiDerHex)), CryptoData(HexStringToBytes(kPublicKeySpkiDerHex)),
...@@ -1009,7 +1009,7 @@ TEST(WebCryptoRsaSsaTest, ImportRsaSsaPublicKeyBadUsage_JWK) { ...@@ -1009,7 +1009,7 @@ TEST(WebCryptoRsaSsaTest, ImportRsaSsaPublicKeyBadUsage_JWK) {
for (size_t i = 0; i < arraysize(bad_usages); ++i) { for (size_t i = 0; i < arraysize(bad_usages); ++i) {
SCOPED_TRACE(i); SCOPED_TRACE(i);
blink::WebCryptoKey public_key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey public_key;
ASSERT_EQ(Status::ErrorCreateKeyBadUsages(), ASSERT_EQ(Status::ErrorCreateKeyBadUsages(),
ImportKeyJwkFromDict( ImportKeyJwkFromDict(
dict, algorithm, false, bad_usages[i], &public_key)); dict, algorithm, false, bad_usages[i], &public_key));
...@@ -1031,8 +1031,8 @@ TEST(WebCryptoRsaSsaTest, GenerateKeyBadUsages) { ...@@ -1031,8 +1031,8 @@ TEST(WebCryptoRsaSsaTest, GenerateKeyBadUsages) {
for (size_t i = 0; i < arraysize(bad_usages); ++i) { for (size_t i = 0; i < arraysize(bad_usages); ++i) {
SCOPED_TRACE(i); SCOPED_TRACE(i);
blink::WebCryptoKey public_key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey public_key;
blink::WebCryptoKey private_key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey private_key;
ASSERT_EQ(Status::ErrorCreateKeyBadUsages(), ASSERT_EQ(Status::ErrorCreateKeyBadUsages(),
GenerateKeyPair(CreateRsaHashedKeyGenAlgorithm( GenerateKeyPair(CreateRsaHashedKeyGenAlgorithm(
...@@ -1054,8 +1054,8 @@ TEST(WebCryptoRsaSsaTest, GenerateKeyPairIntersectUsages) { ...@@ -1054,8 +1054,8 @@ TEST(WebCryptoRsaSsaTest, GenerateKeyPairIntersectUsages) {
const unsigned int modulus_length = 256; const unsigned int modulus_length = 256;
const std::vector<uint8_t> public_exponent = HexStringToBytes("010001"); const std::vector<uint8_t> public_exponent = HexStringToBytes("010001");
blink::WebCryptoKey public_key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey public_key;
blink::WebCryptoKey private_key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey private_key;
ASSERT_EQ(Status::Success(), ASSERT_EQ(Status::Success(),
GenerateKeyPair( GenerateKeyPair(
...@@ -1112,7 +1112,7 @@ TEST(WebCryptoRsaSsaTest, ImportExportJwkRsaPublicKey) { ...@@ -1112,7 +1112,7 @@ TEST(WebCryptoRsaSsaTest, ImportExportJwkRsaPublicKey) {
blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, test.hash); blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, test.hash);
// Import the spki to create a public key // Import the spki to create a public key
blink::WebCryptoKey public_key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey public_key;
ASSERT_EQ(Status::Success(), ASSERT_EQ(Status::Success(),
ImportKey(blink::WebCryptoKeyFormatSpki, ImportKey(blink::WebCryptoKeyFormatSpki,
CryptoData(HexStringToBytes(kPublicKeySpkiDerHex)), CryptoData(HexStringToBytes(kPublicKeySpkiDerHex)),
...@@ -1132,7 +1132,7 @@ TEST(WebCryptoRsaSsaTest, ImportExportJwkRsaPublicKey) { ...@@ -1132,7 +1132,7 @@ TEST(WebCryptoRsaSsaTest, ImportExportJwkRsaPublicKey) {
test.usage)); test.usage));
// Import the JWK back in to create a new key // Import the JWK back in to create a new key
blink::WebCryptoKey public_key2 = blink::WebCryptoKey::createNull(); blink::WebCryptoKey public_key2;
ASSERT_EQ(Status::Success(), ASSERT_EQ(Status::Success(),
ImportKey(blink::WebCryptoKeyFormatJwk, ImportKey(blink::WebCryptoKeyFormatJwk,
CryptoData(jwk), CryptoData(jwk),
...@@ -1160,7 +1160,7 @@ TEST(WebCryptoRsaSsaTest, ImportJwkRsaFailures) { ...@@ -1160,7 +1160,7 @@ TEST(WebCryptoRsaSsaTest, ImportJwkRsaFailures) {
CreateRsaHashedImportAlgorithm(blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, CreateRsaHashedImportAlgorithm(blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5,
blink::WebCryptoAlgorithmIdSha256); blink::WebCryptoAlgorithmIdSha256);
blink::WebCryptoKeyUsageMask usage_mask = blink::WebCryptoKeyUsageVerify; blink::WebCryptoKeyUsageMask usage_mask = blink::WebCryptoKeyUsageVerify;
blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey key;
// An RSA public key JWK _must_ have an "n" (modulus) and an "e" (exponent) // An RSA public key JWK _must_ have an "n" (modulus) and an "e" (exponent)
// entry, while an RSA private key must have those plus at least a "d" // entry, while an RSA private key must have those plus at least a "d"
......
...@@ -75,7 +75,7 @@ bool operator!=(const CryptoData& a, const CryptoData& b) { ...@@ -75,7 +75,7 @@ bool operator!=(const CryptoData& a, const CryptoData& b) {
bool SupportsAesGcm() { bool SupportsAesGcm() {
std::vector<uint8_t> key_raw(16, 0); std::vector<uint8_t> key_raw(16, 0);
blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey key;
Status status = ImportKey(blink::WebCryptoKeyFormatRaw, Status status = ImportKey(blink::WebCryptoKeyFormatRaw,
CryptoData(key_raw), CryptoData(key_raw),
CreateAlgorithm(blink::WebCryptoAlgorithmIdAesGcm), CreateAlgorithm(blink::WebCryptoAlgorithmIdAesGcm),
...@@ -344,7 +344,7 @@ blink::WebCryptoKey ImportSecretKeyFromRaw( ...@@ -344,7 +344,7 @@ blink::WebCryptoKey ImportSecretKeyFromRaw(
const std::vector<uint8_t>& key_raw, const std::vector<uint8_t>& key_raw,
const blink::WebCryptoAlgorithm& algorithm, const blink::WebCryptoAlgorithm& algorithm,
blink::WebCryptoKeyUsageMask usage) { blink::WebCryptoKeyUsageMask usage) {
blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); blink::WebCryptoKey key;
bool extractable = true; bool extractable = true;
EXPECT_EQ(Status::Success(), EXPECT_EQ(Status::Success(),
ImportKey(blink::WebCryptoKeyFormatRaw, ImportKey(blink::WebCryptoKeyFormatRaw,
......
...@@ -238,8 +238,7 @@ struct ImportKeyState : public BaseState { ...@@ -238,8 +238,7 @@ struct ImportKeyState : public BaseState {
key_data(key_data, key_data + key_data_size), key_data(key_data, key_data + key_data_size),
algorithm(algorithm), algorithm(algorithm),
extractable(extractable), extractable(extractable),
usage_mask(usage_mask), usage_mask(usage_mask) {}
key(blink::WebCryptoKey::createNull()) {}
const blink::WebCryptoKeyFormat format; const blink::WebCryptoKeyFormat format;
const std::vector<uint8_t> key_data; const std::vector<uint8_t> key_data;
...@@ -324,8 +323,7 @@ struct UnwrapKeyState : public BaseState { ...@@ -324,8 +323,7 @@ struct UnwrapKeyState : public BaseState {
unwrap_algorithm(unwrap_algorithm), unwrap_algorithm(unwrap_algorithm),
unwrapped_key_algorithm(unwrapped_key_algorithm), unwrapped_key_algorithm(unwrapped_key_algorithm),
extractable(extractable), extractable(extractable),
usages(usages), usages(usages) {}
unwrapped_key(blink::WebCryptoKey::createNull()) {}
const blink::WebCryptoKeyFormat format; const blink::WebCryptoKeyFormat format;
const std::vector<uint8_t> wrapped_key; const std::vector<uint8_t> wrapped_key;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment