Skip to content

Commit bbc6505

Browse files
committed
fix: repair imports and log detailed backup steps
1 parent c2dc88b commit bbc6505

File tree

3 files changed

+123
-59
lines changed

3 files changed

+123
-59
lines changed

app/src/main/kotlin/de/cyb3rko/pincredible/data/PinTable.kt

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@
1616

1717
package de.cyb3rko.pincredible.data
1818

19-
import android.util.Log
2019
import de.cyb3rko.backpack.crypto.CryptoManager
2120
import de.cyb3rko.backpack.data.Serializable
2221
import de.cyb3rko.backpack.utils.ObjectSerializer
22+
import de.cyb3rko.backpack.utils.logD
23+
import de.cyb3rko.backpack.utils.logW
2324
import java.io.ByteArrayInputStream
2425
import java.io.ByteArrayOutputStream
2526

@@ -75,17 +76,25 @@ internal class PinTable : Serializable() {
7576

7677
@Suppress("UNCHECKED_CAST")
7778
override suspend fun loadFromBytes(bytes: ByteArray): Serializable? {
79+
logD(TAG, "Found ${bytes.size} bytes for $CLASS_NAME($SIZE)")
80+
if (bytes.size != SIZE) {
81+
// New PINs should have the correct size, but legacy PINs can have one additional byte
82+
logW(TAG, "Unexpected $CLASS_NAME($SIZE) size: ${bytes.size}")
83+
}
7884
ByteArrayInputStream(bytes).use {
7985
val version = it.read()
80-
Log.d("PINcredible", "Found PinTable v$version")
86+
logD(TAG, "Found $CLASS_NAME v$version")
8187
if (version > getVersion()) {
82-
Log.d("PINcredible", "PinTable version not supported")
88+
logD(TAG, "$CLASS_NAME version not supported")
8389
return null
8490
}
91+
logD(TAG, "Size of $CLASS_NAME-version: ${Byte.SIZE_BYTES} bytes")
8592
val buffer = ByteArray(307)
8693
it.read(buffer)
94+
logD(TAG, "Size of $CLASS_NAME-data: ${buffer.size} bytes")
8795
data = ObjectSerializer.deserialize(buffer) as Array<IntArray>
8896
it.read(buffer)
97+
logD(TAG, "Size of $CLASS_NAME-pattern: ${buffer.size} bytes")
8998
pattern = ObjectSerializer.deserialize(buffer) as Array<IntArray>
9099
}
91100
return this
@@ -94,20 +103,27 @@ internal class PinTable : Serializable() {
94103
override suspend fun toBytes(): ByteArray {
95104
val stream = ByteArrayOutputStream()
96105
stream.use {
97-
it.write(byteArrayOf(getVersion()))
106+
val version = byteArrayOf(getVersion())
107+
logD(TAG, "Size of $CLASS_NAME-version: ${version.size} bytes")
108+
it.write(version)
98109
var byteArray = ObjectSerializer.serialize(data)
99-
Log.d("PINcredible", "Size of PinTable-data: ${byteArray.size}")
110+
logD(TAG, "Size of $CLASS_NAME-data: ${byteArray.size} bytes")
100111
it.write(byteArray)
101112
byteArray = ObjectSerializer.serialize(pattern)
102-
Log.d("PINcredible", "Size of PinTable-pattern: ${byteArray.size}")
113+
logD(TAG, "Size of $CLASS_NAME-pattern: ${byteArray.size} bytes")
103114
it.write(byteArray)
104115
}
105-
return stream.toByteArray()
116+
val output = stream.toByteArray()
117+
logD(TAG, "Size of $CLASS_NAME($SIZE): ${output.size} bytes")
118+
return output
106119
}
107120

108121
override suspend fun getVersion(): Byte = 0
109122

110123
companion object {
124+
private const val CLASS_NAME = "PinTable"
125+
private const val TAG = "PINcredible-PT"
126+
111127
const val ROW_COUNT = 7
112128
const val COLUMN_COUNT = 7
113129
const val SIZE = 615

0 commit comments

Comments
 (0)