add byte array tests for hex and base64

This commit is contained in:
Craig Raw 2025-02-06 15:33:11 +02:00
parent ca758e1288
commit ad60a37d0e

View file

@ -52,6 +52,34 @@ public class Utils {
} }
} }
public static boolean isHex(byte[] bytes) {
if(bytes == null || bytes.length == 0) {
return false;
}
for(byte b : bytes) {
if(!((b >= '0' && b <= '9') || (b >= 'A' && b <= 'F') || (b >= 'a' && b <= 'f'))) {
return false;
}
}
return true;
}
public static boolean isBase64(byte[] bytes) {
if(bytes == null || bytes.length == 0) {
return false;
}
for(byte b : bytes) {
if(!((b >= '0' && b <= '9') || (b >= 'A' && b <= 'Z') || (b >= 'a' && b <= 'z') || (b == '+') || (b == '/') || (b == '='))) {
return false;
}
}
return true;
}
public static String bytesToHex(byte[] bytes) { public static String bytesToHex(byte[] bytes) {
char[] hexChars = new char[bytes.length * 2]; char[] hexChars = new char[bytes.length * 2];
for ( int j = 0; j < bytes.length; j++ ) { for ( int j = 0; j < bytes.length; j++ ) {