Replace absl::optional with std::optional

PiperOrigin-RevId: 507563369
This commit is contained in:
Qin Wang
2023-02-06 13:14:25 -08:00
committed by Copybara-Service
parent a48130f407
commit d1d7cfad56
5 changed files with 18 additions and 18 deletions
-1
View File
@@ -23,7 +23,6 @@ cc_library(
"//internal/platform:logging",
"@boringssl//:crypto",
"@com_google_absl//absl/log:check",
"@com_google_absl//absl/types:optional",
],
)
+5 -5
View File
@@ -16,6 +16,7 @@
#include <algorithm>
#include <array>
#include <optional>
#ifdef NEARBY_CHROMIUM
#include "base/check.h"
@@ -25,7 +26,6 @@
#include "absl/log/check.h" // nogncheck
#endif
#include "absl/types/optional.h"
#include "fastpair/common/constant.h"
#include "fastpair/crypto/decrypted_passkey.h"
#include "fastpair/crypto/decrypted_response.h"
@@ -53,7 +53,7 @@ std::array<uint8_t, kAesBlockByteSize> FastPairDecryption::DecryptBytes(
// (https://developers.google.com/nearby/fast-pair/specifications/characteristics#table1.4)
// and returns the parsed decrypted response
// (https://developers.google.com/nearby/fast-pair/specifications/characteristics#table1.3)
absl::optional<DecryptedResponse> FastPairDecryption::ParseDecryptResponse(
std::optional<DecryptedResponse> FastPairDecryption::ParseDecryptResponse(
const std::array<uint8_t, kAesBlockByteSize>& aes_key_bytes,
const std::array<uint8_t, kAesBlockByteSize>& encrypted_response_bytes) {
std::array<uint8_t, kAesBlockByteSize> decrypted_response_bytes =
@@ -64,7 +64,7 @@ absl::optional<DecryptedResponse> FastPairDecryption::ParseDecryptResponse(
// If the message type index is not the expected fast pair message type, then
// this is not a valid fast pair response.
if (message_type != kKeybasedPairingResponseType) {
return absl::nullopt;
return std::nullopt;
}
std::array<uint8_t, kDecryptedResponseAddressByteSize> address_bytes;
@@ -85,7 +85,7 @@ absl::optional<DecryptedResponse> FastPairDecryption::ParseDecryptResponse(
// (https://developers.google.com/nearby/fast-pair/specifications/characteristics#table2.2)
// TODO(b/263400788) Add unit test to cover this function and fix all Mutants
// warning
absl::optional<DecryptedPasskey> FastPairDecryption::ParseDecryptPasskey(
std::optional<DecryptedPasskey> FastPairDecryption::ParseDecryptPasskey(
const std::array<uint8_t, kAesBlockByteSize>& aes_key_bytes,
const std::array<uint8_t, kAesBlockByteSize>& encrypted_passkey_bytes) {
std::array<uint8_t, kAesBlockByteSize> decrypted_passkey_bytes =
@@ -98,7 +98,7 @@ absl::optional<DecryptedPasskey> FastPairDecryption::ParseDecryptPasskey(
kProviderPasskeyType) {
message_type = FastPairMessageType::kProvidersPasskey;
} else {
return absl::nullopt;
return std::nullopt;
}
uint32_t passkey = decrypted_passkey_bytes[3];
+3 -3
View File
@@ -17,8 +17,8 @@
#include <array>
#include <string>
#include <optional>
#include "absl/types/optional.h"
#include "fastpair/crypto/decrypted_passkey.h"
#include "fastpair/crypto/decrypted_response.h"
@@ -33,11 +33,11 @@ class FastPairDecryption {
const std::array<uint8_t, kAesBlockByteSize>& aes_key_bytes,
const std::array<uint8_t, kAesBlockByteSize>& encrypted_bytes);
static absl::optional<DecryptedResponse> ParseDecryptResponse(
static std::optional<DecryptedResponse> ParseDecryptResponse(
const std::array<uint8_t, 16>& aes_key_bytes,
const std::array<uint8_t, 16>& encrypted_response_bytes);
static absl::optional<DecryptedPasskey> ParseDecryptPasskey(
static std::optional<DecryptedPasskey> ParseDecryptPasskey(
const std::array<uint8_t, 16>& aes_key_bytes,
const std::array<uint8_t, 16>& encrypted_passkey_bytes);
};
+8 -7
View File
@@ -18,6 +18,8 @@
#include <array>
#include <iterator>
#include <string_view>
#include <vector>
#include <optional>
#ifdef NEARBY_CHROMIUM
#include "base/check.h"
@@ -27,7 +29,6 @@
#include "absl/log/check.h" // nogncheck
#endif
#include "absl/types/optional.h"
#include "fastpair/common/constant.h"
#include "fastpair/crypto/fast_pair_key_pair.h"
#include "fastpair/crypto/fast_pair_message_type.h"
@@ -76,13 +77,13 @@ void* KDF(const void* in, size_t inlen, void* out, size_t* outlen) {
// TODO(b/263400788) Add unit test to cover this function and fix all Mutants
// warning
absl::optional<KeyPair> FastPairEncryption::GenerateKeysWithEcdhKeyAgreement(
std::optional<KeyPair> FastPairEncryption::GenerateKeysWithEcdhKeyAgreement(
std::string_view decoded_public_anti_spoofing) {
if (decoded_public_anti_spoofing.size() != kPublicKeyByteSize) {
NEARBY_LOGS(VERBOSE) << "Expected " << kPublicKeyByteSize
<< " byte value for anti-spoofing key. Got:"
<< decoded_public_anti_spoofing.size();
return absl::nullopt;
return std::nullopt;
}
// Generate the secp256r1 key-pair.
@@ -93,7 +94,7 @@ absl::optional<KeyPair> FastPairEncryption::GenerateKeysWithEcdhKeyAgreement(
if (!EC_KEY_generate_key(ec_key.get())) {
NEARBY_LOGS(VERBOSE) << __func__ << ": Failed to generate ec key";
return absl::nullopt;
return std::nullopt;
}
// The ultimate goal here is to get a 64-byte public key. We accomplish this
@@ -109,7 +110,7 @@ absl::optional<KeyPair> FastPairEncryption::GenerateKeysWithEcdhKeyAgreement(
NEARBY_LOGS(VERBOSE) << __func__
<< ": EC_POINT_point2oct failed to convert public key "
"to uncompressed x9.62 format.";
return absl::nullopt;
return std::nullopt;
}
bssl::UniquePtr<EC_POINT> public_anti_spoofing_point =
@@ -120,7 +121,7 @@ absl::optional<KeyPair> FastPairEncryption::GenerateKeysWithEcdhKeyAgreement(
NEARBY_LOGS(VERBOSE)
<< __func__
<< ": Failed to convert Public Anti-Spoofing key to EC_POINT";
return absl::nullopt;
return std::nullopt;
}
uint8_t secret[SHA256_DIGEST_LENGTH];
@@ -130,7 +131,7 @@ absl::optional<KeyPair> FastPairEncryption::GenerateKeysWithEcdhKeyAgreement(
if (computed_key_size != kSharedSecretKeyByteSize) {
NEARBY_LOGS(VERBOSE) << __func__ << ": ECDH_compute_key failed.";
return absl::nullopt;
return std::nullopt;
}
// Take first 16 bytes from secret as the shared secret key.
+2 -2
View File
@@ -20,8 +20,8 @@
#include <array>
#include <string>
#include <string_view>
#include <optional>
#include "absl/types/optional.h"
#include "fastpair/common/constant.h"
#include "fastpair/crypto/fast_pair_key_pair.h"
@@ -32,7 +32,7 @@ namespace fastpair {
* encrypting Fast Pair packets. */
class FastPairEncryption {
public:
static absl::optional<KeyPair> GenerateKeysWithEcdhKeyAgreement(
static std::optional<KeyPair> GenerateKeysWithEcdhKeyAgreement(
std::string_view decoded_public_anti_spoofing);
static std::array<uint8_t, kAesBlockByteSize> EncryptBytes(