Darin Petkov | 86964e0 | 2011-06-29 13:49:28 -0700 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium OS Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef SHILL_CRYPTO_PROVIDER_ |
| 6 | #define SHILL_CRYPTO_PROVIDER_ |
| 7 | |
| 8 | #include <base/file_path.h> |
| 9 | #include <base/memory/scoped_vector.h> |
| 10 | #include <gtest/gtest_prod.h> // for FRIEND_TEST |
| 11 | |
Eric Shienbrood | c74cf9c | 2012-03-02 15:00:35 -0500 | [diff] [blame] | 12 | #include "shill/crypto_interface.h" |
| 13 | |
Darin Petkov | 86964e0 | 2011-06-29 13:49:28 -0700 | [diff] [blame] | 14 | namespace shill { |
| 15 | |
Darin Petkov | 86964e0 | 2011-06-29 13:49:28 -0700 | [diff] [blame] | 16 | class GLib; |
| 17 | |
| 18 | class CryptoProvider { |
| 19 | public: |
| 20 | explicit CryptoProvider(GLib *glib); |
| 21 | |
| 22 | void Init(); |
| 23 | |
| 24 | // Returns |plaintext| encrypted by the highest priority available crypto |
| 25 | // module capable of performing the operation. If no module succeeds, returns |
| 26 | // |plaintext| as is. |
| 27 | std::string Encrypt(const std::string &plaintext); |
| 28 | |
| 29 | // Returns |ciphertext| decrypted by the highest priority available crypto |
| 30 | // module capable of performing the operation. If no module succeeds, returns |
| 31 | // |ciphertext| as is. |
| 32 | std::string Decrypt(const std::string &ciphertext); |
| 33 | |
Albert Chaulk | 0e1cdea | 2013-02-27 15:32:55 -0800 | [diff] [blame] | 34 | void set_key_matter_file(const base::FilePath &path) { |
| 35 | key_matter_file_ = path; |
| 36 | } |
Darin Petkov | 86964e0 | 2011-06-29 13:49:28 -0700 | [diff] [blame] | 37 | |
| 38 | private: |
| 39 | FRIEND_TEST(CryptoProviderTest, Init); |
| 40 | FRIEND_TEST(KeyFileStoreTest, OpenClose); |
| 41 | typedef ScopedVector<CryptoInterface> Cryptos; |
| 42 | |
| 43 | static const char kKeyMatterFile[]; |
| 44 | |
| 45 | GLib *glib_; |
| 46 | |
| 47 | // Registered crypto modules in high to low priority order. |
| 48 | Cryptos cryptos_; |
| 49 | |
Albert Chaulk | 0e1cdea | 2013-02-27 15:32:55 -0800 | [diff] [blame] | 50 | base::FilePath key_matter_file_; |
Darin Petkov | 86964e0 | 2011-06-29 13:49:28 -0700 | [diff] [blame] | 51 | |
| 52 | DISALLOW_COPY_AND_ASSIGN(CryptoProvider); |
| 53 | }; |
| 54 | |
| 55 | } // namespace shill |
| 56 | |
| 57 | #endif // SHILL_CRYPTO_PROVIDER_ |