1 /*
2  * Copyright (C) 2022 Huawei Device Co., Ltd.
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 
16 #include "attest_result_info.h"
17 
18 namespace OHOS {
19 namespace DevAttest {
Marshalling(Parcel &parcel) const20 bool AttestResultInfo::Marshalling(Parcel &parcel) const
21 {
22     if (!parcel.WriteInt32(authResult_) || !parcel.WriteInt32(softwareResult_)) {
23         return false;
24     }
25     if (!parcel.WriteInt32(softwareResultDetail_.size()) || !parcel.WriteInt32Vector(softwareResultDetail_)) {
26         return false;
27     }
28     if (!parcel.WriteInt32(ticketLength_) || !parcel.WriteString(ticket_)) {
29         return false;
30     }
31     return true;
32 }
33 
Unmarshalling(Parcel &parcel)34 sptr<AttestResultInfo> AttestResultInfo::Unmarshalling(Parcel &parcel)
35 {
36     sptr<AttestResultInfo> ptr = (std::make_unique<AttestResultInfo>()).release();
37     if (ptr == nullptr) {
38         return nullptr;
39     }
40     if (!parcel.ReadInt32(ptr->authResult_) || !parcel.ReadInt32(ptr->softwareResult_)) {
41         return nullptr;
42     }
43     int32_t setCount;
44     if (!parcel.ReadInt32(setCount) || setCount != SOFTWARE_RESULT_DETAIL_SIZE) {
45         return nullptr;
46     }
47 
48     ptr->softwareResultDetail_.resize(setCount);
49     parcel.ReadInt32Vector(&ptr->softwareResultDetail_);
50 
51     if (!parcel.ReadInt32(ptr->ticketLength_) || !parcel.ReadString(ptr->ticket_)) {
52         return nullptr;
53     }
54     return ptr;
55 }
56 }
57 }