1 // Copyright 2018 The Android Open Source Project 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #ifndef KEYSTORE_INCLUDE_KEYSTORE_RESPONSE_H_ 16 #define KEYSTORE_INCLUDE_KEYSTORE_RESPONSE_H_ 17 18 #include <binder/Parcel.h> 19 #include <binder/Parcelable.h> 20 #include <utils/String8.h> 21 22 #include "keystore_return_types.h" 23 24 namespace android { 25 namespace security { 26 namespace keystore { 27 28 // struct for holding response code and optionally an error message for keystore 29 // AIDL callbacks 30 struct KeystoreResponse : public ::android::Parcelable { 31 public: 32 KeystoreResponse() = default; KeystoreResponseKeystoreResponse33 explicit KeystoreResponse(const int response_code, const String16& error_msg) 34 : response_code_(response_code), error_msg_(std::make_unique<String16>(error_msg)) {} KeystoreResponseKeystoreResponse35 explicit KeystoreResponse(const int response_code) 36 : response_code_(response_code), error_msg_() {} 37 // NOLINTNEXTLINE(google-explicit-constructor) KeystoreResponseKeystoreResponse38 KeystoreResponse(const ::keystore::KeyStoreServiceReturnCode& rc) 39 : response_code_(rc.getErrorCode()), error_msg_() {} KeystoreResponseKeystoreResponse40 KeystoreResponse(const KeystoreResponse& other) 41 : response_code_(other.response_code_), error_msg_() { 42 if (other.error_msg_) { 43 error_msg_ = std::make_unique<String16>(*other.error_msg_); 44 } 45 } 46 KeystoreResponse(KeystoreResponse&& other) = default; 47 48 status_t readFromParcel(const Parcel* in) override; 49 status_t writeToParcel(Parcel* out) const override; 50 response_codeKeystoreResponse51 int response_code() const { return response_code_; } error_msgKeystoreResponse52 const String16* error_msg() const { return error_msg_.get(); } 53 54 private: 55 int response_code_; 56 std::unique_ptr<String16> error_msg_; 57 }; 58 59 } // namespace keystore 60 } // namespace security 61 } // namespace android 62 63 #endif // KEYSTORE_INCLUDE_KEYSTORE_RESPONSE_H_ 64