diff options
author | albertb@chromium.org <albertb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-07 17:46:12 +0000 |
---|---|---|
committer | albertb@chromium.org <albertb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-07 17:46:12 +0000 |
commit | 7ea4f4bde37b1e2dd56762a8d30400af3016737e (patch) | |
tree | 9b5a1721955235adbb20e8cadcd644f58d2d34bd /chrome/browser/sync/util | |
parent | 07a065e2879272a6cc27ed8e09477c957b479815 (diff) | |
download | chromium_src-7ea4f4bde37b1e2dd56762a8d30400af3016737e.zip chromium_src-7ea4f4bde37b1e2dd56762a8d30400af3016737e.tar.gz chromium_src-7ea4f4bde37b1e2dd56762a8d30400af3016737e.tar.bz2 |
Make Nigori method const and keep track of key parameters.
BUG=none
TEST=NigoriTest
Review URL: http://codereview.chromium.org/2637003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@49071 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/sync/util')
-rw-r--r-- | chrome/browser/sync/util/nigori.cc | 6 | ||||
-rw-r--r-- | chrome/browser/sync/util/nigori.h | 18 |
2 files changed, 17 insertions, 7 deletions
diff --git a/chrome/browser/sync/util/nigori.cc b/chrome/browser/sync/util/nigori.cc index 03e183d..9334e56 100644 --- a/chrome/browser/sync/util/nigori.cc +++ b/chrome/browser/sync/util/nigori.cc @@ -104,7 +104,7 @@ bool Nigori::Init(const std::string& username, const std::string& password) { // Permute[Kenc,Kmac](type || name) bool Nigori::Permute(Type type, const std::string& name, - std::string* permuted) { + std::string* permuted) const { DCHECK_LT(0U, name.size()); NigoriStream plaintext; @@ -147,7 +147,7 @@ std::string GenerateRandomString(size_t size) { } // Enc[Kenc,Kmac](value) -bool Nigori::Encrypt(const std::string& value, std::string* encrypted) { +bool Nigori::Encrypt(const std::string& value, std::string* encrypted) const { DCHECK_LT(0U, value.size()); std::string iv = GenerateRandomString(kIvSize); @@ -180,7 +180,7 @@ bool Nigori::Encrypt(const std::string& value, std::string* encrypted) { return Base64Encode(output, encrypted); } -bool Nigori::Decrypt(const std::string& encrypted, std::string* value) { +bool Nigori::Decrypt(const std::string& encrypted, std::string* value) const { std::string input; if (!Base64Decode(encrypted, &input)) return false; diff --git a/chrome/browser/sync/util/nigori.h b/chrome/browser/sync/util/nigori.h index ad57ad7..0050c48 100644 --- a/chrome/browser/sync/util/nigori.h +++ b/chrome/browser/sync/util/nigori.h @@ -39,15 +39,22 @@ class Nigori { // |username| and |password| are kept constant, a given |type| and |name| pair // always yields the same |permuted| value. Note that |permuted| will be // Base64 encoded. - bool Permute(Type type, const std::string& name, std::string* permuted); + bool Permute(Type type, const std::string& name, std::string* permuted) const; // Encrypts |value|. Note that on success, |encrypted| will be Base64 // encoded. - bool Encrypt(const std::string& value, std::string* encrypted); + bool Encrypt(const std::string& value, std::string* encrypted) const; // Decrypts |value| into |decrypted|. It is assumed that |value| is Base64 // encoded. - bool Decrypt(const std::string& value, std::string* decrypted); + bool Decrypt(const std::string& value, std::string* decrypted) const; + + // The next three getters return the parameters used to initialize the keys. + // Given the hostname, username and password, another Nigori object capable of + // encrypting and decrypting the same data as this one could be initialized. + const std::string& hostname() const { return hostname_; } + const std::string& username() const { return username_; } + const std::string& password() const { return password_; } static const char kSaltSalt[]; // The salt used to derive the user salt. static const size_t kSaltKeySizeInBits = 128; @@ -61,7 +68,10 @@ class Nigori { static const size_t kSigningIterations = 1004; private: - const std::string hostname_; + std::string hostname_; + std::string username_; + std::string password_; + scoped_ptr<base::SymmetricKey> user_key_; scoped_ptr<base::SymmetricKey> encryption_key_; scoped_ptr<base::SymmetricKey> mac_key_; |