mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-22 02:18:26 +00:00
Update scalafmt settings
This commit is contained in:
@ -43,7 +43,7 @@ object Key {
|
||||
if (dataStr.isEmpty) Left(s"No separator found in key string: $str")
|
||||
else
|
||||
for {
|
||||
mac <- Mac.fromString(macStr)
|
||||
mac <- Mac.fromString(macStr)
|
||||
data <- ByteVector.fromBase32Descriptive(dataStr.dropWhile(_ == ':'))
|
||||
} yield Key(data, mac)
|
||||
}
|
||||
|
@ -17,15 +17,15 @@ sealed trait Mac {
|
||||
}
|
||||
object Mac {
|
||||
case object Sha1 extends Mac {
|
||||
val identifier = TimeBasedOneTimePasswordGenerator.TOTP_ALGORITHM_HMAC_SHA1
|
||||
val identifier = TimeBasedOneTimePasswordGenerator.TOTP_ALGORITHM_HMAC_SHA1
|
||||
val keyLengthBits = 160
|
||||
}
|
||||
case object Sha256 extends Mac {
|
||||
val identifier = TimeBasedOneTimePasswordGenerator.TOTP_ALGORITHM_HMAC_SHA256
|
||||
val identifier = TimeBasedOneTimePasswordGenerator.TOTP_ALGORITHM_HMAC_SHA256
|
||||
val keyLengthBits = 256
|
||||
}
|
||||
case object Sha512 extends Mac {
|
||||
val identifier = TimeBasedOneTimePasswordGenerator.TOTP_ALGORITHM_HMAC_SHA512
|
||||
val identifier = TimeBasedOneTimePasswordGenerator.TOTP_ALGORITHM_HMAC_SHA512
|
||||
val keyLengthBits = 512
|
||||
}
|
||||
|
||||
|
@ -37,7 +37,7 @@ object Totp {
|
||||
def apply(setts: Settings): Totp =
|
||||
new Totp {
|
||||
|
||||
val settings = setts
|
||||
val settings = setts
|
||||
private val generator = makeGenerator(setts)
|
||||
|
||||
def generate(key: Key, time: Instant): OnetimePassword =
|
||||
|
@ -18,7 +18,7 @@ class KeyTest extends FunSuite {
|
||||
|
||||
test("generate and read in key") {
|
||||
val jkey = Key.generateJavaKey(Mac.Sha1)
|
||||
val key = Key.fromSecretKey(jkey).fold(sys.error, identity)
|
||||
val key = Key.fromSecretKey(jkey).fold(sys.error, identity)
|
||||
assertEquals(jkey, key.toJavaKey)
|
||||
}
|
||||
|
||||
@ -30,9 +30,9 @@ class KeyTest extends FunSuite {
|
||||
}
|
||||
|
||||
test("encode/decode json") {
|
||||
val key = Key.generate[IO](Mac.Sha1).unsafeRunSync()
|
||||
val key = Key.generate[IO](Mac.Sha1).unsafeRunSync()
|
||||
val keyJson = key.asJson
|
||||
val newKey = keyJson.as[Key].fold(throw _, identity)
|
||||
val newKey = keyJson.as[Key].fold(throw _, identity)
|
||||
assertEquals(key, newKey)
|
||||
}
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ import scodec.bits.ByteVector
|
||||
class TotpTest extends FunSuite {
|
||||
|
||||
val totp = Totp.default
|
||||
val key = Key(ByteVector.fromValidBase64("GGFWIWYnHB8F5Dp87iS2HP86k4A="), Mac.Sha1)
|
||||
val key = Key(ByteVector.fromValidBase64("GGFWIWYnHB8F5Dp87iS2HP86k4A="), Mac.Sha1)
|
||||
val time = Instant.parse("2021-08-29T18:42:00Z")
|
||||
|
||||
test("generate password") {
|
||||
@ -34,12 +34,12 @@ class TotpTest extends FunSuite {
|
||||
}
|
||||
|
||||
for {
|
||||
mac <- Mac.all.toList
|
||||
mac <- Mac.all.toList
|
||||
plen <- PassLength.all.toList
|
||||
} test(s"generate ${mac.identifier} with ${plen.toInt} characters") {
|
||||
val key = Key.generate[IO](mac).unsafeRunSync()
|
||||
val key = Key.generate[IO](mac).unsafeRunSync()
|
||||
val totp = Totp(Settings(mac, plen, 30.seconds))
|
||||
val otp = totp.generate(key, time)
|
||||
val otp = totp.generate(key, time)
|
||||
assertEquals(otp.pass.length, plen.toInt)
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user