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 {
namespace webcrypto {
GenerateKeyResult::GenerateKeyResult()
: type_(TYPE_NULL),
secret_key_(blink::WebCryptoKey::createNull()),
public_key_(blink::WebCryptoKey::createNull()),
private_key_(blink::WebCryptoKey::createNull()) {
GenerateKeyResult::GenerateKeyResult() : type_(TYPE_NULL) {
}
GenerateKeyResult::Type GenerateKeyResult::type() const {
......
......@@ -284,8 +284,8 @@ Status RsaHashedAlgorithm::GenerateKey(
return Status::OperationError();
}
blink::WebCryptoKey public_key = blink::WebCryptoKey::createNull();
blink::WebCryptoKey private_key = blink::WebCryptoKey::createNull();
blink::WebCryptoKey public_key;
blink::WebCryptoKey private_key;
// Note that extractable is unconditionally set to true. This is because per
// the WebCrypto spec generated public keys are always public.
......
......@@ -109,7 +109,7 @@ TEST(WebCryptoAesGcmTest, GenerateKeyBadLength) {
}
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) {
SCOPED_TRACE(i);
EXPECT_EQ(Status::ErrorGenerateKeyLength(),
......
......@@ -25,7 +25,7 @@ blink::WebCryptoAlgorithm CreateAesKwKeyGenAlgorithm(
TEST(WebCryptoAesKwTest, GenerateKeyBadLength) {
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) {
SCOPED_TRACE(i);
EXPECT_EQ(Status::ErrorGenerateKeyLength(),
......@@ -35,7 +35,7 @@ TEST(WebCryptoAesKwTest, GenerateKeyBadLength) {
}
TEST(WebCryptoAesKwTest, ImportKeyJwkKeyOpsWrapUnwrap) {
blink::WebCryptoKey key = blink::WebCryptoKey::createNull();
blink::WebCryptoKey key;
base::DictionaryValue dict;
dict.SetString("kty", "oct");
dict.SetString("k", "GADWrMRHwQfoNaXU5fZvTg==");
......@@ -87,7 +87,7 @@ TEST(WebCryptoAesKwTest, ImportExportJwk) {
}
TEST(WebCryptoAesKwTest, AesKwKeyImport) {
blink::WebCryptoKey key = blink::WebCryptoKey::createNull();
blink::WebCryptoKey key;
blink::WebCryptoAlgorithm algorithm =
CreateAlgorithm(blink::WebCryptoAlgorithmIdAesKw);
......@@ -180,7 +180,7 @@ TEST(WebCryptoAesKwTest, UnwrapFailures) {
const std::vector<uint8_t> 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
// should fail.
......@@ -237,7 +237,7 @@ TEST(WebCryptoAesKwTest, AesKwRawSymkeyWrapUnwrapKnownAnswer) {
EXPECT_BYTES_EQ(test_ciphertext, wrapped_key);
// Unwrap the known ciphertext to get a new test_key.
blink::WebCryptoKey unwrapped_key = blink::WebCryptoKey::createNull();
blink::WebCryptoKey unwrapped_key;
ASSERT_EQ(
Status::Success(),
UnwrapKey(blink::WebCryptoKeyFormatRaw,
......@@ -282,7 +282,7 @@ TEST(WebCryptoAesKwTest, AesKwRawSymkeyUnwrapSignVerifyHmac) {
test_kek, wrapping_algorithm, blink::WebCryptoKeyUsageUnwrapKey);
// Unwrap the known ciphertext.
blink::WebCryptoKey key = blink::WebCryptoKey::createNull();
blink::WebCryptoKey key;
ASSERT_EQ(
Status::Success(),
UnwrapKey(blink::WebCryptoKeyFormatRaw,
......@@ -349,7 +349,7 @@ TEST(WebCryptoAesKwTest, AesKwRawSymkeyWrapUnwrapErrors) {
// Unwrap with wrapped data too small must fail.
const std::vector<uint8_t> small_data(test_ciphertext.begin(),
test_ciphertext.begin() + 23);
blink::WebCryptoKey unwrapped_key = blink::WebCryptoKey::createNull();
blink::WebCryptoKey unwrapped_key;
EXPECT_EQ(Status::ErrorDataTooSmall(),
UnwrapKey(blink::WebCryptoKeyFormatRaw,
CryptoData(small_data),
......@@ -395,7 +395,7 @@ TEST(WebCryptoAesKwTest, AesKwRawSymkeyUnwrapCorruptData) {
// Unwrap of a corrupted version of the known ciphertext should fail, due to
// AES-KW's built-in integrity check.
blink::WebCryptoKey unwrapped_key = blink::WebCryptoKey::createNull();
blink::WebCryptoKey unwrapped_key;
EXPECT_EQ(Status::OperationError(),
UnwrapKey(blink::WebCryptoKeyFormatRaw,
CryptoData(Corrupted(test_ciphertext)),
......@@ -432,7 +432,7 @@ TEST(WebCryptoAesKwTest, AesKwJwkSymkeyUnwrapKnownData) {
wrapping_key_data, wrapping_algorithm, blink::WebCryptoKeyUsageUnwrapKey);
// Unwrap the known wrapped key data to produce a new key
blink::WebCryptoKey unwrapped_key = blink::WebCryptoKey::createNull();
blink::WebCryptoKey unwrapped_key;
ASSERT_EQ(
Status::Success(),
UnwrapKey(blink::WebCryptoKeyFormatJwk,
......@@ -483,7 +483,7 @@ TEST(WebCryptoAesKwTest, ImportKeyBadUsage_Raw) {
for (size_t i = 0; i < arraysize(bad_usages); ++i) {
SCOPED_TRACE(i);
blink::WebCryptoKey key = blink::WebCryptoKey::createNull();
blink::WebCryptoKey key;
ASSERT_EQ(Status::ErrorCreateKeyBadUsages(),
ImportKey(blink::WebCryptoKeyFormatRaw,
CryptoData(key_bytes),
......@@ -510,7 +510,7 @@ TEST(WebCryptoAesKwTest, UnwrapHmacKeyBadUsage_JWK) {
};
// Import the wrapping key.
blink::WebCryptoKey wrapping_key = blink::WebCryptoKey::createNull();
blink::WebCryptoKey wrapping_key;
ASSERT_EQ(Status::Success(),
ImportKey(blink::WebCryptoKeyFormatRaw,
CryptoData(std::vector<uint8_t>(16)),
......@@ -529,7 +529,7 @@ TEST(WebCryptoAesKwTest, UnwrapHmacKeyBadUsage_JWK) {
for (size_t i = 0; i < arraysize(bad_usages); ++i) {
SCOPED_TRACE(i);
blink::WebCryptoKey key = blink::WebCryptoKey::createNull();
blink::WebCryptoKey key;
ASSERT_EQ(
Status::ErrorCreateKeyBadUsages(),
......@@ -560,7 +560,7 @@ TEST(WebCryptoAesKwTest, UnwrapRsaSsaPublicKeyBadUsage_JWK) {
};
// Import the wrapping key.
blink::WebCryptoKey wrapping_key = blink::WebCryptoKey::createNull();
blink::WebCryptoKey wrapping_key;
ASSERT_EQ(Status::Success(),
ImportKey(blink::WebCryptoKeyFormatRaw,
CryptoData(std::vector<uint8_t>(16)),
......@@ -584,7 +584,7 @@ TEST(WebCryptoAesKwTest, UnwrapRsaSsaPublicKeyBadUsage_JWK) {
for (size_t i = 0; i < arraysize(bad_usages); ++i) {
SCOPED_TRACE(i);
blink::WebCryptoKey key = blink::WebCryptoKey::createNull();
blink::WebCryptoKey key;
ASSERT_EQ(Status::ErrorCreateKeyBadUsages(),
UnwrapKey(blink::WebCryptoKeyFormatJwk,
......
......@@ -118,7 +118,7 @@ TEST(WebCryptoHmacTest, GenerateKeyIsRandom) {
std::vector<std::vector<uint8_t> > keys;
for (int i = 0; i < 16; ++i) {
std::vector<uint8_t> key_bytes;
blink::WebCryptoKey key = blink::WebCryptoKey::createNull();
blink::WebCryptoKey key;
blink::WebCryptoAlgorithm algorithm =
CreateHmacKeyGenAlgorithm(blink::WebCryptoAlgorithmIdSha1, 512);
ASSERT_EQ(Status::Success(), GenerateSecretKey(algorithm, true, 0, &key));
......@@ -143,7 +143,7 @@ TEST(WebCryptoHmacTest, GenerateKeyIsRandom) {
// If the key length is not provided, then the block size is used.
TEST(WebCryptoHmacTest, GenerateKeyNoLengthSha1) {
blink::WebCryptoKey key = blink::WebCryptoKey::createNull();
blink::WebCryptoKey key;
blink::WebCryptoAlgorithm algorithm =
CreateHmacKeyGenAlgorithm(blink::WebCryptoAlgorithmIdSha1, 0);
ASSERT_EQ(Status::Success(), GenerateSecretKey(algorithm, true, 0, &key));
......@@ -161,7 +161,7 @@ TEST(WebCryptoHmacTest, GenerateKeyNoLengthSha1) {
// If the key length is not provided, then the block size is used.
TEST(WebCryptoHmacTest, GenerateKeyNoLengthSha512) {
blink::WebCryptoKey key = blink::WebCryptoKey::createNull();
blink::WebCryptoKey key;
blink::WebCryptoAlgorithm algorithm =
CreateHmacKeyGenAlgorithm(blink::WebCryptoAlgorithmIdSha512, 0);
ASSERT_EQ(Status::Success(), GenerateSecretKey(algorithm, true, 0, &key));
......@@ -176,7 +176,7 @@ TEST(WebCryptoHmacTest, GenerateKeyNoLengthSha512) {
}
TEST(WebCryptoHmacTest, ImportKeyJwkKeyOpsSignVerify) {
blink::WebCryptoKey key = blink::WebCryptoKey::createNull();
blink::WebCryptoKey key;
base::DictionaryValue dict;
dict.SetString("kty", "oct");
dict.SetString("k", "GADWrMRHwQfoNaXU5fZvTg==");
......@@ -210,7 +210,7 @@ TEST(WebCryptoHmacTest, ImportKeyJwkKeyOpsSignVerify) {
// Test 'use' inconsistent with 'key_ops'.
TEST(WebCryptoHmacTest, ImportKeyJwkUseInconsisteWithKeyOps) {
blink::WebCryptoKey key = blink::WebCryptoKey::createNull();
blink::WebCryptoKey key;
base::DictionaryValue dict;
dict.SetString("kty", "oct");
dict.SetString("k", "GADWrMRHwQfoNaXU5fZvTg==");
......@@ -233,7 +233,7 @@ TEST(WebCryptoHmacTest, ImportKeyJwkUseInconsisteWithKeyOps) {
// Test JWK composite 'sig' use
TEST(WebCryptoHmacTest, ImportKeyJwkUseSig) {
blink::WebCryptoKey key = blink::WebCryptoKey::createNull();
blink::WebCryptoKey key;
base::DictionaryValue dict;
dict.SetString("kty", "oct");
dict.SetString("k", "GADWrMRHwQfoNaXU5fZvTg==");
......@@ -256,7 +256,7 @@ TEST(WebCryptoHmacTest, ImportJwkInputConsistency) {
// inconsistent with the input value, the operation must fail.
// Consistency rules when JWK value is not present: Inputs should be used.
blink::WebCryptoKey key = blink::WebCryptoKey::createNull();
blink::WebCryptoKey key;
bool extractable = false;
blink::WebCryptoAlgorithm algorithm =
CreateHmacImportAlgorithm(blink::WebCryptoAlgorithmIdSha256);
......@@ -408,7 +408,7 @@ TEST(WebCryptoHmacTest, ImportJwkHappy) {
// This test verifies the happy path of JWK import, including the application
// of the imported key material.
blink::WebCryptoKey key = blink::WebCryptoKey::createNull();
blink::WebCryptoKey key;
bool extractable = false;
blink::WebCryptoAlgorithm algorithm =
CreateHmacImportAlgorithm(blink::WebCryptoAlgorithmIdSha256);
......@@ -488,7 +488,7 @@ TEST(WebCryptoHmacTest, ExportJwkEmptyKey) {
CreateHmacImportAlgorithm(blink::WebCryptoAlgorithmIdSha1);
blink::WebCryptoKeyUsageMask usages = blink::WebCryptoKeyUsageSign;
blink::WebCryptoKey key = blink::WebCryptoKey::createNull();
blink::WebCryptoKey key;
// Import a zero-byte HMAC key.
const char key_data_hex[] = "";
......@@ -527,7 +527,7 @@ TEST(WebCryptoHmacTest, ExportJwkEmptyKey) {
TEST(WebCryptoHmacTest, ImportRawKeyTooLarge) {
CryptoData big_data(NULL, UINT_MAX); // Invalid data of big length.
blink::WebCryptoKey key = blink::WebCryptoKey::createNull();
blink::WebCryptoKey key;
EXPECT_EQ(
Status::ErrorDataTooLarge(),
ImportKey(blink::WebCryptoKeyFormatRaw,
......
......@@ -47,7 +47,7 @@ TEST(WebCryptoRsaOaepTest, ImportPkcs8WithRsaEncryption) {
return;
}
blink::WebCryptoKey private_key = blink::WebCryptoKey::createNull();
blink::WebCryptoKey private_key;
ASSERT_EQ(Status::Success(),
ImportKey(blink::WebCryptoKeyFormatPkcs8,
CryptoData(HexStringToBytes(kPrivateKeyPkcs8DerHex)),
......@@ -67,7 +67,7 @@ TEST(WebCryptoRsaOaepTest, ImportPublicJwkWithNoAlg) {
scoped_ptr<base::DictionaryValue> jwk(CreatePublicKeyJwkDict());
blink::WebCryptoKey public_key = blink::WebCryptoKey::createNull();
blink::WebCryptoKey public_key;
ASSERT_EQ(Status::Success(),
ImportKeyJwkFromDict(*jwk.get(),
CreateRsaHashedImportAlgorithm(
......@@ -87,7 +87,7 @@ TEST(WebCryptoRsaOaepTest, ImportPublicJwkWithMatchingAlg) {
scoped_ptr<base::DictionaryValue> jwk(CreatePublicKeyJwkDict());
jwk->SetString("alg", "RSA-OAEP");
blink::WebCryptoKey public_key = blink::WebCryptoKey::createNull();
blink::WebCryptoKey public_key;
ASSERT_EQ(Status::Success(),
ImportKeyJwkFromDict(*jwk.get(),
CreateRsaHashedImportAlgorithm(
......@@ -107,7 +107,7 @@ TEST(WebCryptoRsaOaepTest, ImportPublicJwkWithMismatchedAlgFails) {
scoped_ptr<base::DictionaryValue> jwk(CreatePublicKeyJwkDict());
jwk->SetString("alg", "RSA-OAEP-512");
blink::WebCryptoKey public_key = blink::WebCryptoKey::createNull();
blink::WebCryptoKey public_key;
ASSERT_EQ(Status::ErrorJwkAlgorithmInconsistent(),
ImportKeyJwkFromDict(*jwk.get(),
CreateRsaHashedImportAlgorithm(
......@@ -128,7 +128,7 @@ TEST(WebCryptoRsaOaepTest, ImportPublicJwkWithMismatchedTypeFails) {
jwk->SetString("kty", "oct");
jwk->SetString("alg", "RSA-OAEP");
blink::WebCryptoKey public_key = blink::WebCryptoKey::createNull();
blink::WebCryptoKey public_key;
ASSERT_EQ(Status::ErrorJwkUnexpectedKty("RSA"),
ImportKeyJwkFromDict(*jwk.get(),
CreateRsaHashedImportAlgorithm(
......@@ -160,7 +160,7 @@ TEST(WebCryptoRsaOaepTest, ExportPublicJwk) {
jwk->SetString("alg", test_data.expected_jwk_alg);
// Import the key in a known-good format
blink::WebCryptoKey public_key = blink::WebCryptoKey::createNull();
blink::WebCryptoKey public_key;
ASSERT_EQ(Status::Success(),
ImportKeyJwkFromDict(
*jwk.get(),
......@@ -210,8 +210,8 @@ TEST(WebCryptoRsaOaepTest, EncryptDecryptKnownAnswerTest) {
blink::WebCryptoAlgorithm import_algorithm = CreateRsaHashedImportAlgorithm(
blink::WebCryptoAlgorithmIdRsaOaep, digest_algorithm.id());
blink::WebCryptoKey public_key = blink::WebCryptoKey::createNull();
blink::WebCryptoKey private_key = blink::WebCryptoKey::createNull();
blink::WebCryptoKey public_key;
blink::WebCryptoKey private_key;
ASSERT_NO_FATAL_FAILURE(ImportRsaKeyPair(public_key_der,
private_key_der,
......@@ -256,7 +256,7 @@ TEST(WebCryptoRsaOaepTest, EncryptWithLargeMessageFails) {
scoped_ptr<base::DictionaryValue> jwk(CreatePublicKeyJwkDict());
blink::WebCryptoKey public_key = blink::WebCryptoKey::createNull();
blink::WebCryptoKey public_key;
ASSERT_EQ(Status::Success(),
ImportKeyJwkFromDict(*jwk.get(),
CreateRsaHashedImportAlgorithm(
......@@ -323,7 +323,7 @@ TEST(WebCryptoRsaOaepTest, EncryptWithLargeDigestFails) {
scoped_ptr<base::DictionaryValue> jwk(CreatePublicKeyJwkDict());
blink::WebCryptoKey public_key = blink::WebCryptoKey::createNull();
blink::WebCryptoKey public_key;
ASSERT_EQ(Status::Success(),
ImportKeyJwkFromDict(*jwk.get(),
CreateRsaHashedImportAlgorithm(
......@@ -353,7 +353,7 @@ TEST(WebCryptoRsaOaepTest, DecryptWithLargeMessageFails) {
return;
}
blink::WebCryptoKey private_key = blink::WebCryptoKey::createNull();
blink::WebCryptoKey private_key;
ASSERT_EQ(Status::Success(),
ImportKey(blink::WebCryptoKeyFormatPkcs8,
CryptoData(HexStringToBytes(kPrivateKeyPkcs8DerHex)),
......@@ -387,8 +387,8 @@ TEST(WebCryptoRsaOaepTest, WrapUnwrapRawKey) {
blink::WebCryptoAlgorithm import_algorithm = CreateRsaHashedImportAlgorithm(
blink::WebCryptoAlgorithmIdRsaOaep, blink::WebCryptoAlgorithmIdSha1);
blink::WebCryptoKey public_key = blink::WebCryptoKey::createNull();
blink::WebCryptoKey private_key = blink::WebCryptoKey::createNull();
blink::WebCryptoKey public_key;
blink::WebCryptoKey private_key;
ASSERT_NO_FATAL_FAILURE(ImportRsaKeyPair(
HexStringToBytes(kPublicKeySpkiDerHex),
......@@ -432,7 +432,7 @@ TEST(WebCryptoRsaOaepTest, WrapUnwrapRawKey) {
EXPECT_BYTES_EQ_HEX(key_hex, decrypted_key);
// 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(),
UnwrapKey(blink::WebCryptoKeyFormatRaw,
CryptoData(wrapped_key),
......@@ -505,8 +505,8 @@ TEST(WebCryptoRsaOaepTest, WrapUnwrapJwkSymKey) {
"37f3e1972c45a477e66db95c9609bb27f862700ef93379930786cf751b";
blink::WebCryptoAlgorithm import_algorithm = CreateRsaHashedImportAlgorithm(
blink::WebCryptoAlgorithmIdRsaOaep, blink::WebCryptoAlgorithmIdSha1);
blink::WebCryptoKey public_key = blink::WebCryptoKey::createNull();
blink::WebCryptoKey private_key = blink::WebCryptoKey::createNull();
blink::WebCryptoKey public_key;
blink::WebCryptoKey private_key;
ASSERT_NO_FATAL_FAILURE(ImportRsaKeyPair(
HexStringToBytes(kPublicKey2048SpkiDerHex),
......@@ -551,7 +551,7 @@ TEST(WebCryptoRsaOaepTest, WrapUnwrapJwkSymKey) {
decrypted_jwk, "A128CBC", key_hex, blink::WebCryptoKeyUsageEncrypt));
// 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(),
UnwrapKey(blink::WebCryptoKeyFormatJwk,
CryptoData(wrapped_key),
......@@ -598,7 +598,7 @@ TEST(WebCryptoRsaOaepTest, ImportExportJwkRsaPublicKey) {
test.hash);
// Import the spki to create a public key
blink::WebCryptoKey public_key = blink::WebCryptoKey::createNull();
blink::WebCryptoKey public_key;
ASSERT_EQ(Status::Success(),
ImportKey(blink::WebCryptoKeyFormatSpki,
CryptoData(HexStringToBytes(kPublicKeySpkiDerHex)),
......@@ -618,7 +618,7 @@ TEST(WebCryptoRsaOaepTest, ImportExportJwkRsaPublicKey) {
test.usage));
// 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(),
ImportKey(blink::WebCryptoKeyFormatJwk,
CryptoData(jwk),
......
......@@ -75,7 +75,7 @@ bool operator!=(const CryptoData& a, const CryptoData& b) {
bool SupportsAesGcm() {
std::vector<uint8_t> key_raw(16, 0);
blink::WebCryptoKey key = blink::WebCryptoKey::createNull();
blink::WebCryptoKey key;
Status status = ImportKey(blink::WebCryptoKeyFormatRaw,
CryptoData(key_raw),
CreateAlgorithm(blink::WebCryptoAlgorithmIdAesGcm),
......@@ -344,7 +344,7 @@ blink::WebCryptoKey ImportSecretKeyFromRaw(
const std::vector<uint8_t>& key_raw,
const blink::WebCryptoAlgorithm& algorithm,
blink::WebCryptoKeyUsageMask usage) {
blink::WebCryptoKey key = blink::WebCryptoKey::createNull();
blink::WebCryptoKey key;
bool extractable = true;
EXPECT_EQ(Status::Success(),
ImportKey(blink::WebCryptoKeyFormatRaw,
......
......@@ -238,8 +238,7 @@ struct ImportKeyState : public BaseState {
key_data(key_data, key_data + key_data_size),
algorithm(algorithm),
extractable(extractable),
usage_mask(usage_mask),
key(blink::WebCryptoKey::createNull()) {}
usage_mask(usage_mask) {}
const blink::WebCryptoKeyFormat format;
const std::vector<uint8_t> key_data;
......@@ -324,8 +323,7 @@ struct UnwrapKeyState : public BaseState {
unwrap_algorithm(unwrap_algorithm),
unwrapped_key_algorithm(unwrapped_key_algorithm),
extractable(extractable),
usages(usages),
unwrapped_key(blink::WebCryptoKey::createNull()) {}
usages(usages) {}
const blink::WebCryptoKeyFormat format;
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