Home | History | Annotate | Download | only in webservd
      1 // Copyright 2015 The Android Open Source Project
      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 #ifndef WEBSERVER_WEBSERVD_ENCRYPTOR_H_
     16 #define WEBSERVER_WEBSERVD_ENCRYPTOR_H_
     17 
     18 #include <memory>
     19 #include <string>
     20 
     21 namespace webservd {
     22 
     23 // An abstract class to perform authenticated encryption.
     24 class Encryptor {
     25  public:
     26   virtual ~Encryptor() = default;
     27 
     28   // Encrypts and authenticates the given |plaintext| and emits the
     29   // |ciphertext|. Returns true on success.
     30   virtual bool EncryptWithAuthentication(const std::string& plaintext,
     31                                          std::string* ciphertext) = 0;
     32 
     33   // Decrypts and authenticates the given |ciphertext| and emits the
     34   // |plaintext|. Returns true on success.
     35   virtual bool DecryptWithAuthentication(const std::string& ciphertext,
     36                                          std::string* plaintext) = 0;
     37 
     38   // A factory method to be exported by the default Encryptor implementation
     39   // for a given platform. Like a constructor, this method should not perform
     40   // any significant initialization work. The caller assumes ownership of the
     41   // pointer.
     42   static std::unique_ptr<Encryptor> CreateDefaultEncryptor();
     43 };
     44 
     45 }  // namespace webservd
     46 
     47 #endif  // WEBSERVER_WEBSERVD_ENCRYPTOR_H_
     48