1 /**
2  * Copyright (c) 2015, The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package android.security;
18 
19 import android.compat.annotation.UnsupportedAppUsage;
20 import android.os.Build;
21 import android.os.Parcel;
22 import android.os.Parcelable;
23 
24 /**
25  * Class for handling the additional arguments to some keystore binder calls.
26  * This must be kept in sync with the deserialization code in system/security/keystore.
27  * @hide
28  */
29 public class KeystoreArguments implements Parcelable {
30     public byte[][] args;
31 
32     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
33     public static final @android.annotation.NonNull Parcelable.Creator<KeystoreArguments> CREATOR = new
34             Parcelable.Creator<KeystoreArguments>() {
35                 public KeystoreArguments createFromParcel(Parcel in) {
36                     return new KeystoreArguments(in);
37                 }
38                 public KeystoreArguments[] newArray(int size) {
39                     return new KeystoreArguments[size];
40                 }
41             };
42 
KeystoreArguments()43     public KeystoreArguments() {
44         args = null;
45     }
46 
47     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
KeystoreArguments(byte[][] args)48     public KeystoreArguments(byte[][] args) {
49         this.args = args;
50     }
51 
KeystoreArguments(Parcel in)52     private KeystoreArguments(Parcel in) {
53         readFromParcel(in);
54     }
55 
56     @Override
writeToParcel(Parcel out, int flags)57     public void writeToParcel(Parcel out, int flags) {
58         if (args == null) {
59             out.writeInt(0);
60         } else {
61             out.writeInt(args.length);
62             for (byte[] arg : args) {
63                 out.writeByteArray(arg);
64             }
65         }
66     }
67 
readFromParcel(Parcel in)68     private void readFromParcel(Parcel in) {
69         int length = in.readInt();
70         args = new byte[length][];
71         for (int i = 0; i < length; i++) {
72             args[i] = in.createByteArray();
73         }
74     }
75 
76     @Override
describeContents()77     public int describeContents() {
78         return 0;
79     }
80 }
81