blob: e4a5c82ced9e2f5f755ecafe73cfbdaab0b7bbc6 [file] [log] [blame]
Alex Vakulenkodf381642015-10-08 07:34:23 -07001// 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#include "buffet/keystore_encryptor.h"
16
17#include <memory>
18
19#include <keystore/keystore_client_impl.h>
20
21namespace {
22
23const char kBuffetKeyName[] = "buffet_config_b4f594c3";
24
25} // namespace
26
27namespace buffet {
28
29std::unique_ptr<Encryptor> Encryptor::CreateDefaultEncryptor() {
30 return std::unique_ptr<Encryptor>(
31 new KeystoreEncryptor(std::unique_ptr<keystore::KeystoreClient>(
32 new keystore::KeystoreClientImpl)));
33}
34
35KeystoreEncryptor::KeystoreEncryptor(
36 std::unique_ptr<keystore::KeystoreClient> keystore)
37 : keystore_(std::move(keystore)) {}
38
39bool KeystoreEncryptor::EncryptWithAuthentication(const std::string& plaintext,
40 std::string* ciphertext) {
41 return keystore_->encryptWithAuthentication(kBuffetKeyName, plaintext,
42 ciphertext);
43}
44
45bool KeystoreEncryptor::DecryptWithAuthentication(const std::string& ciphertext,
46 std::string* plaintext) {
47 return keystore_->decryptWithAuthentication(kBuffetKeyName, ciphertext,
48 plaintext);
49}
50
51} // namespace buffet