Commit 17ef705a authored by Omar Morsi's avatar Omar Morsi Committed by Commit Bot

PlatformKeysService: Change a const ref unique_ptr parameter

According to the style guide [*] there should rarely be a need to pass
smart pointers by const ref.

The current implementation of GetPrivateKey accepts a slot smart pointer
by const ref. This CL changes this parameter to a raw pointer.

[*] https://chromium.googlesource.com/chromium/src/+/master/styleguide/c++/c++.md#object-ownership-and-calling-conventions

Bug: 1131435
Change-Id: I4060855d3580ef75e2983ca08ae47091c139b379
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2426404Reviewed-by: default avatarMaksim Ivanov <emaxx@chromium.org>
Reviewed-by: default avatarPavol Marko <pmarko@chromium.org>
Commit-Queue: Omar Morsi <omorsi@google.com>
Cr-Commit-Position: refs/heads/master@{#810145}
parent 1d41b629
...@@ -734,11 +734,10 @@ GetAttributeForKeyState::GetAttributeForKeyState( ...@@ -734,11 +734,10 @@ GetAttributeForKeyState::GetAttributeForKeyState(
// private key will be searched in all slots. // private key will be searched in all slots.
crypto::ScopedSECKEYPrivateKey GetPrivateKey( crypto::ScopedSECKEYPrivateKey GetPrivateKey(
const std::string& public_key_spki_der, const std::string& public_key_spki_der,
const crypto::ScopedPK11Slot& slot) { PK11SlotInfo* slot) {
auto public_key_bytes = base::as_bytes(base::make_span(public_key_spki_der)); auto public_key_bytes = base::as_bytes(base::make_span(public_key_spki_der));
if (slot) { if (slot) {
return crypto::FindNSSKeyFromPublicKeyInfoInSlot(public_key_bytes, return crypto::FindNSSKeyFromPublicKeyInfoInSlot(public_key_bytes, slot);
slot.get());
} }
return crypto::FindNSSKeyFromPublicKeyInfo(public_key_bytes); return crypto::FindNSSKeyFromPublicKeyInfo(public_key_bytes);
} }
...@@ -847,7 +846,7 @@ void GenerateECKeyWithDB(std::unique_ptr<GenerateECKeyState> state, ...@@ -847,7 +846,7 @@ void GenerateECKeyWithDB(std::unique_ptr<GenerateECKeyState> state,
// Does the actual RSA signing on a worker thread. // Does the actual RSA signing on a worker thread.
void SignRSAOnWorkerThread(std::unique_ptr<SignState> state) { void SignRSAOnWorkerThread(std::unique_ptr<SignState> state) {
crypto::ScopedSECKEYPrivateKey rsa_key = crypto::ScopedSECKEYPrivateKey rsa_key =
GetPrivateKey(state->public_key_spki_der_, state->slot_); GetPrivateKey(state->public_key_spki_der_, state->slot_.get());
// Fail if the key was not found or is of the wrong type. // Fail if the key was not found or is of the wrong type.
if (!rsa_key || SECKEY_GetPrivateKeyType(rsa_key.get()) != rsaKey) { if (!rsa_key || SECKEY_GetPrivateKeyType(rsa_key.get()) != rsaKey) {
...@@ -918,7 +917,7 @@ void SignRSAOnWorkerThread(std::unique_ptr<SignState> state) { ...@@ -918,7 +917,7 @@ void SignRSAOnWorkerThread(std::unique_ptr<SignState> state) {
// Does the actual EC Signing on a worker thread. // Does the actual EC Signing on a worker thread.
void SignECOnWorkerThread(std::unique_ptr<SignState> state) { void SignECOnWorkerThread(std::unique_ptr<SignState> state) {
crypto::ScopedSECKEYPrivateKey ec_key = crypto::ScopedSECKEYPrivateKey ec_key =
GetPrivateKey(state->public_key_spki_der_, state->slot_); GetPrivateKey(state->public_key_spki_der_, state->slot_.get());
// Fail if the key was not found or is of the wrong type. // Fail if the key was not found or is of the wrong type.
if (!ec_key || SECKEY_GetPrivateKeyType(ec_key.get()) != ecKey) { if (!ec_key || SECKEY_GetPrivateKeyType(ec_key.get()) != ecKey) {
...@@ -965,7 +964,7 @@ void SignECOnWorkerThread(std::unique_ptr<SignState> state) { ...@@ -965,7 +964,7 @@ void SignECOnWorkerThread(std::unique_ptr<SignState> state) {
// Decides which signing algorithm will be used. Used by SignWithDB(). // Decides which signing algorithm will be used. Used by SignWithDB().
void SignOnWorkerThread(std::unique_ptr<SignState> state) { void SignOnWorkerThread(std::unique_ptr<SignState> state) {
crypto::ScopedSECKEYPrivateKey key = crypto::ScopedSECKEYPrivateKey key =
GetPrivateKey(state->public_key_spki_der_, state->slot_); GetPrivateKey(state->public_key_spki_der_, state->slot_.get());
if (!key) { if (!key) {
state->OnError(FROM_HERE, Status::kErrorKeyNotFound); state->OnError(FROM_HERE, Status::kErrorKeyNotFound);
...@@ -1213,7 +1212,7 @@ void RemoveKeyOnWorkerThread(std::unique_ptr<RemoveKeyState> state) { ...@@ -1213,7 +1212,7 @@ void RemoveKeyOnWorkerThread(std::unique_ptr<RemoveKeyState> state) {
DCHECK(state->slot_.get()); DCHECK(state->slot_.get());
crypto::ScopedSECKEYPrivateKey private_key = crypto::ScopedSECKEYPrivateKey private_key =
GetPrivateKey(state->public_key_spki_der_, state->slot_); GetPrivateKey(state->public_key_spki_der_, state->slot_.get());
if (!private_key) { if (!private_key) {
state->OnError(FROM_HERE, Status::kErrorKeyNotFound); state->OnError(FROM_HERE, Status::kErrorKeyNotFound);
...@@ -1347,7 +1346,7 @@ void SetAttributeForKeyWithDb(std::unique_ptr<SetAttributeForKeyState> state, ...@@ -1347,7 +1346,7 @@ void SetAttributeForKeyWithDb(std::unique_ptr<SetAttributeForKeyState> state,
DCHECK(state->slot_.get()); DCHECK(state->slot_.get());
crypto::ScopedSECKEYPrivateKey private_key = crypto::ScopedSECKEYPrivateKey private_key =
GetPrivateKey(state->public_key_spki_der_, state->slot_); GetPrivateKey(state->public_key_spki_der_, state->slot_.get());
if (!private_key) { if (!private_key) {
state->OnError(FROM_HERE, Status::kErrorKeyNotFound); state->OnError(FROM_HERE, Status::kErrorKeyNotFound);
...@@ -1380,7 +1379,7 @@ void GetAttributeForKeyWithDb(std::unique_ptr<GetAttributeForKeyState> state, ...@@ -1380,7 +1379,7 @@ void GetAttributeForKeyWithDb(std::unique_ptr<GetAttributeForKeyState> state,
DCHECK(state->slot_.get()); DCHECK(state->slot_.get());
crypto::ScopedSECKEYPrivateKey private_key = crypto::ScopedSECKEYPrivateKey private_key =
GetPrivateKey(state->public_key_spki_der_, state->slot_); GetPrivateKey(state->public_key_spki_der_, state->slot_.get());
if (!private_key) { if (!private_key) {
state->OnError(FROM_HERE, Status::kErrorKeyNotFound); state->OnError(FROM_HERE, Status::kErrorKeyNotFound);
......
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