From 7e2eb2425e7b9b6ccb37b7b89f19de3fa7a20c44 Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Sat, 15 May 2021 12:56:49 +0530 Subject: all: reformat with Spotless again Signed-off-by: Harsh Shandilya --- .../msfjarvis/aps/data/passfile/PasswordEntry.kt | 9 ++++-- .../main/kotlin/dev/msfjarvis/aps/util/totp/Otp.kt | 3 +- .../aps/data/passfile/PasswordEntryTest.kt | 8 +++-- .../kotlin/dev/msfjarvis/aps/util/totp/OtpTest.kt | 35 +++++++++++++++++----- 4 files changed, 42 insertions(+), 13 deletions(-) (limited to 'format-common') diff --git a/format-common/src/main/kotlin/dev/msfjarvis/aps/data/passfile/PasswordEntry.kt b/format-common/src/main/kotlin/dev/msfjarvis/aps/data/passfile/PasswordEntry.kt index a65e3494..96337bf7 100644 --- a/format-common/src/main/kotlin/dev/msfjarvis/aps/data/passfile/PasswordEntry.kt +++ b/format-common/src/main/kotlin/dev/msfjarvis/aps/data/passfile/PasswordEntry.kt @@ -115,11 +115,13 @@ constructor( .lineSequence() .filter { line -> return@filter when { - USERNAME_FIELDS.any { prefix -> line.startsWith(prefix, ignoreCase = true) } && !foundUsername -> { + USERNAME_FIELDS.any { prefix -> line.startsWith(prefix, ignoreCase = true) } && + !foundUsername -> { foundUsername = true false } - line.startsWith("otpauth://", ignoreCase = true) || line.startsWith("totp:", ignoreCase = true) -> { + line.startsWith("otpauth://", ignoreCase = true) || + line.startsWith("totp:", ignoreCase = true) -> { false } else -> { @@ -174,7 +176,8 @@ constructor( private fun findUsername(): String? { extraContentString.splitToSequence("\n").forEach { line -> for (prefix in USERNAME_FIELDS) { - if (line.startsWith(prefix, ignoreCase = true)) return line.substring(prefix.length).trimStart() + if (line.startsWith(prefix, ignoreCase = true)) + return line.substring(prefix.length).trimStart() } } return null diff --git a/format-common/src/main/kotlin/dev/msfjarvis/aps/util/totp/Otp.kt b/format-common/src/main/kotlin/dev/msfjarvis/aps/util/totp/Otp.kt index 832529e9..65284441 100644 --- a/format-common/src/main/kotlin/dev/msfjarvis/aps/util/totp/Otp.kt +++ b/format-common/src/main/kotlin/dev/msfjarvis/aps/util/totp/Otp.kt @@ -23,7 +23,8 @@ internal object Otp { check(STEAM_ALPHABET.size == 26) } - fun calculateCode(secret: String, counter: Long, algorithm: String, digits: String) = runCatching { + fun calculateCode(secret: String, counter: Long, algorithm: String, digits: String) = + runCatching { val algo = "Hmac${algorithm.uppercase(Locale.ROOT)}" val decodedSecret = BASE_32.decode(secret) val secretKey = SecretKeySpec(decodedSecret, algo) diff --git a/format-common/src/test/kotlin/dev/msfjarvis/aps/data/passfile/PasswordEntryTest.kt b/format-common/src/test/kotlin/dev/msfjarvis/aps/data/passfile/PasswordEntryTest.kt index 2520853c..fad58be7 100644 --- a/format-common/src/test/kotlin/dev/msfjarvis/aps/data/passfile/PasswordEntryTest.kt +++ b/format-common/src/test/kotlin/dev/msfjarvis/aps/data/passfile/PasswordEntryTest.kt @@ -19,7 +19,8 @@ import org.junit.Test @OptIn(ExperimentalCoroutinesApi::class, ExperimentalTime::class) internal class PasswordEntryTest { - private fun makeEntry(content: String) = PasswordEntry(fakeClock, testFinder, testScope, content.encodeToByteArray()) + private fun makeEntry(content: String) = + PasswordEntry(fakeClock, testFinder, testScope, content.encodeToByteArray()) @Test fun testGetPassword() { @@ -49,7 +50,10 @@ internal class PasswordEntryTest { assertEquals("blubb", makeEntry("\nblubb").extraContentString) assertEquals("blubb", makeEntry("blubb\npassword: foo").extraContentString) assertEquals("blubb", makeEntry("password: foo\nblubb").extraContentString) - assertEquals("blubb\nusername: bar", makeEntry("blubb\npassword: foo\nusername: bar").extraContentString) + assertEquals( + "blubb\nusername: bar", + makeEntry("blubb\npassword: foo\nusername: bar").extraContentString + ) assertEquals("", makeEntry("\n").extraContentString) assertEquals("", makeEntry("").extraContentString) } diff --git a/format-common/src/test/kotlin/dev/msfjarvis/aps/util/totp/OtpTest.kt b/format-common/src/test/kotlin/dev/msfjarvis/aps/util/totp/OtpTest.kt index e6dc372d..4c01ac74 100644 --- a/format-common/src/test/kotlin/dev/msfjarvis/aps/util/totp/OtpTest.kt +++ b/format-common/src/test/kotlin/dev/msfjarvis/aps/util/totp/OtpTest.kt @@ -15,16 +15,34 @@ internal class OtpTest { @Test fun testOtpGeneration6Digits() { - assertEquals("953550", Otp.calculateCode("JBSWY3DPEHPK3PXP", 1593333298159 / (1000 * 30), "SHA1", "6").get()) - assertEquals("275379", Otp.calculateCode("JBSWY3DPEHPK3PXP", 1593333571918 / (1000 * 30), "SHA1", "6").get()) - assertEquals("867507", Otp.calculateCode("JBSWY3DPEHPK3PXP", 1593333600517 / (1000 * 57), "SHA1", "6").get()) + assertEquals( + "953550", + Otp.calculateCode("JBSWY3DPEHPK3PXP", 1593333298159 / (1000 * 30), "SHA1", "6").get() + ) + assertEquals( + "275379", + Otp.calculateCode("JBSWY3DPEHPK3PXP", 1593333571918 / (1000 * 30), "SHA1", "6").get() + ) + assertEquals( + "867507", + Otp.calculateCode("JBSWY3DPEHPK3PXP", 1593333600517 / (1000 * 57), "SHA1", "6").get() + ) } @Test fun testOtpGeneration10Digits() { - assertEquals("0740900914", Otp.calculateCode("JBSWY3DPEHPK3PXP", 1593333655044 / (1000 * 30), "SHA1", "10").get()) - assertEquals("0070632029", Otp.calculateCode("JBSWY3DPEHPK3PXP", 1593333691405 / (1000 * 30), "SHA1", "10").get()) - assertEquals("1017265882", Otp.calculateCode("JBSWY3DPEHPK3PXP", 1593333728893 / (1000 * 83), "SHA1", "10").get()) + assertEquals( + "0740900914", + Otp.calculateCode("JBSWY3DPEHPK3PXP", 1593333655044 / (1000 * 30), "SHA1", "10").get() + ) + assertEquals( + "0070632029", + Otp.calculateCode("JBSWY3DPEHPK3PXP", 1593333691405 / (1000 * 30), "SHA1", "10").get() + ) + assertEquals( + "1017265882", + Otp.calculateCode("JBSWY3DPEHPK3PXP", 1593333728893 / (1000 * 83), "SHA1", "10").get() + ) } @Test @@ -42,7 +60,10 @@ internal class OtpTest { "127764", Otp.calculateCode("JBSWY3DPEHPK3PXPAAAAAAAA", 1593367111963 / (1000 * 30), "SHA1", "6").get() ) - assertEquals("047515", Otp.calculateCode("JBSWY3DPEHPK3PXPAAAAA", 1593367171420 / (1000 * 30), "SHA1", "6").get()) + assertEquals( + "047515", + Otp.calculateCode("JBSWY3DPEHPK3PXPAAAAA", 1593367171420 / (1000 * 30), "SHA1", "6").get() + ) } @Test -- cgit v1.2.3