Skip to content

Commit 3e17b3a

Browse files
authored
Make some private cryptography methods suspend (#3040)
1 parent 8c3dbdc commit 3e17b3a

3 files changed

Lines changed: 15 additions & 15 deletions

File tree

library/src/commonMain/kotlin/com/lagradost/cloudstream3/extractors/ByseSX.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,15 @@ open class ByseSX : ExtractorApi() {
8686
}
8787

8888
@OptIn(DelicateCryptographyApi::class)
89-
private fun decryptPlayback(playback: Playback): String? {
89+
private suspend fun decryptPlayback(playback: Playback): String? {
9090
val keyBytes = buildAesKey(playback)
9191
val ivBytes = b64UrlDecode(playback.iv)
9292
val cipherBytes = b64UrlDecode(playback.payload)
9393

94-
val aesKey = aesGcm.keyDecoder().decodeFromByteArrayBlocking(AES.Key.Format.RAW, keyBytes)
94+
val aesKey = aesGcm.keyDecoder().decodeFromByteArray(AES.Key.Format.RAW, keyBytes)
9595
// 128-bit GCM tag (default)
9696
val cipher = aesKey.cipher()
97-
val plainBytes = cipher.decryptWithIvBlocking(ivBytes, cipherBytes)
97+
val plainBytes = cipher.decryptWithIv(ivBytes, cipherBytes)
9898

9999
var jsonStr = plainBytes.decodeToString()
100100
if (jsonStr.startsWith("\uFEFF")) jsonStr = jsonStr.substring(1)

library/src/commonMain/kotlin/com/lagradost/cloudstream3/extractors/Rabbitstream.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,12 @@ open class Rabbitstream : ExtractorApi() {
133133
return extractedKey to sources
134134
}
135135

136-
private inline fun <reified T> decryptMapped(input: String, key: String): T? {
136+
private inline suspend fun <reified T> decryptMapped(input: String, key: String): T? {
137137
val decrypt = decrypt(input, key)
138138
return AppUtils.tryParseJson(decrypt)
139139
}
140140

141-
private fun decrypt(input: String, key: String): String {
141+
private suspend fun decrypt(input: String, key: String): String {
142142
return decryptSourceUrl(
143143
generateKey(
144144
salt = base64DecodeArray(input).copyOfRange(8, 16),
@@ -147,7 +147,7 @@ open class Rabbitstream : ExtractorApi() {
147147
)
148148
}
149149

150-
private fun generateKey(salt: ByteArray, secret: ByteArray): ByteArray {
150+
private suspend fun generateKey(salt: ByteArray, secret: ByteArray): ByteArray {
151151
var key = md5(secret + salt)
152152
var currentKey = key
153153
while (currentKey.size < 48) {
@@ -157,18 +157,18 @@ open class Rabbitstream : ExtractorApi() {
157157
return currentKey
158158
}
159159

160-
private fun md5(input: ByteArray): ByteArray =
161-
md5Hasher.hashBlocking(input)
160+
private suspend fun md5(input: ByteArray): ByteArray =
161+
md5Hasher.hash(input)
162162

163163
@OptIn(DelicateCryptographyApi::class)
164-
private fun decryptSourceUrl(decryptionKey: ByteArray, sourceUrl: String): String {
164+
private suspend fun decryptSourceUrl(decryptionKey: ByteArray, sourceUrl: String): String {
165165
val cipherData = base64DecodeArray(sourceUrl)
166166
val encrypted = cipherData.copyOfRange(16, cipherData.size)
167167
val keyBytes = decryptionKey.copyOfRange(0, 32)
168168
val ivBytes = decryptionKey.copyOfRange(32, decryptionKey.size)
169169

170-
val aesKey = aesCbc.keyDecoder().decodeFromByteArrayBlocking(AES.Key.Format.RAW, keyBytes)
171-
val decryptedData = aesKey.cipher(padding = true).decryptWithIvBlocking(ivBytes, encrypted)
170+
val aesKey = aesCbc.keyDecoder().decodeFromByteArray(AES.Key.Format.RAW, keyBytes)
171+
val decryptedData = aesKey.cipher(padding = true).decryptWithIv(ivBytes, encrypted)
172172
return decryptedData.decodeToString()
173173
}
174174

library/src/commonMain/kotlin/com/lagradost/cloudstream3/extractors/helper/GogoHelper.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,22 +39,22 @@ object GogoHelper {
3939
// https://github.com/saikou-app/saikou/blob/45d0a99b8a72665a29a1eadfb38c506b842a29d7/app/src/main/java/ani/saikou/parsers/anime/extractors/GogoCDN.kt#L97
4040
// No Licence on the function
4141
@OptIn(DelicateCryptographyApi::class)
42-
private fun cryptoHandler(
42+
private suspend fun cryptoHandler(
4343
string: String,
4444
iv: String,
4545
secretKeyString: String,
4646
encrypt: Boolean = true,
4747
): String {
4848
val ivBytes = iv.encodeToByteArray()
4949
val keyBytes = secretKeyString.encodeToByteArray()
50-
val aesKey = aesCbc.keyDecoder().decodeFromByteArrayBlocking(AES.Key.Format.RAW, keyBytes)
50+
val aesKey = aesCbc.keyDecoder().decodeFromByteArray(AES.Key.Format.RAW, keyBytes)
5151
val cipher = aesKey.cipher(padding = true)
5252

5353
return if (!encrypt) {
54-
val plainBytes = cipher.decryptWithIvBlocking(ivBytes, base64DecodeArray(string))
54+
val plainBytes = cipher.decryptWithIv(ivBytes, base64DecodeArray(string))
5555
plainBytes.decodeToString()
5656
} else {
57-
base64Encode(cipher.encryptWithIvBlocking(ivBytes, string.encodeToByteArray()))
57+
base64Encode(cipher.encryptWithIv(ivBytes, string.encodeToByteArray()))
5858
}
5959
}
6060

0 commit comments

Comments
 (0)