blob: 6152b80bf2ca9f43c0a4c90a37ede7c7ee3c46cf [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:
Paul Stewarta794cd62015-06-16 13:13:10 -070022 explicit CryptoProvider(GLib* glib);
Darin Petkov86964e02011-06-29 13:49:28 -070023
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.
Paul Stewarta794cd62015-06-16 13:13:10 -070029 std::string Encrypt(const std::string& plaintext);
Darin Petkov86964e02011-06-29 13:49:28 -070030
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.
Paul Stewarta794cd62015-06-16 13:13:10 -070034 std::string Decrypt(const std::string& ciphertext);
Darin Petkov86964e02011-06-29 13:49:28 -070035
Paul Stewarta794cd62015-06-16 13:13:10 -070036 void set_key_matter_file(const base::FilePath& path) {
Albert Chaulk0e1cdea2013-02-27 15:32:55 -080037 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
Paul Stewarta794cd62015-06-16 13:13:10 -070047 GLib* glib_;
Darin Petkov86964e02011-06-29 13:49:28 -070048
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_