| Index: remoting/protocol/pairing_registry.cc
|
| diff --git a/remoting/protocol/pairing_registry.cc b/remoting/protocol/pairing_registry.cc
|
| index 10098b03ed74850a820670e1f9b5646a2d68caec..6c9cc66ac3504c9ce18ac5acb0407b07ea9cf136 100644
|
| --- a/remoting/protocol/pairing_registry.cc
|
| +++ b/remoting/protocol/pairing_registry.cc
|
| @@ -12,35 +12,63 @@
|
| namespace remoting {
|
| namespace protocol {
|
|
|
| -// How many bytes of random data to use for the client id and shared secret.
|
| +// How many bytes of random data to use for the shared secret.
|
| const int kKeySize = 16;
|
|
|
| -PairingRegistry::PairingRegistry(scoped_ptr<Delegate> delegate)
|
| - : delegate_(delegate.Pass()) {
|
| - DCHECK(delegate_);
|
| +PairingRegistry::Pairing::Pairing() {
|
| }
|
|
|
| -PairingRegistry::~PairingRegistry() {
|
| +PairingRegistry::Pairing::Pairing(const base::Time& created_time,
|
| + const std::string& client_name,
|
| + const std::string& client_id,
|
| + const std::string& shared_secret)
|
| + : created_time_(created_time),
|
| + client_name_(client_name),
|
| + client_id_(client_id),
|
| + shared_secret_(shared_secret) {
|
| }
|
|
|
| -PairingRegistry::Pairing PairingRegistry::CreatePairing(
|
| +PairingRegistry::Pairing PairingRegistry::Pairing::Create(
|
| const std::string& client_name) {
|
| - DCHECK(CalledOnValidThread());
|
| -
|
| - Pairing result;
|
| - result.client_name = client_name;
|
| - result.client_id = base::GenerateGUID();
|
| -
|
| - // Create a random shared secret to authenticate this client.
|
| + base::Time created_time = base::Time::Now();
|
| + std::string client_id = base::GenerateGUID();
|
| + std::string shared_secret;
|
| char buffer[kKeySize];
|
| crypto::RandBytes(buffer, arraysize(buffer));
|
| if (!base::Base64Encode(base::StringPiece(buffer, arraysize(buffer)),
|
| - &result.shared_secret)) {
|
| + &shared_secret)) {
|
| LOG(FATAL) << "Base64Encode failed.";
|
| }
|
| + return Pairing(created_time, client_name, client_id, shared_secret);
|
| +}
|
| +
|
| +PairingRegistry::Pairing::~Pairing() {
|
| +}
|
| +
|
| +bool PairingRegistry::Pairing::operator==(const Pairing& other) const {
|
| + return created_time_ == other.created_time_ &&
|
| + client_id_ == other.client_id_ &&
|
| + client_name_ == other.client_name_ &&
|
| + shared_secret_ == other.shared_secret_;
|
| +}
|
| +
|
| +bool PairingRegistry::Pairing::is_valid() const {
|
| + return !client_id_.empty() && !shared_secret_.empty();
|
| +}
|
| +
|
| +PairingRegistry::PairingRegistry(scoped_ptr<Delegate> delegate)
|
| + : delegate_(delegate.Pass()) {
|
| + DCHECK(delegate_);
|
| +}
|
| +
|
| +PairingRegistry::~PairingRegistry() {
|
| +}
|
|
|
| - // Save the result via the Delegate and return it to the caller.
|
| - delegate_->AddPairing(result);
|
| +PairingRegistry::Pairing PairingRegistry::CreatePairing(
|
| + const std::string& client_name) {
|
| + DCHECK(CalledOnValidThread());
|
| + Pairing result = Pairing::Create(client_name);
|
| + delegate_->AddPairing(result, AddPairingCallback());
|
| return result;
|
| }
|
|
|
| @@ -51,8 +79,12 @@ void PairingRegistry::GetPairing(const std::string& client_id,
|
| }
|
|
|
| void NotImplementedPairingRegistryDelegate::AddPairing(
|
| - const PairingRegistry::Pairing& new_paired_client) {
|
| + const PairingRegistry::Pairing& new_paired_client,
|
| + const PairingRegistry::AddPairingCallback& callback) {
|
| NOTIMPLEMENTED();
|
| + if (!callback.is_null()) {
|
| + callback.Run(false);
|
| + }
|
| }
|
|
|
| void NotImplementedPairingRegistryDelegate::GetPairing(
|
| @@ -62,6 +94,5 @@ void NotImplementedPairingRegistryDelegate::GetPairing(
|
| callback.Run(PairingRegistry::Pairing());
|
| }
|
|
|
| -
|
| } // namespace protocol
|
| } // namespace remoting
|
|
|