/** * Validates a string to ensure all its bytes are in the Base32 alphabet. * Implementation is case-insensitive and converts the given string to * upper case before evaluating. * * @param data the string to test * @return True if the given string can be decoded using Base32 */ public static boolean isBase32(String data) { return data == null ? false : Base32Hex.isInAlphabet(data.toUpperCase()); }
@Override public int read() throws IOException { int data = super.read(); if (!b32.isInAlphabet((byte) data)) { throw new IOException("Data is not base32 encoded."); } return super.read(); } }
@Override public int read(byte[] b, int offset, int len) throws IOException { int numRead = super.read(b, offset, len); if (numRead > 0) { byte[] copy = b; if (numRead < b.length) { // isBase32 checks the whole length of byte[], we need to limit it to numRead copy = Arrays.copyOf(b, numRead); } if (!b32.isInAlphabet(copy, true)) { throw new IOException("Data is not base32 encoded."); } } return numRead; }
@Override public int read(byte[] b) throws IOException { int numRead = super.read(b); if (numRead > 0) { byte[] copy = b; if (numRead < b.length) { // isBase32 checks the whole length of byte[], we need to limit it to numRead copy = Arrays.copyOf(b, numRead); } if (!b32.isInAlphabet(copy, true)) { throw new IOException("Data is not base32 encoded."); } } return numRead; }
if (isInAlphabet(pad) || isWhiteSpace(pad)) { throw new IllegalArgumentException("pad must not be in alphabet or whitespace");
/** * Validates a string to ensure all its bytes are in the Base32 alphabet. * Implementation is case-insensitive and converts the given string to * upper case before evaluating. * * @param data the string to test * @return True if the given string can be decoded using Base32 */ public static boolean isBase32(String data) { return data == null ? false : Base32Hex.isInAlphabet(data.toUpperCase()); }
@Override public int read() throws IOException { int data = super.read(); if (!b32.isInAlphabet((byte) data)) { throw new IOException("Data is not base32 encoded."); } return super.read(); } }
@Override public int read(byte[] b) throws IOException { int numRead = super.read(b); if (numRead > 0) { byte[] copy = b; if (numRead < b.length) { // isBase32 checks the whole length of byte[], we need to limit it to numRead copy = Arrays.copyOf(b, numRead); } if (!b32.isInAlphabet(copy, true)) { throw new IOException("Data is not base32 encoded."); } } return numRead; }
@Override public int read(byte[] b, int offset, int len) throws IOException { int numRead = super.read(b, offset, len); if (numRead > 0) { byte[] copy = b; if (numRead < b.length) { // isBase32 checks the whole length of byte[], we need to limit it to numRead copy = Arrays.copyOf(b, numRead); } if (!b32.isInAlphabet(copy, true)) { throw new IOException("Data is not base32 encoded."); } } return numRead; }
/** * Converts a string to a byte array. * * @param base32String The input Base32 string. * @return The output byte array. */ public static byte[] getBytes(final String base32String) { final Base32 codec = new Base32(); final byte[] encodedBytes = StringEncoder.getBytes(base32String); if (!codec.isInAlphabet(encodedBytes, true)) { throw new IllegalArgumentException("malformed base32 string passed to getBytes"); } return codec.decode(encodedBytes); }
/** * Converts a string to a byte array. * * @param base32String The input Base32 string. * @return The output byte array. */ public static byte[] getBytes(final String base32String) { final Base32 codec = new Base32(); final byte[] encodedBytes = StringEncoder.getBytes(base32String); if (!codec.isInAlphabet(encodedBytes, true)) { throw new IllegalArgumentException("malformed base32 string passed to getBytes"); } return codec.decode(encodedBytes); }
if (isInAlphabet(pad) || isWhiteSpace(pad)) { throw new IllegalArgumentException("pad must not be in alphabet or whitespace");
if (isInAlphabet(pad) || isWhiteSpace(pad)) { throw new IllegalArgumentException("pad must not be in alphabet or whitespace");
if (isInAlphabet(pad) || isWhiteSpace(pad)) { throw new IllegalArgumentException("pad must not be in alphabet or whitespace");
if (isInAlphabet(pad) || isWhiteSpace(pad)) { throw new IllegalArgumentException("pad must not be in alphabet or whitespace");