From d83d36015e06b891438384f297a7e7c7b5ecc8fa Mon Sep 17 00:00:00 2001 From: Luna712 <142361265+Luna712@users.noreply.github.com> Date: Fri, 10 Jul 2026 14:48:41 -0600 Subject: [PATCH 1/3] M3u8Helper: make getDecrypted() suspend --- .../kotlin/com/lagradost/cloudstream3/utils/M3u8Helper.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/library/src/commonMain/kotlin/com/lagradost/cloudstream3/utils/M3u8Helper.kt b/library/src/commonMain/kotlin/com/lagradost/cloudstream3/utils/M3u8Helper.kt index d34f5f500e9..da99504ddf8 100644 --- a/library/src/commonMain/kotlin/com/lagradost/cloudstream3/utils/M3u8Helper.kt +++ b/library/src/commonMain/kotlin/com/lagradost/cloudstream3/utils/M3u8Helper.kt @@ -100,15 +100,15 @@ object M3u8Helper2 { } @OptIn(DelicateCryptographyApi::class) - fun getDecrypted( + suspend fun getDecrypted( secretKey: ByteArray, data: ByteArray, iv: ByteArray = byteArrayOf(), index: Int, ): ByteArray { val ivKey = if (iv.isEmpty()) defaultIv(index) else iv - val aesKey = aesCbc.keyDecoder().decodeFromByteArrayBlocking(AES.Key.Format.RAW, secretKey) - return aesKey.cipher(padding = true).decryptWithIvBlocking(ivKey, data) + val aesKey = aesCbc.keyDecoder().decodeFromByteArray(AES.Key.Format.RAW, secretKey) + return aesKey.cipher(padding = true).decryptWithIv(ivKey, data) } private fun getParentLink(url: String): String { From 52b6eeb0fae31caf0f8f7f20724af408b92a49f4 Mon Sep 17 00:00:00 2001 From: Luna712 <142361265+Luna712@users.noreply.github.com> Date: Sat, 11 Jul 2026 14:38:03 -0600 Subject: [PATCH 2/3] Use getDecryptedBytes for the new version --- .../cloudstream3/utils/M3u8Helper.kt | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/library/src/commonMain/kotlin/com/lagradost/cloudstream3/utils/M3u8Helper.kt b/library/src/commonMain/kotlin/com/lagradost/cloudstream3/utils/M3u8Helper.kt index da99504ddf8..181f3effb64 100644 --- a/library/src/commonMain/kotlin/com/lagradost/cloudstream3/utils/M3u8Helper.kt +++ b/library/src/commonMain/kotlin/com/lagradost/cloudstream3/utils/M3u8Helper.kt @@ -2,6 +2,7 @@ package com.lagradost.cloudstream3.utils import com.lagradost.api.Log import com.lagradost.cloudstream3.ErrorLoadingException +import com.lagradost.cloudstream3.Prerelease import com.lagradost.cloudstream3.app import dev.whyoleg.cryptography.CryptographyProvider import dev.whyoleg.cryptography.DelicateCryptographyApi @@ -25,7 +26,6 @@ class M3u8Helper { } } - data class M3u8Stream( val streamUrl: String, val quality: Int? = null, @@ -100,7 +100,8 @@ object M3u8Helper2 { } @OptIn(DelicateCryptographyApi::class) - suspend fun getDecrypted( + @Prerelease + suspend fun getDecryptedBytes( secretKey: ByteArray, data: ByteArray, iv: ByteArray = byteArrayOf(), @@ -111,6 +112,24 @@ object M3u8Helper2 { return aesKey.cipher(padding = true).decryptWithIv(ivKey, data) } + // Deprecate after next stable + /* @Deprecated( + message = "Renamed to getDecryptedBytes", + replaceWith = ReplaceWith("getDecryptedBytes(secretKey, data, iv, index)"), + level = DeprecationLevel.WARNING, + ) */ + @OptIn(DelicateCryptographyApi::class) + fun getDecrypted( + secretKey: ByteArray, + data: ByteArray, + iv: ByteArray = byteArrayOf(), + index: Int, + ): ByteArray { + val ivKey = if (iv.isEmpty()) defaultIv(index) else iv + val aesKey = aesCbc.keyDecoder().decodeFromByteArrayBlocking(AES.Key.Format.RAW, secretKey) + return aesKey.cipher(padding = true).decryptWithIvBlocking(ivKey, data) + } + private fun getParentLink(url: String): String { val split = url.split("/").toMutableList() split.removeAt(split.lastIndex) @@ -239,7 +258,7 @@ object M3u8Helper2 { if (tsData.size < 128 && tsData.all { it >= 0 }) throw ErrorLoadingException("ASCII found instead of data") return if (isEncrypted) { - getDecrypted(encryptionData, tsData, encryptionIv, index) + getDecryptedBytes(encryptionData, tsData, encryptionIv, index) } else { tsData } From 226f7c84d2450d1a487b5e4b284212402b698130 Mon Sep 17 00:00:00 2001 From: Luna712 <142361265+Luna712@users.noreply.github.com> Date: Sat, 11 Jul 2026 15:17:32 -0600 Subject: [PATCH 3/3] Add commented wrapper --- .../kotlin/com/lagradost/cloudstream3/utils/M3u8Helper.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/library/src/commonMain/kotlin/com/lagradost/cloudstream3/utils/M3u8Helper.kt b/library/src/commonMain/kotlin/com/lagradost/cloudstream3/utils/M3u8Helper.kt index 181f3effb64..2711e17fd98 100644 --- a/library/src/commonMain/kotlin/com/lagradost/cloudstream3/utils/M3u8Helper.kt +++ b/library/src/commonMain/kotlin/com/lagradost/cloudstream3/utils/M3u8Helper.kt @@ -125,6 +125,8 @@ object M3u8Helper2 { iv: ByteArray = byteArrayOf(), index: Int, ): ByteArray { + // After next stable, we can just make this a wrapper + // return runBlocking { getDecryptedBytes(secretKey, data, iv, index) } val ivKey = if (iv.isEmpty()) defaultIv(index) else iv val aesKey = aesCbc.keyDecoder().decodeFromByteArrayBlocking(AES.Key.Format.RAW, secretKey) return aesKey.cipher(padding = true).decryptWithIvBlocking(ivKey, data)