309a3ecfa246
refactor: Dedupe hex-string parser used by both vault shapes (v2.9.5)
- time
- 2026-07-30 14:13 UTC · 2 months ago
- machine
- koh2
- parent
- 942f3c20cdcf
↓ peach-android-309a3ecf.tar.gzatlas at this save
files changed4 files
VERSION+1 −1app/build.gradle+1 −1app/src/main/java/com/peachpasswords/vault/BrowserSlot.kt+13 −12app/src/main/java/com/peachpasswords/vault/VaultRepository.kt+0 −9app/build.gradle+1 −1
@@ -32,7 +32,7 @@3232 minSdk 263333 targetSdk 353434 // Keep the Android code in Gradle; the semantic name comes from root VERSION.35- versionCode 24015035+ versionCode 2401513636 versionName semanticVersion3737 3838 testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"app/src/main/java/com/peachpasswords/vault/BrowserSlot.kt+13 −12
@@ -181,21 +181,22 @@181181 }182182 }183183 184- private fun unhex(s: String): ByteArray {185- require(s.length % 2 == 0) { "odd-length hex" }186- return ByteArray(s.length / 2) { i ->187- ((hexDigit(s[i * 2]) shl 4) or hexDigit(s[i * 2 + 1])).toByte()188- }189- }184+ private fun b64(b: ByteArray): String = Base64.getEncoder().encodeToString(b)185+}190186 191- private fun hexDigit(c: Char): Int = when (c) {192- in '0'..'9' -> c - '0'193- in 'a'..'f' -> c - 'a' + 10194- in 'A'..'F' -> c - 'A' + 10195- else -> throw IllegalArgumentException("bad hex digit")187+/** Hex -> bytes. Lowercase or uppercase digits; throws on odd length or bad char. */188+internal fun unhex(s: String): ByteArray {189+ require(s.length % 2 == 0) { "odd-length hex" }190+ return ByteArray(s.length / 2) { i ->191+ ((hexDigit(s[i * 2]) shl 4) or hexDigit(s[i * 2 + 1])).toByte()196192 }193+}197194 198- private fun b64(b: ByteArray): String = Base64.getEncoder().encodeToString(b)195+private fun hexDigit(c: Char): Int = when (c) {196+ in '0'..'9' -> c - '0'197+ in 'a'..'f' -> c - 'a' + 10198+ in 'A'..'F' -> c - 'A' + 10199+ else -> throw IllegalArgumentException("bad hex digit")199200 }200201 201202 /**app/src/main/java/com/peachpasswords/vault/VaultRepository.kt+0 −9
@@ -31,15 +31,6 @@3131 3232 private fun b64(bytes: ByteArray): String = Base64.getEncoder().withoutPadding().encodeToString(bytes)3333 private fun unb64(s: String): ByteArray = Base64.getDecoder().decode(s)34-private fun unhex(s: String): ByteArray {35- require(s.length % 2 == 0) { "odd-length hex" }36- return ByteArray(s.length / 2) { i ->37- val hi = Character.digit(s[i * 2], 16)38- val lo = Character.digit(s[i * 2 + 1], 16)39- require(hi >= 0 && lo >= 0) { "bad hex digit" }40- ((hi shl 4) or lo).toByte()41- }42-}4334 4435 /** Cap on retained past passwords per entry. Mirrors the browser PASSWORD_HISTORY_MAX. */4536 private const val PASSWORD_HISTORY_MAX = 50