OperationResult.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. #include "include/keystore/OperationResult.h"
  18. #include <utility>
  19. #include <binder/Parcel.h>
  20. #include <keystore/keymaster_types.h>
  21. #include "keystore_aidl_hidl_marshalling_utils.h"
  22. namespace android {
  23. namespace security {
  24. namespace keymaster {
  25. using keystore::keymaster::ErrorCode;
  26. using ::android::status_t;
  27. OperationResult::OperationResult() : resultCode(), token(), handle(0), inputConsumed(0), data() {}
  28. status_t OperationResult::readFromParcel(const Parcel* inn) {
  29. const Parcel& in = *inn;
  30. resultCode = ErrorCode(in.readInt32());
  31. token = in.readStrongBinder();
  32. handle = static_cast<uint64_t>(in.readInt64());
  33. inputConsumed = in.readInt32();
  34. data = keystore::readKeymasterBlob(in);
  35. outParams = keystore::readParamSetFromParcel(in);
  36. return OK;
  37. }
  38. status_t OperationResult::writeToParcel(Parcel* out) const {
  39. out->writeInt32(resultCode.getErrorCode());
  40. out->writeStrongBinder(token);
  41. out->writeInt64(handle);
  42. out->writeInt32(inputConsumed);
  43. keystore::writeKeymasterBlob(data, out);
  44. keystore::writeParamSetToParcel(outParams, out);
  45. return OK;
  46. }
  47. OperationResult operationFailed(const ::keystore::KeyStoreServiceReturnCode& error) {
  48. OperationResult opResult = {};
  49. opResult.resultCode = error;
  50. return opResult;
  51. }
  52. } // namespace keymaster
  53. } // namespace security
  54. } // namespace android