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)16class COMPONENT_EXPORT(NET_EXTRAS) CookieCryptoDelegate { 17 public: 18 CookieCryptoDelegate() = default; 19 20 virtual ~CookieCryptoDelegate() = default; 21 22 CookieCryptoDelegate(const CookieCryptoDelegate&) = delete; 23 CookieCryptoDelegate& operator=(const CookieCryptoDelegate&) = delete; 24 25 // Called to initialize the delegate. `EncryptString` and `DecryptString` may 26 // only be called once the `callback` has executed. `callback` executes on the 27 // same sequence as the call to `Init` either synchronously or asynchronously. 28 // Note: `Init` may be called multiple times and implementers should handle 29 // that appropriately by servicing every callback either synchronously or 30 // asynchronously. 31 virtual void Init(base::OnceClosure callback) = 0; 32 33 // Encrypt `plaintext` string and store the result in `ciphertext`. Returns 34 // true if the encryption succeeded. This must only be called after the 35 // callback from `Init` has run. This method can be called on any sequence. 36 virtual bool EncryptString(const std::string& plaintext, 37 std::string* ciphertext) = 0; 38 39 // Decrypt `ciphertext` string and store the result in `plaintext`. Returns 40 // true if the decryption succeeded. This must only be called after the 41 // callback from `Init` has run. This method can be called on any sequence. 42 virtual bool DecryptString(const std::string& ciphertext, 43 std::string* plaintext) = 0; 44 }; 45 46 } // namespace net 47 48 #endif // NET_EXTRAS_SQLITE_COOKIE_CRYPTO_DELEGATE_H_ 49