• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2013 The Chromium Authors
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 NET_EXTRAS_SQLITE_COOKIE_CRYPTO_DELEGATE_H_
6 #define NET_EXTRAS_SQLITE_COOKIE_CRYPTO_DELEGATE_H_
7 
8 #include <string>
9 
10 #include "base/component_export.h"
11 #include "base/functional/callback.h"
12 
13 namespace net {
14 
15 // Implements encryption and decryption for the persistent cookie store.
COMPONENT_EXPORT(NET_EXTRAS)16 class COMPONENT_EXPORT(NET_EXTRAS) CookieCryptoDelegate {
17  public:
18   virtual ~CookieCryptoDelegate() = default;
19 
20   // Called to initialize the delegate. `EncryptString` and `DecryptString` may
21   // only be called once the `callback` has executed. `callback` executes on the
22   // same sequence as the call to `Init` either synchronously or asynchronously.
23   // Note: `Init` may be called multiple times and implementers should handle
24   // that appropriately by servicing every callback either synchronously or
25   // asynchronously.
26   virtual void Init(base::OnceClosure callback) = 0;
27 
28   // Encrypt `plaintext` string and store the result in `ciphertext`. Returns
29   // true if the encryption succeeded.
30   virtual bool EncryptString(const std::string& plaintext,
31                              std::string* ciphertext) = 0;
32 
33   // Decrypt `ciphertext` string and store the result in `plaintext`. Returns
34   // true if the decryption succeeded.
35   virtual bool DecryptString(const std::string& ciphertext,
36                              std::string* plaintext) = 0;
37 };
38 
39 }  // namespace net
40 
41 #endif  // NET_EXTRAS_SQLITE_COOKIE_CRYPTO_DELEGATE_H_
42