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..2711e17fd98 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, @@ -99,6 +99,25 @@ object M3u8Helper2 { return toBytes16Big(index + 1) } + @OptIn(DelicateCryptographyApi::class) + @Prerelease + suspend fun getDecryptedBytes( + secretKey: ByteArray, + data: ByteArray, + iv: ByteArray = byteArrayOf(), + index: Int, + ): ByteArray { + val ivKey = if (iv.isEmpty()) defaultIv(index) else iv + val aesKey = aesCbc.keyDecoder().decodeFromByteArray(AES.Key.Format.RAW, secretKey) + 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, @@ -106,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) @@ -239,7 +260,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 }