Home | History | Annotate | Download | only in sign
      1 /*
      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 
     17 package com.android.tools.build.apkzlib.sign;
     18 
     19 import javax.annotation.Nonnull;
     20 
     21 /**
     22  * Message digest algorithms.
     23  */
     24 public enum DigestAlgorithm {
     25     /**
     26      * SHA-1 digest.
     27      * <p>
     28      * Android 2.3 (API Level 9) to 4.2 (API Level 17) (inclusive) do not support SHA-2
     29      * JAR signatures.
     30      * <p>
     31      * Moreover, platforms prior to API Level 18, without the additional
     32      * Digest-Algorithms attribute, only support SHA or SHA1 algorithm names in .SF and
     33      * MANIFEST.MF attributes.
     34      */
     35     SHA1("SHA1", "SHA-1"),
     36 
     37     /**
     38      * SHA-256 digest.
     39      */
     40     SHA256("SHA-256", "SHA-256");
     41 
     42     /**
     43      * API level which supports {@link #SHA256} with {@link SignatureAlgorithm#RSA} and
     44      * {@link SignatureAlgorithm#ECDSA}.
     45      */
     46     public static final int API_SHA_256_RSA_AND_ECDSA = 18;
     47 
     48     /**
     49      * API level which supports {@link #SHA256} for all {@link SignatureAlgorithm}s.
     50      *
     51      * <p>Before that, SHA256 can only be used with RSA and ECDSA.
     52      */
     53     public static final int API_SHA_256_ALL_ALGORITHMS = 21;
     54 
     55     /**
     56      * Name of algorithm for message digest.
     57      */
     58     @Nonnull
     59     public final String messageDigestName;
     60 
     61     /**
     62      * Name of attribute in signature file with the manifest digest.
     63      */
     64     @Nonnull
     65     public final String manifestAttributeName;
     66 
     67     /**
     68      * Name of attribute in entry (both manifest and signature file) with the entry's digest.
     69      */
     70     @Nonnull
     71     public final String entryAttributeName;
     72 
     73     /**
     74      * Creates a digest algorithm.
     75      *
     76      * @param attributeName attribute name in the signature file
     77      * @param messageDigestName name of algorithm for message digest
     78      */
     79     DigestAlgorithm(@Nonnull String attributeName, @Nonnull String messageDigestName) {
     80         this.messageDigestName = messageDigestName;
     81         this.entryAttributeName = attributeName + "-Digest";
     82         this.manifestAttributeName = attributeName + "-Digest-Manifest";
     83     }
     84 }
     85