| OLD | NEW |
| 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2016 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 "components/policy/core/common/cloud/mock_signing_service.h" | 5 #include "components/policy/core/common/cloud/mock_signing_service.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "components/policy/core/common/cloud/cloud_policy_client.h" | 9 #include "components/policy/core/common/cloud/cloud_policy_client.h" |
| 10 | 10 |
| 11 namespace em = enterprise_management; | 11 namespace em = enterprise_management; |
| 12 | 12 |
| 13 namespace policy { | 13 namespace policy { |
| 14 | 14 |
| 15 const char kSignedDataNonce[] = "+nonce"; | 15 const char kSignedDataNonce[] = "+nonce"; |
| 16 const char kSignature[] = "fake-signature"; | 16 const char kSignature[] = "fake-signature"; |
| 17 | 17 |
| 18 FakeSigningService::FakeSigningService() {} | 18 FakeSigningService::FakeSigningService() {} |
| 19 | 19 |
| 20 FakeSigningService::~FakeSigningService() {} | 20 FakeSigningService::~FakeSigningService() {} |
| 21 | 21 |
| 22 void FakeSigningService::SignRegistrationData( | |
| 23 const em::CertificateBasedDeviceRegistrationData* registration_data, | |
| 24 em::SignedData* signed_data) { | |
| 25 DoSignData(registration_data->SerializeAsString(), signed_data); | |
| 26 } | |
| 27 | |
| 28 void FakeSigningService::SignData(const std::string& data, | 22 void FakeSigningService::SignData(const std::string& data, |
| 29 const SigningCallback& callback) { | 23 const SigningCallback& callback) { |
| 30 em::SignedData signed_data; | 24 em::SignedData signed_data; |
| 31 if (success_) | 25 if (success_) { |
| 32 DoSignData(data, &signed_data); | 26 SignDataSynchronously(data, &signed_data); |
| 27 } |
| 33 callback.Run(success_, signed_data); | 28 callback.Run(success_, signed_data); |
| 34 } | 29 } |
| 35 | 30 |
| 36 void FakeSigningService::DoSignData(const std::string& data, | 31 void FakeSigningService::SignDataSynchronously(const std::string& data, |
| 37 em::SignedData* signed_data) { | 32 em::SignedData* signed_data) { |
| 38 signed_data->set_data(data + kSignedDataNonce); | 33 signed_data->set_data(data + kSignedDataNonce); |
| 39 signed_data->set_signature(kSignature); | 34 signed_data->set_signature(kSignature); |
| 40 signed_data->set_extra_data_bytes(sizeof(kSignedDataNonce) - 1); | 35 signed_data->set_extra_data_bytes(sizeof(kSignedDataNonce) - 1); |
| 41 } | 36 } |
| 42 | 37 |
| 43 void FakeSigningService::set_success(bool success) { | 38 void FakeSigningService::set_success(bool success) { |
| 44 success_ = success; | 39 success_ = success; |
| 45 } | 40 } |
| 46 | 41 |
| 47 MockSigningService::MockSigningService() {} | 42 MockSigningService::MockSigningService() {} |
| 48 | 43 |
| 49 MockSigningService::~MockSigningService() {} | 44 MockSigningService::~MockSigningService() {} |
| 50 | 45 |
| 51 } // namespace policy | 46 } // namespace policy |
| 52 | |
| OLD | NEW |