• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 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 com.android.apksig.internal.apk;
18 
19 import com.android.apksig.ApkVerificationIssue;
20 
21 import java.security.cert.X509Certificate;
22 import java.util.ArrayList;
23 import java.util.List;
24 
25 /**
26  * Base implementation of an APK signer.
27  */
28 public class ApkSignerInfo {
29     public int index;
30     public List<X509Certificate> certs = new ArrayList<>();
31     public List<X509Certificate> certificateLineage = new ArrayList<>();
32 
33     private final List<ApkVerificationIssue> mWarnings = new ArrayList<>();
34     private final List<ApkVerificationIssue> mErrors = new ArrayList<>();
35 
36     /**
37      * Adds a new {@link ApkVerificationIssue} as an error to this signer using the provided {@code
38      * issueId} and {@code params}.
39      */
addError(int issueId, Object... params)40     public void addError(int issueId, Object... params) {
41         mErrors.add(new ApkVerificationIssue(issueId, params));
42     }
43 
44     /**
45      * Adds a new {@link ApkVerificationIssue} as a warning to this signer using the provided {@code
46      * issueId} and {@code params}.
47      */
addWarning(int issueId, Object... params)48     public void addWarning(int issueId, Object... params) {
49         mWarnings.add(new ApkVerificationIssue(issueId, params));
50     }
51 
52     /**
53      * Returns {@code true} if any errors were encountered during verification for this signer.
54      */
containsErrors()55     public boolean containsErrors() {
56         return !mErrors.isEmpty();
57     }
58 
59     /**
60      * Returns {@code true} if any warnings were encountered during verification for this signer.
61      */
containsWarnings()62     public boolean containsWarnings() {
63         return !mWarnings.isEmpty();
64     }
65 
66     /**
67      * Returns the errors encountered during verification for this signer.
68      */
getErrors()69     public List<? extends ApkVerificationIssue> getErrors() {
70         return mErrors;
71     }
72 
73     /**
74      * Returns the warnings encountered during verification for this signer.
75      */
getWarnings()76     public List<? extends ApkVerificationIssue> getWarnings() {
77         return mWarnings;
78     }
79 }
80