From 38efb1fc3f37a71ffa7a8fd7c6b3a2e1aafc19e9 Mon Sep 17 00:00:00 2001 From: Oliver Woodman Date: Fri, 10 Apr 2015 23:12:47 +0100 Subject: [PATCH] Clean up Aes128DataSource. --- .../android/exoplayer/hls/HlsChunkSource.java | 2 +- .../exoplayer/upstream/Aes128DataSource.java | 20 +++++++++++-------- .../upstream/UnexpectedLengthException.java | 1 + 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/library/src/main/java/com/google/android/exoplayer/hls/HlsChunkSource.java b/library/src/main/java/com/google/android/exoplayer/hls/HlsChunkSource.java index f1be4678b3..2e81dd0b2b 100644 --- a/library/src/main/java/com/google/android/exoplayer/hls/HlsChunkSource.java +++ b/library/src/main/java/com/google/android/exoplayer/hls/HlsChunkSource.java @@ -474,7 +474,7 @@ public class HlsChunkSource { System.arraycopy(ivData, offset, ivDataWithPadding, ivDataWithPadding.length - ivData.length + offset, ivData.length - offset); - encryptedDataSource = new Aes128DataSource(secretKey, ivDataWithPadding, upstreamDataSource); + encryptedDataSource = new Aes128DataSource(upstreamDataSource, secretKey, ivDataWithPadding); encryptionKeyUri = keyUri; encryptedDataSourceIv = iv; encryptedDataSourceSecretKey = secretKey; diff --git a/library/src/main/java/com/google/android/exoplayer/upstream/Aes128DataSource.java b/library/src/main/java/com/google/android/exoplayer/upstream/Aes128DataSource.java index 938dd70ef1..2115e5b0bc 100644 --- a/library/src/main/java/com/google/android/exoplayer/upstream/Aes128DataSource.java +++ b/library/src/main/java/com/google/android/exoplayer/upstream/Aes128DataSource.java @@ -34,20 +34,24 @@ import javax.crypto.spec.SecretKeySpec; /** * A {@link DataSource} that decrypts the data read from an upstream source, encrypted with AES-128 * with a 128-bit key and PKCS7 padding. - * */ public class Aes128DataSource implements DataSource { private final DataSource upstream; - private final byte[] secretKey; - private final byte[] iv; + private final byte[] encryptionKey; + private final byte[] encryptionIv; private CipherInputStream cipherInputStream; - public Aes128DataSource(byte[] secretKey, byte[] iv, DataSource upstream) { + /** + * @param upstream The upstream {@link DataSource}. + * @param encryptionKey The encryption key. + * @param encryptionIv The encryption initialization vector. + */ + public Aes128DataSource(DataSource upstream, byte[] encryptionKey, byte[] encryptionIv) { this.upstream = upstream; - this.secretKey = secretKey; - this.iv = iv; + this.encryptionKey = encryptionKey; + this.encryptionIv = encryptionIv; } @Override @@ -61,8 +65,8 @@ public class Aes128DataSource implements DataSource { throw new RuntimeException(e); } - Key cipherKey = new SecretKeySpec(secretKey, "AES"); - AlgorithmParameterSpec cipherIV = new IvParameterSpec(iv); + Key cipherKey = new SecretKeySpec(encryptionKey, "AES"); + AlgorithmParameterSpec cipherIV = new IvParameterSpec(encryptionIv); try { cipher.init(Cipher.DECRYPT_MODE, cipherKey, cipherIV); diff --git a/library/src/main/java/com/google/android/exoplayer/upstream/UnexpectedLengthException.java b/library/src/main/java/com/google/android/exoplayer/upstream/UnexpectedLengthException.java index c7bc6c303d..6c91601485 100644 --- a/library/src/main/java/com/google/android/exoplayer/upstream/UnexpectedLengthException.java +++ b/library/src/main/java/com/google/android/exoplayer/upstream/UnexpectedLengthException.java @@ -20,6 +20,7 @@ import java.io.IOException; /** * Thrown when the length of some data does not match an expected length. */ +@Deprecated public final class UnexpectedLengthException extends IOException { /**