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 #ifndef TINK_AEAD_INTERNAL_AEAD_FROM_ZERO_COPY_H_ 17 #define TINK_AEAD_INTERNAL_AEAD_FROM_ZERO_COPY_H_ 18 19 #include <memory> 20 #include <string> 21 #include <utility> 22 23 #include "absl/memory/memory.h" 24 #include "absl/status/status.h" 25 #include "tink/aead.h" 26 #include "tink/aead/internal/zero_copy_aead.h" 27 #include "tink/subtle/subtle_util.h" 28 #include "tink/util/status.h" 29 #include "tink/util/statusor.h" 30 31 namespace crypto { 32 namespace tink { 33 namespace internal { 34 35 // Aead cipher form a zero-copy one. Given a zero-copy AEAD implementation e.g., 36 // FooAeadZeroCopy, one can simply have: 37 // 38 // std::unique_ptr<Aead> aead = 39 // std::make_unique<AeadFromZeroCopy>(std::move(zero_copy_aead)); 40 class AeadFromZeroCopy : public Aead { 41 public: AeadFromZeroCopy(std::unique_ptr<ZeroCopyAead> aead)42 explicit AeadFromZeroCopy(std::unique_ptr<ZeroCopyAead> aead) 43 : aead_(std::move(aead)) {} 44 45 crypto::tink::util::StatusOr<std::string> Encrypt( 46 absl::string_view plaintext, 47 absl::string_view associated_data) const override; 48 49 crypto::tink::util::StatusOr<std::string> Decrypt( 50 absl::string_view ciphertext, 51 absl::string_view associated_data) const override; 52 53 private: 54 const std::unique_ptr<ZeroCopyAead> aead_; 55 }; 56 57 } // namespace internal 58 } // namespace tink 59 } // namespace crypto 60 61 #endif // TINK_AEAD_INTERNAL_AEAD_FROM_ZERO_COPY_H_ 62