Skip to content

Commit

Permalink
Add direct accessor method for a restricted big integer's secret data.
Browse files Browse the repository at this point in the history
This should avoid creating new secret data objects from string views for APIs
that require secret data objects.

PiperOrigin-RevId: 715482913
Change-Id: I841034230f711fcdfa5d833296759ec84641117a
  • Loading branch information
willinois authored and copybara-github committed Jan 14, 2025
1 parent 8f1b1d4 commit 235b8d9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions tink/core/restricted_big_integer_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ TEST(RestrictedBigIntegerTest, CreateAndGetSecret) {
EXPECT_THAT(restricted_big_integer.SizeInBytes(), Eq(256));
EXPECT_THAT(restricted_big_integer.GetSecret(InsecureSecretKeyAccess::Get()),
Eq(secret_bytes));
EXPECT_THAT(util::SecretDataAsStringView(restricted_big_integer.GetSecretData(
InsecureSecretKeyAccess::Get())),
Eq(secret_bytes));
}

TEST(RestrictedBigIntegerTest, CreateAndGetSecretPadded) {
Expand Down
5 changes: 5 additions & 0 deletions tink/restricted_big_integer.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ class RestrictedBigInteger {
return util::SecretDataAsStringView(secret_);
}

// Returns the secret data of this RestrictedBigInteger object.
const util::SecretData& GetSecretData(SecretKeyAccessToken token) const {
return secret_;
}

int64_t SizeInBytes() const { return secret_.size(); }

bool operator==(const RestrictedBigInteger& other) const;
Expand Down

0 comments on commit 235b8d9

Please sign in to comment.