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 | |
| 12 | namespace shill { |
| 13 | |
| 14 | class CryptoInterface; |
| 15 | class GLib; |
| 16 | |
| 17 | class CryptoProvider { |
| 18 | public: |
| 19 | explicit CryptoProvider(GLib *glib); |
| 20 | |
| 21 | void Init(); |
| 22 | |
| 23 | // Returns |plaintext| encrypted by the highest priority available crypto |
| 24 | // module capable of performing the operation. If no module succeeds, returns |
| 25 | // |plaintext| as is. |
| 26 | std::string Encrypt(const std::string &plaintext); |
| 27 | |
| 28 | // Returns |ciphertext| decrypted by the highest priority available crypto |
| 29 | // module capable of performing the operation. If no module succeeds, returns |
| 30 | // |ciphertext| as is. |
| 31 | std::string Decrypt(const std::string &ciphertext); |
| 32 | |
| 33 | void set_key_matter_file(const FilePath &path) { key_matter_file_ = path; } |
| 34 | |
| 35 | private: |
| 36 | FRIEND_TEST(CryptoProviderTest, Init); |
| 37 | FRIEND_TEST(KeyFileStoreTest, OpenClose); |
| 38 | typedef ScopedVector<CryptoInterface> Cryptos; |
| 39 | |
| 40 | static const char kKeyMatterFile[]; |
| 41 | |
| 42 | GLib *glib_; |
| 43 | |
| 44 | // Registered crypto modules in high to low priority order. |
| 45 | Cryptos cryptos_; |
| 46 | |
| 47 | FilePath key_matter_file_; |
| 48 | |
| 49 | DISALLOW_COPY_AND_ASSIGN(CryptoProvider); |
| 50 | }; |
| 51 | |
| 52 | } // namespace shill |
| 53 | |
| 54 | #endif // SHILL_CRYPTO_PROVIDER_ |