blob: f4d834cb760cd977dbeac3dd17aa66268ab4154c [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
Ben Chanc45688b2014-07-02 23:50:45 -07005#ifndef SHILL_CRYPTO_PROVIDER_H_
6#define SHILL_CRYPTO_PROVIDER_H_
Darin Petkov86964e02011-06-29 13:49:28 -07007
Alex Vakulenko8a532292014-06-16 17:18:44 -07008#include <string>
9
Ben Chana0ddf462014-02-06 11:32:42 -080010#include <base/files/file_path.h>
Darin Petkov86964e02011-06-29 13:49:28 -070011#include <base/memory/scoped_vector.h>
12#include <gtest/gtest_prod.h> // for FRIEND_TEST
13
Eric Shienbroodc74cf9c2012-03-02 15:00:35 -050014#include "shill/crypto_interface.h"
15
Darin Petkov86964e02011-06-29 13:49:28 -070016namespace shill {
17
Darin Petkov86964e02011-06-29 13:49:28 -070018class GLib;
19
20class 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 Chaulk0e1cdea2013-02-27 15:32:55 -080036 void set_key_matter_file(const base::FilePath &path) {
37 key_matter_file_ = path;
38 }
Darin Petkov86964e02011-06-29 13:49:28 -070039
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 Chaulk0e1cdea2013-02-27 15:32:55 -080052 base::FilePath key_matter_file_;
Darin Petkov86964e02011-06-29 13:49:28 -070053
54 DISALLOW_COPY_AND_ASSIGN(CryptoProvider);
55};
56
57} // namespace shill
58
Ben Chanc45688b2014-07-02 23:50:45 -070059#endif // SHILL_CRYPTO_PROVIDER_H_