• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "buffet/keystore_encryptor.h"
16 
17 #include <memory>
18 
19 #include <keystore/keystore_client_impl.h>
20 
21 namespace {
22 
23 const char kBuffetKeyName[] = "buffet_config_b4f594c3";
24 
25 }  // namespace
26 
27 namespace buffet {
28 
CreateDefaultEncryptor()29 std::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 
KeystoreEncryptor(std::unique_ptr<keystore::KeystoreClient> keystore)35 KeystoreEncryptor::KeystoreEncryptor(
36     std::unique_ptr<keystore::KeystoreClient> keystore)
37     : keystore_(std::move(keystore)) {}
38 
EncryptWithAuthentication(const std::string & plaintext,std::string * ciphertext)39 bool KeystoreEncryptor::EncryptWithAuthentication(const std::string& plaintext,
40                                                   std::string* ciphertext) {
41   return keystore_->encryptWithAuthentication(kBuffetKeyName, plaintext,
42                                               ciphertext);
43 }
44 
DecryptWithAuthentication(const std::string & ciphertext,std::string * plaintext)45 bool KeystoreEncryptor::DecryptWithAuthentication(const std::string& ciphertext,
46                                                   std::string* plaintext) {
47   return keystore_->decryptWithAuthentication(kBuffetKeyName, ciphertext,
48                                               plaintext);
49 }
50 
51 }  // namespace buffet
52