• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright (C) 2011 The Android Open Source Project
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //      http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 
17 #ifndef SHILL_CRYPTO_PROVIDER_H_
18 #define SHILL_CRYPTO_PROVIDER_H_
19 
20 #include <string>
21 
22 #include <base/files/file_path.h>
23 #include <base/memory/scoped_vector.h>
24 #include <gtest/gtest_prod.h>  // for FRIEND_TEST
25 
26 #include "shill/crypto_interface.h"
27 
28 namespace shill {
29 
30 class CryptoProvider {
31  public:
32   CryptoProvider();
33 
34   void Init();
35 
36   // Returns |plaintext| encrypted by the highest priority available crypto
37   // module capable of performing the operation. If no module succeeds, returns
38   // |plaintext| as is.
39   std::string Encrypt(const std::string& plaintext);
40 
41   // Returns |ciphertext| decrypted by the highest priority available crypto
42   // module capable of performing the operation. If no module succeeds, returns
43   // |ciphertext| as is.
44   std::string Decrypt(const std::string& ciphertext);
45 
set_key_matter_file(const base::FilePath & path)46   void set_key_matter_file(const base::FilePath& path) {
47     key_matter_file_ = path;
48   }
49 
50  private:
51   FRIEND_TEST(CryptoProviderTest, Init);
52   FRIEND_TEST(KeyFileStoreTest, OpenClose);
53   typedef ScopedVector<CryptoInterface> Cryptos;
54 
55   static const char kKeyMatterFile[];
56 
57   // Registered crypto modules in high to low priority order.
58   Cryptos cryptos_;
59 
60   base::FilePath key_matter_file_;
61 
62   DISALLOW_COPY_AND_ASSIGN(CryptoProvider);
63 };
64 
65 }  // namespace shill
66 
67 #endif  // SHILL_CRYPTO_PROVIDER_H_
68