xref: /aosp_15_r20/external/tink/cc/hybrid/ecies_aead_hkdf_private_key_manager.h (revision e7b1675dde1b92d52ec075b0a92829627f2c52a5)
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_PRIVATE_KEY_MANAGER_H_
17 #define TINK_HYBRID_ECIES_AEAD_HKDF_PRIVATE_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/core/private_key_type_manager.h"
26 #include "tink/hybrid/ecies_aead_hkdf_hybrid_decrypt.h"
27 #include "tink/hybrid_decrypt.h"
28 #include "tink/key_manager.h"
29 #include "tink/util/constants.h"
30 #include "tink/util/errors.h"
31 #include "tink/util/protobuf_helper.h"
32 #include "tink/util/status.h"
33 #include "tink/util/statusor.h"
34 #include "proto/ecies_aead_hkdf.pb.h"
35 #include "proto/tink.pb.h"
36 
37 namespace crypto {
38 namespace tink {
39 
40 class EciesAeadHkdfPrivateKeyManager
41     : public PrivateKeyTypeManager<
42           google::crypto::tink::EciesAeadHkdfPrivateKey,
43           google::crypto::tink::EciesAeadHkdfKeyFormat,
44           google::crypto::tink::EciesAeadHkdfPublicKey, List<HybridDecrypt>> {
45  public:
46   class HybridDecryptFactory : public PrimitiveFactory<HybridDecrypt> {
Create(const google::crypto::tink::EciesAeadHkdfPrivateKey & ecies_private_key)47     crypto::tink::util::StatusOr<std::unique_ptr<HybridDecrypt>> Create(
48         const google::crypto::tink::EciesAeadHkdfPrivateKey& ecies_private_key)
49         const override {
50       return EciesAeadHkdfHybridDecrypt::New(ecies_private_key);
51     }
52   };
53 
EciesAeadHkdfPrivateKeyManager()54   EciesAeadHkdfPrivateKeyManager()
55       : PrivateKeyTypeManager(absl::make_unique<HybridDecryptFactory>()) {}
56 
get_version()57   uint32_t get_version() const override { return 0; }
58 
key_material_type()59   google::crypto::tink::KeyData::KeyMaterialType key_material_type()
60       const override {
61     return google::crypto::tink::KeyData::ASYMMETRIC_PRIVATE;
62   }
63 
get_key_type()64   const std::string& get_key_type() const override { return key_type_; }
65 
66   crypto::tink::util::Status ValidateKey(
67       const google::crypto::tink::EciesAeadHkdfPrivateKey& key) const override;
68 
69   crypto::tink::util::Status ValidateKeyFormat(
70       const google::crypto::tink::EciesAeadHkdfKeyFormat& ecies_key_format)
71       const override;
72 
73   crypto::tink::util::StatusOr<google::crypto::tink::EciesAeadHkdfPrivateKey>
74   CreateKey(const google::crypto::tink::EciesAeadHkdfKeyFormat& key_format)
75       const override;
76 
77   crypto::tink::util::StatusOr<google::crypto::tink::EciesAeadHkdfPublicKey>
78   GetPublicKey(const google::crypto::tink::EciesAeadHkdfPrivateKey& private_key)
79       const override;
80 
81  private:
82   const std::string key_type_ = absl::StrCat(
83       kTypeGoogleapisCom,
84       google::crypto::tink::EciesAeadHkdfPrivateKey().GetTypeName());
85 };
86 
87 }  // namespace tink
88 }  // namespace crypto
89 
90 #endif  // TINK_HYBRID_ECIES_AEAD_HKDF_PRIVATE_KEY_MANAGER_H_
91