mirror of
https://github.com/sparrowwallet/drongo.git
synced 2025-11-05 11:56:38 +00:00
trim whitespace chars before testing if byte array contains only hex or base64 chars
This commit is contained in:
parent
ad60a37d0e
commit
f7d5b4fb8f
1 changed files with 15 additions and 2 deletions
|
|
@ -57,7 +57,7 @@ public class Utils {
|
|||
return false;
|
||||
}
|
||||
|
||||
for(byte b : bytes) {
|
||||
for(byte b : trim(bytes)) {
|
||||
if(!((b >= '0' && b <= '9') || (b >= 'A' && b <= 'F') || (b >= 'a' && b <= 'f'))) {
|
||||
return false;
|
||||
}
|
||||
|
|
@ -71,7 +71,7 @@ public class Utils {
|
|||
return false;
|
||||
}
|
||||
|
||||
for(byte b : bytes) {
|
||||
for(byte b : trim(bytes)) {
|
||||
if(!((b >= '0' && b <= '9') || (b >= 'A' && b <= 'Z') || (b >= 'a' && b <= 'z') || (b == '+') || (b == '/') || (b == '='))) {
|
||||
return false;
|
||||
}
|
||||
|
|
@ -80,6 +80,19 @@ public class Utils {
|
|||
return true;
|
||||
}
|
||||
|
||||
private static byte[] trim(byte[] bytes) {
|
||||
int len = bytes.length;
|
||||
int st = 0;
|
||||
while ((st < len) && Character.isWhitespace((bytes[st] & 0xff))) {
|
||||
st++;
|
||||
}
|
||||
while ((st < len) && Character.isWhitespace((bytes[len - 1] & 0xff))) {
|
||||
len--;
|
||||
}
|
||||
|
||||
return ((st > 0) || (len < bytes.length)) ? Arrays.copyOfRange(bytes, st, len) : bytes;
|
||||
}
|
||||
|
||||
public static String bytesToHex(byte[] bytes) {
|
||||
char[] hexChars = new char[bytes.length * 2];
|
||||
for ( int j = 0; j < bytes.length; j++ ) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue