| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/extensions/api/easy_unlock_private/easy_unlock_private_
api.h" | 5 #include "chrome/browser/extensions/api/easy_unlock_private/easy_unlock_private_
api.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 | 256 |
| 257 EasyUnlockPrivatePerformECDHKeyAgreementFunction:: | 257 EasyUnlockPrivatePerformECDHKeyAgreementFunction:: |
| 258 ~EasyUnlockPrivatePerformECDHKeyAgreementFunction() {} | 258 ~EasyUnlockPrivatePerformECDHKeyAgreementFunction() {} |
| 259 | 259 |
| 260 bool EasyUnlockPrivatePerformECDHKeyAgreementFunction::RunAsync() { | 260 bool EasyUnlockPrivatePerformECDHKeyAgreementFunction::RunAsync() { |
| 261 scoped_ptr<easy_unlock_private::PerformECDHKeyAgreement::Params> params = | 261 scoped_ptr<easy_unlock_private::PerformECDHKeyAgreement::Params> params = |
| 262 easy_unlock_private::PerformECDHKeyAgreement::Params::Create(*args_); | 262 easy_unlock_private::PerformECDHKeyAgreement::Params::Create(*args_); |
| 263 EXTENSION_FUNCTION_VALIDATE(params); | 263 EXTENSION_FUNCTION_VALIDATE(params); |
| 264 | 264 |
| 265 GetCryptoDelegate(browser_context())->PerformECDHKeyAgreement( | 265 GetCryptoDelegate(browser_context())->PerformECDHKeyAgreement( |
| 266 *params, | 266 params->private_key, |
| 267 params->public_key, |
| 267 base::Bind(&EasyUnlockPrivatePerformECDHKeyAgreementFunction::OnData, | 268 base::Bind(&EasyUnlockPrivatePerformECDHKeyAgreementFunction::OnData, |
| 268 this)); | 269 this)); |
| 269 return true; | 270 return true; |
| 270 } | 271 } |
| 271 | 272 |
| 272 void EasyUnlockPrivatePerformECDHKeyAgreementFunction::OnData( | 273 void EasyUnlockPrivatePerformECDHKeyAgreementFunction::OnData( |
| 273 const std::string& secret_key) { | 274 const std::string& secret_key) { |
| 274 // TODO(tbarzic): Improve error handling. | 275 // TODO(tbarzic): Improve error handling. |
| 275 if (!secret_key.empty()) { | 276 if (!secret_key.empty()) { |
| 276 results_ = easy_unlock_private::PerformECDHKeyAgreement::Results::Create( | 277 results_ = easy_unlock_private::PerformECDHKeyAgreement::Results::Create( |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 | 309 |
| 309 EasyUnlockPrivateCreateSecureMessageFunction:: | 310 EasyUnlockPrivateCreateSecureMessageFunction:: |
| 310 ~EasyUnlockPrivateCreateSecureMessageFunction() {} | 311 ~EasyUnlockPrivateCreateSecureMessageFunction() {} |
| 311 | 312 |
| 312 bool EasyUnlockPrivateCreateSecureMessageFunction::RunAsync() { | 313 bool EasyUnlockPrivateCreateSecureMessageFunction::RunAsync() { |
| 313 scoped_ptr<easy_unlock_private::CreateSecureMessage::Params> params = | 314 scoped_ptr<easy_unlock_private::CreateSecureMessage::Params> params = |
| 314 easy_unlock_private::CreateSecureMessage::Params::Create(*args_); | 315 easy_unlock_private::CreateSecureMessage::Params::Create(*args_); |
| 315 EXTENSION_FUNCTION_VALIDATE(params); | 316 EXTENSION_FUNCTION_VALIDATE(params); |
| 316 | 317 |
| 317 GetCryptoDelegate(browser_context())->CreateSecureMessage( | 318 GetCryptoDelegate(browser_context())->CreateSecureMessage( |
| 318 *params, | 319 params->payload, |
| 320 params->key, |
| 321 params->options.associated_data ? |
| 322 *params->options.associated_data : std::string(), |
| 323 params->options.public_metadata ? |
| 324 *params->options.public_metadata : std::string(), |
| 325 params->options.verification_key_id ? |
| 326 *params->options.verification_key_id : std::string(), |
| 327 params->options.decryption_key_id ? |
| 328 *params->options.decryption_key_id : std::string(), |
| 329 params->options.encrypt_type, |
| 330 params->options.sign_type, |
| 319 base::Bind(&EasyUnlockPrivateCreateSecureMessageFunction::OnData, | 331 base::Bind(&EasyUnlockPrivateCreateSecureMessageFunction::OnData, |
| 320 this)); | 332 this)); |
| 321 return true; | 333 return true; |
| 322 } | 334 } |
| 323 | 335 |
| 324 void EasyUnlockPrivateCreateSecureMessageFunction::OnData( | 336 void EasyUnlockPrivateCreateSecureMessageFunction::OnData( |
| 325 const std::string& message) { | 337 const std::string& message) { |
| 326 // TODO(tbarzic): Improve error handling. | 338 // TODO(tbarzic): Improve error handling. |
| 327 if (!message.empty()) { | 339 if (!message.empty()) { |
| 328 results_ = easy_unlock_private::CreateSecureMessage::Results::Create( | 340 results_ = easy_unlock_private::CreateSecureMessage::Results::Create( |
| 329 message); | 341 message); |
| 330 } | 342 } |
| 331 SendResponse(true); | 343 SendResponse(true); |
| 332 } | 344 } |
| 333 | 345 |
| 334 EasyUnlockPrivateUnwrapSecureMessageFunction:: | 346 EasyUnlockPrivateUnwrapSecureMessageFunction:: |
| 335 EasyUnlockPrivateUnwrapSecureMessageFunction() {} | 347 EasyUnlockPrivateUnwrapSecureMessageFunction() {} |
| 336 | 348 |
| 337 EasyUnlockPrivateUnwrapSecureMessageFunction:: | 349 EasyUnlockPrivateUnwrapSecureMessageFunction:: |
| 338 ~EasyUnlockPrivateUnwrapSecureMessageFunction() {} | 350 ~EasyUnlockPrivateUnwrapSecureMessageFunction() {} |
| 339 | 351 |
| 340 bool EasyUnlockPrivateUnwrapSecureMessageFunction::RunAsync() { | 352 bool EasyUnlockPrivateUnwrapSecureMessageFunction::RunAsync() { |
| 341 scoped_ptr<easy_unlock_private::UnwrapSecureMessage::Params> params = | 353 scoped_ptr<easy_unlock_private::UnwrapSecureMessage::Params> params = |
| 342 easy_unlock_private::UnwrapSecureMessage::Params::Create(*args_); | 354 easy_unlock_private::UnwrapSecureMessage::Params::Create(*args_); |
| 343 EXTENSION_FUNCTION_VALIDATE(params); | 355 EXTENSION_FUNCTION_VALIDATE(params); |
| 344 | 356 |
| 345 GetCryptoDelegate(browser_context())->UnwrapSecureMessage( | 357 GetCryptoDelegate(browser_context())->UnwrapSecureMessage( |
| 346 *params, | 358 params->secure_message, |
| 359 params->key, |
| 360 params->options.associated_data ? |
| 361 *params->options.associated_data : std::string(), |
| 362 params->options.encrypt_type, |
| 363 params->options.sign_type, |
| 347 base::Bind(&EasyUnlockPrivateUnwrapSecureMessageFunction::OnData, | 364 base::Bind(&EasyUnlockPrivateUnwrapSecureMessageFunction::OnData, |
| 348 this)); | 365 this)); |
| 349 return true; | 366 return true; |
| 350 } | 367 } |
| 351 | 368 |
| 352 void EasyUnlockPrivateUnwrapSecureMessageFunction::OnData( | 369 void EasyUnlockPrivateUnwrapSecureMessageFunction::OnData( |
| 353 const std::string& data) { | 370 const std::string& data) { |
| 354 // TODO(tbarzic): Improve error handling. | 371 // TODO(tbarzic): Improve error handling. |
| 355 if (!data.empty()) | 372 if (!data.empty()) |
| 356 results_ = easy_unlock_private::UnwrapSecureMessage::Results::Create(data); | 373 results_ = easy_unlock_private::UnwrapSecureMessage::Results::Create(data); |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 524 bool EasyUnlockPrivateGetRemoteDevicesFunction::RunSync() { | 541 bool EasyUnlockPrivateGetRemoteDevicesFunction::RunSync() { |
| 525 Profile* profile = Profile::FromBrowserContext(browser_context()); | 542 Profile* profile = Profile::FromBrowserContext(browser_context()); |
| 526 const base::ListValue* devices = | 543 const base::ListValue* devices = |
| 527 EasyUnlockService::Get(profile)->GetRemoteDevices(); | 544 EasyUnlockService::Get(profile)->GetRemoteDevices(); |
| 528 SetResult(devices ? devices->DeepCopy() : new base::ListValue()); | 545 SetResult(devices ? devices->DeepCopy() : new base::ListValue()); |
| 529 return true; | 546 return true; |
| 530 } | 547 } |
| 531 | 548 |
| 532 } // namespace api | 549 } // namespace api |
| 533 } // namespace extensions | 550 } // namespace extensions |
| OLD | NEW |