API-style comments and ktlint formatting
Every comment is reduced to its first sentence plus @param, @return and @throws tags. Comment lines: 20040 to 8526. ktlint 1.8 applied with its default (official Kotlin) style across all modules; 262 files reformatted. The 264 remaining ktlint findings are naming and filename rules, which are code changes, and are left alone. Comments and formatting only. 1208 tests pass, counted from the XML. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5.1
parent
8a7f40fb13
commit
2fa430f21c
@@ -9,33 +9,15 @@ import kotlin.test.assertTrue
|
||||
|
||||
/**
|
||||
* Zeroing key material once it has been used (ios#39, Android half).
|
||||
*
|
||||
* The claim being tested is narrow, and the tests are shaped to keep it
|
||||
* narrow. What this buys is that a derived key is not left sitting in the
|
||||
* heap after the one moment it was needed. It is not "the key is gone", a
|
||||
* compacting collector can have moved the array, Android has compressed swap,
|
||||
* and there is no `memset_s` on the JVM. `SecureBytes` says all of that in
|
||||
* prose; these assert only what is actually true.
|
||||
*
|
||||
* The most valuable test here is that the derived keys did not change.
|
||||
* Wiping an intermediate one line too early derives every account secret from
|
||||
* thirty-two zero bytes, which produces a perfectly consistent, perfectly
|
||||
* wrong identity, silently, on every device. That is a far worse failure than
|
||||
* the leak this feature exists to narrow, so it is checked first.
|
||||
*/
|
||||
class SecureBytesTest {
|
||||
|
||||
private val passphrase = "a-long-enough-passphrase"
|
||||
private val salt = ByteArray(16) { it.toByte() }
|
||||
|
||||
// ---- The failure that would matter most -----------------------------
|
||||
// ---- The failure that would matter most -----------------------------.
|
||||
|
||||
/**
|
||||
* The pinned vectors already cover `authSecret` and `accountKeySeed`.
|
||||
* This covers the shape wiping could break without moving a vector: that
|
||||
* the two secrets from one stretch still match the two derived separately.
|
||||
* If the wipe landed between the expansions, the second would be derived
|
||||
* from zeroes and this diverges.
|
||||
*/
|
||||
@Test
|
||||
fun `wiping the intermediate did not change what is derived`() {
|
||||
@@ -45,9 +27,8 @@ class SecureBytesTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* And neither is zeroes, which is what "derived from a wiped buffer"
|
||||
* would look like. A test that only compared the two paths would pass if
|
||||
* BOTH were wrong in the same way.
|
||||
* And neither is zeroes, which is what "derived from a wiped buffer" would
|
||||
* look like.
|
||||
*/
|
||||
@Test
|
||||
fun `no derived secret is a run of zeroes`() {
|
||||
@@ -80,7 +61,7 @@ class SecureBytesTest {
|
||||
assertFalse(identity.contentEquals(account))
|
||||
}
|
||||
|
||||
// ---- The wiping itself ----------------------------------------------
|
||||
// ---- The wiping itself ----------------------------------------------.
|
||||
|
||||
@Test
|
||||
fun `wipe zeroes the array it is given`() {
|
||||
@@ -104,9 +85,7 @@ class SecureBytesTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* The case the `finally` exists for. A derivation that failed
|
||||
* half-way is exactly where the material gets forgotten, so the wipe has to
|
||||
* survive a throw, not sit at the end of a happy path.
|
||||
* The case the `finally` exists for.
|
||||
*/
|
||||
@Test
|
||||
fun `withSecret wipes when the body throws`() {
|
||||
@@ -118,10 +97,7 @@ class SecureBytesTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* The honest limit, asserted rather than left to the prose. A copy
|
||||
* taken before the wipe is untouched by it. This is not a bug to fix, a
|
||||
* `ByteArray` cannot reach copies of itself, and stating it as a passing
|
||||
* test stops anybody reading `wipe` as stronger than it is.
|
||||
* The honest limit, asserted rather than left to the prose.
|
||||
*/
|
||||
@Test
|
||||
fun `a copy taken beforehand survives the wipe`() {
|
||||
@@ -129,8 +105,10 @@ class SecureBytesTest {
|
||||
val copy = SecureBytes.copyOf(secret)
|
||||
SecureBytes.wipe(secret)
|
||||
assertTrue(secret.all { it == 0.toByte() })
|
||||
assertTrue(copy.all { it == 0x41.toByte() },
|
||||
"the copy was wiped too, which would mean these share a buffer")
|
||||
assertTrue(
|
||||
copy.all { it == 0x41.toByte() },
|
||||
"the copy was wiped too, which would mean these share a buffer",
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user