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