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.
......
...@@ -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),
......
...@@ -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