Alex Klyubin | 8effa36 | 2015-06-24 16:06:55 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 The Android Open Source Project |
Chad Brubaker | 45ff13e | 2015-01-21 14:00:55 -0800 | [diff] [blame] | 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 | * |
Alex Klyubin | 8effa36 | 2015-06-24 16:06:55 -0700 | [diff] [blame] | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
Chad Brubaker | 45ff13e | 2015-01-21 14:00:55 -0800 | [diff] [blame] | 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 | |
Mathew Inwood | 4dbdcf4 | 2018-08-16 18:49:37 +0100 | [diff] [blame] | 19 | import android.annotation.UnsupportedAppUsage; |
Chad Brubaker | 45ff13e | 2015-01-21 14:00:55 -0800 | [diff] [blame] | 20 | import android.os.IBinder; |
| 21 | import android.os.Parcel; |
| 22 | import android.os.Parcelable; |
| 23 | |
Chad Brubaker | 45ff13e | 2015-01-21 14:00:55 -0800 | [diff] [blame] | 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; |
Chad Brubaker | 4cd8e50 | 2015-03-17 18:23:10 -0700 | [diff] [blame] | 32 | public final long operationHandle; |
Chad Brubaker | 45ff13e | 2015-01-21 14:00:55 -0800 | [diff] [blame] | 33 | public final int inputConsumed; |
| 34 | public final byte[] output; |
Chad Brubaker | 966486e | 2015-06-01 12:57:06 -0700 | [diff] [blame] | 35 | public final KeymasterArguments outParams; |
Chad Brubaker | 45ff13e | 2015-01-21 14:00:55 -0800 | [diff] [blame] | 36 | |
Mathew Inwood | 4dbdcf4 | 2018-08-16 18:49:37 +0100 | [diff] [blame] | 37 | @UnsupportedAppUsage |
Chad Brubaker | 45ff13e | 2015-01-21 14:00:55 -0800 | [diff] [blame] | 38 | public static final Parcelable.Creator<OperationResult> CREATOR = new |
| 39 | Parcelable.Creator<OperationResult>() { |
Alex Klyubin | 00af27b | 2015-06-01 16:07:53 -0700 | [diff] [blame] | 40 | @Override |
Chad Brubaker | 45ff13e | 2015-01-21 14:00:55 -0800 | [diff] [blame] | 41 | public OperationResult createFromParcel(Parcel in) { |
| 42 | return new OperationResult(in); |
| 43 | } |
| 44 | |
Alex Klyubin | 00af27b | 2015-06-01 16:07:53 -0700 | [diff] [blame] | 45 | @Override |
Chad Brubaker | 45ff13e | 2015-01-21 14:00:55 -0800 | [diff] [blame] | 46 | public OperationResult[] newArray(int length) { |
| 47 | return new OperationResult[length]; |
| 48 | } |
| 49 | }; |
| 50 | |
Alex Klyubin | 00af27b | 2015-06-01 16:07:53 -0700 | [diff] [blame] | 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 | |
Janis Danisevskis | b0358e7 | 2018-11-02 10:34:07 -0700 | [diff] [blame] | 62 | public OperationResult(int resultCode) { |
| 63 | this(resultCode, null, 0, 0, null, null); |
| 64 | } |
| 65 | |
Chad Brubaker | 45ff13e | 2015-01-21 14:00:55 -0800 | [diff] [blame] | 66 | protected OperationResult(Parcel in) { |
| 67 | resultCode = in.readInt(); |
| 68 | token = in.readStrongBinder(); |
Chad Brubaker | 4cd8e50 | 2015-03-17 18:23:10 -0700 | [diff] [blame] | 69 | operationHandle = in.readLong(); |
Chad Brubaker | 45ff13e | 2015-01-21 14:00:55 -0800 | [diff] [blame] | 70 | inputConsumed = in.readInt(); |
| 71 | output = in.createByteArray(); |
Chad Brubaker | 966486e | 2015-06-01 12:57:06 -0700 | [diff] [blame] | 72 | outParams = KeymasterArguments.CREATOR.createFromParcel(in); |
Chad Brubaker | 45ff13e | 2015-01-21 14:00:55 -0800 | [diff] [blame] | 73 | } |
| 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 Brubaker | 4cd8e50 | 2015-03-17 18:23:10 -0700 | [diff] [blame] | 84 | out.writeLong(operationHandle); |
Chad Brubaker | 45ff13e | 2015-01-21 14:00:55 -0800 | [diff] [blame] | 85 | out.writeInt(inputConsumed); |
| 86 | out.writeByteArray(output); |
Chad Brubaker | 966486e | 2015-06-01 12:57:06 -0700 | [diff] [blame] | 87 | outParams.writeToParcel(out, flags); |
Chad Brubaker | 45ff13e | 2015-01-21 14:00:55 -0800 | [diff] [blame] | 88 | } |
| 89 | } |