Decode the action in Base NP advertisements back into a list of Data Elements

PiperOrigin-RevId: 466204445
This commit is contained in:
Janusz Sobczak
2022-08-08 19:39:05 -07:00
committed by Copybara-Service
parent 076b00ed61
commit 6e6ae3ebd7
9 changed files with 140 additions and 18 deletions
@@ -30,6 +30,7 @@ namespace presence {
namespace {
using ::testing::ElementsAre;
using ::testing::Return;
using ::testing::UnorderedElementsAre;
using ::testing::status::StatusIs;
class MockCredentialManager : public CredentialManagerImpl {
@@ -83,6 +84,27 @@ TEST(AdvertisementDecoder, DecodeBaseNpPublicAdvertisement) {
DataElement(9, absl::HexStringToBytes("EEFF"))));
}
TEST(AdvertisementDecoder, DecodeBaseNpPWithActionField) {
std::string salt = "AB";
MockCredentialManager credential_manager;
AdvertisementDecoder decoder(&credential_manager);
auto result =
decoder.DecodeAdvertisement(absl::HexStringToBytes("002041420326B840"));
EXPECT_OK(result);
EXPECT_THAT(*result,
UnorderedElementsAre(
DataElement(DataElement::kSaltFieldType, salt),
DataElement(DataElement::kPublicIdentityFieldType, ""),
DataElement(DataElement::kContextTimestampFieldType,
absl::HexStringToBytes("0B")),
DataElement(DataElement::kActionFieldType,
action::kTapToTransferAction),
DataElement(DataElement::kActionFieldType,
action::kNearbyShareAction)));
}
TEST(AdvertisementDecoder, InvalidAdvertisementFieldTooShort) {
MockCredentialManager credential_manager;
AdvertisementDecoder decoder(&credential_manager);