• 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 long timestamp;
31     public List<X509Certificate> certs = new ArrayList<>();
32     public List<X509Certificate> certificateLineage = new ArrayList<>();
33 
34     private final List<ApkVerificationIssue> mWarnings = new ArrayList<>();
35     private final List<ApkVerificationIssue> mErrors = new ArrayList<>();
36 
37     /**
38      * Adds a new {@link ApkVerificationIssue} as an error to this signer using the provided {@code
39      * issueId} and {@code params}.
40      */
addError(int issueId, Object... params)41     public void addError(int issueId, Object... params) {
42         mErrors.add(new ApkVerificationIssue(issueId, params));
43     }
44 
45     /**
46      * Adds a new {@link ApkVerificationIssue} as a warning to this signer using the provided {@code
47      * issueId} and {@code params}.
48      */
addWarning(int issueId, Object... params)49     public void addWarning(int issueId, Object... params) {
50         mWarnings.add(new ApkVerificationIssue(issueId, params));
51     }
52 
53     /**
54      * Returns {@code true} if any errors were encountered during verification for this signer.
55      */
containsErrors()56     public boolean containsErrors() {
57         return !mErrors.isEmpty();
58     }
59 
60     /**
61      * Returns {@code true} if any warnings were encountered during verification for this signer.
62      */
containsWarnings()63     public boolean containsWarnings() {
64         return !mWarnings.isEmpty();
65     }
66 
67     /**
68      * Returns the errors encountered during verification for this signer.
69      */
getErrors()70     public List<? extends ApkVerificationIssue> getErrors() {
71         return mErrors;
72     }
73 
74     /**
75      * Returns the warnings encountered during verification for this signer.
76      */
getWarnings()77     public List<? extends ApkVerificationIssue> getWarnings() {
78         return mWarnings;
79     }
80 }
81