From a2d15d543864de17bfd0678baad7577e6d08fd82 Mon Sep 17 00:00:00 2001 From: William Conner Date: Thu, 18 Jul 2024 08:36:52 -0700 Subject: [PATCH] Switch key id type from int to int32_t. PiperOrigin-RevId: 653631453 Change-Id: I83fcb029b3edc8a85871136ef2a1027d93b3f201 --- tink/core/keyset_handle_builder.cc | 9 +++++---- tink/internal/keyset_handle_builder_entry.cc | 5 +++-- tink/internal/keyset_handle_builder_entry.h | 7 ++++--- tink/keyset_handle.h | 6 +++--- tink/keyset_handle_builder.h | 9 +++++---- 5 files changed, 20 insertions(+), 16 deletions(-) diff --git a/tink/core/keyset_handle_builder.cc b/tink/core/keyset_handle_builder.cc index cefb0dcd..f733b71c 100644 --- a/tink/core/keyset_handle_builder.cc +++ b/tink/core/keyset_handle_builder.cc @@ -16,6 +16,7 @@ #include "tink/keyset_handle_builder.h" +#include #include #include #include @@ -49,7 +50,7 @@ namespace { using ::google::crypto::tink::Keyset; void SetBuilderEntryAttributes(KeyStatus status, bool is_primary, - absl::optional id, + absl::optional id, KeysetHandleBuilder::Entry* entry) { entry->SetStatus(status); if (is_primary) { @@ -95,8 +96,8 @@ KeysetHandleBuilder::Entry KeysetHandleBuilder::Entry::CreateFromParams( return entry; } -util::StatusOr KeysetHandleBuilder::NextIdFromKeyIdStrategy( - internal::KeyIdStrategy strategy, const std::set& ids_so_far) { +util::StatusOr KeysetHandleBuilder::NextIdFromKeyIdStrategy( + internal::KeyIdStrategy strategy, const std::set& ids_so_far) { if (strategy.strategy == internal::KeyIdStrategyEnum::kFixedId) { if (!strategy.id_requirement.has_value()) { return util::Status(absl::StatusCode::kInvalidArgument, @@ -177,7 +178,7 @@ util::StatusOr KeysetHandleBuilder::Build() { util::Status assigned_ids_status = CheckIdAssignments(); if (!assigned_ids_status.ok()) return assigned_ids_status; - std::set ids_so_far; + std::set ids_so_far; for (KeysetHandleBuilder::Entry& entry : entries_) { util::StatusOr id = NextIdFromKeyIdStrategy(entry.GetKeyIdStrategy(), ids_so_far); diff --git a/tink/internal/keyset_handle_builder_entry.cc b/tink/internal/keyset_handle_builder_entry.cc index 1df5a35b..4609db06 100644 --- a/tink/internal/keyset_handle_builder_entry.cc +++ b/tink/internal/keyset_handle_builder_entry.cc @@ -16,6 +16,7 @@ #include "tink/internal/keyset_handle_builder_entry.h" +#include #include #include @@ -166,7 +167,7 @@ void KeysetHandleBuilderEntry::SetRandomId() { strategy_.id_requirement = absl::nullopt; } -util::StatusOr> KeyEntry::CreateKeysetKey(int id) { +util::StatusOr> KeyEntry::CreateKeysetKey(int32_t id) { util::StatusOr key_status = ToKeyStatusType(key_status_); if (!key_status.ok()) return key_status.status(); @@ -192,7 +193,7 @@ util::StatusOr> KeyEntry::CreateKeysetKey(int id) { } util::StatusOr> ParametersEntry::CreateKeysetKey( - int id) { + int32_t id) { util::StatusOr key_status = ToKeyStatusType(key_status_); if (!key_status.ok()) return key_status.status(); diff --git a/tink/internal/keyset_handle_builder_entry.h b/tink/internal/keyset_handle_builder_entry.h index fa3812a8..9db3ef4a 100644 --- a/tink/internal/keyset_handle_builder_entry.h +++ b/tink/internal/keyset_handle_builder_entry.h @@ -17,6 +17,7 @@ #ifndef TINK_INTERNAL_KEYSET_HANDLE_BUILDER_ENTRY_H_ #define TINK_INTERNAL_KEYSET_HANDLE_BUILDER_ENTRY_H_ +#include #include #include @@ -79,7 +80,7 @@ class KeysetHandleBuilderEntry { // `Key` object or a `Parameters` object. virtual crypto::tink::util::StatusOr< crypto::tink::util::SecretProto> - CreateKeysetKey(int id) = 0; + CreateKeysetKey(int32_t id) = 0; protected: KeyStatus key_status_ = KeyStatus::kDisabled; @@ -103,7 +104,7 @@ class KeyEntry : public KeysetHandleBuilderEntry { crypto::tink::util::StatusOr< crypto::tink::util::SecretProto> - CreateKeysetKey(int id) override; + CreateKeysetKey(int32_t id) override; private: std::shared_ptr key_; @@ -123,7 +124,7 @@ class ParametersEntry : public KeysetHandleBuilderEntry { crypto::tink::util::StatusOr< crypto::tink::util::SecretProto> - CreateKeysetKey(int id) override; + CreateKeysetKey(int32_t id) override; private: std::shared_ptr parameters_; diff --git a/tink/keyset_handle.h b/tink/keyset_handle.h index 89474539..89ae7bfb 100644 --- a/tink/keyset_handle.h +++ b/tink/keyset_handle.h @@ -71,7 +71,7 @@ class KeysetHandle { // ID should be unique (though currently Tink still accepts keysets with // repeated IDs). - int GetId() const { return id_; } + int32_t GetId() const { return id_; } // Should return true for exactly one entry (though currently Tink still // accepts keysets which have no entry marked as primary). @@ -86,7 +86,7 @@ class KeysetHandle { friend class KeysetHandle; friend class KeysetHandleBuilder; - Entry(std::shared_ptr key, KeyStatus status, int id, + Entry(std::shared_ptr key, KeyStatus status, int32_t id, bool is_primary) : key_(std::move(key)), status_(status), @@ -95,7 +95,7 @@ class KeysetHandle { std::shared_ptr key_; KeyStatus status_; - int id_; + int32_t id_; bool is_primary_; }; diff --git a/tink/keyset_handle_builder.h b/tink/keyset_handle_builder.h index 838229d9..449ae546 100644 --- a/tink/keyset_handle_builder.h +++ b/tink/keyset_handle_builder.h @@ -17,6 +17,7 @@ #ifndef TINK_KEYSET_HANDLE_BUILDER_H_ #define TINK_KEYSET_HANDLE_BUILDER_H_ +#include #include #include #include @@ -95,7 +96,7 @@ class KeysetHandleBuilder { KeyStatus GetStatus() const { return entry_->GetStatus(); } // Assigns a fixed id when this keyset is built. - void SetFixedId(int id) { entry_->SetFixedId(id); } + void SetFixedId(int32_t id) { entry_->SetFixedId(id); } // Assigns an unused random id when this keyset is built. void SetRandomId() { entry_->SetRandomId(); } @@ -124,7 +125,7 @@ class KeysetHandleBuilder { crypto::tink::util::StatusOr< crypto::tink::util::SecretProto> - CreateKeysetKey(int id) { + CreateKeysetKey(int32_t id) { return entry_->CreateKeysetKey(id); } @@ -162,8 +163,8 @@ class KeysetHandleBuilder { private: // Select the next key id based on the given strategy. - crypto::tink::util::StatusOr NextIdFromKeyIdStrategy( - internal::KeyIdStrategy strategy, const std::set& ids_so_far); + crypto::tink::util::StatusOr NextIdFromKeyIdStrategy( + internal::KeyIdStrategy strategy, const std::set& ids_so_far); // Unset primary flag on all entries. void ClearPrimary();