mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-24 16:57:50 +00:00
Optimise Validation
This commit is contained in:
parent
593e417af5
commit
73bd407203
@ -1,11 +1,11 @@
|
||||
package org.session.libsignal.utilities
|
||||
|
||||
object PublicKeyValidation {
|
||||
private val HEX_CHARACTERS = "0123456789ABCDEF".toSet()
|
||||
private val HEX_CHARACTERS = "0123456789ABCDEFabcdef".toSet()
|
||||
private val INVALID_PREFIXES = setOf(IdPrefix.GROUP, IdPrefix.BLINDED, IdPrefix.BLINDEDV2)
|
||||
|
||||
fun isValid(candidate: String, isPrefixRequired: Boolean = true): Boolean = hasValidLength(candidate) && isValidHexEncoding(candidate) && (!isPrefixRequired || IdPrefix.fromValue(candidate) != null)
|
||||
fun hasValidPrefix(candidate: String) = IdPrefix.fromValue(candidate) !in INVALID_PREFIXES
|
||||
private fun hasValidLength(candidate: String) = candidate.length == 66
|
||||
private fun isValidHexEncoding(candidate: String) = HEX_CHARACTERS.containsAll(candidate.uppercase().toSet())
|
||||
private fun isValidHexEncoding(candidate: String) = HEX_CHARACTERS.containsAll(candidate.toSet())
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user