clean code and fix signature to null

This commit is contained in:
callebtc
2025-07-20 22:33:19 +02:00
parent 9ba7dc5181
commit 554b687ad8
3 changed files with 5 additions and 68 deletions
@@ -286,66 +286,3 @@ class EncryptionService(private val context: Context) {
Log.d(TAG, "🔌 EncryptionService shut down")
}
}
/**
* Message padding utilities - exact same as iOS version
*/
object MessagePadding {
// Standard block sizes for padding
private val blockSizes = listOf(256, 512, 1024, 2048)
/**
* Add PKCS#7-style padding to reach target size
*/
fun pad(data: ByteArray, targetSize: Int): ByteArray {
if (data.size >= targetSize) return data
val paddingNeeded = targetSize - data.size
// PKCS#7 only supports padding up to 255 bytes
if (paddingNeeded > 255) return data
val padded = ByteArray(targetSize)
System.arraycopy(data, 0, padded, 0, data.size)
// Fill with random bytes except the last byte
val random = SecureRandom()
random.nextBytes(padded.sliceArray(data.size until targetSize - 1))
// Last byte indicates padding length (PKCS#7)
padded[targetSize - 1] = paddingNeeded.toByte()
return padded
}
/**
* Remove padding from data
*/
fun unpad(data: ByteArray): ByteArray {
if (data.isEmpty()) return data
// Last byte tells us how much padding to remove
val paddingLength = (data.last().toInt() and 0xFF)
if (paddingLength <= 0 || paddingLength > data.size) return data
return data.sliceArray(0 until (data.size - paddingLength))
}
/**
* Find optimal block size for data
*/
fun optimalBlockSize(dataSize: Int): Int {
// Account for encryption overhead (~16 bytes for AES-GCM tag)
val totalSize = dataSize + 16
// Find smallest block that fits
for (blockSize in blockSizes) {
if (totalSize <= blockSize) {
return blockSize
}
}
// For very large messages, just use the original size
return dataSize
}
}