diff options
author | Bartosz Przydatek <przydatek@google.com> | 2017-04-03 14:03:30 +0000 |
---|---|---|
committer | Thai Duong <thaidn@google.com> | 2017-04-06 13:39:42 -0700 |
commit | 7a13a308a36bccb04f83b697165807288fd565db (patch) | |
tree | 272fb8c5748a60c657234860987f0ee599222faf /cc/mac/hmac_key_manager.h | |
parent | b5b0d6901ccfe0bb9db8db3128a16f1dffbf487d (diff) | |
download | tink-7a13a308a36bccb04f83b697165807288fd565db.tar.gz |
Simplifying KeyManager-interface and adding HmacKeyManager.
Change-Id: I54a686a839e172dfc43c97a8ccb8d059d985ceec
ORIGINAL_AUTHOR=Bartosz Przydatek <przydatek@google.com>
GitOrigin-RevId: 54ad8ce84d88b71ec147f08fc5d40c94769fa690
Diffstat (limited to 'cc/mac/hmac_key_manager.h')
-rw-r--r-- | cc/mac/hmac_key_manager.h | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/cc/mac/hmac_key_manager.h b/cc/mac/hmac_key_manager.h new file mode 100644 index 000000000..e3e312077 --- /dev/null +++ b/cc/mac/hmac_key_manager.h @@ -0,0 +1,84 @@ +// Copyright 2017 Google Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/////////////////////////////////////////////////////////////////////////////// + +#include <algorithm> +#include <vector> + +#ifndef TINK_MAC_HMAC_KEY_MANAGER_H_ +#define TINK_MAC_HMAC_KEY_MANAGER_H_ + +#include "cc/mac.h" +#include "cc/key_manager.h" +#include "cc/util/errors.h" +#include "cc/util/status.h" +#include "cc/util/statusor.h" +#include "google/protobuf/message.h" +#include "proto/hmac.pb.h" +#include "proto/tink.pb.h" + +namespace cloud { +namespace crypto { +namespace tink { + +class HmacKeyManager : public KeyManager<Mac> { + public: + HmacKeyManager() : key_type_(kKeyType) {} + + // Constructs an instance of HMAC-Mac for the given 'key'. + util::StatusOr<std::unique_ptr<Mac>> GetPrimitive( + const google::cloud::crypto::tink::KeyData& key_data) const override; + + // Constructs an instance of HMAC-Mac for the given 'key'. + util::StatusOr<std::unique_ptr<Mac>> + GetPrimitive(const google::protobuf::Message& key) const override; + + // Generates a new random HMAC key, based on the specified 'key_template'. + util::StatusOr<std::unique_ptr<google::protobuf::Message>> NewKey( + const google::cloud::crypto::tink::KeyTemplate& key_template) + const override; + + // Returns the type_url identifying the key type handled by this manager. + const std::string& get_key_type() const override; + + // Returns the version of this key manager. + int get_version() const override; + + virtual ~HmacKeyManager() {} + + private: + static constexpr char kKeyTypePrefix[] = "type.googleapis.com/"; + static constexpr char kKeyType[] = + "type.googleapis.com/google.cloud.crypto.tink.HmacKey"; + + std::string key_type_; + + // Constructs an instance of HMAC-Mac for the given 'key'. + util::StatusOr<std::unique_ptr<Mac>> + GetPrimitiveImpl(const google::cloud::crypto::tink::HmacKey& key) const; + + util::Status Validate( + const google::cloud::crypto::tink::HmacParams& params) const; + util::Status Validate( + const google::cloud::crypto::tink::HmacKey& key) const; + util::Status Validate( + const google::cloud::crypto::tink::HmacKeyFormat& key_format) const; +}; + +} // namespace tink +} // namespace crypto +} // namespace cloud + +#endif // TINK_MAC_HMAC_KEY_MANAGER_H_ |