From 73bd4072031365aa79d90c93001035ba161f3291 Mon Sep 17 00:00:00 2001 From: bemusementpark Date: Tue, 16 Jul 2024 01:07:20 +0930 Subject: [PATCH] Optimise Validation --- .../main/java/org/session/libsignal/utilities/Validation.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libsignal/src/main/java/org/session/libsignal/utilities/Validation.kt b/libsignal/src/main/java/org/session/libsignal/utilities/Validation.kt index d0453fc140..fdf9bd386f 100644 --- a/libsignal/src/main/java/org/session/libsignal/utilities/Validation.kt +++ b/libsignal/src/main/java/org/session/libsignal/utilities/Validation.kt @@ -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()) }