Return empty PSK if unrecognized

This commit is contained in:
Mygod
2018-07-12 22:08:56 +08:00
parent 580b7620c5
commit d9d5c55ff4

View File

@@ -31,9 +31,11 @@ class P2pSupplicantConfiguration {
fun readPsk(): String? { fun readPsk(): String? {
return try { return try {
val match = pskParser.findAll(content ?: return null).single() val match = pskParser.findAll(content ?: return null).single()
if (match.groups[2] == null && match.groups[3] == null) "" else {
val result = match.groupValues[2] + match.groupValues[3] // only one will match and hold non-empty value val result = match.groupValues[2] + match.groupValues[3] // only one will match and hold non-empty value
check(result.length in 8..63) check(result.length in 8..63)
result result
}
} catch (e: NoSuchElementException) { } catch (e: NoSuchElementException) {
Toast.makeText(app, e.message, Toast.LENGTH_LONG).show() Toast.makeText(app, e.message, Toast.LENGTH_LONG).show()
null null