xref: /aosp_15_r20/external/tink/cc/hybrid/internal/hpke_encrypt.h (revision e7b1675dde1b92d52ec075b0a92829627f2c52a5)
1 // Copyright 2021 Google LLC
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 
17 #ifndef TINK_HYBRID_INTERNAL_HPKE_ENCRYPT_H_
18 #define TINK_HYBRID_INTERNAL_HPKE_ENCRYPT_H_
19 
20 #include <memory>
21 #include <string>
22 
23 #include "tink/hybrid_encrypt.h"
24 #include "tink/util/statusor.h"
25 #include "proto/hpke.pb.h"
26 
27 namespace crypto {
28 namespace tink {
29 
30 class HpkeEncrypt : public HybridEncrypt {
31  public:
32   // Copyable and movable.
33   HpkeEncrypt(const HpkeEncrypt& other) = default;
34   HpkeEncrypt& operator=(const HpkeEncrypt& other) = default;
35   HpkeEncrypt(HpkeEncrypt&& other) = default;
36   HpkeEncrypt& operator=(HpkeEncrypt&& other) = default;
37 
38   static crypto::tink::util::StatusOr<std::unique_ptr<HybridEncrypt>> New(
39       const google::crypto::tink::HpkePublicKey& recipient_public_key);
40 
41   crypto::tink::util::StatusOr<std::string> Encrypt(
42       absl::string_view plaintext,
43       absl::string_view context_info) const override;
44 
45  private:
HpkeEncrypt(const google::crypto::tink::HpkePublicKey & recipient_public_key)46   explicit HpkeEncrypt(
47       const google::crypto::tink::HpkePublicKey& recipient_public_key)
48       : recipient_public_key_(recipient_public_key) {}
49 
50   google::crypto::tink::HpkePublicKey recipient_public_key_;
51 };
52 
53 }  // namespace tink
54 }  // namespace crypto
55 
56 #endif  // TINK_HYBRID_INTERNAL_HPKE_ENCRYPT_H_
57