1 // Copyright 2017 Google Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 // 15 /////////////////////////////////////////////////////////////////////////////// 16 #ifndef TINK_HYBRID_ECIES_AEAD_HKDF_PUBLIC_KEY_MANAGER_H_ 17 #define TINK_HYBRID_ECIES_AEAD_HKDF_PUBLIC_KEY_MANAGER_H_ 18 19 #include <memory> 20 #include <string> 21 22 #include "absl/memory/memory.h" 23 #include "absl/strings/str_cat.h" 24 #include "tink/core/key_type_manager.h" 25 #include "tink/hybrid/ecies_aead_hkdf_hybrid_encrypt.h" 26 #include "tink/hybrid_encrypt.h" 27 #include "tink/key_manager.h" 28 #include "tink/util/constants.h" 29 #include "tink/util/errors.h" 30 #include "tink/util/protobuf_helper.h" 31 #include "tink/util/status.h" 32 #include "tink/util/statusor.h" 33 #include "proto/ecies_aead_hkdf.pb.h" 34 #include "proto/tink.pb.h" 35 36 namespace crypto { 37 namespace tink { 38 39 class EciesAeadHkdfPublicKeyManager 40 : public KeyTypeManager<google::crypto::tink::EciesAeadHkdfPublicKey, void, 41 List<HybridEncrypt>> { 42 public: 43 class HybridEncryptFactory : public PrimitiveFactory<HybridEncrypt> { Create(const google::crypto::tink::EciesAeadHkdfPublicKey & ecies_public_key)44 crypto::tink::util::StatusOr<std::unique_ptr<HybridEncrypt>> Create( 45 const google::crypto::tink::EciesAeadHkdfPublicKey& ecies_public_key) 46 const override { 47 return EciesAeadHkdfHybridEncrypt::New(ecies_public_key); 48 } 49 }; 50 EciesAeadHkdfPublicKeyManager()51 EciesAeadHkdfPublicKeyManager() 52 : KeyTypeManager(absl::make_unique<HybridEncryptFactory>()) {} 53 get_version()54 uint32_t get_version() const override { return 0; } 55 key_material_type()56 google::crypto::tink::KeyData::KeyMaterialType key_material_type() 57 const override { 58 return google::crypto::tink::KeyData::ASYMMETRIC_PUBLIC; 59 } 60 get_key_type()61 const std::string& get_key_type() const override { return key_type_; } 62 63 crypto::tink::util::Status ValidateKey( 64 const google::crypto::tink::EciesAeadHkdfPublicKey& key) const override; 65 66 crypto::tink::util::Status ValidateParams( 67 const google::crypto::tink::EciesAeadHkdfParams& params) const; 68 private: 69 const std::string key_type_ = absl::StrCat( 70 kTypeGoogleapisCom, 71 google::crypto::tink::EciesAeadHkdfPublicKey().GetTypeName()); 72 }; 73 74 } // namespace tink 75 } // namespace crypto 76 77 #endif // TINK_HYBRID_ECIES_AEAD_HKDF_PUBLIC_KEY_MANAGER_H_ 78