1 /*
2  * Copyright (C) 2019 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 "Keymaster4_1HidlTest.h"
18 
19 namespace android::hardware::keymaster::V4_1::test {
20 
21 using std::string;
22 
SetUp()23 void Keymaster4_1HidlTest::SetUp() {
24     keymaster41_ = IKeymasterDevice::getService(GetParam());
25     InitializeKeymaster(keymaster41_);
26 }
27 
ProcessMessage(const HidlBuf & key_blob,KeyPurpose operation,const string & message,const AuthorizationSet & in_params)28 auto Keymaster4_1HidlTest::ProcessMessage(const HidlBuf& key_blob, KeyPurpose operation,
29                                           const string& message, const AuthorizationSet& in_params)
30         -> std::tuple<ErrorCode, string, AuthorizationSet /* out_params */> {
31     AuthorizationSet begin_out_params;
32     V4_0::ErrorCode result = Begin(operation, key_blob, in_params, &begin_out_params, &op_handle_);
33     AuthorizationSet out_params(std::move(begin_out_params));
34     if (result != V4_0::ErrorCode::OK) {
35         return {convert(result), {}, out_params};
36     }
37 
38     string output;
39     size_t consumed = 0;
40     AuthorizationSet update_params;
41     AuthorizationSet update_out_params;
42     result = Update(op_handle_, update_params, message, &update_out_params, &output, &consumed);
43     out_params.push_back(update_out_params);
44     if (result != V4_0::ErrorCode::OK) {
45         return {convert(result), output, out_params};
46     }
47 
48     string unused;
49     AuthorizationSet finish_params;
50     AuthorizationSet finish_out_params;
51     result = Finish(op_handle_, finish_params, message.substr(consumed), unused, &finish_out_params,
52                     &output);
53     op_handle_ = V4_0::test::kOpHandleSentinel;
54     out_params.push_back(finish_out_params);
55 
56     return {convert(result), output, out_params};
57 }
58 
59 }  // namespace android::hardware::keymaster::V4_1::test
60