0
0
mirror of https://github.com/markusfisch/BinaryEye.git synced 2024-09-20 12:02:17 +02:00

Apply auto formatting

This commit is contained in:
Markus Fisch 2019-09-08 21:15:12 +02:00
parent 8152cb6a24
commit 8c22a8ab00
2 changed files with 13 additions and 6 deletions

View File

@ -26,8 +26,9 @@ class OtpauthParser private constructor(private val match: MatchResult) {
val counter: Int
get() = parameterCounter.toInt()
private val isHotp: Boolean = otpType == "hotp"
val isValid: Boolean = (labelIssuer.isNotEmpty() == parameterIssuer.isEmpty() || labelIssuer.isEmpty())
&& secret.isNotEmpty() && isHotp == parameterCounter.isNotEmpty()
val isValid: Boolean =
(labelIssuer.isNotEmpty() == parameterIssuer.isEmpty() || labelIssuer.isEmpty())
&& secret.isNotEmpty() && isHotp == parameterCounter.isNotEmpty()
val uri: Uri
get() = Uri.Builder().apply {
@ -53,7 +54,8 @@ class OtpauthParser private constructor(private val match: MatchResult) {
}.build()
companion object {
private const val issuerAndAccount = """(?:(?:([^?:]+)(?::|%3A)(?:%20)*([^?]+))|([^?]+))"""//.toRegex()
private const val issuerAndAccount =
"""(?:(?:([^?:]+)(?::|%3A)(?:%20)*([^?]+))|([^?]+))"""//.toRegex()
/** allowing `padding` even though it should not be there, will be removed in output*/
private const val secret = """(?:secret=([2-7A-Z]+)=*)"""//.toRegex()
/** `\2` references the issuer of [issuerAndAccount] */
@ -63,7 +65,9 @@ class OtpauthParser private constructor(private val match: MatchResult) {
private const val period = """(?:period=([0-9]+))"""//.toRegex()
private const val counter = """(?:counter=([0-9]+))"""//.toRegex()
private val otpauthRegex =
"""^otpauth://([ht]otp)/$issuerAndAccount\?(?:&?(?:$secret|$issuer|$algorithm|$digits|$period|$counter))+$""".toRegex(RegexOption.IGNORE_CASE)
"""^otpauth://([ht]otp)/$issuerAndAccount\?(?:&?(?:$secret|$issuer|$algorithm|$digits|$period|$counter))+$""".toRegex(
RegexOption.IGNORE_CASE
)
operator fun invoke(input: String): OtpauthParser? {
return otpauthRegex.matchEntire(input)?.let(::OtpauthParser)?.takeIf { it.isValid }

View File

@ -1,9 +1,12 @@
package de.markusfisch.android.binaryeye.actions.vtype
object VTypeParser {
private const val BACKSLASH_R_LEGACY = "(?:\u000D\u000A|[\u000A\u000B\u000C\u000D\u0085\u2028\u2029])"
private const val BACKSLASH_R_LEGACY =
"(?:\u000D\u000A|[\u000A\u000B\u000C\u000D\u0085\u2028\u2029])"
private val vTypeRegex =
"""^BEGIN:(VCARD|VEVENT)(?:$BACKSLASH_R_LEGACY.+?:[\s\S]+?)+?${BACKSLASH_R_LEGACY}END:\1$BACKSLASH_R_LEGACY?$""".toRegex(RegexOption.IGNORE_CASE)
"""^BEGIN:(VCARD|VEVENT)(?:$BACKSLASH_R_LEGACY.+?:[\s\S]+?)+?${BACKSLASH_R_LEGACY}END:\1$BACKSLASH_R_LEGACY?$""".toRegex(
RegexOption.IGNORE_CASE
)
private val propertyRegex = """^(.+?):([\s\S]*?)$""".toRegex(RegexOption.MULTILINE)
fun parseVType(data: String): String? =