blob: 96f4f7136a5a35be7fa5cf54f874c93481827760 [file] [log] [blame]
// Copyright 2015 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef BUFFET_ENCRYPTOR_H_
#define BUFFET_ENCRYPTOR_H_
#include <memory>
#include <string>
#include <base/macros.h>
namespace buffet {
// An abstract class to perform authenticated encryption.
class Encryptor {
public:
Encryptor() = default;
virtual ~Encryptor() = default;
// Encrypts and authenticates the given |plaintext| and emits the
// |ciphertext|. Returns true on success.
virtual bool EncryptWithAuthentication(const std::string& plaintext,
std::string* ciphertext) = 0;
// Decrypts and authenticates the given |ciphertext| and emits the
// |plaintext|. Returns true on success.
virtual bool DecryptWithAuthentication(const std::string& ciphertext,
std::string* plaintext) = 0;
// A factory method to be exported by the default Encryptor implementation
// for a given platform. Like a constructor, this method should not perform
// any significant initialization work. The caller assumes ownership of the
// pointer.
static std::unique_ptr<Encryptor> CreateDefaultEncryptor();
private:
DISALLOW_COPY_AND_ASSIGN(Encryptor);
};
} // namespace buffet
#endif // BUFFET_ENCRYPTOR_H_