Use credential_id to correlate matched credential back to original

Upon succesfully dectypting an advertisements, the decoding library returns the id of the credential which was used to decrypt. We then use this id to correlate the decoded adv back to the original shared_credential which was used to decrypt it and save this and propagate it in the result returned to the caller

PiperOrigin-RevId: 646179759
This commit is contained in:
hai007
2024-06-24 12:16:34 -07:00
committed by Copybara-Service
parent 0ad19f3ce9
commit cdd6870af2
3 changed files with 41 additions and 7 deletions
@@ -29,13 +29,19 @@ namespace presence {
// Implements the Rust backed parsing and decrypting of advertisement bytes
class AdvertisementDecoderImpl : public AdvertisementDecoder {
public:
AdvertisementDecoderImpl() : cred_book_(InitializeCredentialBook(nullptr)) {}
AdvertisementDecoderImpl()
: cred_book_(InitializeCredentialBook(nullptr)),
private_credentials_(
std::vector<::nearby::internal::SharedCredential>()) {}
explicit AdvertisementDecoderImpl(
absl::flat_hash_map<nearby::internal::IdentityType,
std::vector<internal::SharedCredential>>*
credentials_map)
: cred_book_(InitializeCredentialBook(credentials_map)) {}
: cred_book_(InitializeCredentialBook(credentials_map)),
private_credentials_(
(*credentials_map)
[internal::IdentityType::IDENTITY_TYPE_PRIVATE_GROUP]) {}
absl::StatusOr<Advertisement> DecodeAdvertisement(
absl::string_view advertisement) override;
@@ -46,6 +52,7 @@ class AdvertisementDecoderImpl : public AdvertisementDecoder {
std::vector<::nearby::internal::SharedCredential>>*
credentials_map);
nearby_protocol::CredentialBook cred_book_;
std::vector<::nearby::internal::SharedCredential> private_credentials_;
};
} // namespace presence