Chromium Code Reviews| Index: remoting/protocol/key_pair.cc |
| diff --git a/remoting/host/host_key_pair.cc b/remoting/protocol/key_pair.cc |
| similarity index 74% |
| rename from remoting/host/host_key_pair.cc |
| rename to remoting/protocol/key_pair.cc |
| index ff0f2cfcb380d33a5f1aed33b6738ea778f01aac..966f4d7872733706d23526e40c2976ad0e4835a5 100644 |
| --- a/remoting/host/host_key_pair.cc |
| +++ b/remoting/protocol/key_pair.cc |
| @@ -2,7 +2,7 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| -#include "remoting/host/host_key_pair.h" |
| +#include "remoting/protocol/key_pair.h" |
| #include <limits> |
| #include <string> |
| @@ -15,19 +15,19 @@ |
| #include "crypto/rsa_private_key.h" |
| #include "crypto/signature_creator.h" |
| #include "net/base/x509_certificate.h" |
| -#include "remoting/host/host_config.h" |
| namespace remoting { |
| +namespace protocol { |
| -HostKeyPair::HostKeyPair() { } |
| +KeyPair::KeyPair() { } |
| -HostKeyPair::~HostKeyPair() { } |
| +KeyPair::~KeyPair() { } |
| -void HostKeyPair::Generate() { |
| +void KeyPair::Generate() { |
| key_.reset(crypto::RSAPrivateKey::Create(2048)); |
| } |
| -bool HostKeyPair::LoadFromString(const std::string& key_base64) { |
| +bool KeyPair::LoadFromString(const std::string& key_base64) { |
| std::string key_str; |
| if (!base::Base64Decode(key_base64, &key_str)) { |
| LOG(ERROR) << "Failed to decode private key."; |
| @@ -44,20 +44,13 @@ bool HostKeyPair::LoadFromString(const std::string& key_base64) { |
| return true; |
| } |
| -bool HostKeyPair::Load(const HostConfig& host_config) { |
| - std::string key_base64; |
| - if (!host_config.GetString(kPrivateKeyConfigPath, &key_base64)) { |
| - LOG(ERROR) << "Private key wasn't found in the config file."; |
| - return false; |
| - } |
| - return LoadFromString(key_base64); |
| -} |
| - |
| -void HostKeyPair::Save(MutableHostConfig* host_config) { |
| - host_config->SetString(kPrivateKeyConfigPath, GetAsString()); |
| +scoped_ptr<KeyPair> KeyPair::Copy() { |
| + scoped_ptr<KeyPair> pair(new KeyPair()); |
| + pair->LoadFromString(this->GetAsString()); |
|
Wez
2013/02/23 03:43:20
Doesn't RSAPrivateKey have a Copy() method now?
rmsousa
2013/02/26 02:38:52
Done.
|
| + return pair.Pass(); |
| } |
| -std::string HostKeyPair::GetAsString() const { |
| +std::string KeyPair::GetAsString() const { |
| // Check that the key initialized. |
| DCHECK(key_.get() != NULL); |
| @@ -71,7 +64,7 @@ std::string HostKeyPair::GetAsString() const { |
| return key_base64; |
| } |
| -std::string HostKeyPair::GetPublicKey() const { |
| +std::string KeyPair::GetPublicKey() const { |
| std::vector<uint8> public_key; |
| key_->ExportPublicKey(&public_key); |
| std::string public_key_str(public_key.begin(), public_key.end()); |
| @@ -80,7 +73,7 @@ std::string HostKeyPair::GetPublicKey() const { |
| return public_key_base64; |
| } |
| -std::string HostKeyPair::GetSignature(const std::string& message) const { |
| +std::string KeyPair::GetSignature(const std::string& message) const { |
| scoped_ptr<crypto::SignatureCreator> signature_creator( |
| crypto::SignatureCreator::Create(key_.get())); |
| signature_creator->Update(reinterpret_cast<const uint8*>(message.c_str()), |
| @@ -93,13 +86,13 @@ std::string HostKeyPair::GetSignature(const std::string& message) const { |
| return signature_base64; |
| } |
| -crypto::RSAPrivateKey* HostKeyPair::CopyPrivateKey() const { |
| +crypto::RSAPrivateKey* KeyPair::CopyPrivateKey() const { |
| std::vector<uint8> key_bytes; |
| CHECK(key_->ExportPrivateKey(&key_bytes)); |
| return crypto::RSAPrivateKey::CreateFromPrivateKeyInfo(key_bytes); |
| } |
| -std::string HostKeyPair::GenerateCertificate() const { |
| +std::string KeyPair::GenerateCertificate() const { |
| scoped_refptr<net::X509Certificate> cert = |
| net::X509Certificate::CreateSelfSigned( |
| key_.get(), "CN=chromoting", |
| @@ -115,4 +108,5 @@ std::string HostKeyPair::GenerateCertificate() const { |
| return encoded; |
| } |
| +} // namespace protocol |
| } // namespace remoting |