File tree 2 files changed +6
-7
lines changed
main/java/org/readium/r2/streamer/parser/epub
test/java/org/readium/r2/streamer/parser/epub
2 files changed +6
-7
lines changed Original file line number Diff line number Diff line change @@ -27,9 +27,7 @@ internal class EpubDeobfuscator(
27
27
@Suppress(" Unused_parameter" )
28
28
fun transform (url : Url , resource : Resource ): Resource =
29
29
resource.flatMap {
30
- val algorithm = resource.sourceUrl
31
- ?.let { encryptionData[it] }
32
- ?.algorithm
30
+ val algorithm = encryptionData[url]?.algorithm
33
31
if (algorithm != null && algorithm2length.containsKey(algorithm)) {
34
32
DeobfuscatingResource (resource, algorithm)
35
33
} else {
@@ -71,9 +69,10 @@ internal class EpubDeobfuscator(
71
69
)
72
70
73
71
private fun deobfuscate (bytes : ByteArray , obfuscationKey : ByteArray , obfuscationLength : Int ) {
74
- val toDeobfuscate = 0 until obfuscationLength
75
- for (i in toDeobfuscate)
72
+ val toDeobfuscate = 0 until obfuscationLength.coerceAtMost(bytes.size)
73
+ for (i in toDeobfuscate) {
76
74
bytes[i] = bytes[i].xor(obfuscationKey[i % obfuscationKey.size])
75
+ }
77
76
}
78
77
79
78
private fun getHashKeyAdobe (pubId : String ) =
Original file line number Diff line number Diff line change @@ -45,8 +45,8 @@ class EpubDeobfuscatorTest {
45
45
46
46
private fun deobfuscate (url : Url , resource : Resource , algorithm : String? ): Resource {
47
47
val encryptionData =
48
- if (resource.sourceUrl != null && algorithm != null ) {
49
- mapOf (resource.sourceUrl as Url to Encryption (algorithm = algorithm))
48
+ if (algorithm != null ) {
49
+ mapOf (url to Encryption (algorithm = algorithm))
50
50
} else {
51
51
emptyMap()
52
52
}
You can’t perform that action at this time.
0 commit comments