mirror of
https://github.com/vector-im/element-android.git
synced 2024-11-16 02:05:06 +08:00
Fix issue with long transactionId
This commit is contained in:
parent
932c478ed5
commit
382fc6f05c
@ -218,6 +218,22 @@ class QrCodeTest : InstrumentedTest {
|
||||
compareArray(byteArray.copyOfRange(23 + 64, byteArray.size), sharedSecretByteArray)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testLongTransactionId() {
|
||||
// Size on two bytes (2_000 = 0x07D0)
|
||||
val longTransactionId = "PatternId_".repeat(200)
|
||||
|
||||
val qrCode = qrCode1.copy(transactionId = longTransactionId)
|
||||
|
||||
val result = qrCode.toEncodedString()
|
||||
val expected = value1.replace("\u0000\u000DMaTransaction", "\u0007\u00D0$longTransactionId")
|
||||
|
||||
result shouldEqual expected
|
||||
|
||||
// Reverse operation
|
||||
expected.toQrCodeData() shouldEqual qrCode
|
||||
}
|
||||
|
||||
// Error cases
|
||||
@Test
|
||||
fun testErrorHeader() {
|
||||
|
@ -94,7 +94,10 @@ fun String.toQrCodeData(): QrCodeData? {
|
||||
cursor++
|
||||
|
||||
// Get transaction length
|
||||
val transactionLength = (byteArray[cursor].toInt() shr 8) + byteArray[cursor + 1].toInt()
|
||||
val bigEndian1 = ensurePositive(byteArray[cursor])
|
||||
val bigEndian2 = ensurePositive(byteArray[cursor + 1])
|
||||
|
||||
val transactionLength = bigEndian1 * 0x0100 + bigEndian2
|
||||
|
||||
cursor++
|
||||
cursor++
|
||||
@ -121,3 +124,11 @@ fun String.toQrCodeData(): QrCodeData? {
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
|
||||
fun ensurePositive(byte: Byte): Int {
|
||||
return if (byte < 0) {
|
||||
256 + byte
|
||||
} else {
|
||||
byte.toInt()
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user