diff options
author | Thomas Holenstein <tholenst@google.com> | 2018-09-17 08:41:00 -0700 |
---|---|---|
committer | Tink Team <noreply@google.com> | 2018-09-20 16:19:41 -0700 |
commit | 614495b384bbe1ce5ad10509a68b70c666495a6f (patch) | |
tree | 06986e85b2de15aaba39c69fb2ba3dc40375b59e /cc/mac/hmac_key_manager.h | |
parent | 82a73ab705e81682e3f2a562f3cf2e9099a46890 (diff) | |
download | tink-614495b384bbe1ce5ad10509a68b70c666495a6f.tar.gz |
Move the functions GetPrimitive from each keymanager into the common superclass, as they are really the same everywhere.
Additionally, when doing so, I replace a reinterpret_cast with a static_cast. As a rule of thumb, using reinterpret_cast is bad.
PiperOrigin-RevId: 213277620
GitOrigin-RevId: f8e5eebd4eb3881d43a999bbb1cd4cf814956efa
Diffstat (limited to 'cc/mac/hmac_key_manager.h')
-rw-r--r-- | cc/mac/hmac_key_manager.h | 29 |
1 files changed, 10 insertions, 19 deletions
diff --git a/cc/mac/hmac_key_manager.h b/cc/mac/hmac_key_manager.h index 092cc09ab..56b4e8f96 100644 --- a/cc/mac/hmac_key_manager.h +++ b/cc/mac/hmac_key_manager.h @@ -13,16 +13,16 @@ // limitations under the License. // /////////////////////////////////////////////////////////////////////////////// +#ifndef TINK_MAC_HMAC_KEY_MANAGER_H_ +#define TINK_MAC_HMAC_KEY_MANAGER_H_ #include <algorithm> #include <vector> -#ifndef TINK_MAC_HMAC_KEY_MANAGER_H_ -#define TINK_MAC_HMAC_KEY_MANAGER_H_ - #include "absl/strings/string_view.h" -#include "tink/mac.h" +#include "tink/core/key_manager_base.h" #include "tink/key_manager.h" +#include "tink/mac.h" #include "tink/util/errors.h" #include "tink/util/protobuf_helper.h" #include "tink/util/status.h" @@ -33,7 +33,8 @@ namespace crypto { namespace tink { -class HmacKeyManager : public KeyManager<Mac> { +class HmacKeyManager + : public KeyManagerBase<Mac, google::crypto::tink::HmacKey> { public: static constexpr char kKeyType[] = "type.googleapis.com/google.crypto.tink.HmacKey"; @@ -41,16 +42,6 @@ class HmacKeyManager : public KeyManager<Mac> { HmacKeyManager(); - // Constructs an instance of HMAC-Mac for the given 'key_data', - // which must contain HmacKey-proto. - crypto::tink::util::StatusOr<std::unique_ptr<Mac>> GetPrimitive( - const google::crypto::tink::KeyData& key_data) const override; - - // Constructs an instance of HMAC-Mac for the given 'key', - // which must be HmacKey-proto. - crypto::tink::util::StatusOr<std::unique_ptr<Mac>> - GetPrimitive(const portable_proto::MessageLite& key) const override; - // Returns the type_url identifying the key type handled by this manager. const std::string& get_key_type() const override; @@ -63,6 +54,10 @@ class HmacKeyManager : public KeyManager<Mac> { virtual ~HmacKeyManager() {} + protected: + crypto::tink::util::StatusOr<std::unique_ptr<Mac>> GetPrimitiveFromKey( + const google::crypto::tink::HmacKey& hmac_key) const override; + private: friend class HmacKeyFactory; @@ -73,10 +68,6 @@ class HmacKeyManager : public KeyManager<Mac> { std::string key_type_; std::unique_ptr<KeyFactory> key_factory_; - // Constructs an instance of HMAC-Mac for the given 'key'. - crypto::tink::util::StatusOr<std::unique_ptr<Mac>> - GetPrimitiveImpl(const google::crypto::tink::HmacKey& key) const; - static crypto::tink::util::Status Validate( const google::crypto::tink::HmacParams& params); static crypto::tink::util::Status Validate( |