diff options
Diffstat (limited to 'chromium/components/webcrypto')
4 files changed, 22 insertions, 17 deletions
diff --git a/chromium/components/webcrypto/algorithms/aes_cbc_unittest.cc b/chromium/components/webcrypto/algorithms/aes_cbc_unittest.cc index 86c67db9842..88204984a12 100644 --- a/chromium/components/webcrypto/algorithms/aes_cbc_unittest.cc +++ b/chromium/components/webcrypto/algorithms/aes_cbc_unittest.cc @@ -6,7 +6,10 @@ #include <stddef.h> #include <stdint.h> +#include <utility> + #include "base/macros.h" +#include "base/memory/ptr_util.h" #include "base/values.h" #include "components/webcrypto/algorithm_dispatch.h" #include "components/webcrypto/algorithms/test_helpers.h" @@ -219,7 +222,7 @@ TEST_F(WebCryptoAesCbcTest, ImportKeyJwkEmptyKeyOps) { dict.SetString("kty", "oct"); dict.SetBoolean("ext", false); dict.SetString("k", "GADWrMRHwQfoNaXU5fZvTg"); - dict.Set("key_ops", new base::ListValue); // Takes ownership. + dict.Set("key_ops", base::MakeUnique<base::ListValue>()); // The JWK does not contain encrypt usages. EXPECT_EQ(Status::ErrorJwkKeyopsInconsistent(), @@ -260,8 +263,8 @@ TEST_F(WebCryptoAesCbcTest, ImportKeyJwkKeyOpsEncryptDecrypt) { base::DictionaryValue dict; dict.SetString("kty", "oct"); dict.SetString("k", "GADWrMRHwQfoNaXU5fZvTg"); - base::ListValue* key_ops = new base::ListValue; - dict.Set("key_ops", key_ops); // Takes ownership. + base::ListValue* key_ops = + dict.SetList("key_ops", base::MakeUnique<base::ListValue>()); key_ops->AppendString("encrypt"); @@ -298,10 +301,9 @@ TEST_F(WebCryptoAesCbcTest, ImportKeyJwkKeyOpsNotSuperset) { base::DictionaryValue dict; dict.SetString("kty", "oct"); dict.SetString("k", "GADWrMRHwQfoNaXU5fZvTg"); - base::ListValue* key_ops = new base::ListValue; - dict.Set("key_ops", key_ops); // Takes ownership. - + auto key_ops = base::MakeUnique<base::ListValue>(); key_ops->AppendString("encrypt"); + dict.Set("key_ops", std::move(key_ops)); EXPECT_EQ( Status::ErrorJwkKeyopsInconsistent(), @@ -364,10 +366,9 @@ TEST_F(WebCryptoAesCbcTest, ImportJwkKeyOpsLacksUsages) { dict.SetString("kty", "oct"); dict.SetString("k", "GADWrMRHwQfoNaXU5fZvTg"); - base::ListValue* key_ops = new base::ListValue; - // Note: the following call makes dict assume ownership of key_ops. - dict.Set("key_ops", key_ops); + auto key_ops = base::MakeUnique<base::ListValue>(); key_ops->AppendString("foo"); + dict.Set("key_ops", std::move(key_ops)); EXPECT_EQ(Status::ErrorJwkKeyopsInconsistent(), ImportKeyJwkFromDict( dict, CreateAlgorithm(blink::kWebCryptoAlgorithmIdAesCbc), diff --git a/chromium/components/webcrypto/algorithms/aes_kw_unittest.cc b/chromium/components/webcrypto/algorithms/aes_kw_unittest.cc index 293510021f2..12dea24036a 100644 --- a/chromium/components/webcrypto/algorithms/aes_kw_unittest.cc +++ b/chromium/components/webcrypto/algorithms/aes_kw_unittest.cc @@ -6,6 +6,7 @@ #include <stdint.h> #include "base/macros.h" +#include "base/memory/ptr_util.h" #include "base/stl_util.h" #include "base/values.h" #include "components/webcrypto/algorithm_dispatch.h" @@ -58,8 +59,8 @@ TEST_F(WebCryptoAesKwTest, ImportKeyJwkKeyOpsWrapUnwrap) { base::DictionaryValue dict; dict.SetString("kty", "oct"); dict.SetString("k", "GADWrMRHwQfoNaXU5fZvTg"); - base::ListValue* key_ops = new base::ListValue; - dict.Set("key_ops", key_ops); // Takes ownership. + base::ListValue* key_ops = + dict.SetList("key_ops", base::MakeUnique<base::ListValue>()); key_ops->AppendString("wrapKey"); diff --git a/chromium/components/webcrypto/algorithms/hmac_unittest.cc b/chromium/components/webcrypto/algorithms/hmac_unittest.cc index fe5b331323e..a57cdd825be 100644 --- a/chromium/components/webcrypto/algorithms/hmac_unittest.cc +++ b/chromium/components/webcrypto/algorithms/hmac_unittest.cc @@ -6,7 +6,10 @@ #include <stddef.h> #include <stdint.h> +#include <utility> + #include "base/logging.h" +#include "base/memory/ptr_util.h" #include "base/values.h" #include "components/webcrypto/algorithm_dispatch.h" #include "components/webcrypto/algorithms/test_helpers.h" @@ -228,8 +231,8 @@ TEST_F(WebCryptoHmacTest, ImportKeyJwkKeyOpsSignVerify) { base::DictionaryValue dict; dict.SetString("kty", "oct"); dict.SetString("k", "GADWrMRHwQfoNaXU5fZvTg"); - base::ListValue* key_ops = new base::ListValue; - dict.Set("key_ops", key_ops); // Takes ownership. + base::ListValue* key_ops = + dict.SetList("key_ops", base::MakeUnique<base::ListValue>()); key_ops->AppendString("sign"); @@ -258,14 +261,14 @@ TEST_F(WebCryptoHmacTest, ImportKeyJwkUseInconsisteWithKeyOps) { base::DictionaryValue dict; dict.SetString("kty", "oct"); dict.SetString("k", "GADWrMRHwQfoNaXU5fZvTg"); - base::ListValue* key_ops = new base::ListValue; - dict.Set("key_ops", key_ops); // Takes ownership. - dict.SetString("alg", "HS256"); dict.SetString("use", "sig"); + + auto key_ops = base::MakeUnique<base::ListValue>(); key_ops->AppendString("sign"); key_ops->AppendString("verify"); key_ops->AppendString("encrypt"); + dict.Set("key_ops", std::move(key_ops)); EXPECT_EQ( Status::ErrorJwkUseAndKeyopsInconsistent(), ImportKeyJwkFromDict( diff --git a/chromium/components/webcrypto/jwk.cc b/chromium/components/webcrypto/jwk.cc index 326ce2b8862..50f81bb75d8 100644 --- a/chromium/components/webcrypto/jwk.cc +++ b/chromium/components/webcrypto/jwk.cc @@ -353,7 +353,7 @@ JwkWriter::JwkWriter(const std::string& algorithm, const std::string& kty) { if (!algorithm.empty()) dict_.SetString("alg", algorithm); - dict_.Set("key_ops", CreateJwkKeyOpsFromWebCryptoUsages(usages).release()); + dict_.Set("key_ops", CreateJwkKeyOpsFromWebCryptoUsages(usages)); dict_.SetBoolean("ext", extractable); dict_.SetString("kty", kty); } |