From d1d7cfad560720c3a3593b3cf93f69eb248cd401 Mon Sep 17 00:00:00 2001 From: Qin Wang Date: Mon, 6 Feb 2023 13:10:14 -0800 Subject: [PATCH] Replace absl::optional with std::optional PiperOrigin-RevId: 507563369 --- fastpair/crypto/BUILD | 1 - fastpair/crypto/fast_pair_decryption.cc | 10 +++++----- fastpair/crypto/fast_pair_decryption.h | 6 +++--- fastpair/crypto/fast_pair_encryption.cc | 15 ++++++++------- fastpair/crypto/fast_pair_encryption.h | 4 ++-- 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/fastpair/crypto/BUILD b/fastpair/crypto/BUILD index 9dd2c09d..dc9b48b6 100644 --- a/fastpair/crypto/BUILD +++ b/fastpair/crypto/BUILD @@ -23,7 +23,6 @@ cc_library( "//internal/platform:logging", "@boringssl//:crypto", "@com_google_absl//absl/log:check", - "@com_google_absl//absl/types:optional", ], ) diff --git a/fastpair/crypto/fast_pair_decryption.cc b/fastpair/crypto/fast_pair_decryption.cc index 08b3be21..c591332d 100644 --- a/fastpair/crypto/fast_pair_decryption.cc +++ b/fastpair/crypto/fast_pair_decryption.cc @@ -16,6 +16,7 @@ #include #include +#include #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 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 FastPairDecryption::ParseDecryptResponse( +std::optional FastPairDecryption::ParseDecryptResponse( const std::array& aes_key_bytes, const std::array& encrypted_response_bytes) { std::array decrypted_response_bytes = @@ -64,7 +64,7 @@ absl::optional 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 address_bytes; @@ -85,7 +85,7 @@ absl::optional 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 FastPairDecryption::ParseDecryptPasskey( +std::optional FastPairDecryption::ParseDecryptPasskey( const std::array& aes_key_bytes, const std::array& encrypted_passkey_bytes) { std::array decrypted_passkey_bytes = @@ -98,7 +98,7 @@ absl::optional FastPairDecryption::ParseDecryptPasskey( kProviderPasskeyType) { message_type = FastPairMessageType::kProvidersPasskey; } else { - return absl::nullopt; + return std::nullopt; } uint32_t passkey = decrypted_passkey_bytes[3]; diff --git a/fastpair/crypto/fast_pair_decryption.h b/fastpair/crypto/fast_pair_decryption.h index ef3e0779..a7a4a7b3 100644 --- a/fastpair/crypto/fast_pair_decryption.h +++ b/fastpair/crypto/fast_pair_decryption.h @@ -17,8 +17,8 @@ #include #include +#include -#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& aes_key_bytes, const std::array& encrypted_bytes); - static absl::optional ParseDecryptResponse( + static std::optional ParseDecryptResponse( const std::array& aes_key_bytes, const std::array& encrypted_response_bytes); - static absl::optional ParseDecryptPasskey( + static std::optional ParseDecryptPasskey( const std::array& aes_key_bytes, const std::array& encrypted_passkey_bytes); }; diff --git a/fastpair/crypto/fast_pair_encryption.cc b/fastpair/crypto/fast_pair_encryption.cc index dd8e6d70..def14312 100644 --- a/fastpair/crypto/fast_pair_encryption.cc +++ b/fastpair/crypto/fast_pair_encryption.cc @@ -18,6 +18,8 @@ #include #include #include +#include +#include #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 FastPairEncryption::GenerateKeysWithEcdhKeyAgreement( +std::optional 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 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 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 public_anti_spoofing_point = @@ -120,7 +121,7 @@ absl::optional 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 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. diff --git a/fastpair/crypto/fast_pair_encryption.h b/fastpair/crypto/fast_pair_encryption.h index 35a3ecb7..8961284a 100644 --- a/fastpair/crypto/fast_pair_encryption.h +++ b/fastpair/crypto/fast_pair_encryption.h @@ -20,8 +20,8 @@ #include #include #include +#include -#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 GenerateKeysWithEcdhKeyAgreement( + static std::optional GenerateKeysWithEcdhKeyAgreement( std::string_view decoded_public_anti_spoofing); static std::array EncryptBytes(