diff options
author | tholenst <tholenst@google.com> | 2019-08-14 07:41:42 -0700 |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2019-08-14 07:42:15 -0700 |
commit | 0fd34cd156c706d8aff2683b01983e97a6478f47 (patch) | |
tree | f1b4aa96e2d2e6f72c569a79fe0011c27f4854f6 /cc/mac/hmac_key_manager.h | |
parent | 20c54d69df44442d64aec19963808f091b0236af (diff) | |
download | tink-0fd34cd156c706d8aff2683b01983e97a6478f47.tar.gz |
Migrate the HmacKeyManger to a KeyTypeManager.
We will migrate the test in an upcoming cl.
PiperOrigin-RevId: 263347373
Diffstat (limited to 'cc/mac/hmac_key_manager.h')
-rw-r--r-- | cc/mac/hmac_key_manager.h | 56 |
1 files changed, 34 insertions, 22 deletions
diff --git a/cc/mac/hmac_key_manager.h b/cc/mac/hmac_key_manager.h index 1597fb292..772fb0168 100644 --- a/cc/mac/hmac_key_manager.h +++ b/cc/mac/hmac_key_manager.h @@ -20,9 +20,11 @@ #include <vector> #include "absl/strings/string_view.h" -#include "tink/core/key_manager_base.h" -#include "tink/key_manager.h" +#include "tink/core/key_type_manager.h" #include "tink/mac.h" +#include "tink/subtle/hmac_boringssl.h" +#include "tink/util/constants.h" +#include "tink/util/enums.h" #include "tink/util/errors.h" #include "tink/util/protobuf_helper.h" #include "tink/util/status.h" @@ -34,36 +36,46 @@ namespace crypto { namespace tink { class HmacKeyManager - : public KeyManagerBase<Mac, google::crypto::tink::HmacKey> { + : public KeyTypeManager<google::crypto::tink::HmacKey, + google::crypto::tink::HmacKeyFormat, List<Mac>> { public: - static constexpr uint32_t kVersion = 0; + class MacFactory : public PrimitiveFactory<Mac> { + crypto::tink::util::StatusOr<std::unique_ptr<Mac>> Create( + const google::crypto::tink::HmacKey& hmac_key) const override { + return subtle::HmacBoringSsl::New( + util::Enums::ProtoToSubtle(hmac_key.params().hash()), + hmac_key.params().tag_size(), hmac_key.key_value()); + } + }; - HmacKeyManager(); + HmacKeyManager() : KeyTypeManager(absl::make_unique<MacFactory>()) {} - // Returns the version of this key manager. - uint32_t get_version() const override; + uint32_t get_version() const override { return 0; } - // Returns a factory that generates keys of the key type - // handled by this manager. - const KeyFactory& get_key_factory() const override; + google::crypto::tink::KeyData::KeyMaterialType key_material_type() + const override { + return google::crypto::tink::KeyData::SYMMETRIC; + } - virtual ~HmacKeyManager() {} + const std::string& get_key_type() const override { return key_type_; } - protected: - crypto::tink::util::StatusOr<std::unique_ptr<Mac>> GetPrimitiveFromKey( - const google::crypto::tink::HmacKey& hmac_key) const override; + + crypto::tink::util::Status ValidateKey( + const google::crypto::tink::HmacKey& key) const override; + + crypto::tink::util::Status ValidateKeyFormat( + const google::crypto::tink::HmacKeyFormat& key_format) const override; + + crypto::tink::util::StatusOr<google::crypto::tink::HmacKey> CreateKey( + const google::crypto::tink::HmacKeyFormat& key_format) const override; private: - friend class HmacKeyFactory; + crypto::tink::util::Status ValidateParams( + const google::crypto::tink::HmacParams& params) const; - std::unique_ptr<KeyFactory> key_factory_; - static crypto::tink::util::Status Validate( - const google::crypto::tink::HmacParams& params); - static crypto::tink::util::Status Validate( - const google::crypto::tink::HmacKey& key); - static crypto::tink::util::Status Validate( - const google::crypto::tink::HmacKeyFormat& key_format); + const std::string key_type_ = absl::StrCat( + kTypeGoogleapisCom, google::crypto::tink::HmacKey().GetTypeName()); }; } // namespace tink |