diff options
| author | Kenny Root <kroot@google.com> | 2013-04-02 14:04:24 -0700 |
|---|---|---|
| committer | Kenny Root <kroot@google.com> | 2013-04-02 14:22:03 -0700 |
| commit | 6c918cec31f396bb19597d107856122173c90594 (patch) | |
| tree | c834a08e601e9e872054f0de625305711cd530c7 /core/tests | |
| parent | 006c633896e6738297e7bc96128c56b03fbf8d01 (diff) | |
| download | frameworks_base-6c918cec31f396bb19597d107856122173c90594.zip frameworks_base-6c918cec31f396bb19597d107856122173c90594.tar.gz frameworks_base-6c918cec31f396bb19597d107856122173c90594.tar.bz2 | |
Add direct API to get ManifestDigest
This makes it faster for applications that don't want to collect all the
certificates but do want the AndroidManifest.xml digest.
Bug: 8528639
Change-Id: Ide9498d0981188960af194a9568387337c075bcc
Diffstat (limited to 'core/tests')
| -rw-r--r-- | core/tests/coretests/src/android/content/pm/ManifestDigestTest.java | 67 |
1 files changed, 27 insertions, 40 deletions
diff --git a/core/tests/coretests/src/android/content/pm/ManifestDigestTest.java b/core/tests/coretests/src/android/content/pm/ManifestDigestTest.java index cc8c4a6..37495e1 100644 --- a/core/tests/coretests/src/android/content/pm/ManifestDigestTest.java +++ b/core/tests/coretests/src/android/content/pm/ManifestDigestTest.java @@ -18,64 +18,51 @@ package android.content.pm; import android.os.Parcel; import android.test.AndroidTestCase; -import android.util.Base64; -import java.util.jar.Attributes; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.security.MessageDigest; public class ManifestDigestTest extends AndroidTestCase { - private static final byte[] DIGEST_1 = { + private static final byte[] MESSAGE_1 = { (byte) 0x00, (byte) 0xAA, (byte) 0x55, (byte) 0xFF }; - private static final String DIGEST_1_STR = Base64.encodeToString(DIGEST_1, Base64.DEFAULT); - - private static final byte[] DIGEST_2 = { - (byte) 0x0A, (byte) 0xA5, (byte) 0xF0, (byte) 0x5A - }; - - private static final String DIGEST_2_STR = Base64.encodeToString(DIGEST_2, Base64.DEFAULT); - - private static final Attributes.Name SHA1_DIGEST = new Attributes.Name("SHA1-Digest"); - - private static final Attributes.Name MD5_DIGEST = new Attributes.Name("MD5-Digest"); - - public void testManifestDigest_FromAttributes_Null() { + public void testManifestDigest_FromInputStream_Null() { assertNull("Attributes were null, so ManifestDigest.fromAttributes should return null", - ManifestDigest.fromAttributes(null)); + ManifestDigest.fromInputStream(null)); } - public void testManifestDigest_FromAttributes_NoAttributes() { - Attributes a = new Attributes(); + public void testManifestDigest_FromInputStream_ThrowsIoException() { + InputStream is = new InputStream() { + @Override + public int read() throws IOException { + throw new IOException(); + } + }; - assertNull("There were no attributes to extract, so ManifestDigest should be null", - ManifestDigest.fromAttributes(a)); + assertNull("InputStream threw exception, so ManifestDigest should be null", + ManifestDigest.fromInputStream(is)); } - public void testManifestDigest_FromAttributes_SHA1PreferredOverMD5() { - Attributes a = new Attributes(); - a.put(SHA1_DIGEST, DIGEST_1_STR); - - a.put(MD5_DIGEST, DIGEST_2_STR); - - ManifestDigest fromAttributes = ManifestDigest.fromAttributes(a); - - assertNotNull("A valid ManifestDigest should be returned", fromAttributes); + public void testManifestDigest_Equals() throws Exception { + InputStream is = new ByteArrayInputStream(MESSAGE_1); - ManifestDigest created = new ManifestDigest(DIGEST_1); + ManifestDigest expected = + new ManifestDigest(MessageDigest.getInstance("SHA-256").digest(MESSAGE_1)); - assertEquals("SHA-1 should be preferred over MD5: " + created.toString() + " vs. " - + fromAttributes.toString(), created, fromAttributes); + ManifestDigest actual = ManifestDigest.fromInputStream(is); + assertEquals(expected, actual); - assertEquals("Hash codes should be the same: " + created.toString() + " vs. " - + fromAttributes.toString(), created.hashCode(), fromAttributes - .hashCode()); + ManifestDigest unexpected = new ManifestDigest(new byte[0]); + assertFalse(unexpected.equals(actual)); } - public void testManifestDigest_Parcel() { - Attributes a = new Attributes(); - a.put(SHA1_DIGEST, DIGEST_1_STR); + public void testManifestDigest_Parcel() throws Exception { + InputStream is = new ByteArrayInputStream(MESSAGE_1); - ManifestDigest digest = ManifestDigest.fromAttributes(a); + ManifestDigest digest = ManifestDigest.fromInputStream(is); Parcel p = Parcel.obtain(); digest.writeToParcel(p, 0); |
