Chromium Code Reviews| Index: sync/util/cryptographer.cc |
| diff --git a/sync/util/cryptographer.cc b/sync/util/cryptographer.cc |
| index f6b0e65565ab82a1883237520cb0ddea53c1ea23..350a237d898695f3c7cf99f829be38d1cf8fa96b 100644 |
| --- a/sync/util/cryptographer.cc |
| +++ b/sync/util/cryptographer.cc |
| @@ -52,6 +52,25 @@ void Cryptographer::Bootstrap(const std::string& restored_bootstrap_token) { |
| AddKeyImpl(nigori.release()); |
| } |
| + void Cryptographer::BootstrapKeystoreKey( |
| + const std::string& restored_bootstrap_token) { |
| + if (keystore_nigori_) { |
| + NOTREACHED(); |
| + return; |
| + } |
| + |
| + scoped_ptr<Nigori> nigori(UnpackBootstrapToken(restored_bootstrap_token)); |
| + if (!nigori.get()) |
| + return; |
| + // AddKeyImpl updates the default nigori, so we save the current default and |
| + // make sure the keystore_nigori_ gets updated instead. |
| + NigoriMap::value_type* old_default = default_nigori_; |
|
rlarocque
2012/06/13 23:35:04
Why use linked_ptr<>*?
Nicolas Zea
2012/06/15 00:42:07
Because they're also contained within the nigori k
|
| + if (AddKeyImpl(nigori.release())) { |
| + keystore_nigori_ = default_nigori_; |
| + default_nigori_ = old_default; |
| + } |
| +} |
| + |
| bool Cryptographer::CanDecrypt(const sync_pb::EncryptedData& data) const { |
| return nigoris_.end() != nigoris_.find(data.key_name()); |
| } |
| @@ -222,6 +241,15 @@ bool Cryptographer::GetBootstrapToken(std::string* token) const { |
| return PackBootstrapToken(default_nigori_->second.get(), token); |
| } |
| +bool Cryptographer::GetKeystoreKeyBootstrapToken( |
| + std::string* token) const { |
| + DCHECK(token); |
| + if (!HasKeystoreKey()) |
| + return false; |
| + |
| + return PackBootstrapToken(keystore_nigori_->second.get(), token); |
| +} |
| + |
| bool Cryptographer::PackBootstrapToken(const Nigori* nigori, |
| std::string* pack_into) const { |
| DCHECK(pack_into); |
| @@ -325,7 +353,7 @@ bool Cryptographer::SetKeystoreKey(const std::string& keystore_key) { |
| return false; |
| } |
| -bool Cryptographer::HasKeystoreKey() { |
| +bool Cryptographer::HasKeystoreKey() const { |
| return keystore_nigori_ != NULL; |
| } |