1/*
2 * Copyright (C) 2011 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.content.pm;
18
19import android.os.Parcel;
20import android.os.Parcelable;
21
22import java.security.PublicKey;
23
24/**
25 * Contains information about a package verifier as used by
26 * {@code PackageManagerService} during package verification.
27 *
28 * @hide
29 */
30public class VerifierInfo implements Parcelable {
31    /** Package name of the verifier. */
32    public final String packageName;
33
34    /** Signatures used to sign the package verifier's package. */
35    public final PublicKey publicKey;
36
37    /**
38     * Creates an object that represents a verifier info object.
39     *
40     * @param packageName the package name in Java-style. Must not be {@code
41     *            null} or empty.
42     * @param publicKey the public key for the signer encoded in Base64. Must
43     *            not be {@code null} or empty.
44     * @throws IllegalArgumentException if either argument is null or empty.
45     */
46    public VerifierInfo(String packageName, PublicKey publicKey) {
47        if (packageName == null || packageName.length() == 0) {
48            throw new IllegalArgumentException("packageName must not be null or empty");
49        } else if (publicKey == null) {
50            throw new IllegalArgumentException("publicKey must not be null");
51        }
52
53        this.packageName = packageName;
54        this.publicKey = publicKey;
55    }
56
57    private VerifierInfo(Parcel source) {
58        packageName = source.readString();
59        publicKey = (PublicKey) source.readSerializable();
60    }
61
62    @Override
63    public int describeContents() {
64        return 0;
65    }
66
67    @Override
68    public void writeToParcel(Parcel dest, int flags) {
69        dest.writeString(packageName);
70        dest.writeSerializable(publicKey);
71    }
72
73    public static final Parcelable.Creator<VerifierInfo> CREATOR
74            = new Parcelable.Creator<VerifierInfo>() {
75        public VerifierInfo createFromParcel(Parcel source) {
76            return new VerifierInfo(source);
77        }
78
79        public VerifierInfo[] newArray(int size) {
80            return new VerifierInfo[size];
81        }
82    };
83}