1 //
2 // Copyright (C) 2013 The Android Open Source Project
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //      http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 
17 #include "shill/mock_crypto_util_proxy.h"
18 
19 #include <string>
20 #include <vector>
21 
22 #include "shill/callbacks.h"
23 #include "shill/error.h"
24 #include "shill/event_dispatcher.h"
25 #include "shill/testing.h"
26 
27 using testing::_;
28 using testing::DoAll;
29 using testing::Return;
30 
31 namespace shill {
32 
MockCryptoUtilProxy(EventDispatcher * dispatcher)33 MockCryptoUtilProxy::MockCryptoUtilProxy(
34     EventDispatcher* dispatcher)
35     : CryptoUtilProxy(dispatcher) {
36   ON_CALL(*this, VerifyDestination(_, _, _, _, _, _, _, _, _))
37       .WillByDefault(DoAll(SetOperationFailedInArgumentAndWarn<8>(),
38                            Return(false)));
39   ON_CALL(*this, EncryptData(_, _, _, _))
40       .WillByDefault(DoAll(SetOperationFailedInArgumentAndWarn<3>(),
41                            Return(false)));
42 }
43 
~MockCryptoUtilProxy()44 MockCryptoUtilProxy::~MockCryptoUtilProxy() {}
45 
RealVerifyDestination(const std::string & certificate,const std::string & public_key,const std::string & nonce,const std::string & signed_data,const std::string & destination_udn,const std::vector<uint8_t> & ssid,const std::string & bssid,const ResultBoolCallback & result_callback,Error * error)46 bool MockCryptoUtilProxy::RealVerifyDestination(
47     const std::string& certificate,
48     const std::string& public_key,
49     const std::string& nonce,
50     const std::string& signed_data,
51     const std::string& destination_udn,
52     const std::vector<uint8_t>& ssid,
53     const std::string& bssid,
54     const ResultBoolCallback& result_callback,
55     Error* error) {
56   return CryptoUtilProxy::VerifyDestination(certificate, public_key,
57                                             nonce, signed_data,
58                                             destination_udn, ssid, bssid,
59                                             result_callback, error);
60 }
61 
RealEncryptData(const std::string & public_key,const std::string & data,const ResultStringCallback & result_callback,Error * error)62 bool MockCryptoUtilProxy::RealEncryptData(
63     const std::string& public_key,
64     const std::string& data,
65     const ResultStringCallback& result_callback,
66     Error* error) {
67   return CryptoUtilProxy::EncryptData(public_key, data,
68                                       result_callback, error);
69 }
70 
RealStartShimForCommand(const std::string & command,const std::string & input,const StringCallback & result_handler)71 bool MockCryptoUtilProxy::RealStartShimForCommand(
72     const std::string& command,
73     const std::string& input,
74     const StringCallback& result_handler) {
75   return CryptoUtilProxy::StartShimForCommand(command, input,
76                                               result_handler);
77 }
78 
79 }  // namespace shill
80