1 /*
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 
20 #include <utility>
21 
22 #include <binder/Parcel.h>
23 
24 #include <keystore/keymaster_types.h>
25 
26 #include "keystore_aidl_hidl_marshalling_utils.h"
27 
28 namespace android {
29 namespace security {
30 namespace keymaster {
31 
32 using ::android::status_t;
33 using ::keystore::ErrorCode;
34 
OperationResult()35 OperationResult::OperationResult() : resultCode(), token(), handle(0), inputConsumed(0), data() {}
36 
readFromParcel(const Parcel * inn)37 status_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 
writeToParcel(Parcel * out) const48 status_t OperationResult::writeToParcel(Parcel* out) const {
49     out->writeInt32(resultCode.getErrorCode());
50     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 
operationFailed(const::keystore::KeyStoreServiceReturnCode & error)58 OperationResult operationFailed(const ::keystore::KeyStoreServiceReturnCode& error) {
59     OperationResult opResult = {};
60     opResult.resultCode = error;
61     return opResult;
62 }
63 
64 }  // namespace keymaster
65 }  // namespace security
66 }  // namespace android
67