Use std::move for key strings.

[ Cherry-pick of v19 http://go/wvgerrit/219351 ]
[ Merge of http://go/wvgerrit/219455 ]

Coverity discovered an oppertunity to use the C++'s move semantics
for the prov 4.0 keys.  A similar possibility was available for the
matching wrapped key.  The CryptoWrappedKey class was updated to
enable moving of the wrapped key as well.

Bug: 406539167
Bug: 391469176
Change-Id: I7d76013638c220fc81d6d9c42add2516abd7374a
This commit is contained in:
Alex Dale
2025-04-21 17:07:29 -07:00
parent a2cdce4296
commit 207edd9b79
2 changed files with 6 additions and 2 deletions

View File

@@ -5,6 +5,7 @@
#define WVCDM_CORE_CRYPTO_WRAPPED_KEY_H_
#include <string>
#include <utility>
namespace wvcdm {
@@ -18,6 +19,8 @@ class CryptoWrappedKey {
CryptoWrappedKey() {}
CryptoWrappedKey(Type type, const std::string& key)
: type_(type), key_(key) {}
CryptoWrappedKey(Type type, std::string&& key)
: type_(type), key_(std::move(key)) {}
Type type() const { return type_; }
void set_type(Type type) { type_ = type; }
@@ -26,6 +29,7 @@ class CryptoWrappedKey {
// Mutable reference getter for passing to OMECrypto.
std::string& key() { return key_; }
void set_key(const std::string& key) { key_ = key; }
void set_key(std::string&& key) { key_ = std::move(key); }
void Clear() {
type_ = kUninitialized;

View File

@@ -651,10 +651,10 @@ CdmResponseType CertificateProvisioning::GetProvisioning40RequestInternal(
// Need the wrapped Prov 4.0 private key to store once the response
// is received. The wrapped key is not available in the response.
prov40_wrapped_private_key_ =
CryptoWrappedKey(private_key_type, wrapped_private_key);
CryptoWrappedKey(private_key_type, std::move(wrapped_private_key));
// Store the public key from the request. This is used to match
// up the response with the most recently generated request.
prov40_public_key_ = public_key;
prov40_public_key_ = std::move(public_key);
state_ = is_oem_prov_request ? kOemRequestSent : kDrmRequestSent;
return CdmResponseType(NO_ERROR);