blob: 2930d07fe47773d6d5842bf54976d880dbdc50ef [file] [log] [blame]
Darin Petkov86964e02011-06-29 13:49:28 -07001// 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 Shienbroodc74cf9c2012-03-02 15:00:35 -050012#include "shill/crypto_interface.h"
13
Darin Petkov86964e02011-06-29 13:49:28 -070014namespace shill {
15
Darin Petkov86964e02011-06-29 13:49:28 -070016class GLib;
17
18class 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 Chaulk0e1cdea2013-02-27 15:32:55 -080034 void set_key_matter_file(const base::FilePath &path) {
35 key_matter_file_ = path;
36 }
Darin Petkov86964e02011-06-29 13:49:28 -070037
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 Chaulk0e1cdea2013-02-27 15:32:55 -080050 base::FilePath key_matter_file_;
Darin Petkov86964e02011-06-29 13:49:28 -070051
52 DISALLOW_COPY_AND_ASSIGN(CryptoProvider);
53};
54
55} // namespace shill
56
57#endif // SHILL_CRYPTO_PROVIDER_