blob: c278eb3b85fdce1a7b530c2b312d5c8be503ac73 [file] [log] [blame]
Alex Klyubin8effa362015-06-24 16:06:55 -07001/*
2 * Copyright (C) 2015 The Android Open Source Project
Chad Brubaker45ff13e2015-01-21 14:00:55 -08003 *
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 *
Alex Klyubin8effa362015-06-24 16:06:55 -07008 * http://www.apache.org/licenses/LICENSE-2.0
Chad Brubaker45ff13e2015-01-21 14:00:55 -08009 *
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
17package android.security.keymaster;
18
Mathew Inwood4dbdcf42018-08-16 18:49:37 +010019import android.annotation.UnsupportedAppUsage;
Chad Brubaker45ff13e2015-01-21 14:00:55 -080020import android.os.IBinder;
21import android.os.Parcel;
22import android.os.Parcelable;
23
Chad Brubaker45ff13e2015-01-21 14:00:55 -080024/**
25 * Class for handling the parceling of return values from keymaster crypto operations
26 * (begin/update/finish).
27 * @hide
28 */
29public class OperationResult implements Parcelable {
30 public final int resultCode;
31 public final IBinder token;
Chad Brubaker4cd8e502015-03-17 18:23:10 -070032 public final long operationHandle;
Chad Brubaker45ff13e2015-01-21 14:00:55 -080033 public final int inputConsumed;
34 public final byte[] output;
Chad Brubaker966486e2015-06-01 12:57:06 -070035 public final KeymasterArguments outParams;
Chad Brubaker45ff13e2015-01-21 14:00:55 -080036
Mathew Inwood4dbdcf42018-08-16 18:49:37 +010037 @UnsupportedAppUsage
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -070038 public static final @android.annotation.NonNull Parcelable.Creator<OperationResult> CREATOR = new
Chad Brubaker45ff13e2015-01-21 14:00:55 -080039 Parcelable.Creator<OperationResult>() {
Alex Klyubin00af27b2015-06-01 16:07:53 -070040 @Override
Chad Brubaker45ff13e2015-01-21 14:00:55 -080041 public OperationResult createFromParcel(Parcel in) {
42 return new OperationResult(in);
43 }
44
Alex Klyubin00af27b2015-06-01 16:07:53 -070045 @Override
Chad Brubaker45ff13e2015-01-21 14:00:55 -080046 public OperationResult[] newArray(int length) {
47 return new OperationResult[length];
48 }
49 };
50
Alex Klyubin00af27b2015-06-01 16:07:53 -070051 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
Janis Danisevskisb0358e72018-11-02 10:34:07 -070062 public OperationResult(int resultCode) {
63 this(resultCode, null, 0, 0, null, null);
64 }
65
Chad Brubaker45ff13e2015-01-21 14:00:55 -080066 protected OperationResult(Parcel in) {
67 resultCode = in.readInt();
68 token = in.readStrongBinder();
Chad Brubaker4cd8e502015-03-17 18:23:10 -070069 operationHandle = in.readLong();
Chad Brubaker45ff13e2015-01-21 14:00:55 -080070 inputConsumed = in.readInt();
71 output = in.createByteArray();
Chad Brubaker966486e2015-06-01 12:57:06 -070072 outParams = KeymasterArguments.CREATOR.createFromParcel(in);
Chad Brubaker45ff13e2015-01-21 14:00:55 -080073 }
74
75 @Override
76 public int describeContents() {
77 return 0;
78 }
79
80 @Override
81 public void writeToParcel(Parcel out, int flags) {
82 out.writeInt(resultCode);
83 out.writeStrongBinder(token);
Chad Brubaker4cd8e502015-03-17 18:23:10 -070084 out.writeLong(operationHandle);
Chad Brubaker45ff13e2015-01-21 14:00:55 -080085 out.writeInt(inputConsumed);
86 out.writeByteArray(output);
Chad Brubaker966486e2015-06-01 12:57:06 -070087 outParams.writeToParcel(out, flags);
Chad Brubaker45ff13e2015-01-21 14:00:55 -080088 }
89}