aboutsummaryrefslogtreecommitdiff
path: root/passgen/diceware/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'passgen/diceware/src/main')
-rw-r--r--passgen/diceware/src/main/kotlin/dev/msfjarvis/aps/passgen/diceware/WordListParser.kt21
1 files changed, 21 insertions, 0 deletions
diff --git a/passgen/diceware/src/main/kotlin/dev/msfjarvis/aps/passgen/diceware/WordListParser.kt b/passgen/diceware/src/main/kotlin/dev/msfjarvis/aps/passgen/diceware/WordListParser.kt
new file mode 100644
index 00000000..5351aaa1
--- /dev/null
+++ b/passgen/diceware/src/main/kotlin/dev/msfjarvis/aps/passgen/diceware/WordListParser.kt
@@ -0,0 +1,21 @@
+/*
+ * Copyright © 2014-2021 The Android Password Store Authors. All Rights Reserved.
+ * SPDX-License-Identifier: GPL-3.0-only
+ */
+
+package dev.msfjarvis.aps.passgen.diceware
+
+import java.io.InputStream
+
+internal object WordListParser {
+ fun parse(wordlistStream: InputStream) =
+ wordlistStream
+ .bufferedReader()
+ .lineSequence()
+ .map { line -> line.split(DELIMITER) }
+ .filter { items -> items.size == 2 && items[0].toIntOrNull() != null }
+ .map { items -> items[0].toInt() to items[1] }
+ .toMap()
+
+ private const val DELIMITER = "\t"
+}