Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
SDK
/
exoplayer
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
0dc25671
authored
Oct 13, 2021
by
olly
Committed by
Oliver Woodman
Oct 13, 2021
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Remove one method class in crypto package
PiperOrigin-RevId: 402787577
parent
02719fd5
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
32 additions
and
47 deletions
library/core/src/main/java/com/google/android/exoplayer2/upstream/crypto/AesCipherDataSink.java
library/core/src/main/java/com/google/android/exoplayer2/upstream/crypto/AesCipherDataSource.java
library/core/src/main/java/com/google/android/exoplayer2/upstream/crypto/AesFlushingCipher.java
library/core/src/main/java/com/google/android/exoplayer2/upstream/crypto/CryptoUtil.java
library/core/src/main/java/com/google/android/exoplayer2/upstream/crypto/AesCipherDataSink.java
View file @
0dc25671
...
...
@@ -66,10 +66,12 @@ public final class AesCipherDataSink implements DataSink {
@Override
public
void
open
(
DataSpec
dataSpec
)
throws
IOException
{
wrappedDataSink
.
open
(
dataSpec
);
long
nonce
=
CryptoUtil
.
getFNV64Hash
(
dataSpec
.
key
);
cipher
=
new
AesFlushingCipher
(
Cipher
.
ENCRYPT_MODE
,
secretKey
,
nonce
,
dataSpec
.
uriPositionOffset
+
dataSpec
.
position
);
Cipher
.
ENCRYPT_MODE
,
secretKey
,
dataSpec
.
key
,
dataSpec
.
uriPositionOffset
+
dataSpec
.
position
);
}
@Override
...
...
library/core/src/main/java/com/google/android/exoplayer2/upstream/crypto/AesCipherDataSource.java
View file @
0dc25671
...
...
@@ -51,10 +51,12 @@ public final class AesCipherDataSource implements DataSource {
@Override
public
long
open
(
DataSpec
dataSpec
)
throws
IOException
{
long
dataLength
=
upstream
.
open
(
dataSpec
);
long
nonce
=
CryptoUtil
.
getFNV64Hash
(
dataSpec
.
key
);
cipher
=
new
AesFlushingCipher
(
Cipher
.
DECRYPT_MODE
,
secretKey
,
nonce
,
dataSpec
.
uriPositionOffset
+
dataSpec
.
position
);
Cipher
.
DECRYPT_MODE
,
secretKey
,
dataSpec
.
key
,
dataSpec
.
uriPositionOffset
+
dataSpec
.
position
);
return
dataLength
;
}
...
...
library/core/src/main/java/com/google/android/exoplayer2/upstream/crypto/AesFlushingCipher.java
View file @
0dc25671
...
...
@@ -15,6 +15,7 @@
*/
package
com
.
google
.
android
.
exoplayer2
.
upstream
.
crypto
;
import
androidx.annotation.Nullable
;
import
com.google.android.exoplayer2.util.Assertions
;
import
com.google.android.exoplayer2.util.Util
;
import
java.nio.ByteBuffer
;
...
...
@@ -42,6 +43,10 @@ public final class AesFlushingCipher {
private
int
pendingXorBytes
;
public
AesFlushingCipher
(
int
mode
,
byte
[]
secretKey
,
@Nullable
String
nonce
,
long
offset
)
{
this
(
mode
,
secretKey
,
getFNV64Hash
(
nonce
),
offset
);
}
public
AesFlushingCipher
(
int
mode
,
byte
[]
secretKey
,
long
nonce
,
long
offset
)
{
try
{
cipher
=
Cipher
.
getInstance
(
"AES/CTR/NoPadding"
);
...
...
@@ -121,4 +126,23 @@ public final class AesFlushingCipher {
private
byte
[]
getInitializationVector
(
long
nonce
,
long
counter
)
{
return
ByteBuffer
.
allocate
(
16
).
putLong
(
nonce
).
putLong
(
counter
).
array
();
}
/**
* Returns the hash value of the input as a long using the 64 bit FNV-1a hash function. The hash
* values produced by this function are less likely to collide than those produced by {@link
* #hashCode()}.
*/
private
static
long
getFNV64Hash
(
@Nullable
String
input
)
{
if
(
input
==
null
)
{
return
0
;
}
long
hash
=
0
;
for
(
int
i
=
0
;
i
<
input
.
length
();
i
++)
{
hash
^=
input
.
charAt
(
i
);
// This is equivalent to hash *= 0x100000001b3 (the FNV magic prime number).
hash
+=
(
hash
<<
1
)
+
(
hash
<<
4
)
+
(
hash
<<
5
)
+
(
hash
<<
7
)
+
(
hash
<<
8
)
+
(
hash
<<
40
);
}
return
hash
;
}
}
library/core/src/main/java/com/google/android/exoplayer2/upstream/crypto/CryptoUtil.java
deleted
100644 → 0
View file @
02719fd5
/*
* Copyright (C) 2016 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
com
.
google
.
android
.
exoplayer2
.
upstream
.
crypto
;
import
androidx.annotation.Nullable
;
/** Utility functions for the crypto package. */
/* package */
final
class
CryptoUtil
{
private
CryptoUtil
()
{}
/**
* Returns the hash value of the input as a long using the 64 bit FNV-1a hash function. The hash
* values produced by this function are less likely to collide than those produced by {@link
* #hashCode()}.
*/
public
static
long
getFNV64Hash
(
@Nullable
String
input
)
{
if
(
input
==
null
)
{
return
0
;
}
long
hash
=
0
;
for
(
int
i
=
0
;
i
<
input
.
length
();
i
++)
{
hash
^=
input
.
charAt
(
i
);
// This is equivalent to hash *= 0x100000001b3 (the FNV magic prime number).
hash
+=
(
hash
<<
1
)
+
(
hash
<<
4
)
+
(
hash
<<
5
)
+
(
hash
<<
7
)
+
(
hash
<<
8
)
+
(
hash
<<
40
);
}
return
hash
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment