blob: 00a1a1c06e79b737ebd793b4e3d751e4fff1945c [file] [log] [blame]
Shawn Willden8d8c7472016-02-02 08:27:39 -07001/*
2 * Copyright (C) 2016 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
17package android.security.keymaster;
18
19import android.os.Parcel;
20import android.os.Parcelable;
21
22import java.util.ArrayList;
23import java.util.List;
24
25/**
26 * Utility class for the Java side of keystore-generated certificate chains.
27 *
28 * Serialization code for this must be kept in sync with system/security/keystore
29 * @hide
30 */
31public class KeymasterCertificateChain implements Parcelable {
32
33 private List<byte[]> mCertificates;
34
35 public static final Parcelable.Creator<KeymasterCertificateChain> CREATOR = new
36 Parcelable.Creator<KeymasterCertificateChain>() {
37 public KeymasterCertificateChain createFromParcel(Parcel in) {
38 return new KeymasterCertificateChain(in);
39 }
40 public KeymasterCertificateChain[] newArray(int size) {
41 return new KeymasterCertificateChain[size];
42 }
43 };
44
45 public KeymasterCertificateChain() {
46 mCertificates = null;
47 }
48
49 public KeymasterCertificateChain(List<byte[]> mCertificates) {
50 this.mCertificates = mCertificates;
51 }
52
53 private KeymasterCertificateChain(Parcel in) {
54 readFromParcel(in);
55 }
56
Janis Danisevskisb0358e72018-11-02 10:34:07 -070057 /**
58 * Makes a shallow copy of other by copying the reference to the certificate chain list.
59 * @param other
60 */
61 public void shallowCopyFrom(KeymasterCertificateChain other) {
62 this.mCertificates = other.mCertificates;
63 }
64
Shawn Willden8d8c7472016-02-02 08:27:39 -070065 public List<byte[]> getCertificates() {
66 return mCertificates;
67 }
68
69 @Override
70 public void writeToParcel(Parcel out, int flags) {
71 if (mCertificates == null) {
72 out.writeInt(0);
73 } else {
74 out.writeInt(mCertificates.size());
75 for (byte[] arg : mCertificates) {
76 out.writeByteArray(arg);
77 }
78 }
79 }
80
81 public void readFromParcel(Parcel in) {
82 int length = in.readInt();
83 mCertificates = new ArrayList<byte[]>(length);
84 for (int i = 0; i < length; i++) {
85 mCertificates.add(in.createByteArray());
86 }
87 }
88
89 @Override
90 public int describeContents() {
91 return 0;
92 }
93}