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