Stops accepting space as a Valid hex char and requires an even number of chars (padding)
This commit is contained in:
@@ -12,18 +12,19 @@ fun HexKey.hexToByteArray(): ByteArray {
|
|||||||
}
|
}
|
||||||
|
|
||||||
object HexValidator {
|
object HexValidator {
|
||||||
private fun isHex2(c: Char): Boolean {
|
private fun isHexChar(c: Char): Boolean {
|
||||||
return when (c) {
|
return when (c) {
|
||||||
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'A', 'B', 'C', 'D', 'E', 'F', ' ' -> true
|
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'A', 'B', 'C', 'D', 'E', 'F' -> true
|
||||||
else -> false
|
else -> false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun isHex(hex: String?): Boolean {
|
fun isHex(hex: String?): Boolean {
|
||||||
if (hex == null) return false
|
if (hex == null) return false
|
||||||
|
if (hex.length % 2 != 0) return false // must be even
|
||||||
var isHex = true
|
var isHex = true
|
||||||
for (c in hex.toCharArray()) {
|
for (c in hex.toCharArray()) {
|
||||||
if (!isHex2(c)) {
|
if (!isHexChar(c)) {
|
||||||
isHex = false
|
isHex = false
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user