• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 #include "eth_eap_profile.h"
16 
17 namespace OHOS {
18 namespace NetManagerStandard {
19 
Marshalling(Parcel & parcel) const20 bool EthEapProfile::Marshalling(Parcel &parcel) const
21 {
22     if (!parcel.WriteInt32(static_cast<int32_t>(eapMethod)) ||
23         !parcel.WriteInt32(static_cast<int32_t>(phase2Method))) {
24         return false;
25     }
26     if (!parcel.WriteString(identity) || !parcel.WriteString(anonymousIdentity) ||
27         !parcel.WriteString(password) || !parcel.WriteString(caCertAliases) ||
28         !parcel.WriteString(caPath) || !parcel.WriteString(clientCertAliases) ||
29         !parcel.WriteString(certPassword) || !parcel.WriteString(altSubjectMatch) ||
30         !parcel.WriteString(domainSuffixMatch) || !parcel.WriteString(realm) ||
31         !parcel.WriteString(plmn)) {
32         return false;
33     }
34     if (!parcel.WriteInt32(eapSubId)) {
35         return false;
36     }
37     if (!parcel.WriteInt32(certEntry.size())) {
38         return false;
39     }
40     for (const auto entry : certEntry) {
41         if (!parcel.WriteUint8(entry)) {
42             return false;
43         }
44     }
45     return true;
46 }
47 
Unmarshalling(Parcel & parcel)48 EthEapProfile* EthEapProfile::Unmarshalling(Parcel &parcel)
49 {
50     std::unique_ptr<EthEapProfile> ptr = std::make_unique<EthEapProfile>();
51     int32_t eapMeth;
52     int32_t phase2Meth;
53     if (!parcel.ReadInt32(eapMeth) || !parcel.ReadInt32(phase2Meth)) {
54         return nullptr;
55     }
56     ptr->eapMethod = static_cast<EapMethod>(eapMeth);
57     ptr->phase2Method = static_cast<Phase2Method>(phase2Meth);
58     if (!parcel.ReadString(ptr->identity) || !parcel.ReadString(ptr->anonymousIdentity) ||
59         !parcel.ReadString(ptr->password) || !parcel.ReadString(ptr->caCertAliases) ||
60         !parcel.ReadString(ptr->caPath) || !parcel.ReadString(ptr->clientCertAliases) ||
61         !parcel.ReadString(ptr->certPassword) || !parcel.ReadString(ptr->altSubjectMatch) ||
62         !parcel.ReadString(ptr->domainSuffixMatch) || !parcel.ReadString(ptr->realm) ||
63         !parcel.ReadString(ptr->plmn)) {
64         return nullptr;
65     }
66     if (!parcel.ReadInt32(ptr->eapSubId)) {
67         return nullptr;
68     }
69     int32_t size = 0;
70     if (!parcel.ReadInt32(size)) {
71         return nullptr;
72     }
73     uint8_t entry;
74     for (int32_t i = 0; i < size; i++) {
75         if (!parcel.ReadUint8(entry)) {
76             return nullptr;
77         }
78         ptr->certEntry.emplace_back(entry);
79     }
80     return ptr.release();
81 }
82 
83 } // namespace NetManagerStandard
84 } // namespace OHOS