| | |
| | | * Returns the Base64 encoded string representation of this byte string. |
| | | * |
| | | * @return The Base64 encoded string representation of this byte string. |
| | | * @see ByteString#valueOfBase64String(String) |
| | | * @see ByteString#valueOfBase64(String) |
| | | */ |
| | | String toBase64String(); |
| | | |
| | |
| | | * content. |
| | | * @see #toBase64String() |
| | | */ |
| | | public static ByteString valueOfBase64String(final String s) { |
| | | public static ByteString valueOfBase64(final String s) { |
| | | return Base64.decode(s); |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | try { |
| | | value = ByteString.valueOfBase64String(ldifLine.substring(pos)); |
| | | value = ByteString.valueOfBase64(ldifLine.substring(pos)); |
| | | } catch (final LocalizedIllegalArgumentException e) { |
| | | // The value did not have a valid base64-encoding. |
| | | final LocalizableMessage message = |
| | |
| | | |
| | | final String base64DN = ldifLine.substring(pos); |
| | | try { |
| | | dnString = ByteString.valueOfBase64String(base64DN).toString(); |
| | | dnString = ByteString.valueOfBase64(base64DN).toString(); |
| | | } catch (final LocalizedIllegalArgumentException e) { |
| | | // The value did not have a valid base64-encoding. |
| | | final LocalizableMessage message = |
| | |
| | | } |
| | | |
| | | try { |
| | | pair.value = ByteString.valueOfBase64String(ldifLine.substring(pos)).toString(); |
| | | pair.value = ByteString.valueOfBase64(ldifLine.substring(pos)).toString(); |
| | | } catch (final LocalizedIllegalArgumentException e) { |
| | | pair.key = null; |
| | | return ldifLine; |
| | |
| | | |
| | | return new Object[][] { |
| | | { ByteString.empty(), new byte[0] }, |
| | | { ByteString.valueOfBase64String("AAA="), new byte[] { 0x00, 0x00 }}, |
| | | { ByteString.valueOfBase64String("AAAA"), new byte[] { 0x00, 0x00, 0x00 }}, |
| | | { ByteString.valueOfBase64String("AAAAAA=="), new byte[] { 0x00, 0x00, 0x00, 0x00 }}, |
| | | { ByteString.valueOfBase64("AAA="), new byte[] { 0x00, 0x00 }}, |
| | | { ByteString.valueOfBase64("AAAA"), new byte[] { 0x00, 0x00, 0x00 }}, |
| | | { ByteString.valueOfBase64("AAAAAA=="), new byte[] { 0x00, 0x00, 0x00, 0x00 }}, |
| | | { ByteString.valueOf(1), |
| | | new byte[] { (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01 } }, |
| | | { ByteString.valueOf(Integer.MAX_VALUE), |
| | |
| | | expectedExceptions = { LocalizedIllegalArgumentException.class }) |
| | | public void testValueOfBase64ThrowsLIAE(final String invalidBase64) throws Exception { |
| | | Assert.fail("Expected exception but got result: " |
| | | + Arrays.toString(new ByteString[] { ByteString.valueOfBase64String(invalidBase64) })); |
| | | + Arrays.toString(new ByteString[] { ByteString.valueOfBase64(invalidBase64) })); |
| | | } |
| | | |
| | | @Test(dataProvider = "validBase64Data") |
| | | public void testValueOfBase64(final String hexData, final String encodedData) throws Exception { |
| | | final byte[] data = DatatypeConverter.parseHexBinary(hexData); |
| | | final byte[] decodedData = ByteString.valueOfBase64String(encodedData).toByteArray(); |
| | | final byte[] decodedData = ByteString.valueOfBase64(encodedData).toByteArray(); |
| | | Assert.assertEquals(decodedData, data); |
| | | } |
| | | } |
| | |
| | | if (nextChar == ':') { |
| | | final String base64 = remainder.substring(1, remainder.length()); |
| | | try { |
| | | attributeVal = ByteString.valueOfBase64String(base64); |
| | | attributeVal = ByteString.valueOfBase64(base64); |
| | | } catch (final LocalizedIllegalArgumentException e) { |
| | | println(INFO_COMPARE_CANNOT_BASE64_DECODE_ASSERTION_VALUE.get()); |
| | | return ResultCode.CLIENT_SIDE_PARAM_ERROR.intValue(); |