Skip to content

Commit

Permalink
Deprecate GetPrimitive with a custom key manager.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 595621635
Change-Id: Icd0746a77ab42ab1717585ee0c99c11aee3fd58a
  • Loading branch information
tholenst authored and copybara-github committed Jan 4, 2024
1 parent d02529d commit ae4830d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
6 changes: 6 additions & 0 deletions tink/core/keyset_handle_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -989,6 +989,7 @@ TEST_F(KeysetHandleTest, GetPrimitiveWithConfigFips1402FailsWithNonFipsHandle) {
}

// Tests that GetPrimitive(nullptr) fails with a non-ok status.
// TINK-PENDING-REMOVAL-IN-3.0.0-START
TEST_F(KeysetHandleTest, GetPrimitiveNullptrKeyManager) {
Keyset keyset;
AddKeyData(*Registry::NewKeyData(AeadKeyTemplates::Aes128Gcm()).value(),
Expand All @@ -1000,9 +1001,12 @@ TEST_F(KeysetHandleTest, GetPrimitiveNullptrKeyManager) {
ASSERT_THAT(keyset_handle->GetPrimitive<Aead>(nullptr).status(),
test::StatusIs(absl::StatusCode::kInvalidArgument));
}
// TINK-PENDING-REMOVAL-IN-3.0.0-END

// Test creating with custom key manager. For this, we reset the registry before
// asking for the primitive.
// NOLINTBEGIN(whitespace/line_length) (Formatted when commented in)
// TINK-PENDING-REMOVAL-IN-3.0.0-START
TEST_F(KeysetHandleTest, GetPrimitiveCustomKeyManager) {
auto handle_result = KeysetHandle::GenerateNew(AeadKeyTemplates::Aes128Gcm(),
KeyGenConfigGlobalRegistry());
Expand All @@ -1021,6 +1025,8 @@ TEST_F(KeysetHandleTest, GetPrimitiveCustomKeyManager) {
// With custom key manager it works ok.
ASSERT_TRUE(handle->GetPrimitive<Aead>(key_manager.get()).ok());
}
// TINK-PENDING-REMOVAL-IN-3.0.0-END
// NOLINTEND(whitespace/line_length)

// Compile time check: ensures that the KeysetHandle can be copied.
TEST_F(KeysetHandleTest, Copiable) {
Expand Down
6 changes: 5 additions & 1 deletion tink/keyset_handle.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2017 Google Inc.
// Copyright 2017 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -229,10 +229,12 @@ class KeysetHandle {
// KeyManager, as well as the KeyManager and PrimitiveWrapper objects in the
// global registry to create the primitive. The given KeyManager is used for
// keys supported by it. For those, the registry is ignored.
// TINK-PENDING-REMOVAL-IN-3.0.0-START
template <class P>
ABSL_DEPRECATED("Register the keymanager and use GetPrimitive")
crypto::tink::util::StatusOr<std::unique_ptr<P>> GetPrimitive(
const KeyManager<P>* custom_manager) const;
// TINK-PENDING-REMOVAL-IN-3.0.0-END

private:
// The classes below need access to get_keyset();
Expand Down Expand Up @@ -398,6 +400,7 @@ crypto::tink::util::StatusOr<std::unique_ptr<P>> KeysetHandle::GetPrimitive(
return (*wrapper)->Wrap(keyset_, monitoring_annotations_);
}

// TINK-PENDING-REMOVAL-IN-3.0.0-START
template <class P>
crypto::tink::util::StatusOr<std::unique_ptr<P>> KeysetHandle::GetPrimitive(
const KeyManager<P>* custom_manager) const {
Expand All @@ -411,6 +414,7 @@ crypto::tink::util::StatusOr<std::unique_ptr<P>> KeysetHandle::GetPrimitive(
}
return Registry::Wrap<P>(std::move(primitives_result.value()));
}
// TINK-PENDING-REMOVAL-IN-3.0.0-END

} // namespace tink
} // namespace crypto
Expand Down

0 comments on commit ae4830d

Please sign in to comment.