Dmitry Dementyev | a447b3c | 2017-10-27 23:09:53 -0700 | [diff] [blame] | 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 | |
Dmitry Dementyev | a447b3c | 2017-10-27 23:09:53 -0700 | [diff] [blame] | 20 | #include <utility> |
| 21 | |
Shawn Willden | bb22a6c | 2017-12-06 19:35:28 -0700 | [diff] [blame] | 22 | #include <binder/Parcel.h> |
| 23 | |
| 24 | #include <keystore/keymaster_types.h> |
| 25 | |
Dmitry Dementyev | a447b3c | 2017-10-27 23:09:53 -0700 | [diff] [blame] | 26 | #include "keystore_aidl_hidl_marshalling_utils.h" |
Dmitry Dementyev | a447b3c | 2017-10-27 23:09:53 -0700 | [diff] [blame] | 27 | |
| 28 | namespace android { |
| 29 | namespace security { |
| 30 | namespace keymaster { |
| 31 | |
Shawn Willden | 0329a82 | 2017-12-04 13:55:14 -0700 | [diff] [blame] | 32 | using keystore::keymaster::ErrorCode; |
Dmitry Dementyev | a447b3c | 2017-10-27 23:09:53 -0700 | [diff] [blame] | 33 | using ::android::status_t; |
| 34 | |
| 35 | OperationResult::OperationResult() : resultCode(), token(), handle(0), inputConsumed(0), data() {} |
| 36 | |
| 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 | |
| 48 | status_t OperationResult::writeToParcel(Parcel* out) const { |
Branden Archer | 7008074 | 2018-11-20 11:04:11 -0800 | [diff] [blame] | 49 | out->writeInt32(resultCode.getErrorCode()); |
Dmitry Dementyev | a447b3c | 2017-10-27 23:09:53 -0700 | [diff] [blame] | 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 | |
Janis Danisevskis | ff3d7f4 | 2018-10-08 07:15:09 -0700 | [diff] [blame] | 58 | OperationResult operationFailed(const ::keystore::KeyStoreServiceReturnCode& error) { |
| 59 | OperationResult opResult = {}; |
| 60 | opResult.resultCode = error; |
| 61 | return opResult; |
| 62 | } |
| 63 | |
Dmitry Dementyev | a447b3c | 2017-10-27 23:09:53 -0700 | [diff] [blame] | 64 | } // namespace keymaster |
| 65 | } // namespace security |
| 66 | } // namespace android |