1/* 2 * Copyright (c) 2023 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 16import rpc from '@ohos.rpc'; 17import { HiLog } from './HiLog'; 18 19const TAG = 'dlpClass'; 20const ARRAY_LENGTH_MAX = 100; 21const ARRAY_LENGTH_MIN = 0; 22 23export class IAuthUser extends rpc.MessageSequence { 24 public authAccount: string; 25 public authAccountType: number; 26 public dlpFileAccess: number; 27 public permExpiryTime: number; 28 29 constructor( 30 authAccount: string, 31 authAccountType: number, 32 dlpFileAccess: number, 33 permExpiryTime: number 34 ) { 35 super(); 36 this.authAccount = authAccount; 37 this.authAccountType = authAccountType; 38 this.dlpFileAccess = dlpFileAccess; 39 this.permExpiryTime = permExpiryTime; 40 } 41 42 marshalling(dataOut: rpc.MessageSequence): boolean { 43 try { 44 dataOut.writeString(this.authAccount); 45 dataOut.writeInt(this.authAccountType); 46 dataOut.writeInt(this.dlpFileAccess); 47 dataOut.writeLong(this.permExpiryTime); 48 } catch (error) { 49 HiLog.error(TAG, `marshalling exception, error is ${JSON.stringify(error)}`); 50 return false; 51 } 52 return true; 53 } 54 55 unmarshalling(dataIn: rpc.MessageSequence): boolean { 56 try { 57 this.authAccount = dataIn.readString(); 58 this.authAccountType = dataIn.readInt(); 59 this.dlpFileAccess = dataIn.readInt(); 60 this.permExpiryTime = dataIn.readLong(); 61 } catch (error) { 62 HiLog.error(TAG, `unmarshalling exception, error is ${JSON.stringify(error)}`); 63 return false; 64 } 65 return true; 66 } 67} 68 69export default class IDLDLPProperty extends rpc.MessageSequence { 70 public ownerAccount: string; 71 public ownerAccountID: string; 72 public ownerAccountType: number; 73 public authUserList: IAuthUser[]; 74 public contactAccount: string; 75 public offlineAccess: boolean; 76 public everyoneAccessList: number[]; 77 public expireTime: number; 78 79 constructor( 80 ownerAccount: string, 81 ownerAccountID: string, 82 ownerAccountType: number, 83 authUserList: IAuthUser[], 84 contactAccount: string, 85 offlineAccess: boolean, 86 everyoneAccessList: number[], 87 expireTime: number 88 ) { 89 super(); 90 this.ownerAccount = ownerAccount; 91 this.ownerAccountID = ownerAccountID; 92 this.ownerAccountType = ownerAccountType; 93 this.authUserList = authUserList; 94 this.contactAccount = contactAccount; 95 this.offlineAccess = offlineAccess; 96 this.everyoneAccessList = everyoneAccessList; 97 this.expireTime = expireTime; 98 } 99 100 marshalling(dataOut: rpc.MessageSequence): boolean { 101 try { 102 dataOut.writeString(this.ownerAccount); 103 dataOut.writeString(this.ownerAccountID); 104 dataOut.writeInt(this.ownerAccountType); 105 dataOut.writeInt(this.authUserList.length); 106 dataOut.writeParcelableArray(this.authUserList); 107 dataOut.writeString(this.contactAccount); 108 dataOut.writeBoolean(this.offlineAccess); 109 dataOut.writeIntArray(this.everyoneAccessList); 110 dataOut.writeLong(this.expireTime); 111 } catch (error) { 112 HiLog.error(TAG, `marshalling exception, error is ${JSON.stringify(error)}`); 113 return false; 114 } 115 return true; 116 } 117 118 unmarshalling(dataIn: rpc.MessageSequence): boolean { 119 try { 120 this.ownerAccount = dataIn.readString(); 121 this.ownerAccountID = dataIn.readString(); 122 this.ownerAccountType = dataIn.readInt(); 123 let arrayLength:number = dataIn.readInt(); 124 if (arrayLength < ARRAY_LENGTH_MIN || arrayLength > ARRAY_LENGTH_MAX) { 125 return false; 126 } 127 for (let i = 0; i < arrayLength; i++) { 128 this.authUserList.push(new IAuthUser('', 0, 0, 0)); 129 } 130 dataIn.readParcelableArray(this.authUserList); 131 this.contactAccount = dataIn.readString(); 132 this.offlineAccess = dataIn.readBoolean(); 133 this.everyoneAccessList = dataIn.readIntArray(); 134 this.expireTime = dataIn.readLong(); 135 } catch (error) { 136 HiLog.error(TAG, `unmarshalling exception, error is ${JSON.stringify(error)}`); 137 return false; 138 } 139 return true; 140 } 141}