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 | |
Ben Chan | c45688b | 2014-07-02 23:50:45 -0700 | [diff] [blame] | 5 | #ifndef SHILL_CRYPTO_PROVIDER_H_ |
| 6 | #define SHILL_CRYPTO_PROVIDER_H_ |
Darin Petkov | 86964e0 | 2011-06-29 13:49:28 -0700 | [diff] [blame] | 7 | |
Alex Vakulenko | 8a53229 | 2014-06-16 17:18:44 -0700 | [diff] [blame] | 8 | #include <string> |
| 9 | |
Ben Chan | a0ddf46 | 2014-02-06 11:32:42 -0800 | [diff] [blame] | 10 | #include <base/files/file_path.h> |
Darin Petkov | 86964e0 | 2011-06-29 13:49:28 -0700 | [diff] [blame] | 11 | #include <base/memory/scoped_vector.h> |
| 12 | #include <gtest/gtest_prod.h> // for FRIEND_TEST |
| 13 | |
Eric Shienbrood | c74cf9c | 2012-03-02 15:00:35 -0500 | [diff] [blame] | 14 | #include "shill/crypto_interface.h" |
| 15 | |
Darin Petkov | 86964e0 | 2011-06-29 13:49:28 -0700 | [diff] [blame] | 16 | namespace shill { |
| 17 | |
Darin Petkov | 86964e0 | 2011-06-29 13:49:28 -0700 | [diff] [blame] | 18 | class GLib; |
| 19 | |
| 20 | class CryptoProvider { |
| 21 | public: |
| 22 | explicit CryptoProvider(GLib *glib); |
| 23 | |
| 24 | void Init(); |
| 25 | |
| 26 | // Returns |plaintext| encrypted by the highest priority available crypto |
| 27 | // module capable of performing the operation. If no module succeeds, returns |
| 28 | // |plaintext| as is. |
| 29 | std::string Encrypt(const std::string &plaintext); |
| 30 | |
| 31 | // Returns |ciphertext| decrypted by the highest priority available crypto |
| 32 | // module capable of performing the operation. If no module succeeds, returns |
| 33 | // |ciphertext| as is. |
| 34 | std::string Decrypt(const std::string &ciphertext); |
| 35 | |
Albert Chaulk | 0e1cdea | 2013-02-27 15:32:55 -0800 | [diff] [blame] | 36 | void set_key_matter_file(const base::FilePath &path) { |
| 37 | key_matter_file_ = path; |
| 38 | } |
Darin Petkov | 86964e0 | 2011-06-29 13:49:28 -0700 | [diff] [blame] | 39 | |
| 40 | private: |
| 41 | FRIEND_TEST(CryptoProviderTest, Init); |
| 42 | FRIEND_TEST(KeyFileStoreTest, OpenClose); |
| 43 | typedef ScopedVector<CryptoInterface> Cryptos; |
| 44 | |
| 45 | static const char kKeyMatterFile[]; |
| 46 | |
| 47 | GLib *glib_; |
| 48 | |
| 49 | // Registered crypto modules in high to low priority order. |
| 50 | Cryptos cryptos_; |
| 51 | |
Albert Chaulk | 0e1cdea | 2013-02-27 15:32:55 -0800 | [diff] [blame] | 52 | base::FilePath key_matter_file_; |
Darin Petkov | 86964e0 | 2011-06-29 13:49:28 -0700 | [diff] [blame] | 53 | |
| 54 | DISALLOW_COPY_AND_ASSIGN(CryptoProvider); |
| 55 | }; |
| 56 | |
| 57 | } // namespace shill |
| 58 | |
Ben Chan | c45688b | 2014-07-02 23:50:45 -0700 | [diff] [blame] | 59 | #endif // SHILL_CRYPTO_PROVIDER_H_ |