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