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.apksig.internal.apk;
18 
19 /**
20  * APK Signature Scheme v2 content digest algorithm.
21  */
22 public enum ContentDigestAlgorithm {
23     /** SHA2-256 over 1 MB chunks. */
24     CHUNKED_SHA256("SHA-256", 256 / 8),
25 
26     /** SHA2-512 over 1 MB chunks. */
27     CHUNKED_SHA512("SHA-512", 512 / 8),
28 
29     /** SHA2-256 over 4 KB chunks for APK verity. */
30     VERITY_CHUNKED_SHA256("SHA-256", 256 / 8);
31 
32     private final String mJcaMessageDigestAlgorithm;
33     private final int mChunkDigestOutputSizeBytes;
34 
ContentDigestAlgorithm( String jcaMessageDigestAlgorithm, int chunkDigestOutputSizeBytes)35     private ContentDigestAlgorithm(
36             String jcaMessageDigestAlgorithm, int chunkDigestOutputSizeBytes) {
37         mJcaMessageDigestAlgorithm = jcaMessageDigestAlgorithm;
38         mChunkDigestOutputSizeBytes = chunkDigestOutputSizeBytes;
39     }
40 
41     /**
42      * Returns the {@link java.security.MessageDigest} algorithm used for computing digests of
43      * chunks by this content digest algorithm.
44      */
getJcaMessageDigestAlgorithm()45     String getJcaMessageDigestAlgorithm() {
46         return mJcaMessageDigestAlgorithm;
47     }
48 
49     /**
50      * Returns the size (in bytes) of the digest of a chunk of content.
51      */
getChunkDigestOutputSizeBytes()52     int getChunkDigestOutputSizeBytes() {
53         return mChunkDigestOutputSizeBytes;
54     }
55 }