Skip to content
This repository was archived by the owner on Apr 17, 2024. It is now read-only.

Commit 965edf9

Browse files
ioannanedelcucopybara-github
authored andcommitted
Avoid unnecessary copies of RestrictedData in proto serialization (since it's less performant) and use const references instead.
PiperOrigin-RevId: 622133044
1 parent 17b1ce9 commit 965edf9

11 files changed

+16
-16
lines changed

cc/aead/aes_eax_proto_serialization.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ util::StatusOr<AesEaxKey> ParseKey(
172172
"SecretKeyAccess is required");
173173
}
174174
SecretProto<google::crypto::tink::AesEaxKey> proto_key;
175-
RestrictedData restricted_data = serialization.SerializedKeyProto();
175+
const RestrictedData& restricted_data = serialization.SerializedKeyProto();
176176
if (!proto_key->ParseFromString(restricted_data.GetSecret(*token))) {
177177
return util::Status(absl::StatusCode::kInvalidArgument,
178178
"Failed to parse AesEaxKey proto");

cc/aead/aes_gcm_proto_serialization.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ util::StatusOr<AesGcmKey> ParseKey(
172172
"SecretKeyAccess is required");
173173
}
174174
SecretProto<google::crypto::tink::AesGcmKey> proto_key;
175-
RestrictedData restricted_data = serialization.SerializedKeyProto();
175+
const RestrictedData& restricted_data = serialization.SerializedKeyProto();
176176
if (!proto_key->ParseFromString(restricted_data.GetSecret(*token))) {
177177
return util::Status(absl::StatusCode::kInvalidArgument,
178178
"Failed to parse AesGcmKey proto");

cc/aead/aes_gcm_siv_proto_serialization.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ util::StatusOr<AesGcmSivKey> ParseKey(
147147
"Wrong type URL when parsing AesGcmSivKey.");
148148
}
149149
google::crypto::tink::AesGcmSivKey proto_key;
150-
RestrictedData restricted_data = serialization.SerializedKeyProto();
150+
const RestrictedData& restricted_data = serialization.SerializedKeyProto();
151151
if (!proto_key.ParseFromString(restricted_data.GetSecret(*token))) {
152152
return util::Status(absl::StatusCode::kInvalidArgument,
153153
"Failed to parse AesGcmSivKey proto");

cc/aead/chacha20_poly1305_proto_serialization.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ util::StatusOr<ChaCha20Poly1305Key> ParseKey(
138138
"SecretKeyAccess is required");
139139
}
140140
google::crypto::tink::ChaCha20Poly1305Key proto_key;
141-
RestrictedData restricted_data = serialization.SerializedKeyProto();
141+
const RestrictedData& restricted_data = serialization.SerializedKeyProto();
142142
if (!proto_key.ParseFromString(restricted_data.GetSecret(*token))) {
143143
return util::Status(absl::StatusCode::kInvalidArgument,
144144
"Failed to parse ChaCha20Poly1305Key proto");

cc/aead/xchacha20_poly1305_proto_serialization.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ util::StatusOr<XChaCha20Poly1305Key> ParseKey(
146146
"SecretKeyAccess is required");
147147
}
148148
google::crypto::tink::XChaCha20Poly1305Key proto_key;
149-
RestrictedData restricted_data = serialization.SerializedKeyProto();
149+
const RestrictedData& restricted_data = serialization.SerializedKeyProto();
150150
if (!proto_key.ParseFromString(restricted_data.GetSecret(*token))) {
151151
return util::Status(absl::StatusCode::kInvalidArgument,
152152
"Failed to parse XChaCha20Poly1305Key proto");

cc/daead/aes_siv_proto_serialization.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ util::StatusOr<AesSivKey> ParseKey(
142142
"SecretKeyAccess is required");
143143
}
144144
google::crypto::tink::AesSivKey proto_key;
145-
RestrictedData restricted_data = serialization.SerializedKeyProto();
145+
const RestrictedData& restricted_data = serialization.SerializedKeyProto();
146146
if (!proto_key.ParseFromString(restricted_data.GetSecret(*token))) {
147147
return util::Status(absl::StatusCode::kInvalidArgument,
148148
"Failed to parse AesSivKey proto");

cc/hybrid/ecies_proto_serialization.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ util::StatusOr<EciesPublicKey> ParsePublicKey(
613613
}
614614

615615
EciesAeadHkdfPublicKey proto_key;
616-
RestrictedData restricted_data = serialization.SerializedKeyProto();
616+
const RestrictedData& restricted_data = serialization.SerializedKeyProto();
617617
if (!proto_key.ParseFromString(
618618
restricted_data.GetSecret(InsecureSecretKeyAccess::Get()))) {
619619
return util::Status(absl::StatusCode::kInvalidArgument,
@@ -646,7 +646,7 @@ util::StatusOr<EciesPrivateKey> ParsePrivateKey(
646646
"Wrong type URL when parsing EciesAeadHkdfPrivateKey.");
647647
}
648648
EciesAeadHkdfPrivateKey proto_key;
649-
RestrictedData restricted_data = serialization.SerializedKeyProto();
649+
const RestrictedData& restricted_data = serialization.SerializedKeyProto();
650650
if (!proto_key.ParseFromString(restricted_data.GetSecret(*token))) {
651651
return util::Status(absl::StatusCode::kInvalidArgument,
652652
"Failed to parse EciesAeadHkdfPrivateKey proto.");

cc/hybrid/hpke_proto_serialization.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ util::StatusOr<HpkePublicKey> ParsePublicKey(
280280
}
281281

282282
google::crypto::tink::HpkePublicKey proto_key;
283-
RestrictedData restricted_data = serialization.SerializedKeyProto();
283+
const RestrictedData& restricted_data = serialization.SerializedKeyProto();
284284
if (!proto_key.ParseFromString(
285285
restricted_data.GetSecret(InsecureSecretKeyAccess::Get()))) {
286286
return util::Status(absl::StatusCode::kInvalidArgument,
@@ -314,7 +314,7 @@ util::StatusOr<HpkePrivateKey> ParsePrivateKey(
314314
"SecretKeyAccess is required");
315315
}
316316
google::crypto::tink::HpkePrivateKey proto_key;
317-
RestrictedData restricted_data = serialization.SerializedKeyProto();
317+
const RestrictedData& restricted_data = serialization.SerializedKeyProto();
318318
if (!proto_key.ParseFromString(restricted_data.GetSecret(*token))) {
319319
return util::Status(absl::StatusCode::kInvalidArgument,
320320
"Failed to parse HpkePrivateKey proto");

cc/signature/ecdsa_proto_serialization.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ util::StatusOr<EcdsaPublicKey> ParsePublicKey(
309309
}
310310

311311
google::crypto::tink::EcdsaPublicKey proto_key;
312-
RestrictedData restricted_data = serialization.SerializedKeyProto();
312+
const RestrictedData& restricted_data = serialization.SerializedKeyProto();
313313
if (!proto_key.ParseFromString(
314314
restricted_data.GetSecret(InsecureSecretKeyAccess::Get()))) {
315315
return util::Status(absl::StatusCode::kInvalidArgument,
@@ -344,7 +344,7 @@ util::StatusOr<EcdsaPrivateKey> ParsePrivateKey(
344344
"SecretKeyAccess is required");
345345
}
346346
google::crypto::tink::EcdsaPrivateKey proto_key;
347-
RestrictedData restricted_data = serialization.SerializedKeyProto();
347+
const RestrictedData& restricted_data = serialization.SerializedKeyProto();
348348
if (!proto_key.ParseFromString(restricted_data.GetSecret(*token))) {
349349
return util::Status(absl::StatusCode::kInvalidArgument,
350350
"Failed to parse EcdsaPrivateKey proto");

cc/signature/ed25519_proto_serialization.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ util::StatusOr<Ed25519PublicKey> ParsePublicKey(
140140
}
141141

142142
google::crypto::tink::Ed25519PublicKey proto_key;
143-
RestrictedData restricted_data = serialization.SerializedKeyProto();
143+
const RestrictedData& restricted_data = serialization.SerializedKeyProto();
144144
if (!proto_key.ParseFromString(
145145
restricted_data.GetSecret(InsecureSecretKeyAccess::Get()))) {
146146
return util::Status(absl::StatusCode::kInvalidArgument,
@@ -180,7 +180,7 @@ util::StatusOr<Ed25519PrivateKey> ParsePrivateKey(
180180
"SecretKeyAccess is required");
181181
}
182182
google::crypto::tink::Ed25519PrivateKey proto_key;
183-
RestrictedData restricted_data = serialization.SerializedKeyProto();
183+
const RestrictedData& restricted_data = serialization.SerializedKeyProto();
184184
if (!proto_key.ParseFromString(restricted_data.GetSecret(*token))) {
185185
return util::Status(absl::StatusCode::kInvalidArgument,
186186
"Failed to parse Ed25519PrivateKey proto");

cc/signature/rsa_ssa_pss_proto_serialization.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ util::StatusOr<RsaSsaPssPublicKey> ParsePublicKey(
227227
}
228228

229229
google::crypto::tink::RsaSsaPssPublicKey proto_key;
230-
RestrictedData restricted_data = serialization.SerializedKeyProto();
230+
const RestrictedData& restricted_data = serialization.SerializedKeyProto();
231231
if (!proto_key.ParseFromString(
232232
restricted_data.GetSecret(InsecureSecretKeyAccess::Get()))) {
233233
return util::Status(absl::StatusCode::kInvalidArgument,
@@ -264,7 +264,7 @@ util::StatusOr<RsaSsaPssPrivateKey> ParsePrivateKey(
264264
"SecretKeyAccess is required");
265265
}
266266
google::crypto::tink::RsaSsaPssPrivateKey proto_key;
267-
RestrictedData restricted_data = serialization.SerializedKeyProto();
267+
const RestrictedData& restricted_data = serialization.SerializedKeyProto();
268268
if (!proto_key.ParseFromString(restricted_data.GetSecret(*token))) {
269269
return util::Status(absl::StatusCode::kInvalidArgument,
270270
"Failed to parse RsaSsaPssPrivateKey proto");

0 commit comments

Comments
 (0)