blob: 3ff8bc336154e4d3909350b9137fa131fa16de55 [file] [log] [blame]
Dmitry Dementyeva447b3c2017-10-27 23:09:53 -07001/*
2**
3** Copyright 2017, The Android Open Source Project
4**
5** Licensed under the Apache License, Version 2.0 (the "License");
6** you may not use this file except in compliance with the License.
7** You may obtain a copy of the License at
8**
9** http://www.apache.org/licenses/LICENSE-2.0
10**
11** Unless required by applicable law or agreed to in writing, software
12** distributed under the License is distributed on an "AS IS" BASIS,
13** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14** See the License for the specific language governing permissions and
15** limitations under the License.
16*/
17
18#include "include/keystore/OperationResult.h"
19
Dmitry Dementyeva447b3c2017-10-27 23:09:53 -070020#include <utility>
21
Shawn Willdenbb22a6c2017-12-06 19:35:28 -070022#include <binder/Parcel.h>
23
24#include <keystore/keymaster_types.h>
25
Dmitry Dementyeva447b3c2017-10-27 23:09:53 -070026#include "keystore_aidl_hidl_marshalling_utils.h"
Dmitry Dementyeva447b3c2017-10-27 23:09:53 -070027
28namespace android {
29namespace security {
30namespace keymaster {
31
Shawn Willden0329a822017-12-04 13:55:14 -070032using keystore::keymaster::ErrorCode;
Dmitry Dementyeva447b3c2017-10-27 23:09:53 -070033using ::android::status_t;
34
35OperationResult::OperationResult() : resultCode(), token(), handle(0), inputConsumed(0), data() {}
36
37status_t OperationResult::readFromParcel(const Parcel* inn) {
38 const Parcel& in = *inn;
39 resultCode = ErrorCode(in.readInt32());
40 token = in.readStrongBinder();
41 handle = static_cast<uint64_t>(in.readInt64());
42 inputConsumed = in.readInt32();
43 data = keystore::readKeymasterBlob(in);
44 outParams = keystore::readParamSetFromParcel(in);
45 return OK;
46}
47
48status_t OperationResult::writeToParcel(Parcel* out) const {
Branden Archer70080742018-11-20 11:04:11 -080049 out->writeInt32(resultCode.getErrorCode());
Dmitry Dementyeva447b3c2017-10-27 23:09:53 -070050 out->writeStrongBinder(token);
51 out->writeInt64(handle);
52 out->writeInt32(inputConsumed);
53 keystore::writeKeymasterBlob(data, out);
54 keystore::writeParamSetToParcel(outParams, out);
55 return OK;
56}
57
Janis Danisevskisff3d7f42018-10-08 07:15:09 -070058OperationResult operationFailed(const ::keystore::KeyStoreServiceReturnCode& error) {
59 OperationResult opResult = {};
60 opResult.resultCode = error;
61 return opResult;
62}
63
Dmitry Dementyeva447b3c2017-10-27 23:09:53 -070064} // namespace keymaster
65} // namespace security
66} // namespace android