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.keymaster;
18 
19 import android.compat.annotation.UnsupportedAppUsage;
20 import android.os.IBinder;
21 import android.os.Parcel;
22 import android.os.Parcelable;
23 
24 /**
25  * Class for handling the parceling of return values from keymaster crypto operations
26  * (begin/update/finish).
27  * @hide
28  */
29 public class OperationResult implements Parcelable {
30     public final int resultCode;
31     public final IBinder token;
32     public final long operationHandle;
33     public final int inputConsumed;
34     public final byte[] output;
35     public final KeymasterArguments outParams;
36 
37     @UnsupportedAppUsage
38     public static final @android.annotation.NonNull Parcelable.Creator<OperationResult> CREATOR = new
39             Parcelable.Creator<OperationResult>() {
40                 @Override
41                 public OperationResult createFromParcel(Parcel in) {
42                     return new OperationResult(in);
43                 }
44 
45                 @Override
46                 public OperationResult[] newArray(int length) {
47                     return new OperationResult[length];
48                 }
49             };
50 
OperationResult( int resultCode, IBinder token, long operationHandle, int inputConsumed, byte[] output, KeymasterArguments outParams)51     public OperationResult(
52             int resultCode, IBinder token, long operationHandle, int inputConsumed, byte[] output,
53             KeymasterArguments outParams) {
54         this.resultCode = resultCode;
55         this.token = token;
56         this.operationHandle = operationHandle;
57         this.inputConsumed = inputConsumed;
58         this.output = output;
59         this.outParams = outParams;
60     }
61 
OperationResult(int resultCode)62     public OperationResult(int resultCode) {
63         this(resultCode, null, 0, 0, null, null);
64     }
65 
OperationResult(Parcel in)66     protected OperationResult(Parcel in) {
67         resultCode = in.readInt();
68         token = in.readStrongBinder();
69         operationHandle = in.readLong();
70         inputConsumed = in.readInt();
71         output = in.createByteArray();
72         outParams = KeymasterArguments.CREATOR.createFromParcel(in);
73     }
74 
75     @Override
describeContents()76     public int describeContents() {
77         return 0;
78     }
79 
80     @Override
writeToParcel(Parcel out, int flags)81     public void writeToParcel(Parcel out, int flags) {
82         out.writeInt(resultCode);
83         out.writeStrongBinder(token);
84         out.writeLong(operationHandle);
85         out.writeInt(inputConsumed);
86         out.writeByteArray(output);
87         outParams.writeToParcel(out, flags);
88     }
89 }
90