1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-29 07:22:07 +01:00

StringUtils: Fix typo and expose unambiguous alphabet as string

This commit is contained in:
Paul Schaub 2020-07-15 22:15:38 +02:00
parent b7fe56fb9b
commit bb3c491e0c
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311

View file

@ -270,7 +270,12 @@ public class StringUtils {
/** /**
* 24 upper case characters from the latin alphabet and numbers without '0' and 'O'. * 24 upper case characters from the latin alphabet and numbers without '0' and 'O'.
*/ */
private static final char[] UNAMBIGUOUS_NUMBERS_AND_LETTER = "123456789ABCDEFGHIJKLMNPQRSTUVWXYZ".toCharArray(); public static final String UNAMBIGUOUS_NUMBERS_AND_LETTERS_STRING = "123456789ABCDEFGHIJKLMNPQRSTUVWXYZ";
/**
* 24 upper case characters from the latin alphabet and numbers without '0' and 'O'.
*/
private static final char[] UNAMBIGUOUS_NUMBERS_AND_LETTERS = UNAMBIGUOUS_NUMBERS_AND_LETTERS_STRING.toCharArray();
/** /**
* Returns a random String of numbers and letters (lower and upper case) * Returns a random String of numbers and letters (lower and upper case)
@ -294,14 +299,14 @@ public class StringUtils {
// See also https://www.grc.com/haystack.htm // See also https://www.grc.com/haystack.htm
final int REQUIRED_LENGTH = 10; final int REQUIRED_LENGTH = 10;
return randomString(RandomUtil.SECURE_RANDOM.get(), UNAMBIGUOUS_NUMBERS_AND_LETTER, REQUIRED_LENGTH); return randomString(RandomUtil.SECURE_RANDOM.get(), UNAMBIGUOUS_NUMBERS_AND_LETTERS, REQUIRED_LENGTH);
} }
public static String secureUniqueRandomString() { public static String secureUniqueRandomString() {
// 34^13 = 8.11e19 possible combinations, which is > 2^64. // 34^13 = 8.11e19 possible combinations, which is > 2^64.
final int REQUIRED_LENGTH = 13; final int REQUIRED_LENGTH = 13;
return randomString(RandomUtil.SECURE_RANDOM.get(), UNAMBIGUOUS_NUMBERS_AND_LETTER, REQUIRED_LENGTH); return randomString(RandomUtil.SECURE_RANDOM.get(), UNAMBIGUOUS_NUMBERS_AND_LETTERS, REQUIRED_LENGTH);
} }
/** /**
@ -324,7 +329,7 @@ public class StringUtils {
// See also https://www.grc.com/haystack.htm // See also https://www.grc.com/haystack.htm
final int REQUIRED_LENGTH = 24; final int REQUIRED_LENGTH = 24;
return randomString(RandomUtil.SECURE_RANDOM.get(), UNAMBIGUOUS_NUMBERS_AND_LETTER, REQUIRED_LENGTH); return randomString(RandomUtil.SECURE_RANDOM.get(), UNAMBIGUOUS_NUMBERS_AND_LETTERS, REQUIRED_LENGTH);
} }
private static final int RANDOM_STRING_CHUNK_SIZE = 4; private static final int RANDOM_STRING_CHUNK_SIZE = 4;
@ -368,8 +373,8 @@ public class StringUtils {
char[] randomChars = new char[length]; char[] randomChars = new char[length];
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
int index = random.nextInt(UNAMBIGUOUS_NUMBERS_AND_LETTER.length); int index = random.nextInt(UNAMBIGUOUS_NUMBERS_AND_LETTERS.length);
randomChars[i] = UNAMBIGUOUS_NUMBERS_AND_LETTER[index]; randomChars[i] = UNAMBIGUOUS_NUMBERS_AND_LETTERS[index];
} }
return new String(randomChars); return new String(randomChars);
} }