Search in sources :

Example 31 with Decoder

use of java.util.Base64.Decoder in project j2objc by google.

the class Base64Test method testRoundTrip_allBytes_mime_lineLength.

/**
 * check a range of possible line lengths
 */
public void testRoundTrip_allBytes_mime_lineLength() {
    Decoder decoder = Base64.getMimeDecoder();
    byte[] separator = new byte[] { '*' };
    checkRoundTrip_allBytes(Base64.getMimeEncoder(4, separator), decoder, wrapLines("*", ALL_BYTE_VALUES_ENCODED, 4));
    checkRoundTrip_allBytes(Base64.getMimeEncoder(8, separator), decoder, wrapLines("*", ALL_BYTE_VALUES_ENCODED, 8));
    checkRoundTrip_allBytes(Base64.getMimeEncoder(20, separator), decoder, wrapLines("*", ALL_BYTE_VALUES_ENCODED, 20));
    checkRoundTrip_allBytes(Base64.getMimeEncoder(100, separator), decoder, wrapLines("*", ALL_BYTE_VALUES_ENCODED, 100));
    checkRoundTrip_allBytes(Base64.getMimeEncoder(Integer.MAX_VALUE & ~3, separator), decoder, wrapLines("*", ALL_BYTE_VALUES_ENCODED, Integer.MAX_VALUE & ~3));
}
Also used : Decoder(java.util.Base64.Decoder)

Example 32 with Decoder

use of java.util.Base64.Decoder in project j2objc by google.

the class Base64Test method testDecoder_decodeArrayToArray.

/**
 * Tests {@link Decoder#decode(byte[], byte[])} for correctness as well as
 * for consistency with other methods tested elsewhere.
 */
public void testDecoder_decodeArrayToArray() {
    Decoder decoder = Base64.getDecoder();
    // Empty input
    assertEquals(0, decoder.decode(new byte[0], new byte[0]));
    // Test data for non-empty input
    String inputString = "YWJjZWZnaGk=";
    byte[] input = inputString.getBytes(US_ASCII);
    String expectedString = "abcefghi";
    byte[] decodedBytes = expectedString.getBytes(US_ASCII);
    // check test data consistency with other methods that are tested elsewhere
    assertRoundTrip(Base64.getEncoder(), decoder, inputString, decodedBytes);
    // Non-empty input: output array too short
    byte[] tooShort = new byte[decodedBytes.length - 1];
    try {
        decoder.decode(input, tooShort);
        fail();
    } catch (IllegalArgumentException expected) {
    }
    // Non-empty input: output array longer than required
    byte[] tooLong = new byte[decodedBytes.length + 1];
    int tooLongBytesDecoded = decoder.decode(input, tooLong);
    assertEquals(decodedBytes.length, tooLongBytesDecoded);
    assertEquals(0, tooLong[tooLong.length - 1]);
    assertArrayPrefixEquals(tooLong, decodedBytes.length, decodedBytes);
    // Non-empty input: output array has exact minimum required size
    byte[] justRight = new byte[decodedBytes.length];
    int justRightBytesDecoded = decoder.decode(input, justRight);
    assertEquals(decodedBytes.length, justRightBytesDecoded);
    assertArrayEquals(decodedBytes, justRight);
}
Also used : Decoder(java.util.Base64.Decoder)

Example 33 with Decoder

use of java.util.Base64.Decoder in project j2objc by google.

the class Base64Test method testDecoder_decodeByteBuffer_invalidData.

public void testDecoder_decodeByteBuffer_invalidData() {
    Decoder decoder = Base64.getDecoder();
    // Test the two types of byte buffer.
    String inputString = "AAAA AAAA";
    byte[] input = inputString.getBytes(US_ASCII);
    ByteBuffer inputBuffer = ByteBuffer.allocate(input.length);
    inputBuffer.put(input);
    inputBuffer.position(0);
    checkDecoder_decodeByteBuffer_invalidData(decoder, inputBuffer);
    inputBuffer = ByteBuffer.allocateDirect(input.length);
    inputBuffer.put(input);
    inputBuffer.position(0);
    checkDecoder_decodeByteBuffer_invalidData(decoder, inputBuffer);
}
Also used : Decoder(java.util.Base64.Decoder) ByteBuffer(java.nio.ByteBuffer)

Example 34 with Decoder

use of java.util.Base64.Decoder in project j2objc by google.

the class Base64Test method testDecoder_decodeByteBuffer.

public void testDecoder_decodeByteBuffer() {
    Decoder decoder = Base64.getDecoder();
    byte[] emptyByteArray = new byte[0];
    ByteBuffer emptyByteBuffer = ByteBuffer.wrap(emptyByteArray);
    ByteBuffer emptyDecodedBuffer = decoder.decode(emptyByteBuffer);
    assertEquals(emptyByteBuffer, emptyDecodedBuffer);
    assertNotSame(emptyByteArray, emptyDecodedBuffer);
    // Test the two types of byte buffer.
    String inputString = "YWJjZWZnaGk=";
    byte[] input = inputString.getBytes(US_ASCII);
    String expectedString = "abcefghi";
    byte[] expectedBytes = expectedString.getBytes(US_ASCII);
    ByteBuffer inputBuffer = ByteBuffer.allocate(input.length);
    inputBuffer.put(input);
    inputBuffer.position(0);
    checkDecoder_decodeByteBuffer(decoder, inputBuffer, expectedBytes);
    inputBuffer = ByteBuffer.allocateDirect(input.length);
    inputBuffer.put(input);
    inputBuffer.position(0);
    checkDecoder_decodeByteBuffer(decoder, inputBuffer, expectedBytes);
}
Also used : Decoder(java.util.Base64.Decoder) ByteBuffer(java.nio.ByteBuffer)

Example 35 with Decoder

use of java.util.Base64.Decoder in project j2objc by google.

the class Base64Test method testRoundtrip_wrap_basic.

public void testRoundtrip_wrap_basic() throws Exception {
    Encoder encoder = Base64.getEncoder();
    Decoder decoder = Base64.getDecoder();
    checkRoundTrip_wrapInputStream(encoder, decoder);
}
Also used : Encoder(java.util.Base64.Encoder) Decoder(java.util.Base64.Decoder)

Aggregations

Decoder (java.util.Base64.Decoder)27 Base64 (java.util.Base64)21 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)7 Encoder (java.util.Base64.Encoder)7 KeyFactory (java.security.KeyFactory)6 X509EncodedKeySpec (java.security.spec.X509EncodedKeySpec)6 IOException (java.io.IOException)5 InvalidKeySpecException (java.security.spec.InvalidKeySpecException)5 JOSEObjectType (com.nimbusds.jose.JOSEObjectType)4 JWSAlgorithm (com.nimbusds.jose.JWSAlgorithm)4 JWSHeader (com.nimbusds.jose.JWSHeader)4 JWSSigner (com.nimbusds.jose.JWSSigner)4 MACSigner (com.nimbusds.jose.crypto.MACSigner)4 JWKSource (com.nimbusds.jose.jwk.source.JWKSource)4 DefaultJOSEObjectTypeVerifier (com.nimbusds.jose.proc.DefaultJOSEObjectTypeVerifier)4 JWSKeySelector (com.nimbusds.jose.proc.JWSKeySelector)4 JWSVerificationKeySelector (com.nimbusds.jose.proc.JWSVerificationKeySelector)4 JWTClaimsSet (com.nimbusds.jwt.JWTClaimsSet)4 SignedJWT (com.nimbusds.jwt.SignedJWT)4 RSAPublicKey (java.security.interfaces.RSAPublicKey)4