diff options
author | The Android Open Source Project <initial-contribution@android.com> | 2008-12-17 18:03:55 -0800 |
---|---|---|
committer | The Android Open Source Project <initial-contribution@android.com> | 2008-12-17 18:03:55 -0800 |
commit | dd828f42a5c83b4270d4fbf6fce2da1878f1e84a (patch) | |
tree | fdd4b68fa1020f2b6426034c94823419a7236200 /crypto/src | |
parent | fdb2704414a9ed92394ada0d1395e4db86889465 (diff) | |
download | libcore-dd828f42a5c83b4270d4fbf6fce2da1878f1e84a.zip libcore-dd828f42a5c83b4270d4fbf6fce2da1878f1e84a.tar.gz libcore-dd828f42a5c83b4270d4fbf6fce2da1878f1e84a.tar.bz2 |
Code drop from //branches/cupcake/...@124589
Diffstat (limited to 'crypto/src')
134 files changed, 18332 insertions, 885 deletions
diff --git a/crypto/src/main/java/javax/crypto/BadPaddingException.java b/crypto/src/main/java/javax/crypto/BadPaddingException.java index 1b69bc2..19fdaa8 100644 --- a/crypto/src/main/java/javax/crypto/BadPaddingException.java +++ b/crypto/src/main/java/javax/crypto/BadPaddingException.java @@ -15,18 +15,15 @@ * limitations under the License. */ -/** -* @author Vera Y. Petrashkova -* @version $Revision$ -*/ - package javax.crypto; import java.security.GeneralSecurityException; /** - * @com.intel.drl.spec_ref + * The exception that is thrown when a padding mechanism is expected for the + * input data, but the input data does not have the proper padding bytes. * + * @since Android 1.0 */ public class BadPaddingException extends GeneralSecurityException { @@ -36,16 +33,20 @@ public class BadPaddingException extends GeneralSecurityException { private static final long serialVersionUID = -5315033893984728443L; /** - * @com.intel.drl.spec_ref + * Creates a new instance of {@code BadPaddingException} with a message. * + * @param msg + * the message + * @since Android 1.0 */ public BadPaddingException(String msg) { super(msg); } /** - * @com.intel.drl.spec_ref + * Creates a new instance of {@code BadPaddingException} with no message. * + * @since Android 1.0 */ public BadPaddingException() { } diff --git a/crypto/src/main/java/javax/crypto/Cipher.java b/crypto/src/main/java/javax/crypto/Cipher.java index ff94245..ae72226 100644 --- a/crypto/src/main/java/javax/crypto/Cipher.java +++ b/crypto/src/main/java/javax/crypto/Cipher.java @@ -15,11 +15,6 @@ * limitations under the License. */ -/** -* @author Boris V. Kuznetsov -* @version $Revision$ -*/ - package javax.crypto; import java.nio.ByteBuffer; @@ -44,50 +39,80 @@ import org.apache.harmony.crypto.internal.nls.Messages; import org.apache.harmony.security.fortress.Engine; /** - * @com.intel.drl.spec_ref + * This class provides access to implementations of cryptographic ciphers for + * encryption and decryption. Cipher classes can not be instantiated directly, + * one has to call the Cipher's {@code getInstance} method with the name of a + * requested transformation, optionally with a provider. A transformation + * specifies an operation (or a set of operations) as a string in the form: + * <ul> + * <li><i>"algorithm/mode/padding"</i></li> or + * <li><i>"algorithm"</i></li> + * </ul> + * <i>algorithm</i> is the name of a cryptographic algorithm, <i>mode</i> is the + * name of a feedback mode and <i>padding</i> is the name of a padding scheme. + * If <i>mode</i> and/or <i>padding</i> values are omitted, provider specific + * default values will be used. + * <p> + * A valid transformation would be: + * <ul> + * {@code Cipher c = Cipher.getInstance("AES/CBC/PKCS5Padding");} + * </ul> + * When a block cipher is requested in in stream cipher mode, the number of bits + * to be processed at a time can be optionally specified by appending it to the + * mode name. e.g. <i>"AES/CFB8/NoPadding"</i>. If no number is specified, a + * provider specific default value is used. + * </p> * + * @since Android 1.0 */ public class Cipher { /** - * @com.intel.drl.spec_ref - * + * Constant for decryption operation mode. + * + * @since Android 1.0 */ public static final int DECRYPT_MODE = 2; /** - * @com.intel.drl.spec_ref - * + * Constant for encryption operation mode. + * + * @since Android 1.0 */ public static final int ENCRYPT_MODE = 1; /** - * @com.intel.drl.spec_ref - * + * Constant indicating that the key to be unwrapped is a private key. + * + * @since Android 1.0 */ public static final int PRIVATE_KEY = 2; /** - * @com.intel.drl.spec_ref - * + * Constant indicating that the key to be unwrapped is a public key. + * + * @since Android 1.0 */ public static final int PUBLIC_KEY = 1; /** - * @com.intel.drl.spec_ref - * + * Constant indicating that the key to be unwrapped is a secret key. + * + * @since Android 1.0 */ public static final int SECRET_KEY = 3; /** - * @com.intel.drl.spec_ref - * + * Constant for key unwrapping operation mode. + * + * @since Android 1.0 */ public static final int UNWRAP_MODE = 4; /** - * @com.intel.drl.spec_ref - * + * Constant for key wrapping operation mode. + * + * @since Android 1.0 */ public static final int WRAP_MODE = 3; @@ -99,12 +124,12 @@ public class Cipher { private static final String SERVICE = "Cipher"; //$NON-NLS-1$ /** - * Used to access common engine functionality + * Used to access common engine functionality. */ private static final Engine engine = new Engine(SERVICE); /** - * The provider + * The provider. */ private Provider provider; @@ -121,8 +146,18 @@ public class Cipher { private static SecureRandom sec_rand; /** - * @com.intel.drl.spec_ref - * + * Creates a new Cipher instance. + * + * @param cipherSpi + * the implementation delegate of the cipher. + * @param provider + * the provider of the implementation of this cipher. + * @param transformation + * the name of the transformation that this cipher performs. + * @throws NullPointerException + * if either cipherSpi is {@code null} or provider is {@code + * null} and {@code cipherSpi} is a {@code NullCipherSpi}. + * @since Android 1.0 */ protected Cipher(CipherSpi cipherSpi, Provider provider, String transformation) { @@ -138,8 +173,23 @@ public class Cipher { } /** - * @com.intel.drl.spec_ref - * + * Creates a new Cipher for the specified transformation. The installed + * providers are searched in order for an implementation of the specified + * transformation. The first found provider providing the transformation is + * used to create the cipher. If no provider is found an exception is + * thrown. + * + * @param transformation + * the name of the transformation to create a cipher for. + * @return a cipher for the requested transformation. + * @throws NoSuchAlgorithmException + * if no installed provider can provide the + * <i>transformation</i>, or it is {@code null}, empty or in an + * invalid format. + * @throws NoSuchPaddingException + * if no installed provider can provide the padding scheme in + * the <i>transformation</i>. + * @since Android 1.0 */ public static final Cipher getInstance(String transformation) throws NoSuchAlgorithmException, NoSuchPaddingException { @@ -147,8 +197,26 @@ public class Cipher { } /** - * @com.intel.drl.spec_ref - * + * Creates a new cipher for the specified transformation provided by the + * specified provider. + * + * @param transformation + * the name of the transformation to create a cipher for. + * @param provider + * the name of the provider to ask for the transformation. + * @return a cipher for the requested transformation. + * @throws NoSuchAlgorithmException + * if the specified provider can not provide the + * <i>transformation</i>, or it is {@code null}, empty or in an + * invalid format. + * @throws NoSuchProviderException + * if no provider with the specified name can be found. + * @throws NoSuchPaddingException + * if the requested padding scheme in the <i>transformation</i> + * is not available. + * @throws IllegalArgumentException + * if the specified provider is {@code null}. + * @since Android 1.0 */ public static final Cipher getInstance(String transformation, String provider) throws NoSuchAlgorithmException, @@ -166,8 +234,23 @@ public class Cipher { } /** - * @com.intel.drl.spec_ref - * + * Creates a new cipher for the specified transformation. + * + * @param transformation + * the name of the transformation to create a cipher for. + * @param provider + * the provider to ask for the transformation. + * @return a cipher for the requested transformation. + * @throws NoSuchAlgorithmException + * if the specified provider can not provide the + * <i>transformation</i>, or it is {@code null}, empty or in an + * invalid format. + * @throws NoSuchPaddingException + * if the requested padding scheme in the <i>transformation</i> + * is not available. + * @throws IllegalArgumentException + * if the provider is {@code null}. + * @since Android 1.0 */ public static final Cipher getInstance(String transformation, Provider provider) throws NoSuchAlgorithmException, @@ -289,32 +372,49 @@ public class Cipher { } /** - * @com.intel.drl.spec_ref - * + * Returns the provider of this cipher instance. + * + * @return the provider of this cipher instance. + * @since Android 1.0 */ public final Provider getProvider() { return provider; } /** - * @com.intel.drl.spec_ref - * + * Returns the name of the algorithm of this cipher instance. + * <p> + * This is the name of the <i>transformation</i> argument used in the + * {@code getInstance} call creating this object. + * </p> + * + * @return the name of the algorithm of this cipher instance. + * @since Android 1.0. */ public final String getAlgorithm() { return transformation; } /** - * @com.intel.drl.spec_ref - * + * Returns this ciphers block size (in bytes). + * + * @return this ciphers block size. + * @since Android 1.0 */ public final int getBlockSize() { return spiImpl.engineGetBlockSize(); } /** - * @com.intel.drl.spec_ref - * + * Returns the length in bytes an output buffer needs to be when this cipher + * is updated with {@code inputLen} bytes. + * + * @param inputLen + * the number of bytes of the input. + * @return the output buffer length for the input length. + * @throws IllegalStateException + * if this cipher instance is in an invalid state. + * @since Android 1.0 */ public final int getOutputSize(int inputLen) { if (mode == 0) { @@ -325,24 +425,36 @@ public class Cipher { } /** - * @com.intel.drl.spec_ref - * + * Returns the <i>initialization vector</i> for this cipher instance. + * + * @return the <i>initialization vector</i> for this cipher instance. + * @since Android 1.0 */ public final byte[] getIV() { return spiImpl.engineGetIV(); } /** - * @com.intel.drl.spec_ref - * + * Returns the parameters that where used to create this cipher instance. + * <p> + * These may be a the same parameters that were used to create this cipher + * instance, or may be a combination of default and random parameters, + * depending on the underlying cipher implementation. + * + * @return the parameters that where used to create this cipher instance, or + * {@code null} if this cipher instance does not have any + * parameters. + * @since Android 1.0 */ public final AlgorithmParameters getParameters() { return spiImpl.engineGetParameters(); } /** - * @com.intel.drl.spec_ref - * + * Returns the exemption mechanism associated with this cipher. + * + * @return currently {@code null} + * @since Android 1.0 */ public final ExemptionMechanism getExemptionMechanism() { //FIXME implement getExemptionMechanism @@ -356,8 +468,33 @@ public class Cipher { } /** - * @com.intel.drl.spec_ref - * + * Initializes this cipher instance with the specified key. + * <p> + * The cipher is initialized for the specified operational mode (one of: + * encryption, decryption, key wrapping or key unwrapping) depending on + * {@code opmode}. + * </p> + * If this cipher instance needs any algorithm parameters or random values + * that the specified key can not provide, the underlying implementation of + * this cipher is supposed to generate the required parameters (using its + * provider or random values). + * <p> + * When a cipher instance is initialized by a call to any of the {@code + * init} methods, the state of the instance is overridden, meaning that it + * is equivalent to creating a new instance and calling its {@code init} + * method. + * </p> + * + * @param opmode + * the operation this cipher instance should be initialized for + * (one of: {@code ENCRYPT_MODE}, {@code DECRYPT_MODE}, {@code + * WRAP_MODE} or {@code UNWRAP_MODE}). + * @param key + * the input key for the operation. + * @throws InvalidKeyException + * if the specified key can not be used to initialize this + * cipher instance. + * @since Android 1.0 */ public final void init(int opmode, Key key) throws InvalidKeyException { if (sec_rand == null) { @@ -370,8 +507,38 @@ public class Cipher { } /** - * @com.intel.drl.spec_ref - * + * Initializes this cipher instance with the specified key and a source of + * randomness. + * <p> + * The cipher is initialized for the specified operational mode (one of: + * encryption, decryption, key wrapping or key unwrapping) depending on + * {@code opmode}. + * </p> + * If this cipher instance needs any algorithm parameters or random values + * that the specified key can not provide, the underlying implementation of + * this cipher is supposed to generate the required parameters (using its + * provider or random values). Random values are generated using {@code + * random}; + * <p> + * When a cipher instance is initialized by a call to any of the {@code + * init} methods, the state of the instance is overridden, means it is + * equivalent to creating a new instance and calling it {@code init} method. + * </p> + * + * @param opmode + * the operation this cipher instance should be initialized for + * (one of: {@code ENCRYPT_MODE}, {@code DECRYPT_MODE}, {@code + * WRAP_MODE} or {@code UNWRAP_MODE}). + * @param key + * the input key for the operation. + * @param random + * the source of randomness to use. + * @throws InvalidKeyException + * if the specified key can not be used to initialize this + * cipher instance. + * @throws InvalidParameterException + * if the specified opmode is invalid. + * @since Android 1.0 */ public final void init(int opmode, Key key, SecureRandom random) throws InvalidKeyException { @@ -387,8 +554,37 @@ public class Cipher { } /** - * @com.intel.drl.spec_ref - * + * Initializes this cipher instance with the specified key and algorithm + * parameters. + * <p> + * The cipher is initialized for the specified operational mode (one of: + * encryption, decryption, key wrapping or key unwrapping). + * </p> + * If this cipher instance needs any algorithm parameters and {@code params} + * is {@code null}, the underlying implementation of this cipher is supposed + * to generate the required parameters (using its provider or random + * values). + * <p> + * When a cipher instance is initialized by a call to any of the {@code + * init} methods, the state of the instance is overridden, means it is + * equivalent to creating a new instance and calling it {@code init} method. + * </p> + * + * @param opmode + * the operation this cipher instance should be initialized for + * (one of: {@code ENCRYPT_MODE}, {@code DECRYPT_MODE}, {@code + * WRAP_MODE} or {@code UNWRAP_MODE}). + * @param key + * the input key for the operation. + * @param params + * the algorithm parameters. + * @throws InvalidKeyException + * if the specified key can not be used to initialize this + * cipher instance. + * @throws InvalidAlgorithmParameterException + * it the specified parameters are inappropriate for this + * cipher. + * @since Android 1.0 */ public final void init(int opmode, Key key, AlgorithmParameterSpec params) throws InvalidKeyException, InvalidAlgorithmParameterException { @@ -399,8 +595,42 @@ public class Cipher { } /** - * @com.intel.drl.spec_ref - * + * Initializes this cipher instance with the specified key, algorithm + * parameters and a source of randomness. + * <p> + * The cipher is initialized for the specified operational mode (one of: + * encryption, decryption, key wrapping or key unwrapping) depending on + * {@code opmode}. + * <p> + * If this cipher instance needs any algorithm parameters and {@code params} + * is {@code null}, the underlying implementation of this cipher is supposed + * to generate the required parameters (using its provider or random + * values). Random values are generated using {@code random}; + * <p> + * When a cipher instance is initialized by a call to any of the {@code + * init} methods, the state of the instance is overridden, meaning that it + * is equivalent to creating a new instance and calling it {@code init} + * method. + * + * @param opmode + * the operation this cipher instance should be initialized for + * (one of: {@code ENCRYPT_MODE}, {@code DECRYPT_MODE}, {@code + * WRAP_MODE} or {@code UNWRAP_MODE}). + * @param key + * the input key for the operation. + * @param params + * the algorithm parameters. + * @param random + * the source of randomness to use. + * @throws InvalidKeyException + * if the specified key can not be used to initialize this + * cipher instance. + * @throws InvalidAlgorithmParameterException + * it the specified parameters are inappropriate for this + * cipher. + * @throws InvalidParameterException + * if the specified {@code opmode} is invalid. + * @since Android 1.0 */ public final void init(int opmode, Key key, AlgorithmParameterSpec params, SecureRandom random) throws InvalidKeyException, @@ -420,8 +650,39 @@ public class Cipher { } /** - * @com.intel.drl.spec_ref - * + * Initializes this cipher instance with the specified key and algorithm + * parameters. + * <p> + * The cipher is initialized for the specified operation (one of: + * encryption, decryption, key wrapping or key unwrapping) depending on + * {@code opmode}. + * </p> + * If this cipher instance needs any algorithm parameters and {@code params} + * is {@code null}, the underlying implementation of this cipher is supposed + * to generate the required parameters (using its provider or random + * values). + * <p> + * When a cipher instance is initialized by a call to any of the {@code + * init} methods, the state of the instance is overridden, meaning that it + * is equivalent to creating a new instance and calling it {@code init} + * method. + * </p> + * + * @param opmode + * the operation this cipher instance should be initialized for + * (one of: {@code ENCRYPT_MODE}, {@code DECRYPT_MODE}, {@code + * WRAP_MODE} or {@code UNWRAP_MODE}). + * @param key + * the input key for the operation. + * @param params + * the algorithm parameters. + * @throws InvalidKeyException + * if the specified key can not be used to initialize this + * cipher instance. + * @throws InvalidAlgorithmParameterException + * it the specified parameters are inappropriate for this + * cipher. + * @since Android 1.0 */ public final void init(int opmode, Key key, AlgorithmParameters params) throws InvalidKeyException, InvalidAlgorithmParameterException { @@ -432,8 +693,42 @@ public class Cipher { } /** - * @com.intel.drl.spec_ref - * + * Initializes this cipher instance with the specified key, algorithm + * parameters and a source of randomness. + * <p> + * The cipher will be initialized for the specified operation (one of: + * encryption, decryption, key wrapping or key unwrapping) depending on + * {@code opmode}. + * </p> + * If this cipher instance needs any algorithm parameters and {@code params} + * is {@code null}, the underlying implementation of this cipher is supposed + * to generate the required parameters (using its provider or random + * values). Random values are generated using {@code random}. + * <p> + * When a cipher instance is initialized by a call to any of the {@code + * init} methods, the state of the instance is overridden, means it is + * equivalent to creating a new instance and calling it {@code init} method. + * </p> + * + * @param opmode + * the operation this cipher instance should be initialized for + * (one of: {@code ENCRYPT_MODE}, {@code DECRYPT_MODE}, {@code + * WRAP_MODE} or {@code UNWRAP_MODE}). + * @param key + * the input key for the operation. + * @param params + * the algorithm parameters. + * @param random + * the source of randomness to use. + * @throws InvalidKeyException + * if the specified key can not be used to initialize this + * cipher instance. + * @throws InvalidAlgorithmParameterException + * if the specified parameters are inappropriate for this + * cipher. + * @throws InvalidParameterException + * if the specified {@code opmode} is invalid. + * @since Android 1.0 */ public final void init(int opmode, Key key, AlgorithmParameters params, SecureRandom random) throws InvalidKeyException, @@ -453,8 +748,37 @@ public class Cipher { } /** - * @com.intel.drl.spec_ref - * + * Initializes this cipher instance with the public key from the specified + * certificate. + * <p> + * The cipher will be initialized for the specified operation (one of: + * encryption, decryption, key wrapping or key unwrapping) depending on + * {@code opmode}. + * <p> + * It the type of the certificate is X.509 and the certificate has a <i>key + * usage</i> extension field marked as critical, the specified {@code + * opmode} has the be enabled for this key, otherwise an {@code + * InvalidKeyException} is thrown. + * <p> + * If this cipher instance needs any algorithm parameters that the key in + * the certificate can not provide, the underlying implementation of this + * cipher is supposed to generate the required parameters (using its + * provider or random values). + * <p> + * When a cipher instance is initialized by a call to any of the {@code + * init} methods, the state of the instance is overridden, means it is + * equivalent to creating a new instance and calling it {@code init} method. + * + * @param opmode + * the operation this cipher instance should be initialized for + * (one of: {@code ENCRYPT_MODE}, {@code DECRYPT_MODE}, {@code + * WRAP_MODE} or {@code UNWRAP_MODE}). + * @param certificate + * the certificate. + * @throws InvalidKeyException + * if the public key in the certificate can not be used to + * initialize this cipher instance. + * @since Android 1.0 */ public final void init(int opmode, Certificate certificate) throws InvalidKeyException { @@ -465,8 +789,40 @@ public class Cipher { } /** - * @com.intel.drl.spec_ref - * + * Initializes this cipher instance with the public key from the specified + * certificate and a source of randomness. + * <p> + * The cipher will be initialized for the specified operation (one of: + * encryption, decryption, key wrapping or key unwrapping) depending on + * {@code opmode}. + * </p> + * It the type of the certificate is X.509 and the certificate has a <i>key + * usage</i> extension field marked as critical, the specified {@code + * opmode} has the be enabled for this key, otherwise an {@code + * InvalidKeyException} is thrown. + * <p> + * If this cipher instance needs any algorithm parameters that the key in + * the certificate can not provide, the underlying implementation of this + * cipher is supposed to generate the required parameters (using its + * provider or random values). Random values are generated using {@code + * random}. + * </p> + * When a cipher instance is initialized by a call to any of the {@code + * init} methods, the state of the instance is overridden, means it is + * equivalent to creating a new instance and calling it {@code init} method. + * + * @param opmode + * the operation this cipher instance should be initialized for + * (one of: {@code ENCRYPT_MODE}, {@code DECRYPT_MODE}, {@code + * WRAP_MODE} or {@code UNWRAP_MODE}). + * @param certificate + * the certificate. + * @param random + * the source of randomness to be used. + * @throws InvalidKeyException + * if the public key in the certificate can not be used to + * initialize this cipher instance. + * @since Android 1.0 */ public final void init(int opmode, Certificate certificate, SecureRandom random) throws InvalidKeyException { @@ -516,8 +872,19 @@ public class Cipher { } /** - * @com.intel.drl.spec_ref - * + * Continues a multi-part transformation (encryption or decryption). The + * transformed bytes are returned. + * + * @param input + * the input bytes to transform. + * @return the transformed bytes in a new buffer, or {@code null} if the + * input has zero length. + * @throws IllegalStateException + * if this cipher instance is not initialized for encryption or + * decryption. + * @throws IllegalArgumentException + * if the input is {@code null}. + * @since Android 1.0 */ public final byte[] update(byte[] input) { if (mode != ENCRYPT_MODE && mode != DECRYPT_MODE) { @@ -534,8 +901,25 @@ public class Cipher { } /** - * @com.intel.drl.spec_ref - * + * Continues a multi-part transformation (encryption or decryption). The + * transformed bytes are returned. + * + * @param input + * the input bytes to transform. + * @param inputOffset + * the offset in the input to start. + * @param inputLen + * the length of the input to transform. + * @return the transformed bytes in a new buffer, or {@code null} if the + * input has zero length. + * @throws IllegalStateException + * if this cipher instance is not initialized for encryption or + * decryption. + * @throws IllegalArgumentException + * if the input is {@code null}, or if {@code inputOffset} and + * {@code inputLen} do not specify a valid chunk in the input + * buffer. + * @since Android 1.0 */ public final byte[] update(byte[] input, int inputOffset, int inputLen) { if (mode != ENCRYPT_MODE && mode != DECRYPT_MODE) { @@ -558,8 +942,34 @@ public class Cipher { } /** - * @com.intel.drl.spec_ref - * + * Continues a multi-part transformation (encryption or decryption). The + * transformed bytes are stored in the {@code output} buffer. + * <p> + * If the size of the {@code output} buffer is too small to hold the result, + * a {@code ShortBufferException} is thrown. Use + * {@link Cipher#getOutputSize getOutputSize} to check for the size of the + * output buffer. + * </p> + * + * @param input + * the input bytes to transform. + * @param inputOffset + * the offset in the input to start. + * @param inputLen + * the length of the input to transform. + * @param output + * the output buffer. + * @return the number of bytes placed in output. + * @throws ShortBufferException + * if the size of the {@code output} buffer is too small. + * @throws IllegalStateException + * if this cipher instance is not initialized for encryption or + * decryption. + * @throws IllegalArgumentException + * if the input is {@code null}, the output is {@code null}, or + * if {@code inputOffset} and {@code inputLen} do not specify a + * valid chunk in the input buffer. + * @since Android 1.0 */ public final int update(byte[] input, int inputOffset, int inputLen, byte[] output) throws ShortBufferException { @@ -567,8 +977,36 @@ public class Cipher { } /** - * @com.intel.drl.spec_ref - * + * Continues a multi-part transformation (encryption or decryption). The + * transformed bytes are stored in the {@code output} buffer. + * <p> + * If the size of the {@code output} buffer is too small to hold the result, + * a {@code ShortBufferException} is thrown. Use + * {@link Cipher#getOutputSize getOutputSize} to check for the size of the + * output buffer. + * </p> + * + * @param input + * the input bytes to transform. + * @param inputOffset + * the offset in the input to start. + * @param inputLen + * the length of the input to transform. + * @param output + * the output buffer. + * @param outputOffset + * the offset in the output buffer. + * @return the number of bytes placed in output. + * @throws ShortBufferException + * if the size of the {@code output} buffer is too small. + * @throws IllegalStateException + * if this cipher instance is not initialized for encryption or + * decryption. + * @throws IllegalArgumentException + * if the input is {@code null}, the output is {@code null}, or + * if {@code inputOffset} and {@code inputLen} do not specify a + * valid chunk in the input buffer. + * @since Android 1.0 */ public final int update(byte[] input, int inputOffset, int inputLen, byte[] output, int outputOffset) throws ShortBufferException { @@ -600,8 +1038,30 @@ public class Cipher { } /** - * @com.intel.drl.spec_ref - * + * Continues a multi-part transformation (encryption or decryption). The + * {@code input.remaining()} bytes starting at {@code input.position()} are + * transformed and stored in the {@code output} buffer. + * <p> + * If the {@code output.remaining()} is too small to hold the transformed + * bytes a {@code ShortBufferException} is thrown. Use + * {@link Cipher#getOutputSize getOutputSize} to check for the size of the + * output buffer. + * </p> + * + * @param input + * the input buffer to transform. + * @param output + * the output buffer to store the result within. + * @return the number of bytes stored in the output buffer. + * @throws ShortBufferException + * if the size of the {@code output} buffer is too small. + * @throws IllegalStateException + * if this cipher instance is not initialized for encryption or + * decryption. + * @throws IllegalArgumentException + * if the input buffer and the output buffer are the identical + * object. + * @since Android 1.0 */ public final int update(ByteBuffer input, ByteBuffer output) throws ShortBufferException { @@ -617,8 +1077,22 @@ public class Cipher { } /** - * @com.intel.drl.spec_ref - * + * Finishes a multi-part transformation (encryption or decryption). + * <p> + * Processes any bytes that may have been buffered in previous {@code + * update} calls. + * </p> + * + * @return the final bytes from the transformation. + * @throws IllegalBlockSizeException + * if the size of the resulting bytes is not a multiple of the + * cipher block size. + * @throws BadPaddingException + * if the padding of the data does not match the padding scheme. + * @throws IllegalStateException + * if this cipher instance is not initialized for encryption or + * decryption. + * @since Android 1.0 */ public final byte[] doFinal() throws IllegalBlockSizeException, BadPaddingException { @@ -630,8 +1104,29 @@ public class Cipher { } /** - * @com.intel.drl.spec_ref - * + * Finishes a multi-part transformation (encryption or decryption). + * <p> + * Processes any bytes that may have been buffered in previous {@code + * update} calls. + * </p> + * The final transformed bytes are stored in the {@code output} buffer. + * + * @param output + * the output buffer. + * @param outputOffset + * the offset in the output buffer. + * @return the number of bytes placed in the output buffer. + * @throws IllegalBlockSizeException + * if the size of the resulting bytes is not a multiple of the + * cipher block size. + * @throws ShortBufferException + * if the size of the {@code output} buffer is too small. + * @throws BadPaddingException + * if the padding of the data does not match the padding scheme. + * @throws IllegalStateException + * if this cipher instance is not initialized for encryption or + * decryption. + * @since Android 1.0 */ public final int doFinal(byte[] output, int outputOffset) throws IllegalBlockSizeException, ShortBufferException, @@ -648,8 +1143,24 @@ public class Cipher { } /** - * @com.intel.drl.spec_ref - * + * Finishes a multi-part transformation (encryption or decryption). + * <p> + * Processes the bytes in {@code input} buffer, and any bytes that have been + * buffered in previous {@code update} calls. + * </p> + * + * @param input + * the input buffer. + * @return the final bytes from the transformation. + * @throws IllegalBlockSizeException + * if the size of the resulting bytes is not a multiple of the + * cipher block size. + * @throws BadPaddingException + * if the padding of the data does not match the padding scheme. + * @throws IllegalStateException + * if this cipher instance is not initialized for encryption or + * decryption. + * @since Android 1.0 */ public final byte[] doFinal(byte[] input) throws IllegalBlockSizeException, BadPaddingException { @@ -661,8 +1172,31 @@ public class Cipher { } /** - * @com.intel.drl.spec_ref - * + * Finishes a multi-part transformation (encryption or decryption). + * <p> + * Processes the {@code inputLen} bytes in {@code input} buffer at {@code + * inputOffset}, and any bytes that have been buffered in previous {@code + * update} calls. + * + * @param input + * the input buffer. + * @param inputOffset + * the offset in the input buffer. + * @param inputLen + * the length of the input + * @return the final bytes from the transformation. + * @throws IllegalBlockSizeException + * if the size of the resulting bytes is not a multiple of the + * cipher block size. + * @throws BadPaddingException + * if the padding of the data does not match the padding scheme. + * @throws IllegalStateException + * if this cipher instance is not initialized for encryption or + * decryption. + * @throws IllegalArgumentException + * if {@code inputOffset} and {@code inputLen} do not specify an + * valid chunk in the input buffer. + * @since Android 1.0 */ public final byte[] doFinal(byte[] input, int inputOffset, int inputLen) throws IllegalBlockSizeException, BadPaddingException { @@ -679,8 +1213,35 @@ public class Cipher { } /** - * @com.intel.drl.spec_ref - * + * Finishes a multi-part transformation (encryption or decryption). + * <p> + * Processes the {@code inputLen} bytes in {@code input} buffer at {@code + * inputOffset}, and any bytes that have been buffered in previous {@code + * update} calls. + * + * @param input + * the input buffer. + * @param inputOffset + * the offset in the input buffer. + * @param inputLen + * the length of the input. + * @param output + * the output buffer for the transformed bytes. + * @return the number of bytes placed in the output buffer. + * @throws ShortBufferException + * if the size of the {@code output} buffer is too small. + * @throws IllegalBlockSizeException + * if the size of the resulting bytes is not a multiple of the + * cipher block size. + * @throws BadPaddingException + * if the padding of the data does not match the padding scheme. + * @throws IllegalStateException + * if this cipher instance is not initialized for encryption or + * decryption. + * @throws IllegalArgumentException + * if {@code inputOffset} and {@code inputLen} do not specify an + * valid chunk in the input buffer. + * @since Android 1.0 */ public final int doFinal(byte[] input, int inputOffset, int inputLen, byte[] output) throws ShortBufferException, @@ -689,8 +1250,38 @@ public class Cipher { } /** - * @com.intel.drl.spec_ref - * + * Finishes a multi-part transformation (encryption or decryption). + * <p> + * Processes the {@code inputLen} bytes in {@code input} buffer at {@code + * inputOffset}, and any bytes that have been buffered in previous {@code + * update} calls. + * </p> + * + * @param input + * the input buffer. + * @param inputOffset + * the offset in the input buffer. + * @param inputLen + * the length of the input. + * @param output + * the output buffer for the transformed bytes. + * @param outputOffset + * the offset in the output buffer. + * @return the number of bytes placed in the output buffer. + * @throws ShortBufferException + * if the size of the {@code output} buffer is too small. + * @throws IllegalBlockSizeException + * if the size of the resulting bytes is not a multiple of the + * cipher block size. + * @throws BadPaddingException + * if the padding of the data does not match the padding scheme. + * @throws IllegalStateException + * if this cipher instance is not initialized for encryption or + * decryption. + * @throws IllegalArgumentException + * if {@code inputOffset} and {@code inputLen} do not specify an + * valid chunk in the input buffer. + * @since Android 1.0 */ public final int doFinal(byte[] input, int inputOffset, int inputLen, byte[] output, int outputOffset) throws ShortBufferException, @@ -709,8 +1300,33 @@ public class Cipher { } /** - * @com.intel.drl.spec_ref - * + * Finishes a multi-part transformation (encryption or decryption). + * <p> + * Processes the {@code input.remaining()} bytes in {@code input} buffer at + * {@code input.position()}, and any bytes that have been buffered in + * previous {@code update} calls. The transformed bytes are placed into + * {@code output} buffer. + * </p> + * + * @param input + * the input buffer. + * @param output + * the output buffer. + * @return the number of bytes placed into the output buffer. + * @throws ShortBufferException + * if the size of the {@code output} buffer is too small. + * @throws IllegalBlockSizeException + * if the size of the resulting bytes is not a multiple of the + * cipher block size. + * @throws BadPaddingException + * if the padding of the data does not match the padding scheme. + * @throws IllegalArgumentException + * if the input buffer and the output buffer are the same + * object. + * @throws IllegalStateException + * if this cipher instance is not initialized for encryption or + * decryption. + * @since Android 1.0 */ public final int doFinal(ByteBuffer input, ByteBuffer output) throws ShortBufferException, IllegalBlockSizeException, @@ -727,8 +1343,19 @@ public class Cipher { } /** - * @com.intel.drl.spec_ref - * + * Wraps a key using this cipher instance. + * + * @param key + * the key to wrap. + * @return the wrapped key. + * @throws IllegalBlockSizeException + * if the size of the resulting bytes is not a multiple of the + * cipher block size. + * @throws InvalidKeyException + * if this cipher instance can not wrap this key. + * @throws IllegalStateException + * if this cipher instance is not initialized for wrapping. + * @since Android 1.0 */ public final byte[] wrap(Key key) throws IllegalBlockSizeException, InvalidKeyException { @@ -740,8 +1367,26 @@ public class Cipher { } /** - * @com.intel.drl.spec_ref - * + * Unwraps a key using this cipher instance. + * + * @param wrappedKey + * the wrapped key to unwrap. + * @param wrappedKeyAlgorithm + * the algorithm for the wrapped key. + * @param wrappedKeyType + * the type of the wrapped key (one of: {@code SECRET_KEY + * <code>, <code>PRIVATE_KEY} or {@code PUBLIC_KEY}) + * @return the unwrapped key + * @throws InvalidKeyException + * if the {@code wrappedKey} can not be unwrapped to a key of + * type {@code wrappedKeyType} for the {@code + * wrappedKeyAlgorithm}. + * @throws NoSuchAlgorithmException + * if no provider can be found that can create a key of type + * {@code wrappedKeyType} for the {@code wrappedKeyAlgorithm}. + * @throws IllegalStateException + * if this cipher instance is not initialized for unwrapping. + * @since Android 1.0 */ public final Key unwrap(byte[] wrappedKey, String wrappedKeyAlgorithm, int wrappedKeyType) throws InvalidKeyException, @@ -755,8 +1400,17 @@ public class Cipher { } /** - * @com.intel.drl.spec_ref - * + * Returns the maximum key length for the specified transformation. + * + * @param transformation + * the transformation name. + * @return the maximum key length, currently {@code Integer.MAX_VALUE}. + * @throws NoSuchAlgorithmException + * if no provider for the specified {@code transformation} can + * be found. + * @throws NullPointerException + * if {@code transformation} is {@code null}. + * @since Android 1.0 */ public static final int getMaxAllowedKeyLength(String transformation) throws NoSuchAlgorithmException { @@ -769,8 +1423,19 @@ public class Cipher { } /** - * @com.intel.drl.spec_ref - * + * Returns the maximum cipher parameter value for the specified + * transformation. If there is no maximum limit, {@code null} is returned. + * + * @param transformation + * the transformation name. + * @return a parameter spec holding the maximum value or {@code null}. + * Currently {@code null}. + * @throws NoSuchAlgorithmException + * if no provider for the specified {@code transformation} can + * be found. + * @throws NullPointerException + * if {@code transformation} is {@code null}. + * @since Android 1.0 */ public static final AlgorithmParameterSpec getMaxAllowedParameterSpec( String transformation) throws NoSuchAlgorithmException { diff --git a/crypto/src/main/java/javax/crypto/CipherInputStream.java b/crypto/src/main/java/javax/crypto/CipherInputStream.java index a9258ed..ca64c49 100644 --- a/crypto/src/main/java/javax/crypto/CipherInputStream.java +++ b/crypto/src/main/java/javax/crypto/CipherInputStream.java @@ -15,11 +15,6 @@ * limitations under the License. */ -/** -* @author Alexander Y. Kleymenov -* @version $Revision$ -*/ - package javax.crypto; import java.io.FilterInputStream; @@ -29,7 +24,17 @@ import javax.crypto.NullCipher; import java.security.GeneralSecurityException; /** - * @com.intel.drl.spec_ref + * This class wraps an {@code InputStream} and a cipher so that {@code read()} + * methods return data that are read from the underlying {@code InputStream} and + * processed by the cipher. + * <p> + * The cipher must be initialized for the requested operation before being used + * by a {@code CipherInputStream}. For example, if a cipher initialized for + * decryption is used with a {@code CipherInputStream}, the {@code + * CipherInputStream} tries to read the data an decrypt them before returning. + * </p> + * + * @since Android 1.0 */ public class CipherInputStream extends FilterInputStream { @@ -41,7 +46,14 @@ public class CipherInputStream extends FilterInputStream { private boolean finished; /** - * @com.intel.drl.spec_ref + * Creates a new {@code CipherInputStream} instance for an {@code + * InputStream} and a cipher. + * + * @param is + * the input stream to read data from. + * @param c + * the cipher to process the data with. + * @since Android 1.0 */ public CipherInputStream(InputStream is, Cipher c) { super(is); @@ -49,14 +61,27 @@ public class CipherInputStream extends FilterInputStream { } /** - * @com.intel.drl.spec_ref + * Creates a new {@code CipherInputStream} instance for an {@code + * InputStream} without a cipher. + * <p> + * A {@code NullCipher} is created and used to process the data. + * </p> + * + * @param is + * the input stream to read data from. + * @since Android 1.0 */ protected CipherInputStream(InputStream is) { this(is, new NullCipher()); } /** - * @com.intel.drl.spec_ref + * Reads the next byte from this cipher input stream. + * + * @return the next byte, or {@code -1} if the end of the stream is reached. + * @throws IOException + * if an error occurs. + * @since Android 1.0 */ @Override public int read() throws IOException { @@ -87,7 +112,16 @@ public class CipherInputStream extends FilterInputStream { } /** - * @com.intel.drl.spec_ref + * Reads the next {@code b.length} bytes from this input stream into buffer + * {@code b}. + * + * @param b + * the buffer to be filled with data. + * @return the number of bytes filled into buffer {@code b}, or {@code -1} + * if the end of the stream is reached. + * @throws IOException + * if an error occurs. + * @since Android 1.0 */ @Override public int read(byte[] b) throws IOException { @@ -95,7 +129,26 @@ public class CipherInputStream extends FilterInputStream { } /** - * @com.intel.drl.spec_ref + * Reads the next {@code len} bytes from this input stream into buffer + * {@code b} starting at offset {@code off}. + * <p> + * if {@code b} is {@code null}, the next {@code len} bytes are read and + * discarded. + * </p> + * + * @param b + * the buffer to be filled with data. + * @param off + * the offset to start in the buffer. + * @param len + * the maximum number of bytes to read. + * @return the number of bytes filled into buffer {@code b}, or {@code -1} + * of the of the stream is reached. + * @throws IOException + * if an error occurs. + * @throws NullPointerException + * if the underlying input stream is {@code null}. + * @since Android 1.0 */ @Override public int read(byte[] b, int off, int len) throws IOException { @@ -117,7 +170,20 @@ public class CipherInputStream extends FilterInputStream { } /** - * @com.intel.drl.spec_ref + * Skips up to n bytes from this input stream. + * <p> + * The number of bytes skipped depends on the result of a call to + * {@link CipherInputStream#available() available}. The smaller of n and the + * result are the number of bytes being skipped. + * </p> + * Skipping is (currently) not supported in Android. + * + * @param n + * the number of bytes that should be skipped. + * @return the number of bytes actually skipped. + * @throws IOException + * if an error occurs + * @since Android 1.0 */ @Override public long skip(long n) throws IOException { @@ -133,7 +199,13 @@ public class CipherInputStream extends FilterInputStream { } /** - * @com.intel.drl.spec_ref + * Returns the number of bytes available without blocking. It (currently) + * always returns {@code 0} in Android. + * + * @return the number of bytes available, currently zero. + * @throws IOException + * if an error occurs + * @since Android 1.0 */ @Override public int available() throws IOException { @@ -141,7 +213,12 @@ public class CipherInputStream extends FilterInputStream { } /** - * @com.intel.drl.spec_ref + * Closes this {@code CipherInputStream}, also closes the underlying input + * stream and call {@code doFinal} on the cipher object. + * + * @throws IOException + * if an error occurs. + * @since Android 1.0 */ @Override public void close() throws IOException { @@ -155,11 +232,15 @@ public class CipherInputStream extends FilterInputStream { } /** - * @com.intel.drl.spec_ref + * Returns whether this input stream supports {@code mark} and {@code reset} + * , which it does not. + * + * @return false, since this input stream does not support {@code mark} and + * {@code reset}. + * @since Android 1.0 */ @Override public boolean markSupported() { return false; } } - diff --git a/crypto/src/main/java/javax/crypto/CipherOutputStream.java b/crypto/src/main/java/javax/crypto/CipherOutputStream.java index 739d185..8bce42b 100644 --- a/crypto/src/main/java/javax/crypto/CipherOutputStream.java +++ b/crypto/src/main/java/javax/crypto/CipherOutputStream.java @@ -15,11 +15,6 @@ * limitations under the License. */ -/** -* @author Alexander Y. Kleymenov -* @version $Revision$ -*/ - package javax.crypto; import java.io.FilterOutputStream; @@ -28,7 +23,17 @@ import java.io.OutputStream; import javax.crypto.NullCipher; /** - * @com.intel.drl.spec_ref + * This class wraps an output stream and a cipher so that {@code write} methods + * send the data through the cipher before writing them to the underlying output + * stream. + * <p> + * The cipher must be initialized for the requested operation before being used + * by a {@code CipherOutputStream}. For example, if a cipher initialized for + * encryption is used with a {@code CipherOutputStream}, the {@code + * CipherOutputStream} tries to encrypt the data writing it out. + * </p> + * + * @since Android 1.0 */ public class CipherOutputStream extends FilterOutputStream { @@ -36,7 +41,14 @@ public class CipherOutputStream extends FilterOutputStream { private final byte[] arr = new byte[1]; /** - * @com.intel.drl.spec_ref + * Creates a new {@code CipherOutputStream} instance for an {@code + * OutputStream} and a {@code Cipher}. + * + * @param os + * the output stream to write data to. + * @param c + * the cipher to process the data with. + * @since Android 1.0 */ public CipherOutputStream(OutputStream os, Cipher c) { super(os); @@ -44,14 +56,28 @@ public class CipherOutputStream extends FilterOutputStream { } /** - * @com.intel.drl.spec_ref + * Creates a new {@code CipherOutputStream} instance for an {@code + * OutputStream} without a cipher. + * <p> + * A {@code NullCipher} is created to process the data. + * </p> + * + * @param os + * the output stream to write the data to. + * @since Android 1.0 */ protected CipherOutputStream(OutputStream os) { this(os, new NullCipher()); } /** - * @com.intel.drl.spec_ref + * Writes the single byte to this cipher output stream. + * + * @param b + * the byte to write. + * @throws IOException + * if an error occurs. + * @since Android 1.0 */ @Override public void write(int b) throws IOException { @@ -64,7 +90,13 @@ public class CipherOutputStream extends FilterOutputStream { } /** - * @com.intel.drl.spec_ref + * Writes the buffer of bytes to this cipher output stream. + * + * @param b + * the buffer of bytes. + * @throws IOException + * if an error occurs. + * @since Android 1.0 */ @Override public void write(byte[] b) throws IOException { @@ -72,7 +104,18 @@ public class CipherOutputStream extends FilterOutputStream { } /** - * @com.intel.drl.spec_ref + * Writes the {@code len} bytes from buffer {@code b} starting at offset + * {@code off} to this cipher output stream. + * + * @param b + * the buffer. + * @param off + * the offset to start at. + * @param len + * the number of bytes. + * @throws IOException + * if an error occurs. + * @since Android 1.0 */ @Override public void write(byte[] b, int off, int len) throws IOException { @@ -86,7 +129,10 @@ public class CipherOutputStream extends FilterOutputStream { } /** - * @com.intel.drl.spec_ref + * Flushes this cipher output stream. + * + * @throws IOException + * if an error occurs */ @Override public void flush() throws IOException { @@ -94,7 +140,14 @@ public class CipherOutputStream extends FilterOutputStream { } /** - * @com.intel.drl.spec_ref + * Close this cipher output stream. + * <p> + * On the underlying cipher {@code doFinal} will be invoked, and any + * buffered bytes from the cipher are also written out, and the cipher is + * reset to its initial state. The underlying output stream is also closed. + * + * @throws IOException + * if an error occurs. */ @Override public void close() throws IOException { @@ -120,4 +173,3 @@ public class CipherOutputStream extends FilterOutputStream { } } } - diff --git a/crypto/src/main/java/javax/crypto/CipherSpi.java b/crypto/src/main/java/javax/crypto/CipherSpi.java index 186b23b..f6da929 100644 --- a/crypto/src/main/java/javax/crypto/CipherSpi.java +++ b/crypto/src/main/java/javax/crypto/CipherSpi.java @@ -15,11 +15,6 @@ * limitations under the License. */ -/** -* @author Vera Y. Petrashkova -* @version $Revision$ -*/ - package javax.crypto; import java.security.AlgorithmParameters; @@ -34,98 +29,329 @@ import java.nio.ByteBuffer; import org.apache.harmony.crypto.internal.nls.Messages; /** - * @com.intel.drl.spec_ref + * This class defines the <i>Service Provider Interface</i> (<b>SPI</b>) for + * cryptographic ciphers. + * <p> + * Implementers of cryptographic ciphers must implement all the abstract methods + * for every cipher they implement. {@code CipherSpi} instances are created + * along with ciphers when the {@link Cipher#getInstance} method is called. A + * {@code Cipher} is referenced by a <i>transformation</i>, which is a string + * that describes the operation (or set of operations), always consisting of the + * cipher's name and optionally followed by a mode and a padding, in the form: + * <ul> + * <li>"algorithm"</li>or + * <li>"algorithm/mode/padding"</li> + * </ul> + * The following behavior should be implemented for obtaining {@code Cipher} + * instances. + * </p> + * When one of the {@link Cipher#getInstance} factory methods is called with a + * <i>transformation</i> that is only an <i>algorithm</i>, check if the provider + * defines a {@code CipherSpi} for "algorithm", if so: return it, otherwise + * throw a {@link NoSuchAlgorithmException}. + * <p> + * The following rules apply when a <i>transformation</i> is of the form + * "algorithm/mode/padding": + * <ul> + * 1. The Provider has a {@code CipherSpi} subclass registered for + * "algorithm/mode/padding": return it, otherwise go to step 2. + * </ul> + * <ul> + * 2. The Provider has a {@code CipherSpi} subclass registered for + * "algorithm/mode": instantiate it, call + * {@link CipherSpi#engineSetPadding(String) engineSetPadding(String)} for the + * padding name and return it, otherwise go to step 3. + * </ul> + * <ul> + * 3. The Provider has a {@code CipherSpi} subclass registered for + * "algorithm//padding": instantiate it, call + * {@link CipherSpi#engineSetMode(String) engineSetMode(String)} for the mode + * name and return it, otherwise go to step 4. + * </ul> + * <ul> + * 4. The Provider has a {@code CipherSpi} subclass registered for "algorithm": + * instantiate it, call {@link CipherSpi#engineSetMode(String) + * engineSetMode(String)} for the mode name , call + * {@link CipherSpi#engineSetPadding(String) engineSetPadding(String)} for the + * padding name and return it, otherwise throw a + * {@link NoSuchAlgorithmException}. + * </ul> + * </p> * + * @see Cipher + * @since Android 1.0 */ - public abstract class CipherSpi { /** - * @com.intel.drl.spec_ref - * + * Creates a new {@code CipherSpi} instance. + * + * @since Android 1.0 */ public CipherSpi() { } /** - * @com.intel.drl.spec_ref - * + * Sets the mode for this cipher. + * + * @param mode + * the name of the cipher mode. + * @throws NoSuchAlgorithmException + * if the specified cipher mode is not supported by this + * provider. + * @since Android 1.0 */ protected abstract void engineSetMode(String mode) throws NoSuchAlgorithmException; /** - * @com.intel.drl.spec_ref - * + * Sets the padding method for this cipher. + * + * @param padding + * the name of the padding method. + * @throws NoSuchPaddingException + * if the specified padding method is not supported by this + * cipher. + * @since Android 1.0 */ protected abstract void engineSetPadding(String padding) throws NoSuchPaddingException; /** - * @com.intel.drl.spec_ref - * + * Returns the block size of this cipher (in bytes) + * + * @return the block size of this cipher, or zero if this cipher is not a + * block cipher. + * @since Android 1.0 */ protected abstract int engineGetBlockSize(); /** - * @com.intel.drl.spec_ref - * + * Returns the size for a buffer (in bytes), that the next call to {@code + * update} of {@code doFinal} would return, taking into account any buffered + * data from previous {@code update} calls and padding. + * <p> + * The actual output length of the next call to {@code update} or {@code + * doFinal} may be smaller than the length returned by this method. + * </p> + * + * @param inputLen + * the length of the input (in bytes). + * @return the size for a buffer (in bytes). + * @since Android 1.0 */ protected abstract int engineGetOutputSize(int inputLen); /** - * @com.intel.drl.spec_ref - * + * Returns the Initialization Vector (IV) that was used to initialize this + * cipher or {@code null} if none was used. + * + * @return the Initialization Vector (IV), or {@code null} if none was used. + * @since Android 1.0 */ protected abstract byte[] engineGetIV(); /** - * @com.intel.drl.spec_ref - * + * Returns the parameters that where used to create this cipher instance. + * <p> + * These may be a the same parameters that were used to create this cipher + * instance, or may be a combination of default and random parameters, + * depending on the underlying cipher implementation. + * </p> + * + * @return the parameters that where used to create this cipher instance, or + * {@code null} if this cipher instance does not have any parameters + * at all. + * @since Android 1.0 */ protected abstract AlgorithmParameters engineGetParameters(); /** - * @com.intel.drl.spec_ref - * + * Initializes this cipher instance with the specified key and a source of + * randomness. + * <p> + * The cipher will be initialized for the specified operation (one of: + * encryption, decryption, key wrapping or key unwrapping) depending on + * {@code opmode}. + * </p> + * If this cipher instance needs any algorithm parameters or random values + * that the specified key cannot provide, the underlying implementation of + * this cipher is supposed to generate the required parameters (using its + * provider or random values). Random values will be generated using {@code + * random}; + * <p> + * When a cipher instance is initialized by a call to any of the {@code + * init} methods, the state of the instance is overridden, means it is + * equivalent to creating a new instance and calling it {@code init} method. + * </p> + * + * @param opmode + * the operation this cipher instance should be initialized for + * (one of: {@code ENCRYPT_MODE}, {@code DECRYPT_MODE}, {@code + * WRAP_MODE} or {@code UNWRAP_MODE}). + * @param key + * the input key for the operation. + * @param random + * the source of randomness to use. + * @throws InvalidKeyException + * if the specified key cannot be used to initialize this cipher + * instance. + * @since Android 1.0 */ protected abstract void engineInit(int opmode, Key key, SecureRandom random) throws InvalidKeyException; /** - * @com.intel.drl.spec_ref - * + * Initializes this cipher instance with the specified key, algorithm + * parameters and a source of randomness. + * <p> + * The cipher will be initialized for the specified operation (one of: + * encryption, decryption, key wrapping or key unwrapping) depending on + * {@code opmode}. + * </p> + * If this cipher instance needs any algorithm parameters and {@code params} + * is {@code null}, the underlying implementation of this cipher is supposed + * to generate the required parameters (using its provider or random + * values). Random values are generated using {@code random}. + * <p> + * When a cipher instance is initialized by a call to any of the {@code + * init} methods, the state of the instance is overridden, means it is + * equivalent to creating a new instance and calling it {@code init} method. + * </p> + * + * @param opmode + * the operation this cipher instance should be initialized for + * (one of: {@code ENCRYPT_MODE}, {@code DECRYPT_MODE}, {@code + * WRAP_MODE} or {@code UNWRAP_MODE}). + * @param key + * the input key for the operation. + * @param params + * the algorithm parameters. + * @param random + * the source of randomness to use. + * @throws InvalidKeyException + * if the specified key cannot be used to initialize this cipher + * instance. + * @throws InvalidAlgorithmParameterException + * it the specified parameters are inappropriate for this + * cipher. + * @since Android 1.0 */ protected abstract void engineInit(int opmode, Key key, AlgorithmParameterSpec params, SecureRandom random) throws InvalidKeyException, InvalidAlgorithmParameterException; /** - * @com.intel.drl.spec_ref - * + * Initializes this cipher instance with the specified key, algorithm + * parameters and a source of randomness. + * <p> + * The cipher will be initialized for the specified operation (one of: + * encryption, decryption, key wrapping or key unwrapping) depending on + * {@code opmode}. + * </p> + * If this cipher instance needs any algorithm parameters and {@code params} + * is {@code null}, the underlying implementation of this cipher is supposed + * to generate the required parameters (using its provider or random + * values). Random values are generated using {@code random}. + * <p> + * When a cipher instance is initialized by a call to any of the {@code + * init} methods, the state of the instance is overridden, means it is + * equivalent to creating a new instance and calling it {@code init} method. + * </p> + * + * @param opmode + * the operation this cipher instance should be initialized for + * (one of: {@code ENCRYPT_MODE}, {@code DECRYPT_MODE}, {@code + * WRAP_MODE} or {@code UNWRAP_MODE}). + * @param key + * the input key for the operation. + * @param params + * the algorithm parameters. + * @param random + * the source of randomness to use. + * @throws InvalidKeyException + * if the specified key cannot be used to initialize this cipher + * instance. + * @throws InvalidAlgorithmParameterException + * if the specified parameters are inappropriate for this + * cipher. + * @since Android 1.0 */ protected abstract void engineInit(int opmode, Key key, AlgorithmParameters params, SecureRandom random) throws InvalidKeyException, InvalidAlgorithmParameterException; /** - * @com.intel.drl.spec_ref - * + * Continues a multi-part transformation (encryption or decryption). The + * transformed bytes are returned. + * + * @param input + * the input bytes to transform. + * @param inputOffset + * the offset in the input to start. + * @param inputLen + * the length of the input to transform. + * @return the transformed bytes in a new buffer, or {@code null} if the + * input has zero length. + * @throws IllegalStateException + * if this cipher instance is not initialized for encryption or + * decryption. + * @throws IllegalArgumentException + * if the input is null, or if {@code inputOffset} and {@code + * inputLen} do not specify a valid chunk in the input buffer. + * @since Android 1.0 */ protected abstract byte[] engineUpdate(byte[] input, int inputOffset, int inputLen); /** - * @com.intel.drl.spec_ref - * + * Continues a multi-part transformation (encryption or decryption). The + * transformed bytes are stored in the {@code output} buffer. + * <p> + * If the size of the {@code output} buffer is too small to hold the result, + * a {@code ShortBufferException} is thrown. Use + * {@link Cipher#getOutputSize getOutputSize} to check for the size of the + * output buffer. + * </p> + * + * @param input + * the input bytes to transform. + * @param inputOffset + * the offset in the input to start. + * @param inputLen + * the length of the input to transform. + * @param output + * the output buffer. + * @param outputOffset + * the offset in the output buffer. + * @return the number of bytes placed in output. + * @throws ShortBufferException + * if the size of the {@code output} buffer is too small. + * @since Android 1.0 */ protected abstract int engineUpdate(byte[] input, int inputOffset, int inputLen, byte[] output, int outputOffset) throws ShortBufferException; /** - * @com.intel.drl.spec_ref - * + * Continues a multi-part transformation (encryption or decryption). The + * {@code input.remaining()} bytes starting at {@code input.position()} are + * transformed and stored in the {@code output} buffer. + * <p> + * If the {@code output.remaining()} is too small to hold the transformed + * bytes a {@code ShortBufferException} is thrown. Use + * {@link Cipher#getOutputSize getOutputSize} to check for the size of the + * output buffer. + * </p> + * + * @param input + * the input buffer to transform. + * @param output + * the output buffer to store the result within. + * @return the number of bytes stored in the output buffer. + * @throws ShortBufferException + * if the size of the {@code output} buffer is too small. + * @since Android 1.0 */ protected int engineUpdate(ByteBuffer input, ByteBuffer output) throws ShortBufferException { @@ -164,15 +390,57 @@ public abstract class CipherSpi { } /** - * @com.intel.drl.spec_ref - * + * Finishes a multi-part transformation (encryption or decryption). + * <p> + * Processes the {@code inputLen} bytes in {@code input} buffer at {@code + * inputOffset}, and any bytes that have been buffered in previous {@code + * update} calls. + * </p> + * + * @param input + * the input buffer. + * @param inputOffset + * the offset in the input buffer. + * @param inputLen + * the length of the input. + * @return the final bytes from the transformation. + * @throws IllegalBlockSizeException + * if the size of the resulting bytes is not a multiple of the + * cipher block size. + * @throws BadPaddingException + * if the padding of the data does not match the padding scheme. + * @since Android 1.0 */ protected abstract byte[] engineDoFinal(byte[] input, int inputOffset, int inputLen) throws IllegalBlockSizeException, BadPaddingException; /** - * @com.intel.drl.spec_ref - * + * Finishes a multi-part transformation (encryption or decryption). + * <p> + * Processes the {@code inputLen} bytes in {@code input} buffer at + * {@code inputOffset}, and any bytes that have been buffered in previous + * {@code update} calls. + * </p> + * + * @param input + * the input buffer. + * @param inputOffset + * the offset in the input buffer. + * @param inputLen + * the length of the input. + * @param output + * the output buffer for the transformed bytes. + * @param outputOffset + * the offset in the output buffer. + * @return the number of bytes placed in the output buffer. + * @throws ShortBufferException + * if the size of the {@code output} buffer is too small. + * @throws IllegalBlockSizeException + * if the size of the resulting bytes is not a multiple of the + * cipher block size. + * @throws BadPaddingException + * if the padding of the data does not match the padding scheme. + * @since Android 1.0 */ protected abstract int engineDoFinal(byte[] input, int inputOffset, int inputLen, byte[] output, int outputOffset) @@ -180,8 +448,32 @@ public abstract class CipherSpi { BadPaddingException; /** - * @com.intel.drl.spec_ref - * + * Finishes a multi-part transformation (encryption or decryption). + * <p> + * Processes the {@code input.remaining()} bytes in {@code input} buffer at + * {@code input.position()}, and any bytes that have been buffered in + * previous {@code update} calls. The transformed bytes are placed into + * {@code output} buffer. + * </p> + * + * @param input + * the input buffer. + * @param output + * the output buffer. + * @return the number of bytes placed into the output buffer. + * @throws ShortBufferException + * if the size of the {@code output} buffer is too small. + * @throws IllegalBlockSizeException + * if the size of the resulting bytes is not a multiple of the + * cipher block size. + * @throws BadPaddingException + * if the padding of the data does not match the padding scheme. + * @throws IllegalArgumentException + * if the input buffer and the output buffer are the same + * object. + * @throws IllegalStateException + * if this cipher instance is not initialized for encryption or + * decryption. */ protected int engineDoFinal(ByteBuffer input, ByteBuffer output) throws ShortBufferException, IllegalBlockSizeException, @@ -223,8 +515,20 @@ public abstract class CipherSpi { } /** - * @com.intel.drl.spec_ref - * + * Wraps a key using this cipher instance. This method has been added to + * this class (for backwards compatibility, it cannot be abstract). If this + * method is not overridden, it throws an {@code + * UnsupportedOperationException}. + * + * @param key + * the key to wrap. + * @return the wrapped key + * @throws IllegalBlockSizeException + * if the size of the resulting bytes is not a multiple of the + * cipher block size. + * @throws InvalidKeyException + * if this cipher instance cannot wrap this key. + * @since Android 1.0 */ protected byte[] engineWrap(Key key) throws IllegalBlockSizeException, InvalidKeyException { @@ -233,8 +537,29 @@ public abstract class CipherSpi { } /** - * @com.intel.drl.spec_ref - * + * Unwraps a key using this cipher instance. + * <p> + * This method has been added to this class (for backwards compatibility, it + * cannot be abstract). If this method is not overridden, it throws an + * {@code UnsupportedOperationException}. + * </p> + * + * @param wrappedKey + * the wrapped key to unwrap. + * @param wrappedKeyAlgorithm + * the algorithm for the wrapped key. + * @param wrappedKeyType + * the type of the wrapped key (one of: {@code SECRET_KEY}, + * {@code PRIVATE_KEY} or {@code PUBLIC_KEY}) + * @return the unwrapped key. + * @throws InvalidKeyException + * if the {@code wrappedKey} cannot be unwrapped to a key of + * type {@code wrappedKeyType} for the {@code + * wrappedKeyAlgorithm}. + * @throws NoSuchAlgorithmException + * if no provider can be found that can create a key of type + * {@code wrappedKeyType} for the {@code wrappedKeyAlgorithm}. + * @since Android 1.0 */ protected Key engineUnwrap(byte[] wrappedKey, String wrappedKeyAlgorithm, int wrappedKeyType) throws InvalidKeyException, @@ -244,11 +569,21 @@ public abstract class CipherSpi { } /** - * @com.intel.drl.spec_ref - * + * Returns the size of a specified key object in bits. This method has been + * added to this class (for backwards compatibility, it cannot be abstract). + * If this method is not overridden, it throws an {@code + * UnsupportedOperationException}. + * + * @param key + * the key to get the size for. + * @return the size of a specified key object in bits. + * @throws InvalidKeyException + * if the size of the key cannot be determined by this + * implementation. + * @since Android 1.0 */ protected int engineGetKeySize(Key key) throws InvalidKeyException { throw new UnsupportedOperationException( Messages.getString("crypto.12")); //$NON-NLS-1$ } -}
\ No newline at end of file +} diff --git a/crypto/src/main/java/javax/crypto/EncryptedPrivateKeyInfo.java b/crypto/src/main/java/javax/crypto/EncryptedPrivateKeyInfo.java index 2887794..301cd49 100644 --- a/crypto/src/main/java/javax/crypto/EncryptedPrivateKeyInfo.java +++ b/crypto/src/main/java/javax/crypto/EncryptedPrivateKeyInfo.java @@ -15,11 +15,6 @@ * limitations under the License. */ -/** -* @author Vladimir N. Molotkov, Stepan M. Mishura -* @version $Revision$ -*/ - package javax.crypto; import java.io.IOException; @@ -46,7 +41,24 @@ import org.apache.harmony.security.x509.AlgorithmIdentifier; /** - * @com.intel.drl.spec_ref + * This class implements the {@code EncryptedPrivateKeyInfo} ASN.1 type as + * specified in <a href="http://www.ietf.org/rfc/rfc5208.txt">PKCS + * #8 - Private-Key Information Syntax Standard</a>. + * <p> + * The definition of ASN.1 is as follows: + * </p> + * <dl> + * EncryptedPrivateKeyInfo ::= SEQUENCE { + * <dd>encryptionAlgorithm AlgorithmIdentifier,</dd> + * <dd>encryptedData OCTET STRING }</dd> + * </dl> + * <dl> + * AlgorithmIdentifier ::= SEQUENCE { + * <dd>algorithm OBJECT IDENTIFIER,</dd> + * <dd>parameters ANY DEFINED BY algorithm OPTIONAL }</dd> + * </dl> + * + * @since Android 1.0 */ public class EncryptedPrivateKeyInfo { // Encryption algorithm name @@ -61,7 +73,16 @@ public class EncryptedPrivateKeyInfo { private volatile byte[] encoded; /** - * @com.intel.drl.spec_ref + * Creates an {@code EncryptedPrivateKeyInfo} instance from its encoded + * representation by parsing it. + * + * @param encoded + * the encoded representation of this object + * @throws IOException + * if parsing the encoded representation fails. + * @throws NullPointerException + * if {@code encoded} is {@code null}. + * @since Android 1.0 */ public EncryptedPrivateKeyInfo(byte[] encoded) throws IOException { @@ -104,7 +125,21 @@ public class EncryptedPrivateKeyInfo { } /** - * @com.intel.drl.spec_ref + * Creates an {@code EncryptedPrivateKeyInfo} instance from an algorithm + * name and its encrypted data. + * + * @param encrAlgName + * the name of an algorithm. + * @param encryptedData + * the encrypted data. + * @throws NoSuchAlgorithmException + * if the {@code encrAlgName} is not a supported algorithm. + * @throws NullPointerException + * if {@code encrAlgName} or {@code encryptedData} is {@code + * null}. + * @throws IllegalArgumentException + * if {@code encryptedData} is empty. + * @since Android 1.0 */ public EncryptedPrivateKeyInfo(String encrAlgName, byte[] encryptedData) throws NoSuchAlgorithmException { @@ -129,7 +164,20 @@ public class EncryptedPrivateKeyInfo { } /** - * @com.intel.drl.spec_ref + * Creates an {@code EncryptedPrivateKeyInfo} instance from the + * encryption algorithm parameters an its encrypted data. + * + * @param algParams + * the encryption algorithm parameters. + * @param encryptedData + * the encrypted data. + * @throws NoSuchAlgorithmException + * if the algorithm name of the specified {@code algParams} + * parameter is not supported. + * @throws NullPointerException + * if {@code algParams} or {@code encryptedData} is + * {@code null}. + * @since Android 1.0 */ public EncryptedPrivateKeyInfo(AlgorithmParameters algParams, byte[] encryptedData) @@ -155,21 +203,31 @@ public class EncryptedPrivateKeyInfo { } /** - * @com.intel.drl.spec_ref + * Returns the name of the encryption algorithm. + * + * @return the name of the encryption algorithm. + * @since Android 1.0 */ public String getAlgName() { return algName; } /** - * @com.intel.drl.spec_ref + * Returns the parameters used by the encryption algorithm. + * + * @return the parameters used by the encryption algorithm. + * @since Android 1.0 */ public AlgorithmParameters getAlgParameters() { return algParameters; } /** - * @com.intel.drl.spec_ref + * Returns the encrypted data of this key. + * + * @return the encrypted data of this key, each time this method is called a + * new array is returned. + * @since Android 1.0 */ public byte[] getEncryptedData() { byte[] ret = new byte[encryptedData.length]; @@ -178,7 +236,23 @@ public class EncryptedPrivateKeyInfo { } /** - * @com.intel.drl.spec_ref + * Returns the {@code PKCS8EncodedKeySpec} object extracted from the + * encrypted data. + * <p> + * The cipher must be initialize in either {@code Cipher.DECRYPT_MODE} or + * {@code Cipher.UNWRAP_MODE} with the same parameters and key used for + * encrypting this. + * </p> + * + * @param cipher + * the cipher initialized for decrypting the encrypted data. + * @return the extracted {@code PKCS8EncodedKeySpec}. + * @throws InvalidKeySpecException + * if the specified cipher is not suited to decrypt the + * encrypted data. + * @throws NullPointerException + * if {@code cipher} is {@code null}. + * @since Android 1.0 */ public PKCS8EncodedKeySpec getKeySpec(Cipher cipher) throws InvalidKeySpecException { @@ -204,7 +278,21 @@ public class EncryptedPrivateKeyInfo { } /** - * @com.intel.drl.spec_ref + * Returns the {@code PKCS8EncodedKeySpec} object extracted from the + * encrypted data. + * + * @param decryptKey + * the key to decrypt the encrypted data with. + * @return the extracted {@code PKCS8EncodedKeySpec}. + * @throws NoSuchAlgorithmException + * if no usable cipher can be found to decrypt the encrypted + * data. + * @throws InvalidKeyException + * if {@code decryptKey} is not usable to decrypt the encrypted + * data. + * @throws NullPointerException + * if {@code decryptKey} is {@code null}. + * @since Android 1.0 */ public PKCS8EncodedKeySpec getKeySpec(Key decryptKey) throws NoSuchAlgorithmException, @@ -241,7 +329,27 @@ public class EncryptedPrivateKeyInfo { } /** - * @com.intel.drl.spec_ref + * Returns the {@code PKCS8EncodedKeySpec} object extracted from the + * encrypted data. + * + * @param decryptKey + * the key to decrypt the encrypted data with. + * @param providerName + * the name of a provider whose cipher implementation should be + * used. + * @return the extracted {@code PKCS8EncodedKeySpec}. + * @throws NoSuchProviderException + * if no provider with {@code providerName} can be found. + * @throws NoSuchAlgorithmException + * if no usable cipher can be found to decrypt the encrypted + * data. + * @throws InvalidKeyException + * if {@code decryptKey} is not usable to decrypt the encrypted + * data. + * @throws NullPointerException + * if {@code decryptKey} or {@code providerName} is {@code null} + * . + * @since Android 1.0 */ public PKCS8EncodedKeySpec getKeySpec(Key decryptKey, String providerName) throws NoSuchProviderException, @@ -283,7 +391,23 @@ public class EncryptedPrivateKeyInfo { } /** - * @com.intel.drl.spec_ref + * Returns the {@code PKCS8EncodedKeySpec} object extracted from the + * encrypted data. + * + * @param decryptKey + * the key to decrypt the encrypted data with. + * @param provider + * the provider whose cipher implementation should be used. + * @return the extracted {@code PKCS8EncodedKeySpec}. + * @throws NoSuchAlgorithmException + * if no usable cipher can be found to decrypt the encrypted + * data. + * @throws InvalidKeyException + * if {@code decryptKey} is not usable to decrypt the encrypted + * data. + * @throws NullPointerException + * if {@code decryptKey} or {@code provider} is {@code null}. + * @since Android 1.0 */ public PKCS8EncodedKeySpec getKeySpec(Key decryptKey, Provider provider) throws NoSuchAlgorithmException, @@ -323,7 +447,12 @@ public class EncryptedPrivateKeyInfo { } /** - * @com.intel.drl.spec_ref + * Returns the ASN.1 encoded representation of this object. + * + * @return the ASN.1 encoded representation of this object. + * @throws IOException + * if encoding this object fails. + * @since Android 1.0 */ public byte[] getEncoded() throws IOException { if (encoded == null) { diff --git a/crypto/src/main/java/javax/crypto/ExemptionMechanism.java b/crypto/src/main/java/javax/crypto/ExemptionMechanism.java index 349a190..7c68d28 100644 --- a/crypto/src/main/java/javax/crypto/ExemptionMechanism.java +++ b/crypto/src/main/java/javax/crypto/ExemptionMechanism.java @@ -31,6 +31,12 @@ import java.util.Arrays; import org.apache.harmony.crypto.internal.nls.Messages; import org.apache.harmony.security.fortress.Engine; +/** + * This class implements the functionality of an exemption mechanism such as + * <i>key recovery</i>, <i>key weakening</i>, or <i>key escrow</i>. + * + * @since Android 1.0 + */ public class ExemptionMechanism { // Used to access common engine functionality @@ -54,6 +60,17 @@ public class ExemptionMechanism { // Indicates if blob generated successfully private boolean generated; + /** + * Creates a {@code ExemptionMechanism} instance. + * + * @param exmechSpi + * the implementation delegate. + * @param provider + * the associated provider. + * @param mechanism + * the name of the mechanism. + * @since Android 1.0 + */ protected ExemptionMechanism(ExemptionMechanismSpi exmechSpi, Provider provider, String mechanism) { this.mechanism = mechanism; @@ -62,10 +79,29 @@ public class ExemptionMechanism { isInit = false; } + /** + * Returns the name of this {@code ExemptionMechanism}. + * + * @return the name of this {@code ExemptionMechanism}. + * @since Android 1.0 + */ public final String getName() { return mechanism; } + /** + * Returns a new {@code ExemptionMechanism} instance that provides the + * specified exemption mechanism algorithm. + * + * @param algorithm + * the name of the requested exemption mechanism. + * @return the new {@code ExemptionMechanism} instance. + * @throws NoSuchAlgorithmException + * if the specified algorithm is not available by any provider. + * @throws NullPointerException + * if the algorithm parameter is {@code null}. + * @since Android 1.0 + */ public static final ExemptionMechanism getInstance(String algorithm) throws NoSuchAlgorithmException { if (algorithm == null) { @@ -78,6 +114,26 @@ public class ExemptionMechanism { } } + /** + * Returns a new {@code ExemptionMechansm} instance that provides the + * specified exemption mechanism algorithm from the specified provider. + * + * @param algorithm + * the name of the requested exemption mechanism. + * @param provider + * the name of the provider that is providing the algorithm. + * @return the new {@code ExemptionMechanism} instance. + * @throws NoSuchAlgorithmException + * if the specified algorithm is not provided by the specified + * provider. + * @throws NoSuchProviderException + * if the specified provider is not available. + * @throws NullPointerException + * if the algorithm parameter is {@code null}. + * @throws IllegalArgumentException + * if the provider parameter is {@code null}. + * @since Android 1.0 + */ public static final ExemptionMechanism getInstance(String algorithm, String provider) throws NoSuchAlgorithmException, NoSuchProviderException { @@ -94,6 +150,24 @@ public class ExemptionMechanism { return getInstance(algorithm, impProvider); } + /** + * Returns a new {@code ExemptionMechanism} instance that provides the + * specified exemption mechanism algorithm from the specified provider. + * + * @param algorithm + * the name of the requested exemption mechanism. + * @param provider + * the provider that is providing the algorithm. + * @return the new {@code ExemptionMechanism} instance. + * @throws NoSuchAlgorithmException + * if the specified algorithm is not provided by the specified + * provider. + * @throws NullPointerException + * if the algorithm parameter is {@code null}. + * @throws IllegalArgumentException + * if the provider parameter is {@code null}. + * @since Android 1.0 + */ public static final ExemptionMechanism getInstance(String algorithm, Provider provider) throws NoSuchAlgorithmException { if (algorithm == null) { @@ -109,10 +183,30 @@ public class ExemptionMechanism { } } + /** + * Returns the provider of this {@code ExemptionMechanism} instance. + * + * @return the provider of this {@code ExemptionMechanism} instance. + * @since Android 1.0 + */ public final Provider getProvider() { return provider; } + /** + * Returns whether the result blob for this {@code ExemptionMechanism} + * instance has been generated successfully and that the specified key is + * the same as the one that was used to initialize and generate. + * + * @param key + * the key to verify. + * @return whether the result blob for this {@code ExemptionMechanism} + * instance has been generated successfully. + * @throws ExemptionMechanismException + * if an error occurs while determining whether the result blob + * has been generated successfully. + * @since Android 1.0 + */ public final boolean isCryptoAllowed(Key key) throws ExemptionMechanismException { @@ -124,6 +218,19 @@ public class ExemptionMechanism { return false; } + /** + * Returns the size in bytes for the output buffer needed to hold the output + * of the next {@link #genExemptionBlob} call, given the specified {@code + * inputLen} (in bytes). + * + * @param inputLen + * the specified input length (in bytes). + * @return the size in bytes for the output buffer. + * @throws IllegalStateException + * if this {@code ExemptionMechanism} instance is not + * initialized. + * @since Android 1.0 + */ public final int getOutputSize(int inputLen) throws IllegalStateException { if (!isInit) { throw new IllegalStateException(Messages.getString("crypto.2D")); @@ -131,6 +238,18 @@ public class ExemptionMechanism { return spiImpl.engineGetOutputSize(inputLen); } + /** + * Initializes this {@code ExemptionMechanism} instance with the + * specified key. + * + * @param key + * the key to initialize this instance with. + * @throws InvalidKeyException + * if the key cannot be used to initialize this mechanism. + * @throws ExemptionMechanismException + * if error(s) occur during initialization. + * @since Android 1.0 + */ public final void init(Key key) throws InvalidKeyException, ExemptionMechanismException { generated = false; @@ -139,6 +258,23 @@ public class ExemptionMechanism { isInit = true; } + /** + * Initializes this {@code ExemptionMechanism} instance with the + * specified key and algorithm parameters. + * + * @param key + * the key to initialize this instance with. + * @param param + * the parameters for this exemption mechanism algorithm. + * @throws InvalidKeyException + * if the key cannot be used to initialize this mechanism. + * @throws InvalidAlgorithmParameterException + * if the parameters cannot be used to initialize this + * mechanism. + * @throws ExemptionMechanismException + * if error(s) occur during initialization. + * @since Android 1.0 + */ public final void init(Key key, AlgorithmParameters param) throws InvalidKeyException, InvalidAlgorithmParameterException, ExemptionMechanismException { @@ -148,6 +284,23 @@ public class ExemptionMechanism { isInit = true; } + /** + * Initializes this {@code ExemptionMechanism} instance with the + * specified key and algorithm parameters. + * + * @param key + * the key to initialize this instance with. + * @param param + * the parameters for this exemption mechanism algorithm. + * @throws InvalidKeyException + * if the key cannot be used to initialize this mechanism. + * @throws InvalidAlgorithmParameterException + * the the parameters cannot be used to initialize this + * mechanism. + * @throws ExemptionMechanismException + * if error(s) occur during initialization. + * @since Android 1.0 + */ public final void init(Key key, AlgorithmParameterSpec param) throws InvalidKeyException, InvalidAlgorithmParameterException, ExemptionMechanismException { @@ -157,6 +310,17 @@ public class ExemptionMechanism { isInit = true; } + /** + * Generates the result key blob for this exemption mechanism. + * + * @return the result key blob for this exemption mechanism. + * @throws IllegalStateException + * if this {@code ExemptionMechanism} instance is not + * initialized. + * @throws ExemptionMechanismException + * if error(s) occur during generation. + * @since Android 1.0 + */ public final byte[] genExemptionBlob() throws IllegalStateException, ExemptionMechanismException { if (!isInit) { @@ -168,12 +332,46 @@ public class ExemptionMechanism { return result; } + /** + * Generates the result key blob for this exemption mechanism and stores it + * into the {@code output} buffer. + * + * @param output + * the output buffer for the result key blob. + * @return the number of bytes written to the {@code output} buffer. + * @throws IllegalStateException + * if this {@code ExemptionMechanism} instance is not + * initialized. + * @throws ShortBufferException + * if the provided buffer is too small for the result key blob. + * @throws ExemptionMechanismException + * if error(s) occur during generation. + * @since Android 1.0 + */ public final int genExemptionBlob(byte[] output) throws IllegalStateException, ShortBufferException, ExemptionMechanismException { return genExemptionBlob(output, 0); } + /** + * Generates the result key blob for this exemption mechanism and stores it + * into the {@code output} buffer at offset {@code outputOffset}. + * + * @param output + * the output buffer for the result key blob. + * @param outputOffset + * the offset in the output buffer to start. + * @return the number of bytes written to the {@code output} buffer. + * @throws IllegalStateException + * if this {@code ExemptionMechanism} instance is not + * initialized. + * @throws ShortBufferException + * if the provided buffer is too small for the result key blob. + * @throws ExemptionMechanismException + * if error(s) occur during generation. + * @since Android 1.0 + */ public final int genExemptionBlob(byte[] output, int outputOffset) throws IllegalStateException, ShortBufferException, ExemptionMechanismException { @@ -186,6 +384,11 @@ public class ExemptionMechanism { return len; } + /** + * Frees the references to the key used to initialize this instance. + * + * @since Android 1.0 + */ @Override protected void finalize() { initKey = null; diff --git a/crypto/src/main/java/javax/crypto/ExemptionMechanismException.java b/crypto/src/main/java/javax/crypto/ExemptionMechanismException.java index 1c1ba2c..3af498b 100644 --- a/crypto/src/main/java/javax/crypto/ExemptionMechanismException.java +++ b/crypto/src/main/java/javax/crypto/ExemptionMechanismException.java @@ -15,18 +15,14 @@ * limitations under the License. */ -/** -* @author Vera Y. Petrashkova -* @version $Revision$ -*/ - package javax.crypto; import java.security.GeneralSecurityException; /** - * @com.intel.drl.spec_ref + * This is the base class for {@code ExemptionMechanismException}. * + * @since Android 1.0 */ public class ExemptionMechanismException extends GeneralSecurityException { @@ -36,16 +32,21 @@ public class ExemptionMechanismException extends GeneralSecurityException { private static final long serialVersionUID = 1572699429277957109L; /** - * @com.intel.drl.spec_ref + * Creates a new {@code ExemptionMechanismException} with the specified + * message. * + * @param msg + * the exception message. + * @since Android 1.0 */ public ExemptionMechanismException(String msg) { super(msg); } /** - * @com.intel.drl.spec_ref + * Creates a new {@code ExemptionMechanismException} with no message. * + * @since Android 1.0 */ public ExemptionMechanismException() { } diff --git a/crypto/src/main/java/javax/crypto/ExemptionMechanismSpi.java b/crypto/src/main/java/javax/crypto/ExemptionMechanismSpi.java index d4865b1..cef1516 100644 --- a/crypto/src/main/java/javax/crypto/ExemptionMechanismSpi.java +++ b/crypto/src/main/java/javax/crypto/ExemptionMechanismSpi.java @@ -15,11 +15,6 @@ * limitations under the License. */ -/** -* @author Vera Y. Petrashkova -* @version $Revision$ -*/ - package javax.crypto; import java.security.AlgorithmParameters; @@ -29,56 +24,114 @@ import java.security.Key; import java.security.spec.AlgorithmParameterSpec; /** - * @com.intel.drl.spec_ref + * The <i>Service Provider Interface</i> (<b>SPI</b>) definition for the {@code + * ExemptionMechanism} class. * + * @since Android 1.0 */ public abstract class ExemptionMechanismSpi { + /** - * @com.intel.drl.spec_ref - * + * Creates a new {@code ExemptionMechanismSpi} instance. + * + * @since Android 1.0 */ public ExemptionMechanismSpi() { } /** - * @com.intel.drl.spec_ref - * + * Generates the result key blob for this exemption mechanism. + * + * @return the result key blob for this exemption mechanism. + * @throws ExemptionMechanismException + * if error(s) occur during generation. + * @since Android 1.0 */ protected abstract byte[] engineGenExemptionBlob() throws ExemptionMechanismException; /** - * @com.intel.drl.spec_ref - * + * Generates the result key blob for this exemption mechanism and stores it + * into the {@code output} buffer at offset {@code outputOffset}. + * + * @param output + * the output buffer for the result key blob. + * @param outputOffset + * the offset in the output buffer to start. + * @return the number of bytes written to the {@code output} buffer. + * @throws ShortBufferException + * if the provided buffer is too small for the result key blob. + * @throws ExemptionMechanismException + * if error(s) occur during generation. + * @since Android 1.0 */ protected abstract int engineGenExemptionBlob(byte[] output, int outputOffset) throws ShortBufferException, ExemptionMechanismException; /** - * @com.intel.drl.spec_ref - * + * Returns the size in bytes for the output buffer needed to hold the output + * of the next {@link #engineGenExemptionBlob} call, given the specified + * {@code inputLen} (in bytes). + * + * @param inputLen + * the specified input length (in bytes). + * @return the size in bytes for the output buffer. */ protected abstract int engineGetOutputSize(int inputLen); /** - * @com.intel.drl.spec_ref - * + * Initializes this {@code ExemptionMechanism} instance with the specified + * key. + * + * @param key + * the key to initialize this instance with. + * @throws InvalidKeyException + * if the key cannot be used to initialize this mechanism. + * @throws ExemptionMechanismException + * if error(s) occur during initialization. + * @since Android 1.0 */ protected abstract void engineInit(Key key) throws InvalidKeyException, ExemptionMechanismException; /** - * @com.intel.drl.spec_ref - * + * Initializes this {@code ExemptionMechanism} instance with the specified + * key and algorithm parameters. + * + * @param key + * the key to initialize this instance with. + * @param params + * the parameters for this exemption mechanism algorithm. + * @throws InvalidKeyException + * if the key cannot be used to initialize this mechanism. + * @throws InvalidAlgorithmParameterException + * if the parameters cannot be used to initialize this + * mechanism. + * @throws ExemptionMechanismException + * if error(s) occur during initialization. + * @since Android 1.0 */ protected abstract void engineInit(Key key, AlgorithmParameters params) throws InvalidKeyException, InvalidAlgorithmParameterException, ExemptionMechanismException; /** - * @com.intel.drl.spec_ref - * + * Initializes this {@code ExemptionMechanism} instance with the specified + * key and algorithm parameters. + * + * @param key + * the key to initialize this instance with. + * @param params + * the parameters for this exemption mechanism algorithm. + * @throws InvalidKeyException + * if the key cannot be used to initialize this mechanism. + * @throws InvalidAlgorithmParameterException + * the the parameters cannot be used to initialize this + * mechanism. + * @throws ExemptionMechanismException + * if error(s) occur during initialization. + * @since Android 1.0 */ protected abstract void engineInit(Key key, AlgorithmParameterSpec params) throws InvalidKeyException, InvalidAlgorithmParameterException, diff --git a/crypto/src/main/java/javax/crypto/HmacSpi.java b/crypto/src/main/java/javax/crypto/HmacSpi.java deleted file mode 100644 index 54862d0..0000000 --- a/crypto/src/main/java/javax/crypto/HmacSpi.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright (C) 2007 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package javax.crypto; - -import java.io.ByteArrayOutputStream; -import java.security.InvalidAlgorithmParameterException; -import java.security.InvalidKeyException; -import java.security.Key; -import java.security.spec.AlgorithmParameterSpec; - - -/** - * Internal class implementing HMAC - */ -class HmacSpi extends MacSpi -{ - protected byte[] engineDoFinal() - { - byte[] result = native_compute_sha1_hmac(mKey.getEncoded(), mData.toByteArray()); - engineReset(); - return result; - } - - protected int engineGetMacLength() - { - throw new UnsupportedOperationException("Not implemented"); - } - - protected void engineInit(Key key, AlgorithmParameterSpec params) - throws InvalidKeyException, InvalidAlgorithmParameterException - { - mKey = key; - mData = null; - } - - protected void engineReset() - { - synchronized (mSync) { - mData = null; - } - } - - protected void engineUpdate(byte input) - { - synchronized (mSync) { - if (mData == null) { - mData = new ByteArrayOutputStream(); - } - mData.write(input); - } - } - - protected void engineUpdate(byte[] input, int offset, int len) - { - synchronized (mSync) { - if (mData == null) { - mData = new ByteArrayOutputStream(); - } - mData.write(input, offset, len); - } - } - - private native byte[] native_compute_sha1_hmac(byte[] key, byte[] data); - - private Key mKey; - private ByteArrayOutputStream mData; - private Object mSync = new Object(); -} - diff --git a/crypto/src/main/java/javax/crypto/IllegalBlockSizeException.java b/crypto/src/main/java/javax/crypto/IllegalBlockSizeException.java index 9a6c4d1..e376b85 100644 --- a/crypto/src/main/java/javax/crypto/IllegalBlockSizeException.java +++ b/crypto/src/main/java/javax/crypto/IllegalBlockSizeException.java @@ -15,18 +15,15 @@ * limitations under the License. */ -/** -* @author Vera Y. Petrashkova -* @version $Revision$ -*/ - package javax.crypto; import java.security.GeneralSecurityException; /** - * @com.intel.drl.spec_ref + * The exception, that is thrown when the data length provided to a block cipher + * does not match the block size of the cipher. * + * @since Android 1.0 */ public class IllegalBlockSizeException extends GeneralSecurityException { @@ -36,16 +33,21 @@ public class IllegalBlockSizeException extends GeneralSecurityException { private static final long serialVersionUID = -1965144811953540392L; /** - * @com.intel.drl.spec_ref + * Creates a new {@code IllegalBlockSizeException} with the specified + * message. * + * @param msg + * the message + * @since Android 1.0 */ public IllegalBlockSizeException(String msg) { super(msg); } /** - * @com.intel.drl.spec_ref + * Creates a new {@code IllegalBlockSizeException}. * + * @since Android 1.0 */ public IllegalBlockSizeException() { } diff --git a/crypto/src/main/java/javax/crypto/KeyAgreement.java b/crypto/src/main/java/javax/crypto/KeyAgreement.java index 3a23181..ee1f195 100644 --- a/crypto/src/main/java/javax/crypto/KeyAgreement.java +++ b/crypto/src/main/java/javax/crypto/KeyAgreement.java @@ -15,11 +15,6 @@ * limitations under the License. */ -/** -* @author Vera Y. Petrashkova -* @version $Revision$ -*/ - package javax.crypto; import java.security.InvalidAlgorithmParameterException; @@ -35,12 +30,13 @@ import java.security.spec.AlgorithmParameterSpec; import org.apache.harmony.crypto.internal.nls.Messages; import org.apache.harmony.security.fortress.Engine; - /** - * @com.intel.drl.spec_ref + * This class provides the functionality for a key exchange protocol. This + * enables two or more parties to agree on a secret key for symmetric + * cryptography. * + * @since Android 1.0 */ - public class KeyAgreement { // Used to access common engine functionality @@ -59,8 +55,15 @@ public class KeyAgreement { private final String algorithm; /** - * @com.intel.drl.spec_ref - * + * Creates a new {@code KeyAgreement} instance. + * + * @param keyAgreeSpi + * the <b>SPI</b> delegate. + * @param provider + * the provider providing this KeyAgreement. + * @param algorithm + * the name of the key agreement algorithm. + * @since Android 1.0 */ protected KeyAgreement(KeyAgreementSpi keyAgreeSpi, Provider provider, String algorithm) { @@ -70,24 +73,36 @@ public class KeyAgreement { } /** - * @com.intel.drl.spec_ref - * + * Returns the name of the key agreement algorithm. + * + * @return the name of the key agreement algorithm. + * @since Android 1.0 */ public final String getAlgorithm() { return algorithm; } /** - * @com.intel.drl.spec_ref - * + * Returns the provider for this {@code KeyAgreement} instance. + * + * @return the provider for this {@code KeyAgreement} instance. + * @since Android 1.0 */ public final Provider getProvider() { return provider; } /** - * @com.intel.drl.spec_ref - * + * Creates a new {@code KeyAgreement} for the specified algorithm. + * + * @param algorithm + * the name of the key agreement algorithm to create. + * @return a key agreement for the specified algorithm. + * @throws NoSuchAlgorithmException + * if no installed provider can provide the requested algorithm. + * @throws NullPointerException + * if the specified algorithm is {@code null}. + * @since Android 1.0 */ public static final KeyAgreement getInstance(String algorithm) throws NoSuchAlgorithmException { @@ -102,8 +117,24 @@ public class KeyAgreement { } /** - * @com.intel.drl.spec_ref - * + * Creates a new {@code KeyAgreement} for the specified algorithm from the + * specified provider. + * + * @param algorithm + * the name of the key agreement algorithm to create. + * @param provider + * the name of the provider that provides the requested + * algorithm. + * @return a key agreement for the specified algorithm from the specified + * provider. + * @throws NoSuchAlgorithmException + * if the specified provider cannot provide the requested + * algorithm. + * @throws NoSuchProviderException + * if the specified provider does not exist. + * @throws IllegalArgumentException + * if the specified provider name is {@code null} or empty. + * @since Android 1.0 */ public static final KeyAgreement getInstance(String algorithm, String provider) throws NoSuchAlgorithmException, @@ -119,8 +150,22 @@ public class KeyAgreement { } /** - * @com.intel.drl.spec_ref - * + * Create a new {@code KeyAgreement} for the specified algorithm from the + * specified provider. + * + * @param algorithm + * the name of the key agreement algorithm to create. + * @param provider + * the provider that provides the requested algorithm. + * @return a key agreement for the specified algorithm from the specified + * provider. + * @throws NoSuchAlgorithmException + * if the specified provider cannot provide the requested + * algorithm. + * @throws IllegalArgumentException + * if the specified provider is {@code null}. + * @throws NullPointerException + * if the specified algorithm name is {@code null}. */ public static final KeyAgreement getInstance(String algorithm, Provider provider) throws NoSuchAlgorithmException { @@ -138,16 +183,31 @@ public class KeyAgreement { } /** - * @com.intel.drl.spec_ref - * + * Initializes this {@code KeyAgreement} with the specified key. + * + * @param key + * the key to initialize this key agreement. + * @throws InvalidKeyException + * if the specified key cannot be used to initialize this key + * agreement. + * @since Android 1.0 */ public final void init(Key key) throws InvalidKeyException { spiImpl.engineInit(key, rndm);//new SecureRandom()); } /** - * @com.intel.drl.spec_ref - * + * Initializes this {@code KeyAgreement} with the specified key and the + * specified randomness source. + * + * @param key + * the key to initialize this key agreement. + * @param random + * the source for any randomness needed. + * @throws InvalidKeyException + * if the specified key cannot be used to initialize this key + * agreement. + * @since Android 1.0 */ public final void init(Key key, SecureRandom random) throws InvalidKeyException { @@ -155,8 +215,20 @@ public class KeyAgreement { } /** - * @com.intel.drl.spec_ref - * + * Initializes this {@code KeyAgreement} with the specified key and the + * algorithm parameters. + * + * @param key + * the key to initialize this key agreement. + * @param params + * the parameters for this key agreement algorithm. + * @throws InvalidKeyException + * if the specified key cannot be used to initialize this key + * agreement. + * @throws InvalidAlgorithmParameterException + * if the specified parameters are invalid for this key + * agreement algorithm. + * @since Android 1.0 */ public final void init(Key key, AlgorithmParameterSpec params) throws InvalidKeyException, InvalidAlgorithmParameterException { @@ -164,8 +236,22 @@ public class KeyAgreement { } /** - * @com.intel.drl.spec_ref - * + * Initializes this {@code KeyAgreement} with the specified key, algorithm + * parameters and randomness source. + * + * @param key + * the key to initialize this key agreement. + * @param params + * the parameters for this key agreement algorithm. + * @param random + * the source for any randomness needed. + * @throws InvalidKeyException + * if the specified key cannot be used to initialize this key + * agreement. + * @throws InvalidAlgorithmParameterException + * if the specified parameters are invalid for this key + * agreement algorithm. + * @since Android 1.0 */ public final void init(Key key, AlgorithmParameterSpec params, SecureRandom random) throws InvalidKeyException, @@ -174,8 +260,22 @@ public class KeyAgreement { } /** - * @com.intel.drl.spec_ref - * + * Does the next (or the last) phase of the key agreement, using the + * specified key. + * + * @param key + * the key received from the other party for this phase. + * @param lastPhase + * set to {@code true} if this is the last phase of this key + * agreement. + * @return the intermediate key from this phase or {@code null} if there is + * no intermediate key for this phase. + * @throws InvalidKeyException + * if the specified key cannot be used in this key agreement or + * this phase, + * @throws IllegalStateException + * if this instance has not been initialized. + * @since Android 1.0 */ public final Key doPhase(Key key, boolean lastPhase) throws InvalidKeyException, IllegalStateException { @@ -183,16 +283,31 @@ public class KeyAgreement { } /** - * @com.intel.drl.spec_ref - * + * Generates the shared secret. + * + * @return the generated shared secret. + * @throws IllegalStateException + * if this key agreement is not complete. + * @since Android 1.0 */ public final byte[] generateSecret() throws IllegalStateException { return spiImpl.engineGenerateSecret(); } /** - * @com.intel.drl.spec_ref - * + * Generates the shared secret and stores it into the buffer {@code + * sharedSecred} at {@code offset}. + * + * @param sharedSecret + * the buffer to store the shared secret. + * @param offset + * the offset in the buffer. + * @return the number of bytes stored in the buffer. + * @throws IllegalStateException + * if this key agreement is not complete. + * @throws ShortBufferException + * if the specified buffer is too small for the shared secret. + * @since Android 1.0 */ public final int generateSecret(byte[] sharedSecret, int offset) throws IllegalStateException, ShortBufferException { @@ -200,8 +315,21 @@ public class KeyAgreement { } /** - * @com.intel.drl.spec_ref - * + * Generates the shared secret. + * + * @param algorithm + * the algorithm to for the {@code SecretKey} + * @return the shared secret as a {@code SecretKey} of the specified + * algorithm. + * @throws IllegalStateException + * if this key agreement is not complete. + * @throws NoSuchAlgorithmException + * if the specified algorithm for the secret key does not + * exists. + * @throws InvalidKeyException + * if a {@code SecretKey} with the specified algorithm cannot be + * created using the generated shared secret. + * @since Android 1.0 */ public final SecretKey generateSecret(String algorithm) throws IllegalStateException, NoSuchAlgorithmException, diff --git a/crypto/src/main/java/javax/crypto/KeyAgreementSpi.java b/crypto/src/main/java/javax/crypto/KeyAgreementSpi.java index 23a536b..fa9f377 100644 --- a/crypto/src/main/java/javax/crypto/KeyAgreementSpi.java +++ b/crypto/src/main/java/javax/crypto/KeyAgreementSpi.java @@ -15,11 +15,6 @@ * limitations under the License. */ -/** -* @author Vera Y. Petrashkova -* @version $Revision$ -*/ - package javax.crypto; import java.security.InvalidAlgorithmParameterException; @@ -30,57 +25,125 @@ import java.security.SecureRandom; import java.security.spec.AlgorithmParameterSpec; /** - * @com.intel.drl.spec_ref + * The <i>Service Provider Interface</i> (<b>SPI</b>) definition for the + * {@code KeyAgreement} class. * + * @since Android 1.0 */ public abstract class KeyAgreementSpi { + /** - * @com.intel.drl.spec_ref - * + * Creates a new {@code KeyAgreementSpi} instance. + * + * @since Android 1.0 */ - public KeyAgreementSpi() { } /** - * @com.intel.drl.spec_ref - * + * Does the next (or the last) phase of the key agreement, using the + * specified key. + * + * @param key + * the key received from the other party for this phase. + * @param lastPhase + * set to {@code true} if this is the last phase of this key + * agreement. + * @return the intermediate key from this phase or null if there is no + * intermediate key for this phase. + * @throws InvalidKeyException + * if the specified key cannot be used in this key agreement or + * this phase, + * @throws IllegalStateException + * if this instance has not been initialized. + * @since Android 1.0 */ protected abstract Key engineDoPhase(Key key, boolean lastPhase) throws InvalidKeyException, IllegalStateException; /** - * @com.intel.drl.spec_ref - * + * Generates the shared secret. + * + * @return the generated shared secret. + * @throws IllegalStateException + * if this key agreement is not complete. + * @since Android 1.0 */ protected abstract byte[] engineGenerateSecret() throws IllegalStateException; /** - * @com.intel.drl.spec_ref - * + * Generates the shared secret and stores it into the buffer {@code + * sharedSecred} at {@code offset}. + * + * @param sharedSecret + * the buffer to store the shared secret. + * @param offset + * the offset in the buffer. + * @return the number of bytes stored in the buffer. + * @throws IllegalStateException + * if this key agreement is not complete. + * @throws ShortBufferException + * if the specified buffer is too small for the shared secret. + * @since Android 1.0 */ protected abstract int engineGenerateSecret(byte[] sharedSecret, int offset) throws IllegalStateException, ShortBufferException; /** - * @com.intel.drl.spec_ref - * + * Generates the shared secret. + * + * @param algorithm + * the algorithm to for the {@code SecretKey} + * @return the shared secret as a {@code SecretKey} of the specified + * algorithm. + * @throws IllegalStateException + * if this key agreement is not complete. + * @throws NoSuchAlgorithmException + * if the specified algorithm for the secret key does not + * exists. + * @throws InvalidKeyException + * if a {@code SecretKey} with the specified algorithm cannot be + * created using the generated shared secret. + * @since Android 1.0 */ protected abstract SecretKey engineGenerateSecret(String algorithm) throws IllegalStateException, NoSuchAlgorithmException, InvalidKeyException; /** - * @com.intel.drl.spec_ref - * + * Initializes this {@code KeyAgreementSpi} with the specified key and the + * specified randomness source. + * + * @param key + * the key to initialize this key agreement. + * @param random + * the source for any randomness needed. + * @throws InvalidKeyException + * if the specified key cannot be used to initialize this key + * agreement. + * @since Android 1.0 */ protected abstract void engineInit(Key key, SecureRandom random) throws InvalidKeyException; /** - * @com.intel.drl.spec_ref - * + * Initializes this {@code KeyAgreementSpi} with the specified key, + * algorithm parameters and randomness source. + * + * @param key + * the key to initialize this key agreement. + * @param params + * the parameters for this key agreement algorithm. + * @param random + * the source for any randomness needed. + * @throws InvalidKeyException + * if the specified key cannot be used to initialize this key + * agreement. + * @throws InvalidAlgorithmParameterException + * if the specified parameters are invalid for this key + * agreement algorithm. + * @since Android 1.0 */ protected abstract void engineInit(Key key, AlgorithmParameterSpec params, SecureRandom random) throws InvalidKeyException, diff --git a/crypto/src/main/java/javax/crypto/KeyGenerator.java b/crypto/src/main/java/javax/crypto/KeyGenerator.java index 0f952b8..3243b39 100644 --- a/crypto/src/main/java/javax/crypto/KeyGenerator.java +++ b/crypto/src/main/java/javax/crypto/KeyGenerator.java @@ -15,11 +15,6 @@ * limitations under the License. */ -/** -* @author Vera Y. Petrashkova -* @version $Revision$ -*/ - package javax.crypto; import java.security.InvalidAlgorithmParameterException; @@ -35,10 +30,11 @@ import org.apache.harmony.security.fortress.Engine; /** - * @com.intel.drl.spec_ref + * This class provides the public API for generating symmetric cryptographic + * keys. * + * @since Android 1.0 */ - public class KeyGenerator { // Used to access common engine functionality @@ -57,8 +53,15 @@ public class KeyGenerator { private final String algorithm; /** - * @com.intel.drl.spec_ref - * + * Creates a new {@code KeyGenerator} instance. + * + * @param keyGenSpi + * the implementation delegate. + * @param provider + * the implementation provider. + * @param algorithm + * the name of the algorithm. + * @since Android 1.0 */ protected KeyGenerator(KeyGeneratorSpi keyGenSpi, Provider provider, String algorithm) { @@ -68,24 +71,37 @@ public class KeyGenerator { } /** - * @com.intel.drl.spec_ref - * + * Returns the name of the key generation algorithm. + * + * @return the name of the key generation algorithm. + * @since Android 1.0 */ public final String getAlgorithm() { return algorithm; } /** - * @com.intel.drl.spec_ref - * + * Returns the provider of this {@code KeyGenerator} instance. + * + * @return the provider of this {@code KeyGenerator} instance. + * @since Android 1.0 */ public final Provider getProvider() { return provider; } /** - * @com.intel.drl.spec_ref - * + * Creates a new {@code KeyGenerator} instance that provides the specified + * key algorithm, + * + * @param algorithm + * the name of the requested key algorithm + * @return the new {@code KeyGenerator} instance. + * @throws NoSuchAlgorithmException + * if the specified algorithm is not available by any provider. + * @throws NullPointerException + * if {@code algorithm} is {@code null}. + * @since Android 1.0 */ public static final KeyGenerator getInstance(String algorithm) throws NoSuchAlgorithmException { @@ -100,8 +116,24 @@ public class KeyGenerator { } /** - * @com.intel.drl.spec_ref - * + * Creates a new {@code KeyGenerator} instance that provides the specified + * key algorithm from the specified provider. + * + * @param algorithm + * the name of the requested key algorithm. + * @param provider + * the name of the provider that is providing the algorithm. + * @return the new {@code KeyGenerator} instance. + * @throws NoSuchAlgorithmException + * if the specified algorithm is not provided by the specified + * provider. + * @throws NoSuchProviderException + * if the specified provider is not available. + * @throws IllegalArgumentException + * if the specified provider is name is {@code null} or empty. + * @throws NullPointerException + * if the specified algorithm name is {@code null}. + * @since Android 1.0 */ public static final KeyGenerator getInstance(String algorithm, String provider) throws NoSuchAlgorithmException, @@ -117,8 +149,22 @@ public class KeyGenerator { } /** - * @com.intel.drl.spec_ref - * + * Creates a new {@code KeyGenerator} instance that provides the specified + * key algorithm from the specified provider. + * + * @param algorithm + * the name of the requested key algorithm. + * @param provider + * the provider that is providing the algorithm + * @return the new {@code KeyGenerator} instance. + * @throws NoSuchAlgorithmException + * if the specified algorithm is not provided by the specified + * provider. + * @throws IllegalArgumentException + * if the specified provider is {@code null}. + * @throws NullPointerException + * if the specified algorithm name is {@code null}. + * @since Android 1.0 */ public static final KeyGenerator getInstance(String algorithm, Provider provider) throws NoSuchAlgorithmException { @@ -136,16 +182,25 @@ public class KeyGenerator { } /** - * @com.intel.drl.spec_ref - * + * Generates a secret key. + * + * @return the generated secret key. + * @since Android 1.0 */ public final SecretKey generateKey() { return spiImpl.engineGenerateKey(); } /** - * @com.intel.drl.spec_ref - * + * Initializes this {@code KeyGenerator} instance with the specified + * algorithm parameters. + * + * @param params + * the parameters for the key generation algorithm. + * @throws InvalidAlgorithmParameterException + * if the parameters cannot be used to initialize this key + * generator algorithm. + * @since Android 1.0 */ public final void init(AlgorithmParameterSpec params) throws InvalidAlgorithmParameterException { @@ -153,8 +208,17 @@ public class KeyGenerator { } /** - * @com.intel.drl.spec_ref - * + * Initializes this {@code KeyGenerator} instance with the specified + * algorithm parameters and randomness source. + * + * @param params + * the parameters for the key generation algorithm. + * @param random + * the randomness source for any random bytes. + * @throws InvalidAlgorithmParameterException + * if the parameters cannot be uses to initialize this key + * generator algorithm. + * @since Android 1.0 */ public final void init(AlgorithmParameterSpec params, SecureRandom random) throws InvalidAlgorithmParameterException { @@ -162,24 +226,38 @@ public class KeyGenerator { } /** - * @com.intel.drl.spec_ref - * + * Initializes this {@code KeyGenerator} instance for the specified key size + * (in bits). + * + * @param keysize + * the size of the key (in bits). + * @since Android 1.0 */ public final void init(int keysize) { spiImpl.engineInit(keysize, rndm);//new SecureRandom()); } /** - * @com.intel.drl.spec_ref - * + * Initializes this {@code KeyGenerator} instance for the specified key size + * (in bits) using the specified randomness source. + * + * @param keysize + * the size of the key (in bits). + * @param random + * the randomness source for any random bytes. + * @since Android 1.0 */ public final void init(int keysize, SecureRandom random) { spiImpl.engineInit(keysize, random); } /** - * @com.intel.drl.spec_ref - * + * Initializes this {@code KeyGenerator} with the specified randomness + * source. + * + * @param random + * the randomness source for any random bytes. + * @since Android 1.0 */ public final void init(SecureRandom random) { spiImpl.engineInit(random); diff --git a/crypto/src/main/java/javax/crypto/KeyGeneratorSpi.java b/crypto/src/main/java/javax/crypto/KeyGeneratorSpi.java index 46dd78f..165db69 100644 --- a/crypto/src/main/java/javax/crypto/KeyGeneratorSpi.java +++ b/crypto/src/main/java/javax/crypto/KeyGeneratorSpi.java @@ -15,11 +15,6 @@ * limitations under the License. */ -/** -* @author Vera Y. Petrashkova -* @version $Revision$ -*/ - package javax.crypto; import java.security.InvalidAlgorithmParameterException; @@ -27,39 +22,65 @@ import java.security.SecureRandom; import java.security.spec.AlgorithmParameterSpec; /** - * @com.intel.drl.spec_ref + * The <i>Service Provider Interface</i> (<b>SPI</b>) definition for the + * {@code KeyGenerator} class. * + * @see KeyGenerator + * @since Android 1.0 */ public abstract class KeyGeneratorSpi { + /** - * @com.intel.drl.spec_ref - * + * Creates a new {@code KeyGeneratorSpi} instance. + * + * @since Android 1.0 */ public KeyGeneratorSpi() { } /** - * @com.intel.drl.spec_ref - * + * Generates a secret key. + * + * @return the generated secret key. + * @since Android 1.0 */ protected abstract SecretKey engineGenerateKey(); /** - * @com.intel.drl.spec_ref - * + * Initializes this {@code KeyGeneratorSpi} instance with the specified + * algorithm parameters and randomness source. + * + * @param params + * the parameters for the key generation algorithm. + * @param random + * the randomness source for any random bytes. + * @throws InvalidAlgorithmParameterException + * if the parameters cannot be uses to initialize this key + * generator algorithm. + * @since Android 1.0 */ protected abstract void engineInit(AlgorithmParameterSpec params, SecureRandom random) throws InvalidAlgorithmParameterException; /** - * @com.intel.drl.spec_ref - * + * Initializes this {@code KeyGenerator} instance for the specified key + * size (in bits) using the specified randomness source. + * + * @param keysize + * the size of the key (in bits). + * @param random + * the randomness source for any random bytes. + * @since Android 1.0 */ protected abstract void engineInit(int keysize, SecureRandom random); /** - * @com.intel.drl.spec_ref - * + * Initializes this {@code KeyGenerator} with the specified randomness + * source. + * + * @param random + * the randomness source for any random bytes. + * @since Android 1.0 */ protected abstract void engineInit(SecureRandom random); }
\ No newline at end of file diff --git a/crypto/src/main/java/javax/crypto/Mac.java b/crypto/src/main/java/javax/crypto/Mac.java index c609310..95f4539 100644 --- a/crypto/src/main/java/javax/crypto/Mac.java +++ b/crypto/src/main/java/javax/crypto/Mac.java @@ -15,11 +15,6 @@ * limitations under the License. */ -/** -* @author Vera Y. Petrashkova -* @version $Revision$ -*/ - package javax.crypto; import java.nio.ByteBuffer; @@ -37,10 +32,11 @@ import org.apache.harmony.security.fortress.Engine; /** - * @com.intel.drl.spec_ref + * This class provides the public API for <i>Message Authentication Code</i> + * (MAC) algorithms. * + * @since Android 1.0 */ - public class Mac implements Cloneable { //Used to access common engine functionality @@ -59,8 +55,15 @@ public class Mac implements Cloneable { private boolean isInitMac; /** - * @com.intel.drl.spec_ref - * + * Creates a new {@code Mac} instance. + * + * @param macSpi + * the implementation delegate. + * @param provider + * the implementation provider. + * @param algorithm + * the name of the MAC algorithm. + * @since Android 1.0 */ protected Mac(MacSpi macSpi, Provider provider, String algorithm) { this.provider = provider; @@ -70,26 +73,37 @@ public class Mac implements Cloneable { } /** - * @com.intel.drl.spec_ref - * + * Returns the name of the MAC algorithm. + * + * @return the name of the MAC algorithm. + * @since Android 1.0 */ public final String getAlgorithm() { return algorithm; } /** - * @com.intel.drl.spec_ref - * + * Returns the provider of this {@code Mac} instance. + * + * @return the provider of this {@code Mac} instance. + * @since Android 1.0 */ public final Provider getProvider() { return provider; } /** - * @com.intel.drl.spec_ref + * Creates a new {@code Mac} instance that provides the specified MAC + * algorithm. * - * throws NullPointerException if algorithm is null (instead of - * NoSuchAlgorithmException as in 1.4 release) + * @param algorithm + * the name of the requested MAC algorithm. + * @return the new {@code Mac} instance. + * @throws NoSuchAlgorithmException + * if the specified algorithm is not available by any provider. + * @throws NullPointerException + * if {@code algorithm} is {@code null}. + * @since Android 1.0 */ public static final Mac getInstance(String algorithm) throws NoSuchAlgorithmException { @@ -103,10 +117,24 @@ public class Mac implements Cloneable { } /** - * @com.intel.drl.spec_ref + * Creates a new {@code Mac} instance that provides the specified MAC + * algorithm from the specified provider. * - * throws NullPointerException if algorithm is null (instead of - * NoSuchAlgorithmException as in 1.4 release) + * @param algorithm + * the name of the requested MAC algorithm. + * @param provider + * the name of the provider that is providing the algorithm. + * @return the new {@code Mac} instance. + * @throws NoSuchAlgorithmException + * if the specified algorithm is not provided by the specified + * provider. + * @throws NoSuchProviderException + * if the specified provider is not available. + * @throws IllegalArgumentException + * if the specified provider name is {@code null} or empty. + * @throws NullPointerException + * if {@code algorithm} is {@code null} + * @since Android 1.0. */ public static final Mac getInstance(String algorithm, String provider) throws NoSuchAlgorithmException, NoSuchProviderException { @@ -121,10 +149,22 @@ public class Mac implements Cloneable { } /** - * @com.intel.drl.spec_ref + * Creates a new {@code Mac} instance that provides the specified MAC + * algorithm from the specified provider. * - * throws NullPointerException if algorithm is null (instead of - * NoSuchAlgorithmException as in 1.4 release) + * @param algorithm + * the name of the requested MAC algorithm. + * @param provider + * the provider that is providing the algorithm. + * @return the new {@code Mac} instance. + * @throws NoSuchAlgorithmException + * if the specified algorithm is not provided by the specified + * provider. + * @throws IllegalArgumentException + * if {@code provider} is {@code null}. + * @throws NullPointerException + * if {@code algorithm} is {@code null}. + * @since Android 1.0 */ public static final Mac getInstance(String algorithm, Provider provider) throws NoSuchAlgorithmException { @@ -141,16 +181,29 @@ public class Mac implements Cloneable { } /** - * @com.intel.drl.spec_ref - * + * Returns the length of this MAC (in bytes). + * + * @return the length of this MAC (in bytes). */ public final int getMacLength() { return spiImpl.engineGetMacLength(); } /** - * @com.intel.drl.spec_ref - * + * Initializes this {@code Mac} instance with the specified key and + * algorithm parameters. + * + * @param key + * the key to initialize this algorithm. + * @param params + * the parameters for this algorithm. + * @throws InvalidKeyException + * if the specified key cannot be used to initialize this + * algorithm, or it is null. + * @throws InvalidAlgorithmParameterException + * if the specified parameters cannot be used to initialize this + * algorithm. + * @since Android 1.0 */ public final void init(Key key, AlgorithmParameterSpec params) throws InvalidKeyException, InvalidAlgorithmParameterException { @@ -162,8 +215,17 @@ public class Mac implements Cloneable { } /** - * @com.intel.drl.spec_ref - * + * Initializes this {@code Mac} instance with the specified key. + * + * @param key + * the key to initialize this algorithm. + * @throws InvalidKeyException + * if initialization fails because the provided key is {@code + * null}. + * @throws RuntimeException + * if the specified key cannot be used to initialize this + * algorithm. + * @since Android 1.0 */ public final void init(Key key) throws InvalidKeyException { if (key == null) { @@ -178,8 +240,13 @@ public class Mac implements Cloneable { } /** - * @com.intel.drl.spec_ref - * + * Updates this {@code Mac} instance with the specified byte. + * + * @param input + * the byte + * @throws IllegalStateException + * if this MAC is not initialized. + * @since Android 1.0 */ public final void update(byte input) throws IllegalStateException { if (!isInitMac) { @@ -189,8 +256,21 @@ public class Mac implements Cloneable { } /** - * @com.intel.drl.spec_ref - * + * Updates this {@code Mac} instance with the data from the specified buffer + * {@code input} from the specified {@code offset} and length {@code len}. + * + * @param input + * the buffer. + * @param offset + * the offset in the buffer. + * @param len + * the length of the data in the buffer. + * @throws IllegalStateException + * if this MAC is not initialized. + * @throws IllegalArgumentException + * if {@code offset} and {@code len} do not specified a valid + * chunk in {@code input} buffer. + * @since Android 1.0 */ public final void update(byte[] input, int offset, int len) throws IllegalStateException { @@ -207,8 +287,13 @@ public class Mac implements Cloneable { } /** - * @com.intel.drl.spec_ref - * + * Copies the buffer provided as input for further processing. + * + * @param input + * the buffer. + * @throws IllegalStateException + * if this MAC is not initialized. + * @since Android 1.0 */ public final void update(byte[] input) throws IllegalStateException { if (!isInitMac) { @@ -220,8 +305,15 @@ public class Mac implements Cloneable { } /** - * @com.intel.drl.spec_ref - * + * Updates this {@code Mac} instance with the data from the specified + * buffer, starting at {@link ByteBuffer#position()}, including the next + * {@link ByteBuffer#remaining()} bytes. + * + * @param input + * the buffer. + * @throws IllegalStateException + * if this MAC is not initialized. + * @since Android 1.0 */ public final void update(ByteBuffer input) { if (!isInitMac) { @@ -235,8 +327,18 @@ public class Mac implements Cloneable { } /** - * @com.intel.drl.spec_ref - * + * Computes the digest of this MAC based on the data previously specified in + * {@link #update} calls. + * <p> + * This {@code Mac} instance is reverted to its initial state and can be + * used to start the next MAC computation with the same parameters or + * initialized with different parameters. + * </p> + * + * @return the generated digest. + * @throws IllegalStateException + * if this MAC is not initialized. + * @since Android 1.0 */ public final byte[] doFinal() throws IllegalStateException { if (!isInitMac) { @@ -246,8 +348,27 @@ public class Mac implements Cloneable { } /** - * @com.intel.drl.spec_ref - * + * Computes the digest of this MAC based on the data previously specified in + * {@link #update} calls and stores the digest in the specified {@code + * output} buffer at offset {@code outOffset}. + * <p> + * This {@code Mac} instance is reverted to its initial state and can be + * used to start the next MAC computation with the same parameters or + * initialized with different parameters. + * </p> + * + * @param output + * the output buffer + * @param outOffset + * the offset in the output buffer + * @throws ShortBufferException + * if the specified output buffer is either too small for the + * digest to be stored, the specified output buffer is {@code + * null}, or the specified offset is negative or past the length + * of the output buffer. + * @throws IllegalStateException + * if this MAC is not initialized. + * @since Android 1.0 */ public final void doFinal(byte[] output, int outOffset) throws ShortBufferException, IllegalStateException { @@ -273,8 +394,21 @@ public class Mac implements Cloneable { } /** - * @com.intel.drl.spec_ref - * + * Computes the digest of this MAC based on the data previously specified on + * {@link #update} calls and on the final bytes specified by {@code input} + * (or based on those bytes only). + * <p> + * This {@code Mac} instance is reverted to its initial state and can be + * used to start the next MAC computation with the same parameters or + * initialized with different parameters. + * </p> + * + * @param input + * the final bytes. + * @return the generated digest. + * @throws IllegalStateException + * if this MAC is not initialized. + * @since Android 1.0 */ public final byte[] doFinal(byte[] input) throws IllegalStateException { if (!isInitMac) { @@ -287,16 +421,26 @@ public class Mac implements Cloneable { } /** - * @com.intel.drl.spec_ref - * + * Resets this {@code Mac} instance to its initial state. + * <p> + * This {@code Mac} instance is reverted to its initial state and can be + * used to start the next MAC computation with the same parameters or + * initialized with different parameters. + * </p> + * + * @since Android 1.0 */ public final void reset() { spiImpl.engineReset(); } /** - * @com.intel.drl.spec_ref - * + * Clones this {@code Mac} instance and the underlying implementation. + * + * @return the cloned instance. + * @throws CloneNotSupportedException + * if the underlying implementation does not support cloning. + * @since Android 1.0 */ @Override public final Object clone() throws CloneNotSupportedException { diff --git a/crypto/src/main/java/javax/crypto/MacSpi.java b/crypto/src/main/java/javax/crypto/MacSpi.java index b02560d..4756184 100644 --- a/crypto/src/main/java/javax/crypto/MacSpi.java +++ b/crypto/src/main/java/javax/crypto/MacSpi.java @@ -15,11 +15,6 @@ * limitations under the License. */ -/** -* @author Vera Y. Petrashkova -* @version $Revision$ -*/ - package javax.crypto; import java.security.Key; @@ -29,46 +24,81 @@ import java.security.spec.AlgorithmParameterSpec; import java.nio.ByteBuffer; /** - * @com.intel.drl.spec_ref + * The <i>Service-Provider Interface</i> (<b>SPI</b>) definition for the {@code + * Mac} class. * + * @see Mac + * @since Android 1.0 */ - public abstract class MacSpi { + /** - * @com.intel.drl.spec_ref - * + * Creates a new {@code MacSpi} instance. + * + * @since Android 1.0 */ public MacSpi() { } /** - * @com.intel.drl.spec_ref - * + * Returns the length of this MAC (in bytes). + * + * @return the length of this MAC (in bytes). + * @since Android 1.0 */ protected abstract int engineGetMacLength(); /** - * @com.intel.drl.spec_ref - * + * Initializes this {@code MacSpi} instance with the specified key and + * algorithm parameters. + * + * @param key + * the key to initialize this algorithm. + * @param params + * the parameters for this algorithm. + * @throws InvalidKeyException + * if the specified key cannot be used to initialize this + * algorithm, or it is {@code null}. + * @throws InvalidAlgorithmParameterException + * if the specified parameters cannot be used to initialize this + * algorithm. + * @since Android 1.0 */ protected abstract void engineInit(Key key, AlgorithmParameterSpec params) throws InvalidKeyException, InvalidAlgorithmParameterException; /** - * @com.intel.drl.spec_ref - * + * Updates this {@code MacSpi} instance with the specified byte. + * + * @param input + * the byte. + * @since Android 1.0 */ protected abstract void engineUpdate(byte input); /** - * @com.intel.drl.spec_ref - * + * Updates this {@code MacSpi} instance with the data from the specified + * buffer {@code input} from the specified {@code offset} and length {@code + * len}. + * + * @param input + * the buffer. + * @param offset + * the offset in the buffer. + * @param len + * the length of the data in the buffer. + * @since Android 1.0 */ protected abstract void engineUpdate(byte[] input, int offset, int len); /** - * @com.intel.drl.spec_ref - * + * Updates this {@code MacSpi} instance with the data from the specified + * buffer, starting at {@link ByteBuffer#position()}, including the next + * {@link ByteBuffer#remaining()} bytes. + * + * @param input + * the buffer. + * @since Android 1.0 */ protected void engineUpdate(ByteBuffer input) { if (!input.hasRemaining()) { @@ -90,20 +120,38 @@ public abstract class MacSpi { } /** - * @com.intel.drl.spec_ref - * + * Computes the digest of this MAC based on the data previously specified in + * {@link #engineUpdate} calls. + * <p> + * This {@code MacSpi} instance is reverted to its initial state and + * can be used to start the next MAC computation with the same parameters or + * initialized with different parameters. + * </p> + * + * @return the generated digest. + * @since Android 1.0 */ protected abstract byte[] engineDoFinal(); /** - * @com.intel.drl.spec_ref - * + * Resets this {@code MacSpi} instance to its initial state. + * <p> + * This {@code MacSpi} instance is reverted to its initial state and can be + * used to start the next MAC computation with the same parameters or + * initialized with different parameters. + * </p> + * + * @since Android 1.0 */ protected abstract void engineReset(); /** - * @com.intel.drl.spec_ref - * + * Clones this {@code MacSpi} instance. + * + * @return the cloned instance. + * @throws CloneNotSupportedException + * if cloning is not supported. + * @since Android 1.0 */ @Override public Object clone() throws CloneNotSupportedException { diff --git a/crypto/src/main/java/javax/crypto/NoSuchPaddingException.java b/crypto/src/main/java/javax/crypto/NoSuchPaddingException.java index 0fb196f..4afb8ab 100644 --- a/crypto/src/main/java/javax/crypto/NoSuchPaddingException.java +++ b/crypto/src/main/java/javax/crypto/NoSuchPaddingException.java @@ -15,18 +15,15 @@ * limitations under the License. */ -/** -* @author Vera Y. Petrashkova -* @version $Revision$ -*/ - package javax.crypto; import java.security.GeneralSecurityException; /** - * @com.intel.drl.spec_ref + * The exception that is thrown when the requested padding mechanism is not + * supported. * + * @since Android 1.0 */ public class NoSuchPaddingException extends GeneralSecurityException { @@ -36,16 +33,21 @@ public class NoSuchPaddingException extends GeneralSecurityException { private static final long serialVersionUID = -4572885201200175466L; /** - * @com.intel.drl.spec_ref + * Creates a new {@code NoSuchPaddingException} with the specified + * message. * + * @param msg + * the message. + * @since Android 1.0 */ public NoSuchPaddingException(String msg) { super(msg); } /** - * @com.intel.drl.spec_ref + * Creates a new {@code NoSuchPaddingException}. * + * @since Android 1.0 */ public NoSuchPaddingException() { } diff --git a/crypto/src/main/java/javax/crypto/NullCipher.java b/crypto/src/main/java/javax/crypto/NullCipher.java index 34b3e85..49f96c2 100644 --- a/crypto/src/main/java/javax/crypto/NullCipher.java +++ b/crypto/src/main/java/javax/crypto/NullCipher.java @@ -30,14 +30,15 @@ import org.apache.harmony.crypto.internal.NullCipherSpi; /** - * @com.intel.drl.spec_ref - * + * This class provides an identity cipher that does not transform the input data + * in any way. The <i>encrypted</i> data is identical to the <i>plain text</i>. + * + * @since Android 1.0 */ public class NullCipher extends Cipher { /** - * @com.intel.drl.spec_ref - * + * Creates a new {@code NullCipher} instance. */ public NullCipher() { super(new NullCipherSpi(), null, null); diff --git a/crypto/src/main/java/javax/crypto/SealedObject.java b/crypto/src/main/java/javax/crypto/SealedObject.java index 65b60e4..4e71453 100644 --- a/crypto/src/main/java/javax/crypto/SealedObject.java +++ b/crypto/src/main/java/javax/crypto/SealedObject.java @@ -15,11 +15,6 @@ * limitations under the License. */ -/** -* @author Alexander Y. Kleymenov -* @version $Revision$ -*/ - package javax.crypto; import java.io.ByteArrayInputStream; @@ -40,7 +35,17 @@ import javax.crypto.NoSuchPaddingException; import org.apache.harmony.crypto.internal.nls.Messages; /** - * @com.intel.drl.spec_ref + * A {@code SealedObject} is a wrapper around a {@code serializable} object + * instance and encrypts it using a cryptographic cipher. + * <p> + * Since a {@code SealedObject} instance is a serializable object itself it can + * either be stored or transmitted over an insecure channel. + * </p> + * The wrapped object can later be decrypted (unsealed) using the corresponding + * key and then be deserialized to retrieve the original object.The sealed + * object itself keeps track of the cipher and corresponding parameters. + * + * @since Android 1.0 */ public class SealedObject implements Serializable { @@ -51,7 +56,7 @@ public class SealedObject implements Serializable { private static final long serialVersionUID = 4482838265551344752L; /** - * @com.intel.drl.spec_ref + * The {@link AlgorithmParameters} in encoded format. */ protected byte[] encodedParams; private byte[] encryptedContent; @@ -67,7 +72,25 @@ public class SealedObject implements Serializable { } /** - * @com.intel.drl.spec_ref + * Creates a new {@code SealedObject} instance wrapping the specified object + * and sealing it using the specified cipher. + * <p> + * The cipher must be fully initialized. + * </p> + * + * @param object + * the object to seal, can be {@code null}. + * @param c + * the cipher to encrypt the object. + * @throws IOException + * if the serialization fails. + * @throws IllegalBlockSizeException + * if the specified cipher is a block cipher and the length of + * the serialized data is not a multiple of the ciphers block + * size. + * @throws NullPointerException + * if the cipher is {@code null}. + * @since Android 1.0 */ public SealedObject(Serializable object, Cipher c) throws IOException, IllegalBlockSizeException { @@ -92,7 +115,12 @@ public class SealedObject implements Serializable { } /** - * @com.intel.drl.spec_ref + * Creates a new {@code SealedObject} instance by copying the data from + * the specified object. + * + * @param so + * the object to copy. + * @since Android 1.0 */ protected SealedObject(SealedObject so) { if (so == null) { @@ -105,18 +133,40 @@ public class SealedObject implements Serializable { } /** - * @com.intel.drl.spec_ref + * Returns the algorithm this object was sealed with. + * + * @return the algorithm this object was sealed with. + * @since Android 1.0 */ public final String getAlgorithm() { return sealAlg; } /** - * @com.intel.drl.spec_ref + * Returns the wrapped object, decrypting it using the specified key. + * + * @param key + * the key to decrypt the data with. + * @return the encapsulated object. + * @throws IOException + * if deserialization fails. + * @throws ClassNotFoundException + * if deserialization fails. + * @throws NoSuchAlgorithmException + * if the algorithm to decrypt the data is not available. + * @throws InvalidKeyException + * if the specified key cannot be used to decrypt the data. + * @since Android 1.0 */ public final Object getObject(Key key) throws IOException, ClassNotFoundException, NoSuchAlgorithmException, InvalidKeyException { + // BEGIN android-added + if (key == null) { + throw new InvalidKeyException( + Messages.getString("crypto.05")); + } + // END android-added try { Cipher cipher = Cipher.getInstance(sealAlg); if ((paramsAlg != null) && (paramsAlg.length() != 0)) { @@ -155,7 +205,23 @@ public class SealedObject implements Serializable { } /** - * @com.intel.drl.spec_ref + * Returns the wrapped object, decrypting it using the specified + * cipher. + * + * @param c + * the cipher to decrypt the data. + * @return the encapsulated object. + * @throws IOException + * if deserialization fails. + * @throws ClassNotFoundException + * if deserialization fails. + * @throws IllegalBlockSizeException + * if the specified cipher is a block cipher and the length of + * the serialized data is not a multiple of the ciphers block + * size. + * @throws BadPaddingException + * if the padding of the data does not match the padding scheme. + * @since Android 1.0 */ public final Object getObject(Cipher c) throws IOException, ClassNotFoundException, @@ -171,7 +237,25 @@ public class SealedObject implements Serializable { } /** - * @com.intel.drl.spec_ref + * Returns the wrapped object, decrypting it using the specified key. The + * specified provider is used to retrieve the cipher algorithm. + * + * @param key + * the key to decrypt the data. + * @param provider + * the name of the provider that provides the cipher algorithm. + * @return the encapsulated object. + * @throws IOException + * if deserialization fails. + * @throws ClassNotFoundException + * if deserialization fails. + * @throws NoSuchAlgorithmException + * if the algorithm used to decrypt the data is not available. + * @throws NoSuchProviderException + * if the specified provider is not available. + * @throws InvalidKeyException + * if the specified key cannot be used to decrypt the data. + * @since Android 1.0 */ public final Object getObject(Key key, String provider) throws IOException, ClassNotFoundException, diff --git a/crypto/src/main/java/javax/crypto/SecretKey.java b/crypto/src/main/java/javax/crypto/SecretKey.java index 3c10cda..102f888 100644 --- a/crypto/src/main/java/javax/crypto/SecretKey.java +++ b/crypto/src/main/java/javax/crypto/SecretKey.java @@ -15,25 +15,30 @@ * limitations under the License. */ -/** -* @author Vera Y. Petrashkova -* @version $Revision$ -*/ - package javax.crypto; import java.security.Key; /** - * @com.intel.drl.spec_ref + * A cryptographic secret (symmetric) key. + * <p> + * This interface is a <i>marker interface</i> to group secret keys and to + * provide type safety for. + * </p> + * Implementations of this interface have to overwrite the + * {@link Object#equals(Object) equals} and {@link Object#hashCode() hashCode} + * from {@link java.lang.Object} so comparison is done using the actual key data + * and not the object reference. * + * @since Android 1.0 */ public interface SecretKey extends Key { /** - * @com.intel.drl.spec_ref + * The serialization version identifier. + * * @serial - * + * @since Android 1.0 */ public static final long serialVersionUID = -4795878709595146952L; }
\ No newline at end of file diff --git a/crypto/src/main/java/javax/crypto/SecretKeyFactory.java b/crypto/src/main/java/javax/crypto/SecretKeyFactory.java index adeb456..a420dab 100644 --- a/crypto/src/main/java/javax/crypto/SecretKeyFactory.java +++ b/crypto/src/main/java/javax/crypto/SecretKeyFactory.java @@ -15,11 +15,6 @@ * limitations under the License. */ -/** -* @author Vera Y. Petrashkova -* @version $Revision$ -*/ - package javax.crypto; import java.security.InvalidKeyException; @@ -35,8 +30,19 @@ import org.apache.harmony.security.fortress.Engine; /** - * @com.intel.drl.spec_ref + * The public API for {@code SecretKeyFactory} implementations. + * <p> + * Secret key factories provide the following functionality: + * <ul> + * <li>convert {@link SecretKey} objects to and from {@link KeySpec} objects</li> + * <li>translate {@link SecretKey} objects from one provider implementation to + * another</li> + * </ul> + * Which key specifications are supported by the {@link #generateSecret} and + * {@link #getKeySpec} is provider dependent. + * </p> * + * @since Android 1.0 */ public class SecretKeyFactory { @@ -53,8 +59,15 @@ public class SecretKeyFactory { private final String algorithm; /** - * @com.intel.drl.spec_ref - * + * Creates a new {@code SecretKeyFactory} + * + * @param keyFacSpi + * the SPI delegate. + * @param provider + * the provider providing this key factory. + * @param algorithm + * the algorithm name for the secret key. + * @since Android 1.0 */ protected SecretKeyFactory(SecretKeyFactorySpi keyFacSpi, Provider provider, String algorithm) { @@ -64,24 +77,37 @@ public class SecretKeyFactory { } /** - * @com.intel.drl.spec_ref - * + * Returns the name of the secret key algorithm. + * + * @return the name of the secret key algorithm. + * @since Android 1.0 */ public final String getAlgorithm() { return algorithm; } /** - * @com.intel.drl.spec_ref - * + * Returns the provider for this {@code SecretKeyFactory} instance. + * + * @return the provider for this {@code SecretKeyFactory} instance. + * @since Android 1.0 */ public final Provider getProvider() { return provider; } /** - * @com.intel.drl.spec_ref - * + * Creates a new {@code SecretKeyFactory} instance for the specified key + * algorithm. + * + * @param algorithm + * the name of the key algorithm. + * @return a secret key factory for the specified key algorithm. + * @throws NoSuchAlgorithmException + * if no installed provider can provide the requested algorithm. + * @throws NullPointerException + * if the specified algorithm is {@code null}. + * @since Android 1.0 */ public static final SecretKeyFactory getInstance(String algorithm) throws NoSuchAlgorithmException { @@ -96,8 +122,24 @@ public class SecretKeyFactory { } /** - * @com.intel.drl.spec_ref - * + * Creates a new {@code SecretKeyFactory} instance for the specified key + * algorithm from the specified {@code provider}. + * + * @param algorithm + * the name of the key algorithm. + * @param provider + * the name of the provider that provides the requested + * algorithm. + * @return a secret key factory for the specified key algorithm from the + * specified provider. + * @throws NoSuchAlgorithmException + * if the specified provider cannot provide the requested + * algorithm. + * @throws NoSuchProviderException + * if the specified provider does not exist. + * @throws IllegalArgumentException + * if the specified provider name is {@code null} or empty. + * @since Android 1.0 */ public static final SecretKeyFactory getInstance(String algorithm, String provider) throws NoSuchAlgorithmException, @@ -113,8 +155,23 @@ public class SecretKeyFactory { } /** - * @com.intel.drl.spec_ref - * + * Creates a new {@code SecretKeyFactory} instance for the specified key + * algorithm from the specified provider. + * + * @param algorithm + * the name of the key algorithm. + * @param provider + * the provider that provides the requested algorithm. + * @return a secret key factory for the specified key algorithm from the + * specified provider. + * @throws NoSuchAlgorithmException + * if the specified provider cannot provider the requested + * algorithm. + * @throws IllegalArgumentException + * if the specified provider is {@code null}. + * @throws NullPointerException + * is the specified algorithm name is {@code null}. + * @since Android 1.0 */ public static final SecretKeyFactory getInstance(String algorithm, Provider provider) throws NoSuchAlgorithmException { @@ -132,8 +189,15 @@ public class SecretKeyFactory { } /** - * @com.intel.drl.spec_ref - * + * Generate a secret key from the specified key specification. + * + * @param keySpec + * the key specification. + * @return a secret key. + * @throws InvalidKeySpecException + * if the specified key specification cannot be used to generate + * a secret key. + * @since Android 1.0 */ public final SecretKey generateSecret(KeySpec keySpec) throws InvalidKeySpecException { @@ -141,8 +205,17 @@ public class SecretKeyFactory { } /** - * @com.intel.drl.spec_ref - * + * Returns the key specification of the specified secret key. + * + * @param key + * the secret key to get the specification from. + * @param keySpec + * the target key specification class. + * @return an instance of the specified key specification class. + * @throws InvalidKeySpecException + * if the specified secret key cannot be transformed into the + * requested key specification. + * @since Android 1.0 */ @SuppressWarnings("unchecked") public final KeySpec getKeySpec(SecretKey key, Class keySpec) @@ -151,8 +224,16 @@ public class SecretKeyFactory { } /** - * @com.intel.drl.spec_ref - * + * Translates the specified secret key into an instance of the corresponding + * key from the provider of this key factory. + * + * @param key + * the secret key to translate. + * @return the corresponding translated key. + * @throws InvalidKeyException + * if the specified key cannot be translated using this key + * factory. + * @since Android 1.0 */ public final SecretKey translateKey(SecretKey key) throws InvalidKeyException { diff --git a/crypto/src/main/java/javax/crypto/SecretKeyFactorySpi.java b/crypto/src/main/java/javax/crypto/SecretKeyFactorySpi.java index d72f6d5..f834dbb 100644 --- a/crypto/src/main/java/javax/crypto/SecretKeyFactorySpi.java +++ b/crypto/src/main/java/javax/crypto/SecretKeyFactorySpi.java @@ -15,11 +15,6 @@ * limitations under the License. */ -/** -* @author Vera Y. Petrashkova -* @version $Revision$ -*/ - package javax.crypto; import java.security.InvalidKeyException; @@ -27,36 +22,62 @@ import java.security.spec.InvalidKeySpecException; import java.security.spec.KeySpec; /** - * @com.intel.drl.spec_ref + * The <i>Service Provider Interface</i> (<b>SPI</b>) definition for the {@code + * SecretKeyFactory} class. * + * @since Android 1.0 */ public abstract class SecretKeyFactorySpi { /** - * @com.intel.drl.spec_ref - * + * Creates a new {@code SecretKeyFactorySpi} instance. + * @since Android 1.0 */ public SecretKeyFactorySpi() { } /** - * @com.intel.drl.spec_ref - * + * Generate a secret key from the specified key specification. + * + * @param keySpec + * the key specification. + * @return a secret key. + * @throws InvalidKeySpecException + * if the specified key specification cannot be used to generate + * a secret key. + * @since Android 1.0 */ protected abstract SecretKey engineGenerateSecret(KeySpec keySpec) throws InvalidKeySpecException; /** - * @com.intel.drl.spec_ref - * + * Returns the key specification of the specified secret key. + * + * @param key + * the secret key to get the specification from. + * @param keySpec + * the target key specification class. + * @return an instance of the specified key specification class. + * @throws InvalidKeySpecException + * if the specified secret key cannot be transformed into the + * requested key specification. + * @since Android 1.0 */ @SuppressWarnings("unchecked") protected abstract KeySpec engineGetKeySpec(SecretKey key, Class keySpec) throws InvalidKeySpecException; /** - * @com.intel.drl.spec_ref - * + * Translates the specified secret key into an instance of the corresponding + * key from the provider of this key factory. + * + * @param key + * the secret key to translate. + * @return the corresponding translated key. + * @throws InvalidKeyException + * if the specified key cannot be translated using this key + * factory. + * @since Android 1.0 */ protected abstract SecretKey engineTranslateKey(SecretKey key) throws InvalidKeyException; diff --git a/crypto/src/main/java/javax/crypto/ShortBufferException.java b/crypto/src/main/java/javax/crypto/ShortBufferException.java index d1e44a8..593a31e 100644 --- a/crypto/src/main/java/javax/crypto/ShortBufferException.java +++ b/crypto/src/main/java/javax/crypto/ShortBufferException.java @@ -25,8 +25,10 @@ package javax.crypto; import java.security.GeneralSecurityException; /** - * @com.intel.drl.spec_ref + * The exception that is thrown when the result of an operation is attempted to + * store in a user provided buffer that is too small. * + * @since Android 1.0 */ public class ShortBufferException extends GeneralSecurityException { @@ -36,16 +38,21 @@ public class ShortBufferException extends GeneralSecurityException { private static final long serialVersionUID = 8427718640832943747L; /** - * @com.intel.drl.spec_ref + * Creates a new instance of {@code ShortBufferException} with the + * specified message * + * @param msg + * the exception message. + * @since Android 1.0 */ public ShortBufferException(String msg) { super(msg); } /** - * @com.intel.drl.spec_ref + * Creates a new instance of {@code ShortBufferException}. * + * @since Android 1.0 */ public ShortBufferException() { } diff --git a/crypto/src/main/java/javax/crypto/interfaces/DHKey.java b/crypto/src/main/java/javax/crypto/interfaces/DHKey.java index f128033..f686844 100644 --- a/crypto/src/main/java/javax/crypto/interfaces/DHKey.java +++ b/crypto/src/main/java/javax/crypto/interfaces/DHKey.java @@ -15,24 +15,21 @@ * limitations under the License. */ -/** -* @author Vera Y. Petrashkova -* @version $Revision$ -*/ - package javax.crypto.interfaces; import javax.crypto.spec.DHParameterSpec; /** - * @com.intel.drl.spec_ref + * The interface for a Diffie-Hellman key. * + * @since Android 1.0 */ public interface DHKey { /** - * @com.intel.drl.spec_ref - * + * Returns the parameters for this key. + * + * @return the parameters for this key. */ public DHParameterSpec getParams(); } diff --git a/crypto/src/main/java/javax/crypto/interfaces/DHPrivateKey.java b/crypto/src/main/java/javax/crypto/interfaces/DHPrivateKey.java index 7eda7d4..d39268b 100644 --- a/crypto/src/main/java/javax/crypto/interfaces/DHPrivateKey.java +++ b/crypto/src/main/java/javax/crypto/interfaces/DHPrivateKey.java @@ -15,31 +15,26 @@ * limitations under the License. */ -/** -* @author Vera Y. Petrashkova -* @version $Revision$ -*/ - package javax.crypto.interfaces; import java.math.BigInteger; import java.security.PrivateKey; /** - * @com.intel.drl.spec_ref + * The interface for a private key in the Diffie-Hellman key exchange protocol. * + * @since Android 1.0 */ public interface DHPrivateKey extends DHKey, PrivateKey { /** - * @com.intel.drl.spec_ref - * @serial + * The serialization version identifier. */ public static final long serialVersionUID = 2211791113380396553L; /** - * @com.intel.drl.spec_ref - * + * Returns this key's private value x. + * @return this key's private value x. */ public BigInteger getX(); diff --git a/crypto/src/main/java/javax/crypto/interfaces/DHPublicKey.java b/crypto/src/main/java/javax/crypto/interfaces/DHPublicKey.java index 4d3fb6a..75201a7 100644 --- a/crypto/src/main/java/javax/crypto/interfaces/DHPublicKey.java +++ b/crypto/src/main/java/javax/crypto/interfaces/DHPublicKey.java @@ -15,31 +15,26 @@ * limitations under the License. */ -/** -* @author Vera Y. Petrashkova -* @version $Revision$ -*/ - package javax.crypto.interfaces; import java.math.BigInteger; import java.security.PublicKey; /** - * @com.intel.drl.spec_ref + * The interface for a public key in the Diffie-Hellman key exchange protocol. * + * @since Android 1.0 */ public interface DHPublicKey extends DHKey, PublicKey { /** - * @com.intel.drl.spec_ref - * @serial + * The serial version identifier. */ public static final long serialVersionUID = -6628103563352519193L; /** - * @com.intel.drl.spec_ref - * + * Returns this key's public value Y. + * @return this key's public value Y. */ public BigInteger getY(); }
\ No newline at end of file diff --git a/crypto/src/main/java/javax/crypto/interfaces/PBEKey.java b/crypto/src/main/java/javax/crypto/interfaces/PBEKey.java index 991a4c0..4612ad2 100644 --- a/crypto/src/main/java/javax/crypto/interfaces/PBEKey.java +++ b/crypto/src/main/java/javax/crypto/interfaces/PBEKey.java @@ -15,42 +15,40 @@ * limitations under the License. */ -/** -* @author Vera Y. Petrashkova -* @version $Revision$ -*/ - package javax.crypto.interfaces; import javax.crypto.SecretKey; /** - * @com.intel.drl.spec_ref + * The interface to a <i>password-based-encryption</i> key. * + * @since Android 1.0 */ public interface PBEKey extends SecretKey { /** - * @com.intel.drl.spec_ref - * @serial + * The serial version identifier. */ public static final long serialVersionUID = -1430015993304333921L; /** - * @com.intel.drl.spec_ref - * + * Returns the iteration count, 0 if not specified. + * + * @return the iteration count, 0 if not specified. */ public int getIterationCount(); /** - * @com.intel.drl.spec_ref - * + * Returns a copy of the salt data or null if not specified. + * + * @return a copy of the salt data or null if not specified. */ public byte[] getSalt(); /** - * @com.intel.drl.spec_ref - * + * Returns a copy to the password. + * + * @return a copy to the password. */ public char[] getPassword(); diff --git a/crypto/src/main/java/javax/crypto/interfaces/package.html b/crypto/src/main/java/javax/crypto/interfaces/package.html index e5817d1..04a7c0b 100644 --- a/crypto/src/main/java/javax/crypto/interfaces/package.html +++ b/crypto/src/main/java/javax/crypto/interfaces/package.html @@ -1,16 +1,12 @@ <html> -<head> -<meta http-equiv="Content-Type" content="text/html; charset=us-ascii"> -</head> -<html> -<body> -<p> -This package provides the interfaces needed to implement the Diffie-Hellman (DH) -key agreement's algorithm as specified by PKCS#3. - -The parameters for the DH algorithm must be accessed without unduly restriction as for example -hardware repository for the parameters material. + <body> + <p> + This package provides the interfaces needed to implement the + Diffie-Hellman (DH) key agreement's algorithm as specified by PKCS#3. -</p> -</body> + The parameters for the DH algorithm must be accessed without unduly + restriction as for example hardware repository for the parameters material. + </p> + @since Android 1.0 + </body> </html>
\ No newline at end of file diff --git a/crypto/src/main/java/javax/crypto/package.html b/crypto/src/main/java/javax/crypto/package.html index 20c0c63..3f3bb47 100644 --- a/crypto/src/main/java/javax/crypto/package.html +++ b/crypto/src/main/java/javax/crypto/package.html @@ -5,15 +5,15 @@ <html> <body> <p> -This package provides the classes and interfaces needed to define encryption algorithm, -keys' agreement algorithms and MAC (Message Authentication Code). Stream ciphers are supported -as well as asymmetric, symmetric, block ciphers. -With class {@link javax.crypto.SealedObject} a programmer can secure an object by -encrypting it with a supported cipher. -Not only MAC but also HMAC (Hash MAC) with sha-1 arr supported. - -Ciphers' implementations from different providers ae easily integrated in the package thanks -to the SPI (Security Provider Interface) abstract classes. +This package provides the classes and interfaces for cryptographic applications implementing algorithms for encryption, decryption, or +key agreement. +</p><p> +Stream ciphers are supported as well as asymmetric, symmetric and block ciphers. Cipher implementations from different providers are easily integratable thanks +to the SPI (Security Provider Interface) abstract classes. With class {@link javax.crypto.SealedObject} a programmer can secure an object by +encrypting it with a cipher. +</p><p> +Authentication may be based on MAC (Message Authentication Code) such as HMAC (Hash MAC, i.e. with a SHA-1 hash function). </p> +@since Android 1.0 </body> </html> diff --git a/crypto/src/main/java/javax/crypto/spec/DESKeySpec.java b/crypto/src/main/java/javax/crypto/spec/DESKeySpec.java index 67166ab..2a994d5 100644 --- a/crypto/src/main/java/javax/crypto/spec/DESKeySpec.java +++ b/crypto/src/main/java/javax/crypto/spec/DESKeySpec.java @@ -23,12 +23,14 @@ import java.security.spec.KeySpec; import org.apache.harmony.crypto.internal.nls.Messages; /** - * @com.intel.drl.spec_ref + * The key specification for a DES key. + * + * @since Android 1.0 */ public class DESKeySpec implements KeySpec { /** - * @com.intel.drl.spec_ref + * The length of a DES key in bytes. */ public static final int DES_KEY_LEN = 8; @@ -92,14 +94,29 @@ public class DESKeySpec implements KeySpec { }; /** - * @com.intel.drl.spec_ref + * Creates a new <code>DESKeySpec</code> from the first 8 bytes of the + * specified key data. + * + * @param key + * the key data. + * @throws InvalidKeyException + * if the length of the specified key data is less than 8. */ public DESKeySpec(byte[] key) throws InvalidKeyException { this(key, 0); } /** - * @com.intel.drl.spec_ref + * Creates a new <code>DESKeySpec</code> from the first 8 bytes of the + * specified key data starting at <code>offset</code>. + * + * @param key + * the key data + * @param offset + * the offset to start at. + * @throws InvalidKeyException + * if the length of the specified key data starting at offset is + * less than 8. */ public DESKeySpec(byte[] key, int offset) throws InvalidKeyException { @@ -115,7 +132,9 @@ public class DESKeySpec implements KeySpec { } /** - * @com.intel.drl.spec_ref + * Returns a copy of the key. + * + * @return a copy of the key. */ public byte[] getKey() { byte[] result = new byte[DES_KEY_LEN]; @@ -124,7 +143,18 @@ public class DESKeySpec implements KeySpec { } /** - * @com.intel.drl.spec_ref + * Returns whether the specified key data starting at <code>offset</code> is + * <i>parity-adjusted</i>. + * + * @param key + * the key data. + * @param offset + * the offset to start checking at. + * @return {@code true} if the specified key data is parity-adjusted, + * {@code false} otherwise. + * @throws InvalidKeyException + * if the length of the key data starting at offset is less than + * 8, or the key is null. */ public static boolean isParityAdjusted(byte[] key, int offset) throws InvalidKeyException { @@ -153,7 +183,17 @@ public class DESKeySpec implements KeySpec { } /** - * @com.intel.drl.spec_ref + * Returns whether the specified key data starting at <code>offset</code> is + * weak or semi-weak. + * + * @param key + * the key data. + * @param offset + * the offset to start checking at. + * @return {@code true} if the specified key data is weak or semi-weak. + * @throws InvalidKeyException + * if the length of the key data starting at offset is less than + * 8, or it is null. */ public static boolean isWeak(byte[] key, int offset) throws InvalidKeyException { diff --git a/crypto/src/main/java/javax/crypto/spec/DESedeKeySpec.java b/crypto/src/main/java/javax/crypto/spec/DESedeKeySpec.java index 3c04547..186f07d 100644 --- a/crypto/src/main/java/javax/crypto/spec/DESedeKeySpec.java +++ b/crypto/src/main/java/javax/crypto/spec/DESedeKeySpec.java @@ -14,10 +14,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -/** -* @author Alexander Y. Kleymenov -* @version $Revision$ -*/ package javax.crypto.spec; @@ -27,19 +23,29 @@ import java.security.spec.KeySpec; import org.apache.harmony.crypto.internal.nls.Messages; /** - * @com.intel.drl.spec_ref + * The key specification for a triple-DES (DES-EDE) key. + * + * @since Android 1.0 */ public class DESedeKeySpec implements KeySpec { /** - * @com.intel.drl.spec_ref + * The length of a DES-EDE key in bytes. */ public static final int DES_EDE_KEY_LEN = 24; private final byte[] key; /** - * @com.intel.drl.spec_ref + * Creates a new <code>DESedeKeySpec</code> instance from the first 24 ( + * {@link #DES_EDE_KEY_LEN}) bytes of the specified key data. + * + * @param key + * the key data. + * @throws InvalidKeyException + * if the length of the key data is less than 24. + * @throws NullPointerException + * if the key data is null. */ public DESedeKeySpec(byte[] key) throws InvalidKeyException { @@ -55,7 +61,19 @@ public class DESedeKeySpec implements KeySpec { } /** - * @com.intel.drl.spec_ref + * Creates a new <code>DESedeKeySpec</code> instance from the first 24 ( + * {@link #DES_EDE_KEY_LEN} ) bytes of the specified key data starting at + * <code>offset</code>. + * + * @param key + * the key data + * @param offset + * the offset to start at. + * @throws InvalidKeyException + * if the length of the key data starting at offset is less than + * 24. + * @throws NullPointerException + * if the key data is null. */ public DESedeKeySpec(byte[] key, int offset) throws InvalidKeyException { @@ -71,7 +89,9 @@ public class DESedeKeySpec implements KeySpec { } /** - * @com.intel.drl.spec_ref + * Returns a copy of the key. + * + * @return a copy of the key. */ public byte[] getKey() { byte[] result = new byte [DES_EDE_KEY_LEN]; @@ -80,7 +100,18 @@ public class DESedeKeySpec implements KeySpec { } /** - * @com.intel.drl.spec_ref + * Returns whether the specified key data starting at <code>offset</code> is + * <i>parity-adjusted</i>. + * + * @param key + * the key data. + * @param offset + * the offset to start checking at. + * @return {@code true} if the specified key data is parity-adjusted, + * {@code false} otherwise. + * @throws InvalidKeyException + * if the length of the key data starting at offset is less than + * 24. */ public static boolean isParityAdjusted(byte[] key, int offset) throws InvalidKeyException { diff --git a/crypto/src/main/java/javax/crypto/spec/DHGenParameterSpec.java b/crypto/src/main/java/javax/crypto/spec/DHGenParameterSpec.java index 7beea4b..a149318 100644 --- a/crypto/src/main/java/javax/crypto/spec/DHGenParameterSpec.java +++ b/crypto/src/main/java/javax/crypto/spec/DHGenParameterSpec.java @@ -15,17 +15,15 @@ * limitations under the License. */ -/** -* @author Alexander Y. Kleymenov -* @version $Revision$ -*/ - package javax.crypto.spec; import java.security.spec.AlgorithmParameterSpec; /** - * @com.intel.drl.spec_ref + * The algorithm parameter specification for generating Diffie-Hellman + * parameters used in Diffie-Hellman key agreement. + * + * @since Android 1.0 */ public class DHGenParameterSpec implements AlgorithmParameterSpec { @@ -33,7 +31,13 @@ public class DHGenParameterSpec implements AlgorithmParameterSpec { private final int exponentSize; /** - * @com.intel.drl.spec_ref + * Creates a new <code>DHGenParameterSpec</code> instance with the specified + * parameters. + * + * @param primeSize + * the size of the <i>prime modulus</i> in bits. + * @param exponentSize + * the size of the <i>random exponent</i> in bits. */ public DHGenParameterSpec(int primeSize, int exponentSize) { this.primeSize = primeSize; @@ -41,14 +45,18 @@ public class DHGenParameterSpec implements AlgorithmParameterSpec { } /** - * @com.intel.drl.spec_ref + * Returns the size of the <i>prime modulus</i> in bits. + * + * @return the size of the prime modulus in bits. */ public int getPrimeSize() { return primeSize; } /** - * @com.intel.drl.spec_ref + * Returns the size of the <i>random exponent</i> in bits. + * + * @return the size of the random exponent in bits. */ public int getExponentSize() { return exponentSize; diff --git a/crypto/src/main/java/javax/crypto/spec/DHParameterSpec.java b/crypto/src/main/java/javax/crypto/spec/DHParameterSpec.java index 030cfcb..9bb94b5 100644 --- a/crypto/src/main/java/javax/crypto/spec/DHParameterSpec.java +++ b/crypto/src/main/java/javax/crypto/spec/DHParameterSpec.java @@ -15,18 +15,15 @@ * limitations under the License. */ -/** -* @author Alexander Y. Kleymenov -* @version $Revision$ -*/ - package javax.crypto.spec; import java.math.BigInteger; import java.security.spec.AlgorithmParameterSpec; /** - * @com.intel.drl.spec_ref + * The algorithm parameter specification for the Diffie-Hellman algorithm. + * + * @since Android 1.0 */ public class DHParameterSpec implements AlgorithmParameterSpec { @@ -35,7 +32,13 @@ public class DHParameterSpec implements AlgorithmParameterSpec { private final int l; /** - * @com.intel.drl.spec_ref + * Creates a new <code>DHParameterSpec</code> instance with the specified + * <i>prime modulus</i> and <i>base generator</i>. + * + * @param p + * the prime modulus. + * @param g + * the base generator. */ public DHParameterSpec(BigInteger p, BigInteger g) { this.p = p; @@ -44,7 +47,16 @@ public class DHParameterSpec implements AlgorithmParameterSpec { } /** - * @com.intel.drl.spec_ref + * Creates a new <code>DHParameterSpec</code> instance with the specified + * <i>prime modulus</i>, <i>base generator</i> and size (in bits) of the + * <i>random exponent</i>. + * + * @param p + * the prime modulus. + * @param g + * the base generator. + * @param l + * the size of the random exponent (in bits). */ public DHParameterSpec(BigInteger p, BigInteger g, int l) { this.p = p; @@ -53,21 +65,27 @@ public class DHParameterSpec implements AlgorithmParameterSpec { } /** - * @com.intel.drl.spec_ref + * Returns the <i>prime modulus</i> of this parameter specification. + * + * @return the prime modulus. */ public BigInteger getP() { return p; } /** - * @com.intel.drl.spec_ref + * Returns the <i>base generator</i> of this parameter specification. + * + * @return the base generator. */ public BigInteger getG() { return g; } /** - * @com.intel.drl.spec_ref + * Returns the size (in bits) of the <i>random exponent</i>. + * + * @return the size (in bits) of the random exponent. */ public int getL() { return l; diff --git a/crypto/src/main/java/javax/crypto/spec/DHPrivateKeySpec.java b/crypto/src/main/java/javax/crypto/spec/DHPrivateKeySpec.java index 711d3a7..6652de8 100644 --- a/crypto/src/main/java/javax/crypto/spec/DHPrivateKeySpec.java +++ b/crypto/src/main/java/javax/crypto/spec/DHPrivateKeySpec.java @@ -15,18 +15,15 @@ * limitations under the License. */ -/** -* @author Alexander Y. Kleymenov -* @version $Revision$ -*/ - package javax.crypto.spec; import java.math.BigInteger; import java.security.spec.KeySpec; /** - * @com.intel.drl.spec_ref + * The key specification for a Diffie-Hellman private key. + * + * @since Android 1.0 */ public class DHPrivateKeySpec implements KeySpec { @@ -35,7 +32,16 @@ public class DHPrivateKeySpec implements KeySpec { private final BigInteger g; /** - * @com.intel.drl.spec_ref + * Creates a new <code>DHPrivateKeySpec</code> with the specified <i>private + * value</i> <code>x</code>. <i>prime modulus</i> <code>p</code> and <i>base + * generator</i> <code>g</code>. + * + * @param x + * the private value. + * @param p + * the prime modulus. + * @param g + * the base generator. */ public DHPrivateKeySpec(BigInteger x, BigInteger p, BigInteger g) { this.x = x; @@ -44,24 +50,29 @@ public class DHPrivateKeySpec implements KeySpec { } /** - * @com.intel.drl.spec_ref + * Returns the <i>private value</i> <code>x</code>. + * + * @return the private value <code>x</code>. */ public BigInteger getX() { return x; } /** - * @com.intel.drl.spec_ref + * Returns the <i>prime modulus</i> <code>p</code>. + * + * @return the prime modulus <code>p</code>. */ public BigInteger getP() { return p; } /** - * @com.intel.drl.spec_ref + * Returns the <i>base generator</i> <code>g</code>. + * + * @return the base generator <code>g</code>. */ public BigInteger getG() { return g; } } - diff --git a/crypto/src/main/java/javax/crypto/spec/DHPublicKeySpec.java b/crypto/src/main/java/javax/crypto/spec/DHPublicKeySpec.java index e83640a..68d3267 100644 --- a/crypto/src/main/java/javax/crypto/spec/DHPublicKeySpec.java +++ b/crypto/src/main/java/javax/crypto/spec/DHPublicKeySpec.java @@ -15,18 +15,15 @@ * limitations under the License. */ -/** -* @author Alexander Y. Kleymenov -* @version $Revision$ -*/ - package javax.crypto.spec; import java.math.BigInteger; import java.security.spec.KeySpec; /** - * @com.intel.drl.spec_ref + * The key specification for a Diffie-Hellman public key. + * + * @since Android 1.0 */ public class DHPublicKeySpec implements KeySpec { @@ -35,7 +32,16 @@ public class DHPublicKeySpec implements KeySpec { private final BigInteger g; /** - * @com.intel.drl.spec_ref + * Creates a new <code>DHPublicKeySpec</code> instance with the specified + * <i>public value</i> <code>y</code>, the <i>prime modulus</i> + * <code>p</code> and the <i>base generator</i> <code>g</code>. + * + * @param y + * the public value. + * @param p + * the prime modulus. + * @param g + * the base generator. */ public DHPublicKeySpec(BigInteger y, BigInteger p, BigInteger g) { this.y = y; @@ -44,21 +50,27 @@ public class DHPublicKeySpec implements KeySpec { } /** - * @com.intel.drl.spec_ref + * Returns the <i>public value</i> <code>y</code>. + * + * @return the public value <code>y</code>. */ public BigInteger getY() { return y; } /** - * @com.intel.drl.spec_ref + * Returns the <i>prime modulus</i> <code>p</code>. + * + * @return the prime modulus <code>p</code>. */ public BigInteger getP() { return p; } /** - * @com.intel.drl.spec_ref + * Returns the <i>base generator</i> <code>g</code>; + * + * @return the base generator <code>g</code>; */ public BigInteger getG() { return g; diff --git a/crypto/src/main/java/javax/crypto/spec/IvParameterSpec.java b/crypto/src/main/java/javax/crypto/spec/IvParameterSpec.java index bd77029..2f532a8 100644 --- a/crypto/src/main/java/javax/crypto/spec/IvParameterSpec.java +++ b/crypto/src/main/java/javax/crypto/spec/IvParameterSpec.java @@ -26,14 +26,20 @@ import java.security.spec.AlgorithmParameterSpec; import org.apache.harmony.crypto.internal.nls.Messages; /** - * @com.intel.drl.spec_ref + * The algorithm parameter specification for an <i>initialization vector</i>. */ public class IvParameterSpec implements AlgorithmParameterSpec { private final byte[] iv; /** - * @com.intel.drl.spec_ref + * Creates a new <code>IvParameterSpec</code> instance with the bytes from + * the specified buffer <i>iv</i> used as <i>initialization vector</i>. + * + * @param iv + * the buffer used as initialization vector. + * @throws NullPointerException + * if the specified buffer is null. */ public IvParameterSpec(byte[] iv) { if (iv == null) { @@ -44,7 +50,22 @@ public class IvParameterSpec implements AlgorithmParameterSpec { } /** - * @com.intel.drl.spec_ref + * Creates a new <code>IvParameterSpec</code> instance with <code>len</code> + * bytes from the specified buffer <code>iv</code> starting at + * <code>offset</code>. + * + * @param iv + * the buffer used as initialization vector. + * @param offset + * the offset to start in the buffer. + * @param len + * the length of the data. + * @throws IllegalArgumentException + * if the specified buffer is null or <code>offset</code> and + * <code>len</code> do not specify a valid chunk in the + * specified buffer. + * @throws ArrayIndexOutOfBoundsException + * if <code>offset</code> or <code>len</code> are negative. */ public IvParameterSpec(byte[] iv, int offset, int len) { if ((iv == null) || (iv.length - offset < len)) { @@ -59,7 +80,9 @@ public class IvParameterSpec implements AlgorithmParameterSpec { } /** - * @com.intel.drl.spec_ref + * Returns a copy of the <i>initialization vector</i> data. + * + * @return a copy of the initialization vector data. */ public byte[] getIV() { byte[] res = new byte[iv.length]; diff --git a/crypto/src/main/java/javax/crypto/spec/OAEPParameterSpec.java b/crypto/src/main/java/javax/crypto/spec/OAEPParameterSpec.java index a625cb1..ebb6cce 100644 --- a/crypto/src/main/java/javax/crypto/spec/OAEPParameterSpec.java +++ b/crypto/src/main/java/javax/crypto/spec/OAEPParameterSpec.java @@ -15,11 +15,6 @@ * limitations under the License. */ -/** -* @author Alexander Y. Kleymenov -* @version $Revision$ -*/ - package javax.crypto.spec; import java.security.spec.MGF1ParameterSpec; @@ -27,7 +22,12 @@ import java.security.spec.AlgorithmParameterSpec; import javax.crypto.spec.PSource; /** - * @com.intel.drl.spec_ref + * The algorithm parameter specification for the <i>OAEP Padding</i> algorithm. + * <p> + * This padding algorithm is defined in the <a + * href="http://www.ietf.org/rfc/rfc3447.txt">PKCS #1</a> standard. + * + * @since Android 1.0 */ public class OAEPParameterSpec implements AlgorithmParameterSpec { @@ -37,7 +37,14 @@ public class OAEPParameterSpec implements AlgorithmParameterSpec { private final PSource pSrc; /** - * @com.intel.drl.spec_ref + * The algorithm parameter instance with default values. + * <p> + * It uses the following parameters: + * <ul><li>message digest : <code>"SHA-1"</code></li> + * <li>mask generation function (<i>mgf</i>) : <code>"MGF1"</code></li> + * <li>parameters for the <i>mgf</i> : "SHA-1" {@link MGF1ParameterSpec#SHA1}</li> + * <li>the source of the label <code>L</code>: {@link PSource.PSpecified#DEFAULT}</li> + * </ul> */ public static final OAEPParameterSpec DEFAULT = new OAEPParameterSpec(); @@ -49,7 +56,23 @@ public class OAEPParameterSpec implements AlgorithmParameterSpec { } /** - * @com.intel.drl.spec_ref + * Creates a new <code>OAEPParameterSpec</code> instance with the specified + * <i>message digest</i> algorithm name, <i>mask generation function</i> + * (<i>mgf</i>) algorithm name, <i>parameters</i> for the <i>mgf</i> + * algorithm and the <i>source of the label <code>L</code></i>. + * + * @param mdName + * the message digest algorithm name. + * @param mgfName + * the mask generation function algorithm name. + * @param mgfSpec + * the algorithm parameter specification for the mask generation + * function algorithm. + * @param pSrc + * the source of the label <code>L</code>. + * @throws NullPointerException + * if one of <code>mdName</code>, <code>mgfName</code> or + * <code>pSrc</code> is null. */ public OAEPParameterSpec(String mdName, String mgfName, AlgorithmParameterSpec mgfSpec, PSource pSrc) { @@ -63,28 +86,38 @@ public class OAEPParameterSpec implements AlgorithmParameterSpec { } /** - * @com.intel.drl.spec_ref + * Returns the algorithm name of the <i>message digest</i>. + * + * @return the algorithm name of the message digest. */ public String getDigestAlgorithm() { return mdName; } /** - * @com.intel.drl.spec_ref + * Returns the algorithm name of the <i>mask generation function</i>. + * + * @return the algorithm name of the mask generation function. */ public String getMGFAlgorithm() { return mgfName; } /** - * @com.intel.drl.spec_ref + * Returns the algorithm parameter specification for the mask generation + * function algorithm. + * + * @return the algorithm parameter specification for the mask generation + * function algorithm. */ public AlgorithmParameterSpec getMGFParameters() { return mgfSpec; } /** - * @com.intel.drl.spec_ref + * Returns the source of the label <code>L</code>. + * + * @return the source of the label <code>L</code>. */ public PSource getPSource() { return pSrc; diff --git a/crypto/src/main/java/javax/crypto/spec/PBEKeySpec.java b/crypto/src/main/java/javax/crypto/spec/PBEKeySpec.java index 80e340e..c46617e 100644 --- a/crypto/src/main/java/javax/crypto/spec/PBEKeySpec.java +++ b/crypto/src/main/java/javax/crypto/spec/PBEKeySpec.java @@ -15,11 +15,6 @@ * limitations under the License. */ -/** -* @author Alexander Y. Kleymenov -* @version $Revision$ -*/ - package javax.crypto.spec; import java.security.spec.KeySpec; @@ -28,7 +23,12 @@ import java.util.Arrays; import org.apache.harmony.crypto.internal.nls.Messages; /** - * @com.intel.drl.spec_ref + * The key specification for a <i>password based encryption</i> key. + * <p> + * Password based encryption is described in <a + * href="http://www.ietf.org/rfc/rfc2898.txt">PKCS #5</a>. + * + * @since Android 1.0 */ public class PBEKeySpec implements KeySpec { @@ -38,7 +38,10 @@ public class PBEKeySpec implements KeySpec { private final int keyLength; /** - * @com.intel.drl.spec_ref + * Creates a new <code>PBEKeySpec</code> with the specified password. + * + * @param password + * the password. */ public PBEKeySpec(char[] password) { if (password == null) { @@ -53,7 +56,22 @@ public class PBEKeySpec implements KeySpec { } /** - * @com.intel.drl.spec_ref + * Creates a new <code>PBEKeySpec</code> with the specified password, salt, + * iteration count and the desired length of the derived key. + * + * @param password + * the password. + * @param salt + * the salt. + * @param iterationCount + * the iteration count. + * @param keyLength + * the desired key length of the derived key, + * @throws NullPointerException + * if the salt is null. + * @throws IllegalArgumentException + * if the salt is empty, iteration count is zero or negative or + * the key length is zero or negative. */ public PBEKeySpec(char[] password, byte[] salt, int iterationCount, int keyLength) { @@ -84,7 +102,19 @@ public class PBEKeySpec implements KeySpec { } /** - * @com.intel.drl.spec_ref + * Creates a new <code>PBEKeySpec</code> with the specified password, salt + * and iteration count. + * + * @param password + * the password. + * @param salt + * the salt. + * @param iterationCount + * the iteration count. + * @throws NullPointerException + * if salt is null. + * @throws IllegalArgumentException + * if the salt is empty or iteration count is zero or negative. */ public PBEKeySpec(char[] password, byte[] salt, int iterationCount) { if (salt == null) { @@ -111,7 +141,7 @@ public class PBEKeySpec implements KeySpec { } /** - * @com.intel.drl.spec_ref + * Clears the password by overwriting it. */ public final void clearPassword() { Arrays.fill(password, '?'); @@ -119,7 +149,11 @@ public class PBEKeySpec implements KeySpec { } /** - * @com.intel.drl.spec_ref + * Returns a copy of the password of this key specification. + * + * @return a copy of the password of this key specification. + * @throws IllegalStateException + * if the password has been cleared before. */ public final char[] getPassword() { if (password == null) { @@ -131,7 +165,10 @@ public class PBEKeySpec implements KeySpec { } /** - * @com.intel.drl.spec_ref + * Returns a copy of the salt of this key specification. + * + * @return a copy of the salt of this key specification or null if none is + * specified. */ public final byte[] getSalt() { if (salt == null) { @@ -143,14 +180,18 @@ public class PBEKeySpec implements KeySpec { } /** - * @com.intel.drl.spec_ref + * Returns the iteration count of this key specification. + * + * @return the iteration count of this key specification. */ public final int getIterationCount() { return iterationCount; } /** - * @com.intel.drl.spec_ref + * Returns the desired key length of the derived key. + * + * @return the desired key length of the derived key. */ public final int getKeyLength() { return keyLength; diff --git a/crypto/src/main/java/javax/crypto/spec/PBEParameterSpec.java b/crypto/src/main/java/javax/crypto/spec/PBEParameterSpec.java index 6e220b8..190986e 100644 --- a/crypto/src/main/java/javax/crypto/spec/PBEParameterSpec.java +++ b/crypto/src/main/java/javax/crypto/spec/PBEParameterSpec.java @@ -15,11 +15,6 @@ * limitations under the License. */ -/** -* @author Alexander Y. Kleymenov -* @version $Revision$ -*/ - package javax.crypto.spec; import java.security.spec.AlgorithmParameterSpec; @@ -27,7 +22,14 @@ import java.security.spec.AlgorithmParameterSpec; import org.apache.harmony.crypto.internal.nls.Messages; /** - * @com.intel.drl.spec_ref + * The algorithm parameter specification for a <i>password based encryption</i> + * algorithm. + * <p> + * Password based encryption is described in <a + * href="http://www.ietf.org/rfc/rfc2898.txt">PKCS #5</a>. + * + * @since Android 1.0 + * */ public class PBEParameterSpec implements AlgorithmParameterSpec { @@ -35,7 +37,15 @@ public class PBEParameterSpec implements AlgorithmParameterSpec { private final int iterationCount; /** - * @com.intel.drl.spec_ref + * Creates a new <code>PBEParameterSpec</code> with the specified salt and + * iteration count. + * + * @param salt + * the salt. + * @param iterationCount + * the iteration count. + * @throws NullPointerException + * if salt is null. */ public PBEParameterSpec(byte[] salt, int iterationCount) { if (salt == null) { @@ -47,7 +57,9 @@ public class PBEParameterSpec implements AlgorithmParameterSpec { } /** - * @com.intel.drl.spec_ref + * Returns a copy to the salt. + * + * @return a copy to the salt. */ public byte[] getSalt() { byte[] result = new byte[salt.length]; @@ -56,7 +68,9 @@ public class PBEParameterSpec implements AlgorithmParameterSpec { } /** - * @com.intel.drl.spec_ref + * Returns the iteration count. + * + * @return the iteration count. */ public int getIterationCount() { return iterationCount; diff --git a/crypto/src/main/java/javax/crypto/spec/PSource.java b/crypto/src/main/java/javax/crypto/spec/PSource.java index e83b423..d5bdf1b 100644 --- a/crypto/src/main/java/javax/crypto/spec/PSource.java +++ b/crypto/src/main/java/javax/crypto/spec/PSource.java @@ -15,17 +15,15 @@ * limitations under the License. */ -/** -* @author Alexander Y. Kleymenov -* @version $Revision$ -*/ - package javax.crypto.spec; import org.apache.harmony.crypto.internal.nls.Messages; /** - * @com.intel.drl.spec_ref + * The source of the label <code>L</code> as specified in <a + * href="http://www.ietf.org/rfc/rfc3447.txt"> PKCS #1</a>. + * + * @since Android 1.0 */ public class PSource { @@ -34,7 +32,13 @@ public class PSource { private PSource() {} /** - * @com.intel.drl.spec_ref + * Creates a new <code>PSource</code> instance with the specified source + * algorithm identifier. + * + * @param pSrcName + * the source algorithm identifier. + * @throws NullPointerException + * if pSrcName is null. */ protected PSource(String pSrcName) { if (pSrcName == null) { @@ -44,21 +48,26 @@ public class PSource { } /** - * @com.intel.drl.spec_ref + * Returns the source algorithm identifier. + * + * @return the source algorithm identifier. */ public String getAlgorithm() { return pSrcName; } /** - * @com.intel.drl.spec_ref + * The explicit specification of the parameter <code>P</code> used in the + * source algorithm. + * + * @since Android 1.0 */ public static final class PSpecified extends PSource { private final byte[] p; /** - * @com.intel.drl.spec_ref + * The instance of <code>PSpecified</code> with the default value <code>byte[0]</code> for <code>P</code> */ public static final PSpecified DEFAULT = new PSpecified(); @@ -68,7 +77,13 @@ public class PSource { } /** - * @com.intel.drl.spec_ref + * Creates a new instance of <code>PSpecified</code> with the specified + * parameter <code>P</code>. + * + * @param p + * the parameter <code>P</code>. + * @throws NullPointerException + * if <code>p</code> is null. */ public PSpecified(byte[] p) { super("PSpecified"); //$NON-NLS-1$ @@ -82,7 +97,9 @@ public class PSource { } /** - * @com.intel.drl.spec_ref + * Returns a copy of the value of the parameter <code>P</code>. + * + * @return a copy of the value of the parameter <code>P</code> */ public byte[] getValue() { byte[] result = new byte[p.length]; diff --git a/crypto/src/main/java/javax/crypto/spec/RC2ParameterSpec.java b/crypto/src/main/java/javax/crypto/spec/RC2ParameterSpec.java index 6a24964..bd76cf4 100644 --- a/crypto/src/main/java/javax/crypto/spec/RC2ParameterSpec.java +++ b/crypto/src/main/java/javax/crypto/spec/RC2ParameterSpec.java @@ -15,11 +15,6 @@ * limitations under the License. */ -/** -* @author Alexander Y. Kleymenov -* @version $Revision$ -*/ - package javax.crypto.spec; import java.security.spec.AlgorithmParameterSpec; @@ -28,7 +23,10 @@ import java.util.Arrays; import org.apache.harmony.crypto.internal.nls.Messages; /** - * @com.intel.drl.spec_ref + * The algorithm parameter specification for the <a + * href="http://www.ietf.org/rfc/rfc2268.txt">RC2</a> algorithm. + * + * @since Android 1.0 */ public class RC2ParameterSpec implements AlgorithmParameterSpec { @@ -36,7 +34,11 @@ public class RC2ParameterSpec implements AlgorithmParameterSpec { private final byte[] iv; /** - * @com.intel.drl.spec_ref + * Creates a new <code>RC2ParameterSpec</code> instance with the specified + * effective key length (in bits), + * + * @param effectiveKeyBits + * the effective key length (in bits). */ public RC2ParameterSpec(int effectiveKeyBits) { this.effectiveKeyBits = effectiveKeyBits; @@ -44,7 +46,18 @@ public class RC2ParameterSpec implements AlgorithmParameterSpec { } /** - * @com.intel.drl.spec_ref + * Creates a new <code>RC2ParameterSpec</code> instance with the specified + * effective key length (in bits) and <i>initialization vector</i>. + * <p> + * The size of the <i>initialization vector</i> must be at least 8 bytes + * which are copied to protect them against modification. + * + * @param effectiveKeyBits + * the effective key length (in bits). + * @param iv + * the initialization vector. + * @throws IllegalArgumentException + * if the initialization vector is null or shorter than 8 bytes. */ public RC2ParameterSpec(int effectiveKeyBits, byte[] iv) { if (iv == null) { @@ -59,7 +72,22 @@ public class RC2ParameterSpec implements AlgorithmParameterSpec { } /** - * @com.intel.drl.spec_ref + * Creates a new <code>RC2ParameterSpec</code> instance with the specified + * effective key length (in bits) and <i>initialization vector<i>. + * <p> + * The size of the <i>initialization vector</i> starting at + * <code>offset</code> must be at least 8 bytes which are copied to protect + * them against modification. + * + * @param effectiveKeyBits + * the effective key length (in bits). + * @param iv + * the initialization vector. + * @param offset + * the offset in the initialization vector to start at. + * @throws IllegalArgumentException + * if the initialization vector is null or starting at + * <code>offset</code> is shorter than 8 bytes. */ public RC2ParameterSpec(int effectiveKeyBits, byte[] iv, int offset) { if (iv == null) { @@ -74,14 +102,18 @@ public class RC2ParameterSpec implements AlgorithmParameterSpec { } /** - * @com.intel.drl.spec_ref + * Returns the effective key length (in bits). + * + * @return the effective key length (in bits). */ public int getEffectiveKeyBits() { return effectiveKeyBits; } /** - * @com.intel.drl.spec_ref + * Returns a copy of the initialization vector. + * + * @return a copy of the initialization vector, or null if none specified. */ public byte[] getIV() { if (iv == null) { @@ -93,7 +125,13 @@ public class RC2ParameterSpec implements AlgorithmParameterSpec { } /** - * @com.intel.drl.spec_ref + * Compares the specified object to this <code>RC2ParameterSpec</code> + * instance. + * + * @param obj + * the object to compare. + * @return true if the effective key length and the initialization vector of + * both objects are equal, otherwise false. */ @Override public boolean equals(Object obj) { @@ -109,7 +147,9 @@ public class RC2ParameterSpec implements AlgorithmParameterSpec { } /** - * @com.intel.drl.spec_ref + * Returns the hash code of this <code>RC2ParameterSpec</code> instance. + * + * @return the hash code. */ @Override public int hashCode() { diff --git a/crypto/src/main/java/javax/crypto/spec/RC5ParameterSpec.java b/crypto/src/main/java/javax/crypto/spec/RC5ParameterSpec.java index b4a7fcc..f711f41 100644 --- a/crypto/src/main/java/javax/crypto/spec/RC5ParameterSpec.java +++ b/crypto/src/main/java/javax/crypto/spec/RC5ParameterSpec.java @@ -15,11 +15,6 @@ * limitations under the License. */ -/** -* @author Alexander Y. Kleymenov -* @version $Revision$ -*/ - package javax.crypto.spec; import java.security.spec.AlgorithmParameterSpec; @@ -28,7 +23,10 @@ import java.util.Arrays; import org.apache.harmony.crypto.internal.nls.Messages; /** - * @com.intel.drl.spec_ref + * The algorithm parameter specification for the <a + * href="http://www.ietf.org/rfc/rfc2040.txt">RC5</a> algorithm. + * + * @since Android 1.0 */ public class RC5ParameterSpec implements AlgorithmParameterSpec { @@ -38,7 +36,15 @@ public class RC5ParameterSpec implements AlgorithmParameterSpec { private final byte[] iv; /** - * @com.intel.drl.spec_ref + * Creates a new <code>RC5ParameterSpec</code> instance with the specified + * version, round count an word size (in bits). + * + * @param version + * the version. + * @param rounds + * the round count. + * @param wordSize + * the word size (in bits). */ public RC5ParameterSpec(int version, int rounds, int wordSize) { this.version = version; @@ -48,7 +54,25 @@ public class RC5ParameterSpec implements AlgorithmParameterSpec { } /** - * @com.intel.drl.spec_ref + * Creates a new <code>RC5ParameterSpec</code> instance with the specified + * version, round count, word size (in bits) and an <i>initialization + * vector</i>. + * <p> + * The size of the <i>initialization vector</i> must be at least + * <code>2 * (wordSize / 8)</code> bytes which are copied to protect them + * against modification. + * + * @param version + * the version. + * @param rounds + * the round count. + * @param wordSize + * the word size (in bits). + * @param iv + * the initialization vector. + * @throws IllegalArgumentException + * if the initialization vector is null or shorter than <code>2 + * * (wordSize / 8)</code>. */ public RC5ParameterSpec(int version, int rounds, int wordSize, byte[] iv) { if (iv == null) { @@ -66,7 +90,29 @@ public class RC5ParameterSpec implements AlgorithmParameterSpec { } /** - * @com.intel.drl.spec_ref + * Creates a new <code>RC5ParameterSpec</code> instance with the specified + * version, round count, wordSize (in bits), an <i>initialization vector</i> + * and an offset. + * <p> + * The size of the <i>initialization vector</i> must be at least + * <code>offset + (2 * (wordSize / 8))</code> bytes. The bytes starting at + * <code>offset</code> are copied to protect them against modification. + * + * @param version + * the version. + * @param rounds + * the round count. + * @param wordSize + * the word size (in bits). + * @param iv + * the initialization vector. + * @param offset + * the offset in the initialization vector. + * @throws IllegalArgumentException + * if the initialization vector is null of shorter than + * <code>offset + (2 * (wordSize / 8))</code>. + * @throws ArrayIndexOutOfBoundsException + * if <code>offset</code> is negative. */ public RC5ParameterSpec(int version, int rounds, int wordSize, byte[] iv, int offset) { @@ -88,28 +134,36 @@ public class RC5ParameterSpec implements AlgorithmParameterSpec { } /** - * @com.intel.drl.spec_ref + * Returns the version. + * + * @return the version. */ public int getVersion() { return version; } /** - * @com.intel.drl.spec_ref + * Returns the round count. + * + * @return the round count. */ public int getRounds() { return rounds; } /** - * @com.intel.drl.spec_ref + * Returns the word size (in bits). + * + * @return the word size (in bits). */ public int getWordSize() { return wordSize; } /** - * @com.intel.drl.spec_ref + * Returns a copy of the initialization vector. + * + * @return a copy of the initialization vector, or null if none specified. */ public byte[] getIV() { if (iv == null) { @@ -121,7 +175,13 @@ public class RC5ParameterSpec implements AlgorithmParameterSpec { } /** - * @com.intel.drl.spec_ref + * Compares the specified object with this <code>RC5ParameterSpec</code> + * instance. + * + * @param obj + * the object to compare. + * @return true if version, round count, word size and initializaion vector + * of both objects are equal, otherwise false. */ @Override public boolean equals(Object obj) { @@ -139,7 +199,9 @@ public class RC5ParameterSpec implements AlgorithmParameterSpec { } /** - * @com.intel.drl.spec_ref + * Returns the hash code of this <code>RC5ParameterSpec</code> instance. + * + * @return the hash code. */ @Override public int hashCode() { diff --git a/crypto/src/main/java/javax/crypto/spec/SecretKeySpec.java b/crypto/src/main/java/javax/crypto/spec/SecretKeySpec.java index 1aef40c..897948c 100644 --- a/crypto/src/main/java/javax/crypto/spec/SecretKeySpec.java +++ b/crypto/src/main/java/javax/crypto/spec/SecretKeySpec.java @@ -30,7 +30,11 @@ import javax.crypto.SecretKey; import org.apache.harmony.crypto.internal.nls.Messages; /** - * @com.intel.drl.spec_ref + * A key specification for a <code>SecretKey</code> and also a secret key + * implementation that is provider-independent. It can be used for raw secret + * keys that can be specified as <code>byte[]</code>. + * + * @since Android 1.0 */ public class SecretKeySpec implements SecretKey, KeySpec, Serializable { @@ -44,7 +48,16 @@ public class SecretKeySpec implements SecretKey, KeySpec, Serializable { private final String format = "RAW"; //$NON-NLS-1$ /** - * @com.intel.drl.spec_ref + * Creates a new <code>SecretKeySpec</code> for the specified key data and + * algorithm name. + * + * @param key + * the key data. + * @param algorithm + * the algorithm name. + * @throws IllegalArgumentException + * if the key data or the algorithm name is null or if the key + * data is empty. */ public SecretKeySpec(byte[] key, String algorithm) { if (key == null) { @@ -63,7 +76,24 @@ public class SecretKeySpec implements SecretKey, KeySpec, Serializable { } /** - * @com.intel.drl.spec_ref + * Creates a new <code>SecretKeySpec</code> for the key data from the + * specified buffer <code>key</code> starting at <code>offset</code> with + * length <code>len</code> and the specified <code>algorithm</code> name. + * + * @param key + * the key data. + * @param offset + * the offset. + * @param len + * the size of the key data. + * @param algorithm + * the algorithm name. + * @throws IllegalArgumentException + * if the key data or the algorithm name is null, the key data + * is empty or <code>offset</code> and <code>len</code> do not + * specify a valid chunk in the buffer <code>key</code>. + * @throws ArrayIndexOutOfBoundsException + * if <code>offset</code> or <code>len</code> is negative. */ public SecretKeySpec(byte[] key, int offset, int len, String algorithm) { if (key == null) { @@ -72,9 +102,11 @@ public class SecretKeySpec implements SecretKey, KeySpec, Serializable { if (key.length == 0) { throw new IllegalArgumentException(Messages.getString("crypto.35")); //$NON-NLS-1$ } - if (len < 0) { + // BEGIN android-changed + if (len < 0 || offset < 0) { throw new ArrayIndexOutOfBoundsException(Messages.getString("crypto.36")); //$NON-NLS-1$ } + // END android-changed if ((key.length - offset < len)) { throw new IllegalArgumentException(Messages.getString("crypto.37")); //$NON-NLS-1$ } @@ -87,21 +119,27 @@ public class SecretKeySpec implements SecretKey, KeySpec, Serializable { } /** - * @com.intel.drl.spec_ref + * Returns the algorithm name. + * + * @return the algorithm name. */ public String getAlgorithm() { return algorithm; } /** - * @com.intel.drl.spec_ref + * Returns the name of the format used to encode the key. + * + * @return the format name "RAW". */ public String getFormat() { return format; } /** - * @com.intel.drl.spec_ref + * Returns the encoded form of this secret key. + * + * @return the encoded form of this secret key. */ public byte[] getEncoded() { byte[] result = new byte[key.length]; @@ -110,7 +148,9 @@ public class SecretKeySpec implements SecretKey, KeySpec, Serializable { } /** - * @com.intel.drl.spec_ref + * Returns the hash code of this <code>SecretKeySpec</code> object. + * + * @return the hash code. */ @Override public int hashCode() { @@ -122,7 +162,13 @@ public class SecretKeySpec implements SecretKey, KeySpec, Serializable { } /** - * @com.intel.drl.spec_ref + * Compares the specified object with this <code>SecretKeySpec</code> + * instance. + * + * @param obj + * the object to compare. + * @return true if the algorithm name and key of both object are equal, + * otherwise false. */ @Override public boolean equals(Object obj) { diff --git a/crypto/src/main/java/javax/crypto/spec/package.html b/crypto/src/main/java/javax/crypto/spec/package.html index da03779..f647f75 100644 --- a/crypto/src/main/java/javax/crypto/spec/package.html +++ b/crypto/src/main/java/javax/crypto/spec/package.html @@ -1,19 +1,17 @@ <html> -<head> -<meta http-equiv="Content-Type" content="text/html; charset=us-ascii"> -</head> -<html> -<body> -<p> -This package provides the classes and interfaces needed to specify keys and parameter for -encryption. Following standards are supported: -(1) PKCS#3 Diffie-Hellman ekey agreement's standard; -(2) FIPS-46-2 Data Encryption Standard (DES); -(3) PKCS#5 Password Based Encryption (PBE) standard. -Keys may be specified via algorithm or in a more abstract and general way with ASN.1. + <body> + <p> + This package provides the classes and interfaces needed to specify keys + and parameter for encryption. Following standards are supported: + (1) PKCS#3 Diffie-Hellman ekey agreement's standard; + (2) FIPS-46-2 Data Encryption Standard (DES); + (3) PKCS#5 Password Based Encryption (PBE) standard. + Keys may be specified via algorithm or in a more abstract and general way + with ASN.1. -Keys and algorithm parameters are specified for the following procedures: -(i) DH, (ii) DES, (iii) TripleDES, (iv) PBE, (v) RC2 and (vi) RC5. -</p> -</body> + Keys and algorithm parameters are specified for the following procedures: + (i) DH, (ii) DES, (iii) TripleDES, (iv) PBE, (v) RC2 and (vi) RC5. + </p> + @since Android 1.0 + </body> </html>
\ No newline at end of file diff --git a/crypto/src/main/java/org/apache/harmony/crypto/internal/nls/Messages.java b/crypto/src/main/java/org/apache/harmony/crypto/internal/nls/Messages.java index 6731e00..b61a5cf 100644 --- a/crypto/src/main/java/org/apache/harmony/crypto/internal/nls/Messages.java +++ b/crypto/src/main/java/org/apache/harmony/crypto/internal/nls/Messages.java @@ -21,6 +21,10 @@ * if this tool runs again. Better make changes in the template file. */ +// BEGIN android-note +// Redundant code has been removed and is now called from MsgHelp. +// END android-note + package org.apache.harmony.crypto.internal.nls; @@ -30,8 +34,9 @@ import java.util.Locale; import java.util.MissingResourceException; import java.util.ResourceBundle; -import org.apache.harmony.kernel.vm.VM; +// BEGIN android-changed import org.apache.harmony.luni.util.MsgHelp; +// END android-changed /** * This class retrieves strings from a resource bundle and returns them, @@ -49,8 +54,10 @@ import org.apache.harmony.luni.util.MsgHelp; */ public class Messages { + // BEGIN android-changed private static final String sResource = "org.apache.harmony.crypto.internal.nls.messages"; //$NON-NLS-1$ + // END android-changed /** * Retrieves a message which has no arguments. @@ -60,7 +67,9 @@ public class Messages { * @return String the message for that key in the system message bundle. */ static public String getString(String msg) { + // BEGIN android-changed return MsgHelp.getString(sResource, msg); + // END android-changed } /** @@ -127,6 +136,12 @@ public class Messages { * @return String the message for that key in the system message bundle. */ static public String getString(String msg, Object[] args) { + // BEGIN android-changed return MsgHelp.getString(sResource, msg, args); + // END android-changed } + + // BEGIN android-note + // Duplicate code was dropped in favor of using MsgHelp. + // END android-note } diff --git a/crypto/src/main/native/javax_crypto_HmacSpi.cpp b/crypto/src/main/native/javax_crypto_HmacSpi.cpp deleted file mode 100644 index fed4ec9..0000000 --- a/crypto/src/main/native/javax_crypto_HmacSpi.cpp +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (C) 2006 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include <jni.h> -#include <JNIHelp.h> -//#include <android_runtime/AndroidRuntime.h> -#include <openssl/evp.h> -#include <openssl/hmac.h> -#include <stdint.h> -#include <string.h> - - -jbyteArray native_compute_sha1_hmac(JNIEnv* env, jobject object, - jbyteArray keyArray, jbyteArray dataArray) -{ - uint8_t * output = (uint8_t *)malloc(EVP_MAX_MD_SIZE); - if (!output) { - jniThrowException(env, "java/lang/OutOfMemoryError", NULL); - return NULL; - } - uint32_t outputSize; - - jbyte * key = env->GetByteArrayElements(keyArray, NULL); - int keySize = env->GetArrayLength(keyArray); - - jbyte * data = env->GetByteArrayElements(dataArray, NULL); - int dataSize = env->GetArrayLength(dataArray); - - HMAC(EVP_sha1(), - (unsigned char const *)key, keySize, - (unsigned char const *)data, dataSize, - output, &outputSize); - - env->ReleaseByteArrayElements(keyArray, key, 0); - env->ReleaseByteArrayElements(dataArray, data, 0); - - jbyteArray outputArray = env->NewByteArray(outputSize); - if (!output) { - jniThrowException(env, "java/lang/OutOfMemoryError", NULL); - free(output); - return NULL; - } - - jbyte * outputBytes = env->GetByteArrayElements(outputArray, NULL); - memcpy(outputBytes, output, outputSize); - env->ReleaseByteArrayElements(outputArray, outputBytes, 0); - - free(output); - - return outputArray; -} - -/* - * JNI registration. - */ -static JNINativeMethod sMethods[] = { - /* name, signature, funcPtr */ - { "native_compute_sha1_hmac", "([B[B)[B", (void*)native_compute_sha1_hmac }, -}; - -extern "C" int register_javax_crypto_HmacSpi(JNIEnv* env) -{ - return jniRegisterNativeMethods(env, "javax/crypto/HmacSpi", sMethods, NELEM(sMethods)); -} - - diff --git a/crypto/src/main/native/sub.mk b/crypto/src/main/native/sub.mk deleted file mode 100644 index e02f508..0000000 --- a/crypto/src/main/native/sub.mk +++ /dev/null @@ -1,18 +0,0 @@ -# This file is included by the top-level libcore Android.mk. -# It's not a normal makefile, so we don't include CLEAR_VARS -# or BUILD_*_LIBRARY. - -LOCAL_SRC_FILES := \ - javax_crypto_HmacSpi.cpp - -LOCAL_C_INCLUDES += \ - external/openssl/include - -# Any shared/static libs that are listed here must also -# be listed in libs/nativehelper/Android.mk. -# TODO: fix this requirement - -LOCAL_SHARED_LIBRARIES += \ - libcrypto - -LOCAL_STATIC_LIBRARIES += diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/AllTests.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/AllTests.java new file mode 100644 index 0000000..e00c935 --- /dev/null +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/AllTests.java @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2007 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.harmony.crypto.tests.javax.crypto; + +import junit.framework.Test; +import junit.framework.TestSuite; + +/** + * This is autogenerated source file. Includes tests for package org.apache.harmony.crypto.tests.javax.crypto; + */ + +public class AllTests { + + public static void main(String[] args) { + junit.textui.TestRunner.run(AllTests.suite()); + } + + public static Test suite() { + TestSuite suite = new TestSuite("All tests for package org.apache.harmony.crypto.tests.javax.crypto;"); + // $JUnit-BEGIN$ + + suite.addTestSuite(BadPaddingExceptionTest.class); + suite.addTestSuite(CipherInputStream1Test.class); + suite.addTestSuite(CipherInputStreamTest.class); + suite.addTestSuite(CipherOutputStream1Test.class); + suite.addTestSuite(CipherOutputStreamTest.class); + suite.addTestSuite(CipherSpiTest.class); + suite.addTestSuite(CipherTest.class); + suite.addTestSuite(EncryptedPrivateKeyInfoTest.class); + suite.addTestSuite(ExemptionMechanismExceptionTest.class); + suite.addTestSuite(ExemptionMechanismSpiTest.class); + suite.addTestSuite(ExemptionMechanismTest.class); + suite.addTestSuite(IllegalBlockSizeExceptionTest.class); + suite.addTestSuite(KeyAgreementSpiTest.class); + suite.addTestSuite(KeyAgreementTest.class); + suite.addTestSuite(KeyGeneratorSpiTest.class); + suite.addTestSuite(KeyGeneratorTest.class); + suite.addTestSuite(MacSpiTest.class); + suite.addTestSuite(MacTest.class); + suite.addTestSuite(NoSuchPaddingExceptionTest.class); + suite.addTestSuite(NullCipherTest.class); + suite.addTestSuite(SealedObjectTest.class); + suite.addTestSuite(SecretKeyFactorySpiTest.class); + suite.addTestSuite(SecretKeyFactoryTest.class); + suite.addTestSuite(SecretKeyTest.class); + suite.addTestSuite(ShortBufferExceptionTest.class); + + // $JUnit-END$ + return suite; + } +} diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/BadPaddingExceptionTest.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/BadPaddingExceptionTest.java new file mode 100644 index 0000000..d8721e5 --- /dev/null +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/BadPaddingExceptionTest.java @@ -0,0 +1,123 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Vera Y. Petrashkova +* @version $Revision$ +*/ + +package org.apache.harmony.crypto.tests.javax.crypto; + +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + +import javax.crypto.BadPaddingException; + +import junit.framework.TestCase; + + +/** + * Tests for <code>BadPaddingException</code> class constructors and methods. + * + */ +@TestTargetClass(BadPaddingException.class) +public class BadPaddingExceptionTest extends TestCase { + + public static void main(String[] args) { + } + + /** + * Constructor for BadPaddingExceptionTests. + * + * @param arg0 + */ + public BadPaddingExceptionTest(String arg0) { + super(arg0); + } + + static String[] msgs = { + "", + "Check new message", + "Check new message Check new message Check new message Check new message Check new message" }; + + static Throwable tCause = new Throwable("Throwable for exception"); + + /** + * Test for <code>BadPaddingException()</code> constructor Assertion: + * constructs BadPaddingException with no detail message + */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "BadPaddingException", + methodArgs = {} + ) + }) + public void testBadPaddingException01() { + BadPaddingException tE = new BadPaddingException(); + assertNull("getMessage() must return null.", tE.getMessage()); + assertNull("getCause() must return null", tE.getCause()); + } + + /** + * Test for <code>BadPaddingException(String)</code> constructor + * Assertion: constructs BadPaddingException with detail message msg. + * Parameter <code>msg</code> is not null. + */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "BadPaddingException", + methodArgs = {java.lang.String.class} + ) + }) + public void testBadPaddingException02() { + BadPaddingException tE; + for (int i = 0; i < msgs.length; i++) { + tE = new BadPaddingException(msgs[i]); + assertEquals("getMessage() must return: ".concat(msgs[i]), tE + .getMessage(), msgs[i]); + assertNull("getCause() must return null", tE.getCause()); + } + } + + /** + * Test for <code>BadPaddingException(String)</code> constructor + * Assertion: constructs BadPaddingException when <code>msg</code> is null + */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "BadPaddingException", + methodArgs = {java.lang.String.class} + ) + }) + public void testBadPaddingException03() { + String msg = null; + BadPaddingException tE = new BadPaddingException(msg); + assertNull("getMessage() must return null.", tE.getMessage()); + assertNull("getCause() must return null", tE.getCause()); + } +} diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/CipherInputStream1Test.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/CipherInputStream1Test.java new file mode 100644 index 0000000..baa80d30 --- /dev/null +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/CipherInputStream1Test.java @@ -0,0 +1,323 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Alexander Y. Kleymenov +* @version $Revision$ +*/ + +package org.apache.harmony.crypto.tests.javax.crypto; + +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + +import java.io.ByteArrayInputStream; +import javax.crypto.NullCipher; +import javax.crypto.CipherInputStream; + +import junit.framework.TestCase; + +@TestTargetClass(CipherInputStream.class) +/** + */ + +public class CipherInputStream1Test extends TestCase { + + private static class TestInputStream extends ByteArrayInputStream { + private boolean closed = false; + + public TestInputStream(byte[] data) { + super(data); + } + + public void close() { + closed = true; + } + + public boolean wasClosed() { + return closed; + } + } + + /** + * CipherInputStream(InputStream is) method testing. Tests that + * CipherInputStream uses NullCipher if Cipher is not specified + * in the constructor. + */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "CipherInputStream", + methodArgs = {java.io.InputStream.class} + ) + }) + public void testCipherInputStream() throws Exception { + byte[] data = new byte[] { -127, -100, -50, -10, -1, 0, 1, 10, 50, 127 }; + TestInputStream tis = new TestInputStream(data); + CipherInputStream cis = new CipherInputStream(tis){}; + + for (int i = 0; i < data.length; i++) { + if ((byte) cis.read() != data[i]) { + fail("NullCipher should be used " + + "if Cipher is not specified."); + } + } + if (cis.read() != -1) { + fail("NullCipher should be used if Cipher is not specified."); + } + } + + /** + * read() method testing. Tests that method returns the correct value + * (related to the InputStream) and that it returns -1 at the end of stream. + */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "IOException checking missed.", + targets = { + @TestTarget( + methodName = "read", + methodArgs = {} + ) + }) + public void testRead1() throws Exception { + byte[] data = new byte[] { -127, -100, -50, -10, -1, 0, 1, 10, 50, 127 }; + TestInputStream tis = new TestInputStream(data); + CipherInputStream cis = new CipherInputStream(tis, new NullCipher()); + byte res; + for (int i = 0; i < data.length; i++) { + if ((res = (byte) cis.read()) != data[i]) { + fail("read() returned the incorrect value. " + "Expected: " + + data[i] + ", Got: " + res + "."); + } + } + if (cis.read() != -1) { + fail("read() should return -1 at the end of the stream."); + } + } + + /** + * read(byte[] b) method testing. Tests that method returns the correct + * value (related to the InputStream) and that it returns -1 at the end of + * stream. + */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "IOException checking missed.", + targets = { + @TestTarget( + methodName = "read", + methodArgs = {byte[].class} + ) + }) + public void testRead2() throws Exception { + byte[] data = new byte[] { -127, -100, -50, -10, -1, 0, 1, 10, 50, 127 }; + TestInputStream tis = new TestInputStream(data); + CipherInputStream cis = new CipherInputStream(tis, new NullCipher()); + + int expected = data.length; + byte[] result = new byte[expected]; + + int ind = 0; // index into the data array (to check the got data) + int got = cis.read(result); // the number of got bytes + while (true) { + for (int j = 0; j < got - ind; j++) { + if (result[j] != data[ind + j]) { + fail("read(byte[] b) returned incorrect data."); + } + } + if (got == expected) { + break; + } else if (got > expected) { + fail("The data returned by read(byte[] b) " + + "is larger than expected."); + } else { + ind = got; + got += cis.read(result); + } + } + if (cis.read(result) != -1) { + fail("read(byte[] b) should return -1 " + + "at the end of the stream."); + } + } + + /** + * read(byte[] b, int off, int len) method testing. Tests that method + * returns the correct value (related to the InputStream), that it discards + * bytes in the case of null buffer, and that it returns -1 at the end of + * stream. + */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "IOException checking missed.", + targets = { + @TestTarget( + methodName = "read", + methodArgs = {byte[].class, int.class, int.class} + ) + }) + public void testRead3() throws Exception { + byte[] data = new byte[] { -127, -100, -50, -10, -1, 0, 1, 10, 50, 127 }; + TestInputStream tis = new TestInputStream(data); + CipherInputStream cis = new CipherInputStream(tis, new NullCipher()); + + int expected = data.length; + byte[] result = new byte[expected]; + + int skip = 2; + int ind = skip; // index into the data array (to check the got data) + // should read and discard bytes; + cis.read(null, 0, skip); + int got = skip + cis.read(result, 0, 1); // the number of got bytes + while (true) { + for (int j = 0; j < got - ind; j++) { + assertEquals("read(byte[] b, int off, int len) " + + "returned incorrect data.", result[j], data[ind + j]); + } + if (got == expected) { + break; + } else if (got > expected) { + fail("The data returned by " + + "read(byte[] b, int off, int len) " + + "is larger than expected."); + } else { + ind = got; + got += cis.read(result, 0, 3); + } + } + if (cis.read(result, 0, 1) != -1) { + fail("read() should return -1 at the end of the stream."); + } + } + + /** + * skip(long n) method testing. Tests that the method correctly skips the + * bytes. + */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "IOException checking missed.", + targets = { + @TestTarget( + methodName = "skip", + methodArgs = {long.class} + ) + }) + public void testSkip() throws Exception { + byte[] data = new byte[] { -127, -100, -50, -10, -1, 0, 1, 10, 50, 127 }; + TestInputStream tis = new TestInputStream(data); + CipherInputStream cis = new CipherInputStream(tis, new NullCipher()); + int expected = data.length; + byte[] result = new byte[expected]; + + int skipped = (int) cis.skip(2); + int ind = skipped; + int got = skipped + cis.read(result, 0, 1); // the number of got bytes + while (true) { + for (int j = 0; j < got - ind; j++) { + if (result[j] != data[ind + j]) { + fail("read(byte[] b, int off, int len) " + + "returned incorrect data: Expected " + + data[ind + j] + ", got: " + result[j]); + } + } + if (got == expected) { + break; + } else if (got > expected) { + fail("The data returned by " + + "read(byte[] b, int off, int len) " + + "is larger than expected."); + } else { + ind = got; + got += cis.read(result, 0, 1); + } + } + if ((got = cis.read(result, 0, 1)) != -1) { + fail("read() should return -1 at the end of the stream. " + + "Output is: " + got + "."); + } + } + + /** + * available() method testing. Tests that the method always return 0. + */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "IOException checking missed.", + targets = { + @TestTarget( + methodName = "available", + methodArgs = {} + ) + }) + public void testAvailable() throws Exception { + byte[] data = new byte[] { -127, -100, -50, -10, -1, 0, 1, 10, 50, 127 }; + TestInputStream tis = new TestInputStream(data); + CipherInputStream cis = new CipherInputStream(tis, new NullCipher()); + assertEquals("The returned by available() method value " + + "should be 0.", cis.available(), 0); + } + + /** + * close() method testing. Tests that the method calls the close() + * method of the underlying input stream. + */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "IOException checking missed.", + targets = { + @TestTarget( + methodName = "close", + methodArgs = {} + ) + }) + public void testClose() throws Exception { + byte[] data = new byte[] { -127, -100, -50, -10, -1, 0, 1, 10, 50, 127 }; + TestInputStream tis = new TestInputStream(data); + CipherInputStream cis = new CipherInputStream(tis, new NullCipher()); + cis.close(); + assertTrue("The close() method should call the close() method " + + "of its underlying input stream.", tis.wasClosed()); + } + + /** + * markSupported() method testing. Tests that mark is not supported. + */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "available", + methodArgs = {} + ) + }) + public void testMarkSupported() { + byte[] data = new byte[] {-127, -100, -50, -10, -1, 0, 1, 10, 50, 127}; + TestInputStream tis = new TestInputStream(data); + CipherInputStream cis = new CipherInputStream(tis, new NullCipher()); + assertFalse("The returned by markSupported() method value " + + "should be false.", cis.markSupported()); + } + +} + diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/CipherInputStreamTest.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/CipherInputStreamTest.java new file mode 100644 index 0000000..2c2b4b8 --- /dev/null +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/CipherInputStreamTest.java @@ -0,0 +1,91 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.harmony.crypto.tests.javax.crypto; + +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + +import java.io.BufferedInputStream; +import java.io.ByteArrayInputStream; +import java.io.InputStream; + +import junit.framework.TestCase; + +import javax.crypto.Cipher; +import javax.crypto.CipherInputStream; +import javax.crypto.NullCipher; + +@TestTargetClass(CipherInputStream.class) +public class CipherInputStreamTest extends TestCase { + + /** + * @tests javax.crypto.CipherInputStream#read(byte[] b, int off, int len) + */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "Regression test. Checks NullPointerException", + targets = { + @TestTarget( + methodName = "read", + methodArgs = {byte[].class, int.class, int.class} + ) + }) + public void testReadBII() throws Exception { + // Regression for HARMONY-1080 + CipherInputStream stream = new CipherInputStream(null, new NullCipher()); + try { + stream.read(new byte[1], 1, 0); + fail("NullPointerException expected"); + } catch (NullPointerException e) { + // expected + } + } + + /** + * @tests javax.crypto.CipherInputStream#close() + */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "Regression test. Checks IllegalStateException", + targets = { + @TestTarget( + methodName = "close", + methodArgs = {} + ) + }) + public void testClose() throws Exception { + // Regression for HARMONY-1087 + try { + new CipherInputStream(new ByteArrayInputStream(new byte[] { 1 }), + Cipher.getInstance("DES/CBC/PKCS5Padding")).close(); + fail("IllegalStateException expected!"); + } catch (IllegalStateException e) { + // expected + } + try { + new CipherInputStream(new BufferedInputStream((InputStream) null), + Cipher.getInstance("DES/CBC/PKCS5Padding")).close(); + fail("IllegalStateException expected!"); + } catch (IllegalStateException e) { + // expected + } + } + +} diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/CipherOutputStream1Test.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/CipherOutputStream1Test.java new file mode 100644 index 0000000..7311b9e --- /dev/null +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/CipherOutputStream1Test.java @@ -0,0 +1,257 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Alexander Y. Kleymenov +* @version $Revision$ +*/ + +package org.apache.harmony.crypto.tests.javax.crypto; + +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + +import java.io.BufferedOutputStream; +import java.io.ByteArrayOutputStream; +import java.io.OutputStream; +import java.util.Arrays; +import javax.crypto.NullCipher; +import javax.crypto.CipherOutputStream; +import javax.crypto.Cipher; + +import junit.framework.TestCase; + +@TestTargetClass(CipherOutputStream.class) +/** + */ + +public class CipherOutputStream1Test extends TestCase { + + private static class TestOutputStream extends ByteArrayOutputStream { + private boolean closed = false; + + public void close() { + closed = true; + } + + public boolean wasClosed() { + return closed; + } + } + + /** + * CipherOutputStream(OutputStream os) method testing. Tests that + * CipherOutputStream uses NullCipher if Cipher is not specified + * in the constructor. + */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "CipherOutputStream", + methodArgs = {java.io.OutputStream.class} + ) + }) + public void testCipherOutputStream() throws Exception { + byte[] data = new byte[] { -127, -100, -50, -10, -1, 0, 1, 10, 50, 127 }; + TestOutputStream tos = new TestOutputStream(); + CipherOutputStream cos = new CipherOutputStream(tos){}; + cos.write(data); + cos.flush(); + byte[] result = tos.toByteArray(); + if (!Arrays.equals(result, data)) { + fail("NullCipher should be used " + "if Cipher is not specified."); + } + } + + /** + * write(int b) method testing. Tests that method writes correct values to + * the underlying output stream. + */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "IOException checking missed.", + targets = { + @TestTarget( + methodName = "write", + methodArgs = {int.class} + ) + }) + public void testWrite1() throws Exception { + byte[] data = new byte[] { -127, -100, -50, -10, -1, 0, 1, 10, 50, 127 }; + TestOutputStream tos = new TestOutputStream(); + CipherOutputStream cos = new CipherOutputStream(tos, new NullCipher()); + for (int i = 0; i < data.length; i++) { + cos.write(data[i]); + } + cos.flush(); + byte[] result = tos.toByteArray(); + if (!Arrays.equals(result, data)) { + fail("CipherOutputStream wrote incorrect data."); + } + } + + /** + * write(byte[] b) method testing. Tests that method writes correct values + * to the underlying output stream. + */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "NullPointerException & IOException checking missed.", + targets = { + @TestTarget( + methodName = "write", + methodArgs = {byte[].class} + ) + }) + public void testWrite2() throws Exception { + byte[] data = new byte[] { -127, -100, -50, -10, -1, 0, 1, 10, 50, 127 }; + TestOutputStream tos = new TestOutputStream(); + CipherOutputStream cos = new CipherOutputStream(tos, new NullCipher()); + cos.write(data); + cos.flush(); + byte[] result = tos.toByteArray(); + if (!Arrays.equals(result, data)) { + fail("CipherOutputStream wrote incorrect data."); + } + } + + /** + * write(byte[] b, int off, int len) method testing. + */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "IOException checking missed.", + targets = { + @TestTarget( + methodName = "write", + methodArgs = {byte[].class, int.class, int.class} + ) + }) + public void testWrite3() throws Exception { + byte[] data = new byte[] { -127, -100, -50, -10, -1, 0, 1, 10, 50, 127 }; + TestOutputStream tos = new TestOutputStream(); + CipherOutputStream cos = new CipherOutputStream(tos, new NullCipher()); + for (int i = 0; i < data.length; i++) { + cos.write(data, i, 1); + } + cos.flush(); + byte[] result = tos.toByteArray(); + if (!Arrays.equals(result, data)) { + fail("CipherOutputStream wrote incorrect data."); + } + } + + /** + * @tests write(byte[] b, int off, int len) + */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "Regression test. IllegalArgumentException checked.", + targets = { + @TestTarget( + methodName = "write", + methodArgs = {byte[].class, int.class, int.class} + ) + }) + public void testWrite4() throws Exception { + //Regression for HARMONY-758 + try { + new CipherOutputStream(new BufferedOutputStream((OutputStream) null), new NullCipher()).write(new byte[] {0}, 1, Integer.MAX_VALUE); + } catch (IllegalArgumentException e) { + } + } + + /** + * @tests write(byte[] b, int off, int len) + */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "Regression test. Functional.", + targets = { + @TestTarget( + methodName = "write", + methodArgs = {byte[].class, int.class, int.class} + ) + }) + public void testWrite5() throws Exception { + //Regression for HARMONY-758 + Cipher cf = Cipher.getInstance("DES/CBC/PKCS5Padding"); + NullCipher nc = new NullCipher(); + CipherOutputStream stream1 = new CipherOutputStream(new BufferedOutputStream((OutputStream) null), nc); + CipherOutputStream stream2 = new CipherOutputStream(stream1, cf); + CipherOutputStream stream3 = new CipherOutputStream(stream2, nc); + stream3.write(new byte[] {0}, 0, 0); + //no exception expected + } + + /** + * flush() method testing. Tests that method flushes the data to the + * underlying output stream. + */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "IOException checking missed.", + targets = { + @TestTarget( + methodName = "flush", + methodArgs = {} + ) + }) + public void testFlush() throws Exception { + byte[] data = new byte[] { -127, -100, -50, -10, -1, 0, 1, 10, 50, 127 }; + TestOutputStream tos = new TestOutputStream(); + CipherOutputStream cos = new CipherOutputStream(tos){}; + cos.write(data); + cos.flush(); + byte[] result = tos.toByteArray(); + if (!Arrays.equals(result, data)) { + fail("CipherOutputStream did not flush the data."); + } + } + + /** + * close() method testing. Tests that the method calls the close() method of + * the underlying input stream. + */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "IOException checking missed.", + targets = { + @TestTarget( + methodName = "close", + methodArgs = {} + ) + }) + public void testClose() throws Exception { + byte[] data = new byte[] { -127, -100, -50, -10, -1, 0, 1, 10, 50, 127 }; + TestOutputStream tos = new TestOutputStream(); + CipherOutputStream cos = new CipherOutputStream(tos){}; + cos.write(data); + cos.close(); + byte[] result = tos.toByteArray(); + if (!Arrays.equals(result, data)) { + fail("CipherOutputStream did not flush the data."); + } + assertTrue("The close() method should call the close() method " + + "of its underlying output stream.", tos.wasClosed()); + } +} + diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/CipherOutputStreamTest.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/CipherOutputStreamTest.java new file mode 100644 index 0000000..d4db40d --- /dev/null +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/CipherOutputStreamTest.java @@ -0,0 +1,63 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.harmony.crypto.tests.javax.crypto; + +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + +import java.io.OutputStream; +import javax.crypto.Cipher; +import javax.crypto.CipherOutputStream; + +@TestTargetClass(CipherOutputStream.class) +public class CipherOutputStreamTest extends junit.framework.TestCase { + + /** + * @tests javax.crypto.CipherOutputStream#close() + */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "Regression test. Checks IllegalStateException.", + targets = { + @TestTarget( + methodName = "close", + methodArgs = {} + ) + }) + public void test_close() throws Exception { + // regression test for HARMONY-1139 + try { + new CipherOutputStream((OutputStream) null, Cipher + .getInstance("DES/CBC/PKCS5Padding")).close(); + fail("IllegalStateException expected"); + } catch (IllegalStateException e) { + // expected + } + + CipherOutputStream ch = new CipherOutputStream((OutputStream) null) {}; + try { + new CipherOutputStream(ch, Cipher + .getInstance("DES/CBC/PKCS5Padding")).close(); + fail("IllegalStateException expected"); + } catch (IllegalStateException e) { + // expected + } + } +} diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/CipherSpiTest.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/CipherSpiTest.java new file mode 100644 index 0000000..219be74 --- /dev/null +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/CipherSpiTest.java @@ -0,0 +1,475 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Vera Y. Petrashkova +* @version $Revision$ +*/ + +package org.apache.harmony.crypto.tests.javax.crypto; + +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + +import java.security.spec.AlgorithmParameterSpec; +import java.security.InvalidAlgorithmParameterException; +import java.security.InvalidKeyException; +import java.security.Key; +import java.security.NoSuchAlgorithmException; +import java.security.SecureRandom; +import java.security.AlgorithmParameters; +import javax.crypto.BadPaddingException; +import javax.crypto.IllegalBlockSizeException; +import javax.crypto.NoSuchPaddingException; +import javax.crypto.ShortBufferException; +import javax.crypto.CipherSpi; +import java.nio.ByteBuffer; + +import junit.framework.TestCase; + + +@TestTargetClass(CipherSpi.class) +/** + * Tests for <code>CipherSpi</code> class constructors and methods. + * + */ +public class CipherSpiTest extends TestCase { + class Mock_CipherSpi extends myCipherSpi { + + @Override + protected byte[] engineDoFinal(byte[] input, int inputOffset, int inputLen) throws IllegalBlockSizeException, BadPaddingException { + return super.engineDoFinal(input, inputOffset, inputLen); + } + + @Override + protected int engineDoFinal(byte[] input, int inputOffset, int inputLen, byte[] output, int outputOffset) throws ShortBufferException, IllegalBlockSizeException, BadPaddingException { + return super.engineDoFinal(input, inputOffset, inputLen, output, outputOffset); + } + + @Override + protected int engineGetBlockSize() { + return super.engineGetBlockSize(); + } + + @Override + protected byte[] engineGetIV() { + return super.engineGetIV(); + } + + @Override + protected int engineGetOutputSize(int inputLen) { + return super.engineGetOutputSize(inputLen); + } + + @Override + protected AlgorithmParameters engineGetParameters() { + return super.engineGetParameters(); + } + + @Override + protected void engineInit(int opmode, Key key, SecureRandom random) throws InvalidKeyException { + super.engineInit(opmode, key, random); + } + + @Override + protected void engineInit(int opmode, Key key, AlgorithmParameterSpec params, SecureRandom random) throws InvalidKeyException, InvalidAlgorithmParameterException { + super.engineInit(opmode, key, params, random); + } + + @Override + protected void engineInit(int opmode, Key key, AlgorithmParameters params, SecureRandom random) throws InvalidKeyException, InvalidAlgorithmParameterException { + super.engineInit(opmode, key, params, random); + } + + @Override + protected void engineSetMode(String mode) throws NoSuchAlgorithmException { + super.engineSetMode(mode); + } + + @Override + protected void engineSetPadding(String padding) throws NoSuchPaddingException { + super.engineSetPadding(padding); + } + + @Override + protected byte[] engineUpdate(byte[] input, int inputOffset, int inputLen) { + return super.engineUpdate(input, inputOffset, inputLen); + } + + @Override + protected int engineUpdate(byte[] input, int inputOffset, int inputLen, byte[] output, int outputOffset) throws ShortBufferException { + return super.engineUpdate(input, inputOffset, inputLen, output, outputOffset); + } + + @Override + protected int engineGetKeySize(Key key) throws InvalidKeyException { + return super.engineGetKeySize(key); + } + + @Override + protected byte[] engineWrap(Key key) throws InvalidKeyException, IllegalBlockSizeException { + return super.engineWrap(key); + } + + @Override + protected Key engineUnwrap(byte[] wrappedKey, String wrappedKeyAlgorithm, int wrappedKeyType) throws InvalidKeyException, NoSuchAlgorithmException { + return super.engineUnwrap(wrappedKey, wrappedKeyAlgorithm, wrappedKeyType); + } + } + + /** + * Constructor for CipherSpiTests. + * + * @param arg0 + */ + public CipherSpiTest(String arg0) { + super(arg0); + } + + /** + * Test for <code>CipherSpi</code> constructor + * Assertion: constructs CipherSpi + */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "CipherSpi", + methodArgs = {} + ) + }) + public void testCipherSpiTests01() throws IllegalBlockSizeException, + BadPaddingException, ShortBufferException { + + Mock_CipherSpi cSpi = new Mock_CipherSpi(); + assertEquals("BlockSize is not 0", cSpi.engineGetBlockSize(), 0); + assertEquals("OutputSize is not 0", cSpi.engineGetOutputSize(1), 0); + byte[] bb = cSpi.engineGetIV(); + assertEquals("Length of result byte array is not 0", bb.length, 0); + assertNull("Not null result", cSpi.engineGetParameters()); + byte[] bb1 = new byte[10]; + byte[] bb2 = new byte[10]; + bb = cSpi.engineUpdate(bb1, 1, 2); + assertEquals("Incorrect result of engineUpdate(byte, int, int)", + bb.length, 2); + bb = cSpi.engineDoFinal(bb1, 1, 2); + assertEquals("Incorrect result of engineDoFinal(byte, int, int)", 2, + bb.length); + assertEquals( + "Incorrect result of engineUpdate(byte, int, int, byte, int)", + cSpi.engineUpdate(bb1, 1, 2, bb2, 7), 2); + assertEquals( + "Incorrect result of engineDoFinal(byte, int, int, byte, int)", + 2, cSpi.engineDoFinal(bb1, 1, 2, bb2, 0)); + } + + /** + * Test for <code>engineGetKeySize(Key)</code> method + * Assertion: It throws UnsupportedOperationException if it is not overridden + */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "Functionality not tested.", + targets = { + @TestTarget( + methodName = "engineGetKeySize", + methodArgs = {java.security.Key.class} + ) + }) + public void testCipherSpi02() throws Exception { + Mock_CipherSpi cSpi = new Mock_CipherSpi(); + try { + cSpi.engineGetKeySize(null); + fail("UnsupportedOperationException must be thrown"); + } catch (UnsupportedOperationException e) { + } + } + + /** + * Test for <code>engineWrap(Key)</code> method + * Assertion: It throws UnsupportedOperationException if it is not overridden + */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "Functionality not tested.", + targets = { + @TestTarget( + methodName = "engineWrap", + methodArgs = {java.security.Key.class} + ) + }) + public void testCipherSpi03() throws Exception { + Mock_CipherSpi cSpi = new Mock_CipherSpi(); + try { + cSpi.engineWrap(null); + fail("UnsupportedOperationException must be thrown"); + } catch (UnsupportedOperationException e) { + } + } + + /** + * Test for <code>engineUnwrap(byte[], String, int)</code> method + * Assertion: It throws UnsupportedOperationException if it is not overridden + */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "Functionality not tested.", + targets = { + @TestTarget( + methodName = "engineUnwrap", + methodArgs = {byte[].class, java.lang.String.class, int.class} + ) + }) + public void testCipherSpi04() throws Exception { + Mock_CipherSpi cSpi = new Mock_CipherSpi(); + try { + cSpi.engineUnwrap(new byte[0], "", 0); + fail("UnsupportedOperationException must be thrown"); + } catch (UnsupportedOperationException e) { + } + } + + /** + * Test for <code>engineUpdate(ByteBuffer, ByteBuffer)</code> method + * Assertions: + * throws NullPointerException if one of these buffers is null; + * throws ShortBufferException is there is no space in output to hold result + */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "engineUpdate", + methodArgs = {java.nio.ByteBuffer.class, java.nio.ByteBuffer.class} + ) + }) + public void testCipherSpi05() throws ShortBufferException { + Mock_CipherSpi cSpi = new Mock_CipherSpi(); + byte[] bb = { (byte) 0, (byte) 1, (byte) 2, (byte) 3, (byte) 4, + (byte) 5, (byte) 6, (byte) 7, (byte) 8, (byte) 9, (byte) 10 }; + int pos = 5; + int len = bb.length; + ByteBuffer bbNull = null; + ByteBuffer bb1 = ByteBuffer.allocate(len); + bb1.put(bb); + bb1.position(0); + try { + cSpi.engineUpdate(bbNull, bb1); + fail("NullPointerException must be thrown"); + } catch (NullPointerException e) { + } + try { + cSpi.engineUpdate(bb1, bbNull); + fail("NullPointerException must be thrown"); + } catch (NullPointerException e) { + } + ByteBuffer bb2 = ByteBuffer.allocate(bb.length); + bb1.position(len); + assertEquals("Incorrect number of stored bytes", 0, cSpi.engineUpdate( + bb1, bb2)); + + bb1.position(0); + bb2.position(len - 2); + try { + cSpi.engineUpdate(bb1, bb2); + fail("ShortBufferException bust be thrown. Output buffer remaining: " + .concat(Integer.toString(bb2.remaining()))); + } catch (ShortBufferException e) { + } + bb1.position(10); + bb2.position(0); + assertTrue("Incorrect number of stored bytes", cSpi.engineUpdate(bb1, + bb2) > 0); + bb1.position(bb.length); + cSpi.engineUpdate(bb1, bb2); + + bb1.position(pos); + bb2.position(0); + int res = cSpi.engineUpdate(bb1, bb2); + assertTrue("Incorrect result", res > 0); + } + + /** + * Test for <code>engineDoFinal(ByteBuffer, ByteBuffer)</code> method + * Assertions: + * throws NullPointerException if one of these buffers is null; + * throws ShortBufferException is there is no space in output to hold result + */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "BadPaddingException & IllegalBlockSizeException checking missed.", + targets = { + @TestTarget( + methodName = "engineDoFinal", + methodArgs = {java.nio.ByteBuffer.class, java.nio.ByteBuffer.class} + ) + }) + public void testCipherSpi06() throws BadPaddingException, + ShortBufferException, IllegalBlockSizeException { + Mock_CipherSpi cSpi = new Mock_CipherSpi(); + int len = 10; + byte[] bbuf = new byte[len]; + for (int i = 0; i < bbuf.length; i++) { + bbuf[i] = (byte) i; + } + ByteBuffer bb1 = ByteBuffer.wrap(bbuf); + ByteBuffer bbNull = null; + try { + cSpi.engineDoFinal(bbNull, bb1); + fail("NullPointerException must be thrown"); + } catch (NullPointerException e) { + } + try { + cSpi.engineDoFinal(bb1, bbNull); + fail("NullPointerException must be thrown"); + } catch (NullPointerException e) { + } + ByteBuffer bb2 = ByteBuffer.allocate(len); + bb1.position(bb1.limit()); + assertEquals("Incorrect result", 0, cSpi.engineDoFinal(bb1, bb2)); + + bb1.position(0); + bb2.position(len - 2); + try { + cSpi.engineDoFinal(bb1, bb2); + fail("ShortBufferException must be thrown. Output buffer remaining: " + .concat(Integer.toString(bb2.remaining()))); + } catch (ShortBufferException e) { + } + int pos = 5; + bb1.position(pos); + bb2.position(0); + assertTrue("Incorrect result", cSpi.engineDoFinal(bb1, bb2) > 0); + } +} +/** + * + * Additional class for CipherGeneratorSpi constructor verification + */ + +class myCipherSpi extends CipherSpi { + private byte[] initV; + + private static byte[] resV = { (byte) 7, (byte) 6, (byte) 5, (byte) 4, + (byte) 3, (byte) 2, (byte) 1, (byte) 0 }; + + public myCipherSpi() { + this.initV = new byte[0]; + } + + protected void engineSetMode(String mode) throws NoSuchAlgorithmException { + } + + protected void engineSetPadding(String padding) + throws NoSuchPaddingException { + } + + protected int engineGetBlockSize() { + return 0; + } + + protected int engineGetOutputSize(int inputLen) { + return 0; + } + + protected byte[] engineGetIV() { + return new byte[0]; + } + + protected AlgorithmParameters engineGetParameters() { + return null; + } + + protected void engineInit(int opmode, Key key, SecureRandom random) + throws InvalidKeyException { + } + + protected void engineInit(int opmode, Key key, + AlgorithmParameterSpec params, SecureRandom random) + throws InvalidKeyException, InvalidAlgorithmParameterException { + } + + protected void engineInit(int opmode, Key key, AlgorithmParameters params, + SecureRandom random) throws InvalidKeyException, + InvalidAlgorithmParameterException { + } + + protected byte[] engineUpdate(byte[] input, int inputOffset, int inputLen) { + if (initV.length < inputLen) { + initV = new byte[inputLen]; + } + for (int i = 0; i < inputLen; i++) { + initV[i] = input[inputOffset + i]; + } + return initV; + } + + protected int engineUpdate(byte[] input, int inputOffset, int inputLen, + byte[] output, int outputOffset) throws ShortBufferException { + byte []res = engineUpdate(input, inputOffset, inputLen); + int t = res.length; + if ((output.length - outputOffset) < t) { + throw new ShortBufferException("Update"); + } + for (int i = 0; i < t; i++) { + output[i + outputOffset] = initV[i]; + } + return t; + } + + protected byte[] engineDoFinal(byte[] input, int inputOffset, int inputLen) + throws IllegalBlockSizeException, BadPaddingException { + if (resV.length > inputLen) { + byte[] bb = new byte[inputLen]; + for (int i = 0; i < inputLen; i++) { + bb[i] = resV[i]; + } + return bb; + } + return resV; + } + + protected int engineDoFinal(byte[] input, int inputOffset, int inputLen, + byte[] output, int outputOffset) throws ShortBufferException, + IllegalBlockSizeException, BadPaddingException { + byte[] res = engineDoFinal(input, inputOffset, inputLen); + + int t = res.length; + if ((output.length - outputOffset) < t) { + throw new ShortBufferException("DoFinal"); + } + for (int i = 0; i < t; i++) { + output[i + outputOffset] = res[i]; + } + return t; + } + + + protected int engineUpdate(ByteBuffer input, ByteBuffer output) + throws ShortBufferException { + return super.engineUpdate(input, output); + } + protected int engineDoFinal(ByteBuffer input, ByteBuffer output) + throws ShortBufferException, IllegalBlockSizeException, + BadPaddingException { + return super.engineDoFinal(input, output); + } +} diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/CipherTest.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/CipherTest.java new file mode 100644 index 0000000..f545010 --- /dev/null +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/CipherTest.java @@ -0,0 +1,651 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.harmony.crypto.tests.javax.crypto; + +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.security.AlgorithmParameters; +import java.security.Key; +import java.security.NoSuchAlgorithmException; +import java.security.NoSuchProviderException; +import java.security.Provider; +import java.security.SecureRandom; +import java.security.Security; +import java.security.spec.AlgorithmParameterSpec; +import java.util.Arrays; + +import javax.crypto.Cipher; +import javax.crypto.CipherSpi; +import javax.crypto.KeyGenerator; +import javax.crypto.SecretKeyFactory; +import javax.crypto.ShortBufferException; +import javax.crypto.spec.DESedeKeySpec; +import javax.crypto.spec.IvParameterSpec; + +import tests.support.resource.Support_Resources; +import org.apache.harmony.crypto.tests.support.MyCipher; + +@TestTargetClass(Cipher.class) +public class CipherTest extends junit.framework.TestCase { + + static Key cipherKey; + static final String algorithm = "DESede"; + static final int keyLen = 168; + + static { + try { + KeyGenerator kg = KeyGenerator.getInstance(algorithm); + kg.init(keyLen, new SecureRandom()); + cipherKey = kg.generateKey(); + } catch (Exception e) { + fail("No key " + e); + } + } + + + /** + * @tests javax.crypto.Cipher#getInstance(java.lang.String) + */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "Exceptions checking missed.", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {java.lang.String.class} + ) + }) + public void test_getInstanceLjava_lang_String() throws Exception { + Cipher cipher = Cipher.getInstance("DESede/CBC/PKCS5Padding"); + assertNotNull("Received a null Cipher instance", cipher); + } + + /** + * @tests javax.crypto.Cipher#getInstance(java.lang.String, + * java.lang.String) + */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "NoSuchPaddingException checking missed.", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {java.lang.String.class, java.lang.String.class} + ) + }) + public void test_getInstanceLjava_lang_StringLjava_lang_String() + throws Exception { + + Provider[] providers = Security.getProviders("Cipher.DES"); + + assertNotNull("No installed providers support Cipher.DES", providers); + + for (int i = 0; i < providers.length; i++) { + Cipher cipher = Cipher.getInstance("DES", providers[i].getName()); + assertNotNull("Cipher.getInstance() returned a null value", cipher); + + // Exception case + try { + cipher = Cipher.getInstance("DoBeDoBeDo", providers[i]); + fail("Should have thrown an NoSuchAlgorithmException"); + } catch (NoSuchAlgorithmException e) { + // Expected + } + } + + // Exception case + try { + Cipher.getInstance("DES", (String) null); + fail("Should have thrown an IllegalArgumentException"); + } catch (IllegalArgumentException e) { + // Expected + } + + // Exception case + try { + Cipher.getInstance("DES", "IHaveNotBeenConfigured"); + fail("Should have thrown an NoSuchProviderException"); + } catch (NoSuchProviderException e) { + // Expected + } + } + + /** + * @tests javax.crypto.Cipher#getInstance(java.lang.String, + * java.security.Provider) + */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "Exceptions checking missed.", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {java.lang.String.class, java.security.Provider.class} + ) + }) + public void test_getInstanceLjava_lang_StringLjava_security_Provider() + throws Exception { + + Provider[] providers = Security.getProviders("Cipher.DES"); + + assertNotNull("No installed providers support Cipher.DES", providers); + + for (int i = 0; i < providers.length; i++) { + Cipher cipher = Cipher.getInstance("DES", providers[i]); + assertNotNull("Cipher.getInstance() returned a null value", cipher); + } + } + + /** + * @tests javax.crypto.Cipher#getProvider() + */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getProvider", + methodArgs = {} + ) + }) + public void test_getProvider() throws Exception { + + Provider[] providers = Security.getProviders("Cipher.AES"); + + assertNotNull("No providers support Cipher.AES", providers); + + for (int i = 0; i < providers.length; i++) { + Provider provider = providers[i]; + Cipher cipher = Cipher.getInstance("AES", provider.getName()); + Provider cipherProvider = cipher.getProvider(); + assertTrue("Cipher provider is not the same as that " + + "provided as parameter to getInstance()", cipherProvider + .equals(provider)); + } + } + + /** + * @tests javax.crypto.Cipher#getAlgorithm() + */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getAlgorithm", + methodArgs = {} + ) + }) + public void test_getAlgorithm() throws Exception { + final String algorithm = "DESede/CBC/PKCS5Padding"; + + Cipher cipher = Cipher.getInstance(algorithm); + assertTrue("Cipher algorithm does not match", cipher.getAlgorithm() + .equals(algorithm)); + } + + /** + * @tests javax.crypto.Cipher#getBlockSize() + */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getBlockSize", + methodArgs = {} + ) + }) + public void test_getBlockSize() throws Exception { + final String algorithm = "DESede/CBC/PKCS5Padding"; + + Cipher cipher = Cipher.getInstance(algorithm); + assertEquals("Block size does not match", 8, cipher.getBlockSize()); + } + + /** + * @tests javax.crypto.Cipher#getOutputSize(int) + */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "IllegalStateException checking missed.", + targets = { + @TestTarget( + methodName = "getOutputSize", + methodArgs = {int.class} + ) + }) + public void test_getOutputSizeI() throws Exception { + + SecureRandom sr = new SecureRandom(); + Cipher cipher = Cipher.getInstance(algorithm + "/ECB/PKCS5Padding"); + cipher.init(Cipher.ENCRYPT_MODE, cipherKey, sr); + + // A 25-byte input could result in at least 4 8-byte blocks + int result = cipher.getOutputSize(25); + assertTrue("Output size too small", result > 31); + + // A 8-byte input should result in 2 8-byte blocks + result = cipher.getOutputSize(8); + assertTrue("Output size too small", result > 15); + } + + /** + * @tests javax.crypto.Cipher#init(int, java.security.Key) + */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "Exceptions checking missed.", + targets = { + @TestTarget( + methodName = "init", + methodArgs = {int.class, java.security.Key.class} + ) + }) + public void test_initILjava_security_Key() throws Exception { + Cipher cipher = Cipher.getInstance(algorithm + "/ECB/PKCS5Padding"); + cipher.init(Cipher.ENCRYPT_MODE, cipherKey); + } + + /** + * @tests javax.crypto.Cipher#init(int, java.security.Key, + * java.security.SecureRandom) + */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "Exceptions checking missed.", + targets = { + @TestTarget( + methodName = "init", + methodArgs = {int.class, java.security.Key.class, java.security.SecureRandom.class} + ) + }) + public void test_initILjava_security_KeyLjava_security_SecureRandom() + throws Exception { + SecureRandom sr = new SecureRandom(); + Cipher cipher = Cipher.getInstance(algorithm + "/ECB/PKCS5Padding"); + cipher.init(Cipher.ENCRYPT_MODE, cipherKey, sr); + } + + /** + * @tests javax.crypto.Cipher#init(int, java.security.Key, + * java.security.spec.AlgorithmParameterSpec) + */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "Exceptions checking missed.", + targets = { + @TestTarget( + methodName = "init", + methodArgs = {int.class, java.security.Key.class, java.security.spec.AlgorithmParameterSpec.class} + ) + }) + public void test_initILjava_security_KeyLjava_security_spec_AlgorithmParameterSpec() + throws Exception { + SecureRandom sr = new SecureRandom(); + Cipher cipher = null; + + byte[] iv = null; + AlgorithmParameterSpec ivAVP = null; + + iv = new byte[8]; + sr.nextBytes(iv); + ivAVP = new IvParameterSpec(iv); + + cipher = Cipher.getInstance(algorithm + "/CBC/PKCS5Padding"); + + cipher.init(Cipher.ENCRYPT_MODE, cipherKey, ivAVP); + + byte[] cipherIV = cipher.getIV(); + + assertTrue("IVs differ", Arrays.equals(cipherIV, iv)); + } + + /** + * @tests javax.crypto.Cipher#init(int, java.security.Key, + * java.security.spec.AlgorithmParameterSpec, + * java.security.SecureRandom) + */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "Exceptions checking missed.", + targets = { + @TestTarget( + methodName = "init", + methodArgs = {int.class, java.security.Key.class, java.security.spec.AlgorithmParameterSpec.class, java.security.SecureRandom.class} + ) + }) + public void test_initILjava_security_KeyLjava_security_spec_AlgorithmParameterSpecLjava_security_SecureRandom() + throws Exception { + SecureRandom sr = new SecureRandom(); + Cipher cipher = null; + + byte[] iv = null; + AlgorithmParameterSpec ivAVP = null; + + iv = new byte[8]; + sr.nextBytes(iv); + ivAVP = new IvParameterSpec(iv); + + cipher = Cipher.getInstance(algorithm + "/CBC/PKCS5Padding"); + + cipher.init(Cipher.ENCRYPT_MODE, cipherKey, ivAVP, sr); + + byte[] cipherIV = cipher.getIV(); + + assertTrue("IVs differ", Arrays.equals(cipherIV, iv)); + } + + /** + * @tests javax.crypto.Cipher#update(byte[], int, int) + */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "Exceptions checking missed.", + targets = { + @TestTarget( + methodName = "update", + methodArgs = {byte[].class, int.class, int.class} + ) + }) + public void _test_update$BII() throws Exception { + for (int index = 1; index < 4; index++) { + Cipher c = Cipher.getInstance("DESEDE/CBC/PKCS5Padding"); + + byte[] keyMaterial = loadBytes("hyts_" + "des-ede3-cbc.test" + + index + ".key"); + DESedeKeySpec keySpec = new DESedeKeySpec(keyMaterial); + SecretKeyFactory skf = SecretKeyFactory.getInstance("DESEDE"); + Key k = skf.generateSecret(keySpec); + + byte[] ivMaterial = loadBytes("hyts_" + "des-ede3-cbc.test" + index + + ".iv"); + IvParameterSpec iv = new IvParameterSpec(ivMaterial); + + c.init(Cipher.DECRYPT_MODE, k, iv); + + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + byte[] input = new byte[256]; + String resPath = "hyts_" + "des-ede3-cbc.test" + index + + ".ciphertext"; + InputStream is = Support_Resources.getResourceStream(resPath); + + int bytesRead = is.read(input, 0, 256); + while (bytesRead > 0) { + byte[] output = c.update(input, 0, bytesRead); + if (output != null) { + baos.write(output); + } + bytesRead = is.read(input, 0, 256); + } + + byte[] output = c.doFinal(); + if (output != null) { + baos.write(output); + } + + byte[] decipheredCipherText = baos.toByteArray(); + is.close(); + + byte[] plaintextBytes = loadBytes("hyts_" + "des-ede3-cbc.test" + + index + ".plaintext"); + assertTrue("Operation produced incorrect results", Arrays.equals( + plaintextBytes, decipheredCipherText)); + }// end for + } + + /** + * @tests javax.crypto.Cipher#doFinal() + */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "Exceptions checking missed.", + targets = { + @TestTarget( + methodName = "doFinal", + methodArgs = {} + ) + }) + public void _test_doFinal() throws Exception { + for (int index = 1; index < 4; index++) { + Cipher c = Cipher.getInstance("DESEDE/CBC/PKCS5Padding"); + + byte[] keyMaterial = loadBytes("hyts_" + "des-ede3-cbc.test" + + index + ".key"); + DESedeKeySpec keySpec = new DESedeKeySpec(keyMaterial); + SecretKeyFactory skf = SecretKeyFactory.getInstance("DESEDE"); + Key k = skf.generateSecret(keySpec); + + byte[] ivMaterial = loadBytes("hyts_" + "des-ede3-cbc.test" + index + + ".iv"); + IvParameterSpec iv = new IvParameterSpec(ivMaterial); + + c.init(Cipher.ENCRYPT_MODE, k, iv); + + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + byte[] input = new byte[256]; + String resPath = "hyts_" + "des-ede3-cbc.test" + index + + ".plaintext"; + InputStream is = Support_Resources.getResourceStream(resPath); + + int bytesRead = is.read(input, 0, 256); + while (bytesRead > 0) { + byte[] output = c.update(input, 0, bytesRead); + if (output != null) { + baos.write(output); + } + bytesRead = is.read(input, 0, 256); + } + byte[] output = c.doFinal(); + if (output != null) { + baos.write(output); + } + byte[] encryptedPlaintext = baos.toByteArray(); + is.close(); + + byte[] cipherText = loadBytes("hyts_" + "des-ede3-cbc.test" + index + + ".ciphertext"); + assertTrue("Operation produced incorrect results", Arrays.equals( + encryptedPlaintext, cipherText)); + }// end for + } + + private byte[] loadBytes(String resPath) { + try { + InputStream is = Support_Resources.getResourceStream(resPath); + + ByteArrayOutputStream out = new ByteArrayOutputStream(); + byte[] buff = new byte[1024]; + int readlen; + while ((readlen = is.read(buff)) > 0) { + out.write(buff, 0, readlen); + } + is.close(); + return out.toByteArray(); + } catch (IOException e) { + return null; + } + } + +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getParameters", + methodArgs = {} + ) + }) + public void testGetParameters() throws Exception { + Cipher c = Cipher.getInstance("DES"); + assertNull(c.getParameters()); + } + + /* + * Class under test for int update(byte[], int, int, byte[], int) + */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "Checks ShortBufferException", + targets = { + @TestTarget( + methodName = "update", + methodArgs = {byte[].class, int.class, int.class, byte[].class, int.class} + ) + }) + public void testUpdatebyteArrayintintbyteArrayint() throws Exception { + Cipher c = Cipher.getInstance("DESede"); + c.init(Cipher.ENCRYPT_MODE, cipherKey); + byte[] b = {1,2,3,4,5,6,7,8,9,10}; + byte[] b1 = new byte[6]; + try { + c.update(b, 0, 10, b1, 5); + fail("No expected ShortBufferException"); + } catch (ShortBufferException e) { + } + } + + /* + * Class under test for int doFinal(byte[], int, int, byte[], int) + */ +@TestInfo( + level = TestLevel.TODO, + purpose = "Empty test.", + targets = { + @TestTarget( + methodName = "doFinal", + methodArgs = {byte[].class, int.class, int.class, byte[].class, int.class} + ) + }) + public void testDoFinalbyteArrayintintbyteArrayint() throws Exception { + Cipher c = Cipher.getInstance("DESede"); + c.init(Cipher.ENCRYPT_MODE, cipherKey); + byte[] b = {1,2,3,4,5,6,7,8,9,10}; + byte[] b1 = new byte[6]; + // FIXME Failed on BC provider + // try { + // c.doFinal(b, 3, 6, b1, 5); + // fail("No expected ShortBufferException"); + // } catch (ShortBufferException e) { + // } + } + +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "Exceptions checked only.", + targets = { + @TestTarget( + methodName = "getMaxAllowedKeyLength", + methodArgs = {java.lang.String.class} + ) + }) + public void testGetMaxAllowedKeyLength() throws NoSuchAlgorithmException { + try { + Cipher.getMaxAllowedKeyLength(null); + fail("No expected NullPointerException"); + } catch (NullPointerException e) { + } + try { + Cipher.getMaxAllowedKeyLength("//CBC/PKCS5Paddin"); + fail("No expected NoSuchAlgorithmException"); + } catch (NoSuchAlgorithmException e) { + } + try { + Cipher.getMaxAllowedKeyLength("/DES/CBC/PKCS5Paddin/1"); + fail("No expected NoSuchAlgorithmException"); + } catch (NoSuchAlgorithmException e) { + } + } + +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "Exceptions checked only.", + targets = { + @TestTarget( + methodName = "getMaxAllowedParameterSpec", + methodArgs = {java.lang.String.class} + ) + }) + public void testGetMaxAllowedParameterSpec() + throws NoSuchAlgorithmException { + try { + Cipher.getMaxAllowedParameterSpec(null); + fail("No expected NullPointerException"); + } catch (NullPointerException e) { + } + try { + Cipher.getMaxAllowedParameterSpec("/DES//PKCS5Paddin"); + fail("No expected NoSuchAlgorithmException"); + } catch (NoSuchAlgorithmException e) { + } + try { + Cipher.getMaxAllowedParameterSpec("/DES/CBC/ /1"); + fail("No expected NoSuchAlgorithmException"); + } catch (NoSuchAlgorithmException e) { + } + } + + /** + * @tests javax.crypto.Cipher#Cipher(CipherSpi cipherSpi, Provider provider, + * String transformation) + */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "Cipher", + methodArgs = {javax.crypto.CipherSpi.class, java.security.Provider.class, java.lang.String.class} + ) + }) + public void test_Ctor() throws Exception { + // Regression for Harmony-1184 + try { + new testCipher(null, null, "s"); + fail("NullPointerException expected"); + } catch (NullPointerException e) { + // expected + } + + try { + new testCipher(new MyCipher(), null, "s"); + fail("NullPointerException expected for 'null' provider"); + } catch (NullPointerException e) { + // expected + } + + try { + new testCipher(null, new Provider("qwerty", 1.0, "qwerty") {}, "s"); + fail("NullPointerException expected for 'null' cipherSpi"); + } catch (NullPointerException e) { + // expected + } + } + + class testCipher extends Cipher { + testCipher(CipherSpi c, Provider p, String s) { + super(c, p, s); + } + } +} diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/EncryptedPrivateKeyInfoTest.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/EncryptedPrivateKeyInfoTest.java new file mode 100644 index 0000000..8b0ba39 --- /dev/null +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/EncryptedPrivateKeyInfoTest.java @@ -0,0 +1,2302 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Vladimir N. Molotkov +* @version $Revision$ +*/ + +package org.apache.harmony.crypto.tests.javax.crypto; + +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + +import java.io.IOException; +import java.security.AlgorithmParameters; +import java.security.InvalidAlgorithmParameterException; +import java.security.InvalidKeyException; +import java.security.Key; +import java.security.KeyPair; +import java.security.KeyPairGenerator; +import java.security.NoSuchAlgorithmException; +import java.security.Provider; +import java.security.Security; +import java.security.spec.InvalidKeySpecException; +import java.security.spec.InvalidParameterSpecException; +import java.security.spec.PKCS8EncodedKeySpec; +import java.util.Arrays; + +import javax.crypto.BadPaddingException; +import javax.crypto.Cipher; +import javax.crypto.EncryptedPrivateKeyInfo; +import javax.crypto.IllegalBlockSizeException; +import javax.crypto.KeyGenerator; +import javax.crypto.NoSuchPaddingException; +import javax.crypto.SecretKeyFactory; +import javax.crypto.spec.PBEKeySpec; +import javax.crypto.spec.PBEParameterSpec; + +import org.apache.harmony.crypto.tests.support.EncryptedPrivateKeyInfoData; + +import junit.framework.TestCase; + +@TestTargetClass(EncryptedPrivateKeyInfo.class) +/** + * Test for EncryptedPrivateKeyInfo class. + * + * All binary data for this test were generated using BEA JRockit j2sdk1.4.2_04 + * (http://www.bea.com) with security providers list extended by Bouncy Castle's + * one (http://www.bouncycastle.org) + */ +public class EncryptedPrivateKeyInfoTest extends TestCase { + + private static final Provider[] provider = Security.getProviders(); + + /** + * Algorithm names/transformations used in roundtrip tests of + * getKeySpec(...) methods + */ + private static final String[][] algName = { + // AES + { "AES", null }, + // {"AES", "AES/ECB/PKCS5Padding"}, + // {"AES", "AES/CBC/PKCS5Padding"}, + // {"AES", "AES/OFB/PKCS5Padding"}, + // {"AES", "AES/CFB/PKCS5Padding"}, + // {"2.16.840.1.101.3.4.1.1", null}, + // {"2.16.840.1.101.3.4.1.2", null}, + // {"2.16.840.1.101.3.4.1.3", null}, + // {"2.16.840.1.101.3.4.1.4", null}, + // {"2.16.840.1.101.3.4.1.5", null}, + // {"2.16.840.1.101.3.4.1.21", null}, + // {"2.16.840.1.101.3.4.1.22", null}, + // {"2.16.840.1.101.3.4.1.23", null}, + // {"2.16.840.1.101.3.4.1.24", null}, + // {"2.16.840.1.101.3.4.1.25", null}, + // {"2.16.840.1.101.3.4.1.41", null}, + // {"2.16.840.1.101.3.4.1.42", null}, + // {"2.16.840.1.101.3.4.1.43", null}, + // {"2.16.840.1.101.3.4.1.44", null}, + // {"2.16.840.1.101.3.4.1.45", null}, + + // Blowfish + // NO OIDs for Blowfish defined (?) + { "Blowfish", null }, + // {"Blowfish","Blowfish/CBC/PKCS5Padding"}, + // {"Blowfish","Blowfish/CFB/PKCS5Padding"}, + // {"Blowfish","Blowfish/OFB/PKCS5Padding"}, + // {"Blowfish","Blowfish/PCBC/PKCS5Padding"}, + + // DES: OIW OIDs only + // {iso(1) identified-organization(3) oiw(14) secsig(3) + // algorithms(2) desECB(6)} + // 1.3.14.3.2.6 + // 1.3.14.3.2.7 + // 1.3.14.3.2.8 + // 1.3.14.3.2.9 + { "DES", null }, + // {"DES", "DES/CBC/PKCS5Padding"}, + // {"DES","DES/CFB/PKCS5Padding"}, + // {"DES","DES/OFB/PKCS5Padding"}, + // {"DES","DES/PCBC/PKCS5Padding"}, + + // DESede (=TripleDes) + //{iso(1) identified-organization(3) oiw(14) secsig(3) + // algorithms(2) desEDE(17)} + // 1.3.14.3.2.17 + // {"DESede",null}, + // {"DESede","DESede/CBC/PKCS5Padding"}, + // {"DESede","DESede/CFB/PKCS5Padding"}, + // {"DESede","DESede/OFB/PKCS5Padding"}, + // {"DESede","DESede/PCBC/PKCS5Padding"}, + { "TripleDES", null }, + // {"TripleDES","TripleDES/CBC/PKCS5Padding"}, + // {"TripleDES","TripleDES/CFB/PKCS5Padding"}, + // {"TripleDES","TripleDES/OFB/PKCS5Padding"}, + // {"TripleDES","TripleDES/PCBC/PKCS5Padding"}, + + // PBEWith<digest>And<encryption> + { "PBEWithMD5AndTripleDES", null }, + // {iso(1) member-body(2) us(840) rsadsi(113549) pkcs(1) pkcs-5(5) + // pbeWithMD5AndDES-CBC(3)} + { "PBEWithMD5AndDES", "PBEWithMD5AndDES/CBC/PKCS5Padding" }, + { "PBEWithMD5AndDES", null }, { "PBEWithHmacSHA1AndDESede", null }, + // more oids: + // {iso(1) member-body(2) us(840) nortelnetworks(113533) entrust(7) + // algorithms(66) pbeWithMD5AndCAST5-CBC(12)} + // + // also named pbeWithSHAAnd128BitRC4, pbeWithSHA1And128BitRC4: + // {iso(1) member-body(2) us(840) rsadsi(113549) pkcs(1) pkcs-12(12) + // pkcs-12-PbeIds(1) pkcs-12-OfflineTransportMode(1)} + // + // {iso(1) member-body(2) us(840) rsadsi(113549) pkcs(1) pkcs-12(12) + // pkcs-12-PbeIds(1)} + + // pbeWithSHAAnd40BitRC4(2) pbeWithSHAAnd3-KeyTripleDES-CBC(3) + // pbeWithSHAAnd2-KeyTripleDES-CBC(4) pbeWithSHAAnd128BitRC2-CBC(5) + // pbeWithSHAAnd40BitRC2-CBC(6) + + // DiffieHellman + { "DiffieHellman", null }, // 1.2.840.10046.2.1 + // {"DH",null}, // 1.2.840.10046.2.1 + // {"1.2.840.113549.1.3.1", null}, + + { "DSA", null }, // 1.2.840.10040.4.1 + + { "RC2", null }, + + { "RC4", null }, + + { "RC5", null }, + + // {"1.2.840.113549.1.12.1.1",null}, + // {"1.2.840.113549.1.12.1.2",null}, + { "1.2.840.113549.1.12.1.3", null }, + { "PBEWithSHA1AndDESede", null }, + // {"1.2.840.113549.1.12.1.4",null}, + // {"1.2.840.113549.1.12.1.5",null}, + // {"1.2.840.113549.1.12.1.6",null}, + // {"ELGAMAL/PKCS1", "ELGAMAL/ECB/PKCS1PADDING"}, + // {"ELGAMAL/PKCS1","ELGAMAL/NONE/PKCS1PADDING"}, + // {"PBEWITHSHAAND3-KEYTRIPLEDES-CBC", null}, + // {"PBEWITHSHA1ANDDESEDE", null}, + // {"PBEWithSHAAnd3KeyTripleDES",null}, + // {"PBEWITHSHAAND3-KEYTRIPLEDES-CBC",null}, + // + // {"RC5-32",null}, + // + // {"RSA/1", "RSA/1/PKCS1PADDING"}, + // {"RSA/2", "RSA/2/PKCS1PADDING"}, + // {"RSA/ISO9796-1", "RSA/ECB/ISO9796-1PADDING"}, + // {"RSA", "RSA/ECB/NOPADDING"}, + // {"RSA/OAEP", "RSA/ECB/OAEPPADDING"}, + // {"RSA/PKCS1", "RSA/ECB/PKCS1PADDING"}, + // {"RSA/ISO9796-1", "RSA/NONE/ISO9796-1PADDING"}, + // {"RSA", "RSA/NONE/NOPADDING"}, + // {"RSA/OAEP", "RSA/NONE/OAEPPADDING"}, + // {"RSA/PKCS1", "RSA/NONE/PKCS1PADDING"}, + // {"RSA",null}, // 1.2.840.113549.1.1.1 + // {"1.2.840.113549.1.1.1", null}, + }; + + /** + * Test #1 for <code>EncryptedPrivateKeyInfo(byte[])</code> constructor + * <br> + * Assertion: creates <code>EncryptedPrivateKeyInfo</code> instance <br> + * Test preconditions: valid parameters passed <br> + * Expected: must pass without any exceptions + * + * @throws IOException + * @throws NoSuchAlgorithmException + */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "This is a complete subset of tests for EncryptedPrivateKeyInfo(byte[]) constructor.", + targets = { + @TestTarget( + methodName = "EncryptedPrivateKeyInfo", + methodArgs = {byte[].class} + ) + }) + public final void testEncryptedPrivateKeyInfobyteArray1() throws Exception { + new EncryptedPrivateKeyInfo(EncryptedPrivateKeyInfoData + .getValidEncryptedPrivateKeyInfoEncoding("DH")); + } + + /** + * Test #2 for <code>EncryptedPrivateKeyInfo(byte[])</code> constructor + * <br> + * Assertion: <code>NullPointerException</code> if encoding is + * <code>null</code><br> + * Test preconditions: <code>null</code> passed as a parameter <br> + * Expected: <code>NullPointerException</code> + * + * @throws IOException + */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "This is a complete subset of tests for EncryptedPrivateKeyInfo(byte[]) constructor.", + targets = { + @TestTarget( + methodName = "EncryptedPrivateKeyInfo", + methodArgs = {byte[].class} + ) + }) + public final void testEncryptedPrivateKeyInfobyteArray2() + throws IOException { + try { + new EncryptedPrivateKeyInfo(null); + fail(getName() + ": NullPointerException has not been thrown"); + } catch (NullPointerException ok) { + } + } + + /** + * Test #3 for <code>EncryptedPrivateKeyInfo(byte[])</code> constructor + * <br> + * Assertion: <code>IOException</code> if encoding is wrong <br> + * Test preconditions: wrong encoding passed as a parameter <br> + * Expected: <code>IOException</code> + */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "This is a complete subset of tests for EncryptedPrivateKeyInfo(byte[]) constructor.", + targets = { + @TestTarget( + methodName = "EncryptedPrivateKeyInfo", + methodArgs = {byte[].class} + ) + }) + public final void testEncryptedPrivateKeyInfobyteArray3() { + try { + new EncryptedPrivateKeyInfo(new byte[0]); + fail(getName() + ": IOException has not been thrown"); + } catch (IOException ok) { + } + } + + /** + * Test #4 for <code>EncryptedPrivateKeyInfo(byte[])</code> constructor + * <br> + * Assertion: <code>IOException</code> if encoding is wrong <br> + * Test preconditions: wrong encoding passed as a parameter <br> + * Expected: <code>IOException</code> + */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "This is a complete subset of tests for EncryptedPrivateKeyInfo(byte[]) constructor.", + targets = { + @TestTarget( + methodName = "EncryptedPrivateKeyInfo", + methodArgs = {byte[].class} + ) + }) + public final void testEncryptedPrivateKeyInfobyteArray4() { + try { + new EncryptedPrivateKeyInfo(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, + 10 }); + fail(getName() + ": IOException has not been thrown"); + } catch (IOException ok) { + } + } + + /** + * Test #5 for <code>EncryptedPrivateKeyInfo(byte[])</code> constructor + * <br> + * Assertion: <code>IOException</code> if encoding is wrong <br> + * Test preconditions: wrong encoding passed as a parameter <br> + * Expected: <code>IOException</code> + */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "This is a complete subset of tests for EncryptedPrivateKeyInfo(byte[]) constructor.", + targets = { + @TestTarget( + methodName = "EncryptedPrivateKeyInfo", + methodArgs = {byte[].class} + ) + }) + public final void testEncryptedPrivateKeyInfobyteArray5() throws Exception { + byte[] enc = null; + try { + // 1: get valid encoding + enc = EncryptedPrivateKeyInfoData + .getValidEncryptedPrivateKeyInfoEncoding("DSA"); + + // ... and corrupt it (set wrong alg OID length) + enc[9] = (byte) 6; + + new EncryptedPrivateKeyInfo(enc); + fail(getName() + "(1): IOException has not been thrown"); + } catch (IOException ok) { + } + + try { + // 2: get valid encoding + enc = EncryptedPrivateKeyInfoData + .getValidEncryptedPrivateKeyInfoEncoding("DSA"); + // ... and corrupt it (set wrong encrypted data tag) + enc[307] = (byte) 6; + new EncryptedPrivateKeyInfo(enc); + fail(getName() + "(2): IOException has not been thrown"); + } catch (IOException ok) { + } + + try { + // 3: get valid encoding + enc = EncryptedPrivateKeyInfoData + .getValidEncryptedPrivateKeyInfoEncoding("DSA"); + // ... and corrupt it (set wrong encrypted data length) + enc[310] = (byte) 1; + new EncryptedPrivateKeyInfo(enc); + fail(getName() + "(3): IOException has not been thrown"); + } catch (IOException ok) { + } + + try { + // 4: get valid encoding + enc = EncryptedPrivateKeyInfoData + .getValidEncryptedPrivateKeyInfoEncoding("DSA"); + // ... and corrupt it (set wrong tag for alg params sequence) + enc[17] = (byte) 0x29; + EncryptedPrivateKeyInfo epki = new EncryptedPrivateKeyInfo(enc); + + if (epki.getAlgParameters() == null) { + // This kind of encoding corruption can + // be only determined while AlgorithmParameters + // initialization BUT No AlgorithmParameters instance + // available for algName0[i][0]. + // So just skip this sub test + } else { + fail(getName() + "(4): IOException has not been thrown"); + } + + } catch (IOException ok) { + } + + try { + // 5: get valid encoding + enc = EncryptedPrivateKeyInfoData + .getValidEncryptedPrivateKeyInfoEncoding("DSA"); + // ... and corrupt it (set wrong length for alg params sequence) + enc[20] = (byte) 0x1d; + new EncryptedPrivateKeyInfo(enc); + fail(getName() + "(5): IOException has not been thrown"); + } catch (IOException ok) { + } + + try { + // 6: get valid encoding + enc = EncryptedPrivateKeyInfoData + .getValidEncryptedPrivateKeyInfoEncoding("DSA"); + // ... and corrupt it (set wrong length for alg params sequence) + enc[20] = (byte) 0x1f; + new EncryptedPrivateKeyInfo(enc); + fail(getName() + "(6): IOException has not been thrown"); + } catch (IOException ok) { + } + } + + /** + * Test #6 for <code>EncryptedPrivateKeyInfo(byte[])</code> constructor + * <br> + * Assertion: byte array is copied to prevent subsequent modification <br> + * Test preconditions: valid array passed then modified <br> + * Expected: getEncoded(), invoked after above modification, must return + * array as it was before the modification + * + * @throws IOException + */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "This is a complete subset of tests for EncryptedPrivateKeyInfo(byte[]) constructor.", + targets = { + @TestTarget( + methodName = "EncryptedPrivateKeyInfo", + methodArgs = {byte[].class} + ) + }) + public final void testEncryptedPrivateKeyInfobyteArray6() throws Exception { + byte[] encoded = EncryptedPrivateKeyInfoData + .getValidEncryptedPrivateKeyInfoEncoding("DSA"); + byte[] encodedCopy = encoded.clone(); + // pass valid array + EncryptedPrivateKeyInfo epki = new EncryptedPrivateKeyInfo(encodedCopy); + // modify array passed + encodedCopy[9] = (byte) 6; + // check that internal state has not been affected + assertTrue(Arrays.equals(encoded, epki.getEncoded())); + } + + /** + * Test #1 for <code>EncryptedPrivateKeyInfo(String, byte[])</code> + * constructor <br> + * Assertion: creates <code>EncryptedPrivateKeyInfo</code> instance <br> + * Test preconditions: valid parameters passed <br> + * Expected: must pass without any exceptions + */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "This is a complete subset of tests for EncryptedPrivateKeyInfo(String, byte[]) constructor.", + targets = { + @TestTarget( + methodName = "EncryptedPrivateKeyInfo", + methodArgs = {java.lang.String.class, byte[].class} + ) + }) + public final void testEncryptedPrivateKeyInfoStringbyteArray1() { + boolean performed = false; + + for (int i = 0; i < EncryptedPrivateKeyInfoData.algName0.length; i++) { + try { + new EncryptedPrivateKeyInfo( + EncryptedPrivateKeyInfoData.algName0[i][0], + EncryptedPrivateKeyInfoData.encryptedData); + performed = true; + } catch (NoSuchAlgorithmException allowed) { + } + } + + assertTrue("Test not performed", performed); + } + + /** + * Test #2 for <code>EncryptedPrivateKeyInfo(String, byte[])</code> + * constructor <br> + * Assertion: <code>NoSuchAlgorithmException</code>- if the specified + * algorithm is not supported <br> + * Test preconditions: pass nonexistent algorithm name <br> + * Expected: <code>NoSuchAlgorithmException</code> + */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "This is a complete subset of tests for EncryptedPrivateKeyInfo(String, byte[]) constructor.", + targets = { + @TestTarget( + methodName = "EncryptedPrivateKeyInfo", + methodArgs = {java.lang.String.class, byte[].class} + ) + }) + public final void testEncryptedPrivateKeyInfoStringbyteArray2() { + try { + new EncryptedPrivateKeyInfo("bla-bla", + EncryptedPrivateKeyInfoData.encryptedData); + fail(getName() + ": NoSuchAlgorithmException has not been thrown"); + } catch (NoSuchAlgorithmException ok) { + } + + try { + new EncryptedPrivateKeyInfo("", + EncryptedPrivateKeyInfoData.encryptedData); + fail(getName() + ": NoSuchAlgorithmException has not been thrown"); + } catch (NoSuchAlgorithmException ok) { + } + } + + /** + * Test #3 for <code>EncryptedPrivateKeyInfo(String, byte[])</code> + * constructor <br> + * Assertion: <code>NullPointerException</code>- if the specified + * algorithm or encrypted data is <code>null</code><br> + * Test preconditions: pass <code>null</code> as algorithm name then as + * encrypted data <br> + * Expected: <code>NullPointerException</code> in both cases + * + * @throws NoSuchAlgorithmException + */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "This is a complete subset of tests for EncryptedPrivateKeyInfo(String, byte[]) constructor.", + targets = { + @TestTarget( + methodName = "EncryptedPrivateKeyInfo", + methodArgs = {java.lang.String.class, byte[].class} + ) + }) + public final void testEncryptedPrivateKeyInfoStringbyteArray3() + throws NoSuchAlgorithmException { + // pass null as name + try { + new EncryptedPrivateKeyInfo((String) null, + EncryptedPrivateKeyInfoData.encryptedData); + fail(getName() + ": NullPointerException has not been thrown"); + } catch (NullPointerException ok) { + } + + // pass null as encrypted data + try { + new EncryptedPrivateKeyInfo("DSA", null); + fail(getName() + ": NullPointerException has not been thrown"); + } catch (NullPointerException ok) { + } + } + + /** + * Test #4 for <code>EncryptedPrivateKeyInfo(String, byte[])</code> + * constructor <br> + * Assertion: <code>IllegalArgumentException</code>- if encrypted data is + * empty, i.e. 0-length <br> + * Test preconditions: pass empty encrypted data <br> + * Expected: <code>IllegalArgumentException</code> + */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "This is a complete subset of tests for EncryptedPrivateKeyInfo(String, byte[]) constructor.", + targets = { + @TestTarget( + methodName = "EncryptedPrivateKeyInfo", + methodArgs = {java.lang.String.class, byte[].class} + ) + }) + public final void testEncryptedPrivateKeyInfoStringbyteArray4() + throws Exception { + try { + new EncryptedPrivateKeyInfo("DSA", new byte[] {}); + fail(getName() + ": IllegalArgumentException has not been thrown"); + } catch (IllegalArgumentException ok) { + } + } + + /** + * Test #5 for <code>EncryptedPrivateKeyInfo(String, byte[])</code> + * constructor <br> + * Assertion: byte array is copied to prevent subsequent modification <br> + * Test preconditions: valid array passed then modified <br> + * Expected: getEncryptedData(), invoked after above modification, must + * return array as it was before the modification + * + * @throws IOException + */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "This is a complete subset of tests for EncryptedPrivateKeyInfo(String, byte[]) constructor.", + targets = { + @TestTarget( + methodName = "EncryptedPrivateKeyInfo", + methodArgs = {java.lang.String.class, byte[].class} + ) + }) + public final void testEncryptedPrivateKeyInfoStringbyteArray5() + throws Exception { + byte[] encryptedDataCopy = EncryptedPrivateKeyInfoData.encryptedData + .clone(); + // pass valid array + EncryptedPrivateKeyInfo epki = new EncryptedPrivateKeyInfo("DSA", + encryptedDataCopy); + // modify array passed + encryptedDataCopy[0] = (byte) 6; + // check that internal state has not been affected + assertTrue(Arrays.equals(EncryptedPrivateKeyInfoData.encryptedData, + epki.getEncryptedData())); + } + + /** + * @tests javax/crypto/EncryptedPrivateKeyInfo(String, byte[]) + * Checks exception order + */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "This is a complete subset of tests for EncryptedPrivateKeyInfo(String, byte[]) constructor.", + targets = { + @TestTarget( + methodName = "EncryptedPrivateKeyInfo", + methodArgs = {java.lang.String.class, byte[].class} + ) + }) + public final void testEncryptedPrivateKeyInfoStringbyteArray6() { + //Regression for HARMONY-768 + try { + new EncryptedPrivateKeyInfo("0", new byte[] {}); + fail("NoSuchAlgorithmException expected"); + } catch (NoSuchAlgorithmException e) { + //expected + } + } + + /** + * Test #1 for + * <code>EncryptedPrivateKeyInfo(java.security.AlgorithmParameters, byte[]) + * </code> + * constructor <br> + * Assertion: creates <code>EncryptedPrivateKeyInfo</code> instance <br> + * Test preconditions: valid parameters passed <br> + * Expected: must pass without any exceptions + * + * @throws IOException + */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "Functionality checked. NoSuchAlgorithmException should be tested for complete tests subset.", + targets = { + @TestTarget( + methodName = "EncryptedPrivateKeyInfo", + methodArgs = {java.security.AlgorithmParameters.class, byte[].class} + ) + }) + public final void testEncryptedPrivateKeyInfoAlgorithmParametersbyteArray1() + throws IOException { + + boolean performed = false; + for (int i = 0; i < EncryptedPrivateKeyInfoData.algName0.length; i++) { + try { + AlgorithmParameters ap = AlgorithmParameters + .getInstance(EncryptedPrivateKeyInfoData.algName0[i][0]); + // use pregenerated AlgorithmParameters encodings + ap.init(EncryptedPrivateKeyInfoData.getParametersEncoding( + EncryptedPrivateKeyInfoData.algName0[i][0])); + + new EncryptedPrivateKeyInfo(ap, + EncryptedPrivateKeyInfoData.encryptedData); + + performed = true; + } catch (NoSuchAlgorithmException allowedFailure) { + } + } + assertTrue("Test not performed", performed); + } + + /** + * Test #2 for + * <code>EncryptedPrivateKeyInfo(java.security.AlgorithmParameters, byte[]) + * </code> + * constructor <br> + * Assertion: <code>NullPointerException</code>- if the specified + * algorithm parameters or encrypted data is <code>null</code><br> + * Test preconditions: pass <code>null</code> as algorithm parameters then + * as encrypted data <br> + * Expected: <code>NullPointerException</code> in both cases + * + * @throws NoSuchAlgorithmException + * @throws IOException + */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "NullPointerException checked.", + targets = { + @TestTarget( + methodName = "EncryptedPrivateKeyInfo", + methodArgs = {java.security.AlgorithmParameters.class, byte[].class} + ) + }) + public final void testEncryptedPrivateKeyInfoAlgorithmParametersbyteArray2() + throws NoSuchAlgorithmException, IOException { + // 1: pass null as AlgorithmParameters + try { + new EncryptedPrivateKeyInfo((AlgorithmParameters) null, + EncryptedPrivateKeyInfoData.encryptedData); + fail(getName() + ": NullPointerException has not been thrown"); + } catch (NullPointerException ok) { + } + + // 2: pass null as encrypted data + try { + AlgorithmParameters ap = AlgorithmParameters.getInstance("DSA"); + // use pregenerated AlgorithmParameters encodings + ap.init(EncryptedPrivateKeyInfoData.getParametersEncoding("DSA")); + new EncryptedPrivateKeyInfo(ap, null); + fail(getName() + ": NullPointerException has not been thrown"); + } catch (NullPointerException ok) { + } + } + + /** + * Test #3 for + * <code>EncryptedPrivateKeyInfo(java.security.AlgorithmParameters, byte[]) + * </code> + * constructor <br> + * Assertion: <code>IllegalArgumentException</code>- if encrypted data is + * empty, i.e. 0-length <br> + * Test preconditions: pass empty encrypted data <br> + * Expected: <code>IllegalArgumentException</code> + * + * @throws NoSuchAlgorithmException + * @throws IOException + */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "IllegalArgumentException checked.", + targets = { + @TestTarget( + methodName = "EncryptedPrivateKeyInfo", + methodArgs = {java.security.AlgorithmParameters.class, byte[].class} + ) + }) + public final void testEncryptedPrivateKeyInfoAlgorithmParametersbyteArray3() + throws Exception { + try { + AlgorithmParameters ap = AlgorithmParameters.getInstance("DSA"); + // use pregenerated AlgorithmParameters encodings + ap.init(EncryptedPrivateKeyInfoData.getParametersEncoding("DSA")); + + new EncryptedPrivateKeyInfo(ap, new byte[] {}); + fail(getName() + ": IllegalArgumentException has not been thrown"); + + } catch (IllegalArgumentException ok) { + } + } + + /** + * Test #4 for + * <code>EncryptedPrivateKeyInfo(java.security.AlgorithmParameters, byte[]) + * </code> + * constructor <br> + * Assertion: byte array is copied to prevent subsequent modification <br> + * Test preconditions: valid array passed then modified <br> + * Expected: getEncryptedData(), invoked after above modification, must + * return array as it was before the modification + * + * @throws IOException + */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "Functionality checked.", + targets = { + @TestTarget( + methodName = "EncryptedPrivateKeyInfo", + methodArgs = {java.security.AlgorithmParameters.class, byte[].class} + ) + }) + public final void testEncryptedPrivateKeyInfoAlgorithmParametersbyteArray4() + throws Exception { + AlgorithmParameters ap = AlgorithmParameters.getInstance("DSA"); + // use pregenerated AlgorithmParameters encodings + ap.init(EncryptedPrivateKeyInfoData.getParametersEncoding("DSA")); + + byte[] encryptedDataCopy = EncryptedPrivateKeyInfoData.encryptedData.clone(); + // pass valid array + EncryptedPrivateKeyInfo epki = new EncryptedPrivateKeyInfo(ap, + encryptedDataCopy); + + // modify array passed + encryptedDataCopy[0] = (byte) 6; + + // check that internal state has not been affected + assertTrue(Arrays.equals(EncryptedPrivateKeyInfoData.encryptedData, + epki.getEncryptedData())); + } + + /** + * Test #1 for <code>getAlgParameters()</code> method <br> + * Assertion: returns the algorithm parameters <br> + * Test preconditions: test object created using ctor which takes encoded + * form as the only parameter; encoded form passed contains algorithm + * parameters encoding <br> + * Expected: corresponding algorithm parameters must be returned + * + * @throws IOException + */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "This is a complete subset of tests for getAlgParameters method.", + targets = { + @TestTarget( + methodName = "getAlgParameters", + methodArgs = {} + ) + }) + public final void testGetAlgParameters01() throws IOException { + boolean performed = false; + for (int i = 0; i < EncryptedPrivateKeyInfoData.algName0.length; i++) { + try { + EncryptedPrivateKeyInfo epki = new EncryptedPrivateKeyInfo( + EncryptedPrivateKeyInfoData + .getValidEncryptedPrivateKeyInfoEncoding( + EncryptedPrivateKeyInfoData.algName0[i][0])); + + AlgorithmParameters apar = epki.getAlgParameters(); + if (apar == null) { + continue; + } + + // check that method under test returns + // parameters with the same encoded form + assertTrue(Arrays + .equals( + EncryptedPrivateKeyInfoData + .getParametersEncoding(EncryptedPrivateKeyInfoData.algName0[i][0]), + apar.getEncoded())); + performed = true; + } catch (NoSuchAlgorithmException allowedFailure) { + } + } + assertTrue("Test not performed", performed); + } + +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "This is a complete subset of tests for getAlgParameters method.", + targets = { + @TestTarget( + methodName = "getAlgParameters", + methodArgs = {} + ) + }) + public final void testGetAlgParameters01_01() throws Exception { + byte[] validEncodingWithUnknownAlgOID = EncryptedPrivateKeyInfoData + .getValidEncryptedPrivateKeyInfoEncoding("DH"); + // correct oid value + validEncodingWithUnknownAlgOID[18] = 0; + EncryptedPrivateKeyInfo epki = new EncryptedPrivateKeyInfo( + validEncodingWithUnknownAlgOID); + + assertNull(epki.getAlgParameters()); + } + + /** + * Test #2 for <code>getAlgParameters()</code> method <br> + * Assertion: returns the algorithm parameters <br> + * Test preconditions: test object created using ctor which takes encoded + * form as the only parameter; encoded form passed does not contain + * algorithm parameters encoding <br> + * Expected: <code>null</code> must be returned + * + * @throws IOException + */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "This is a complete subset of tests for getAlgParameters method.", + targets = { + @TestTarget( + methodName = "getAlgParameters", + methodArgs = {} + ) + }) + public final void testGetAlgParameters02() throws IOException { + boolean performed = false; + for (int i = 0; i < EncryptedPrivateKeyInfoData.algName0.length; i++) { + try { + EncryptedPrivateKeyInfo epki = new EncryptedPrivateKeyInfo( + EncryptedPrivateKeyInfoData + .getValidEncryptedPrivateKeyInfoEncoding( + EncryptedPrivateKeyInfoData.algName0[i][0], + false)); + + // check that method under test returns null + assertNull(epki.getAlgParameters()); + + performed = true; + } catch (NoSuchAlgorithmException allowedFailure) { + } + } + assertTrue("Test not performed", performed); + } + + /** + * Test #3 for <code>getAlgParameters()</code> method <br> + * Assertion: returns the algorithm parameters <br> + * Test #6 for <code>EncryptedPrivateKeyInfo(String, byte[])</code> + * constructor <br> + * Assertion: ...This constructor will use null as the value of the + * algorithm parameters. <br> + * Test preconditions: test object created using ctor which takes algorithm + * name and encrypted data as a parameters <br> + * Expected: <code>null</code> must be returned + * + * @throws IOException + */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "This is a complete subset of tests for getAlgParameters method.", + targets = { + @TestTarget( + methodName = "getAlgParameters", + methodArgs = {} + ) + }) + public final void testGetAlgParameters03() throws IOException { + boolean performed = false; + for (int i = 0; i < EncryptedPrivateKeyInfoData.algName0.length; i++) { + try { + EncryptedPrivateKeyInfo epki = new EncryptedPrivateKeyInfo( + EncryptedPrivateKeyInfoData.algName0[i][0], + EncryptedPrivateKeyInfoData.encryptedData); + + // check that method under test returns null + // for object constructed in such a way + assertNull(epki.getAlgParameters()); + + performed = true; + } catch (NoSuchAlgorithmException allowedFailure) { + } + } + assertTrue("Test not performed", performed); + } + + /** + * Test #4 for <code>getAlgParameters()</code> method <br> + * Assertion: returns the algorithm parameters <br> + * Test preconditions: test object created using ctor which takes + * AlgorithmParameters and encrypted data as a parameters; <br> + * Expected: the same algorithm parameters as ones passed to the ctor must be + * returned + * + * @throws IOException + */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "This is a complete subset of tests for getAlgParameters method.", + targets = { + @TestTarget( + methodName = "getAlgParameters", + methodArgs = {} + ) + }) + public final void testGetAlgParameters04() throws IOException { + boolean performed = false; + for (int i = 0; i < EncryptedPrivateKeyInfoData.algName0.length; i++) { + try { + AlgorithmParameters ap = AlgorithmParameters + .getInstance(EncryptedPrivateKeyInfoData.algName0[i][0]); + // use pregenerated AlgorithmParameters encodings + ap + .init(EncryptedPrivateKeyInfoData + .getParametersEncoding( + EncryptedPrivateKeyInfoData.algName0[i][0])); + + EncryptedPrivateKeyInfo epki = new EncryptedPrivateKeyInfo(ap, + EncryptedPrivateKeyInfoData.encryptedData); + + // check that method under test returns + // the same parameters instance + assertSame(ap, epki.getAlgParameters()); + + performed = true; + } catch (NoSuchAlgorithmException allowedFailure) { + } + } + assertTrue("Test not performed", performed); + } + + /** + * Test #1 for <code>getEncryptedData()</code> method <br> + * Assertion: returns the encrypted data <br> + * Test preconditions: test object created using ctor which takes encoded + * form as the only parameter; encoded form passed contains encrypted data + * <br> + * Expected: the equivalent encrypted data must be returned + * + * @throws IOException + */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "This is a complete subset of tests for getEncryptedData method.", + targets = { + @TestTarget( + methodName = "getEncryptedData", + methodArgs = {} + ) + }) + public final void testGetEncryptedData01() throws IOException { + boolean performed = false; + for (int i = 0; i < EncryptedPrivateKeyInfoData.algName0.length; i++) { + try { + EncryptedPrivateKeyInfo epki = new EncryptedPrivateKeyInfo( + EncryptedPrivateKeyInfoData + .getValidEncryptedPrivateKeyInfoEncoding( + EncryptedPrivateKeyInfoData.algName0[i][0])); + + // check that method under test returns + // valid encrypted data + assertTrue(Arrays.equals( + EncryptedPrivateKeyInfoData.encryptedData, epki + .getEncryptedData())); + + performed = true; + } catch (NoSuchAlgorithmException allowedFailure) { + } + } + assertTrue("Test not performed", performed); + } + + /** + * Test #2 for <code>getEncryptedData()</code> method <br> + * Assertion: returns the encrypted data <br> + * Test preconditions: test object created using ctor which takes algorithm + * name and encrypted data as a parameters <br> + * Expected: the equivalent encrypted data must be returned + */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "This is a complete subset of tests for getEncryptedData method.", + targets = { + @TestTarget( + methodName = "getEncryptedData", + methodArgs = {} + ) + }) + public final void testGetEncryptedData02() { + boolean performed = false; + for (int i = 0; i < EncryptedPrivateKeyInfoData.algName0.length; i++) { + try { + EncryptedPrivateKeyInfo epki = new EncryptedPrivateKeyInfo( + EncryptedPrivateKeyInfoData.algName0[i][0], + EncryptedPrivateKeyInfoData.encryptedData); + + // check that method under test returns + // valid encrypted data + assertTrue(Arrays.equals( + EncryptedPrivateKeyInfoData.encryptedData, epki + .getEncryptedData())); + + performed = true; + } catch (NoSuchAlgorithmException allowedFailure) { + } + } + assertTrue("Test not performed", performed); + } + + /** + * Test #3 for <code>getEncryptedData()</code> method <br> + * Assertion: returns the encrypted data <br> + * Test preconditions: test object created using ctor which takes algorithm + * parameters and encrypted data as a parameters <br> + * Expected: the equivalent encrypted data must be returned + * + * @throws IOException + */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "This is a complete subset of tests for getEncryptedData method.", + targets = { + @TestTarget( + methodName = "getEncryptedData", + methodArgs = {} + ) + }) + public final void testGetEncryptedData03() throws IOException { + boolean performed = false; + for (int i = 0; i < EncryptedPrivateKeyInfoData.algName0.length; i++) { + try { + AlgorithmParameters ap = AlgorithmParameters + .getInstance(EncryptedPrivateKeyInfoData.algName0[i][0]); + // use pregenerated AlgorithmParameters encodings + ap.init(EncryptedPrivateKeyInfoData.getParametersEncoding( + EncryptedPrivateKeyInfoData.algName0[i][0])); + + EncryptedPrivateKeyInfo epki = new EncryptedPrivateKeyInfo(ap, + EncryptedPrivateKeyInfoData.encryptedData); + + // check that method under test returns + // valid encrypted data + assertTrue(Arrays.equals( + EncryptedPrivateKeyInfoData.encryptedData, epki + .getEncryptedData())); + + performed = true; + } catch (NoSuchAlgorithmException allowedFailure) { + } + } + assertTrue("Test not performed", performed); + } + + /** + * Test #4 for <code>getEncryptedData()</code> method <br> + * Assertion: returns a new array each time this method is called <br> + * Test preconditions: test object created using ctor which takes algorithm + * name and encrypted data as a parameters <br> + * Expected: refs to encrypted data byte array passed to the ctor and + * returned by the method under test must be different + */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "This is a complete subset of tests for getEncryptedData method.", + targets = { + @TestTarget( + methodName = "getEncryptedData", + methodArgs = {} + ) + }) + public final void testGetEncryptedData04() { + boolean performed = false; + for (int i = 0; i < EncryptedPrivateKeyInfoData.algName0.length; i++) { + try { + EncryptedPrivateKeyInfo epki = new EncryptedPrivateKeyInfo( + EncryptedPrivateKeyInfoData.algName0[i][0], + EncryptedPrivateKeyInfoData.encryptedData); + + // check that method under test returns + // new array each time + byte[] ecd1 = epki.getEncryptedData(); + byte[] ecd2 = epki.getEncryptedData(); + assertNotSame(EncryptedPrivateKeyInfoData.encryptedData, ecd1); + assertNotSame(EncryptedPrivateKeyInfoData.encryptedData, ecd2); + assertNotSame(ecd1, ecd2); + + performed = true; + } catch (NoSuchAlgorithmException allowedFailure) { + } + } + assertTrue("Test not performed", performed); + } + + /** + * Test #1 for <code>getEncoded()</code> method <br> + * Assertion: returns the ASN.1 encoding of this object <br> + * Test preconditions: test object created using ctor which takes encoded + * form as the only parameter <br> + * Expected: equivalent encoded form must be returned + * + * @throws IOException + */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "IOException checking missed.", + targets = { + @TestTarget( + methodName = "getEncoded", + methodArgs = {} + ) + }) + public final void testGetEncoded01() throws IOException { + boolean performed = false; + for (int i = 0; i < EncryptedPrivateKeyInfoData.algName0.length; i++) { + try { + byte[] enc = EncryptedPrivateKeyInfoData + .getValidEncryptedPrivateKeyInfoEncoding( + EncryptedPrivateKeyInfoData.algName0[i][0]); + EncryptedPrivateKeyInfo epki = new EncryptedPrivateKeyInfo(enc); + + // check that method under test returns + // valid encoded form + assertTrue(Arrays.equals(enc, epki.getEncoded())); + + performed = true; + } catch (NoSuchAlgorithmException allowedFailure) { + } + } + assertTrue("Test not performed", performed); + } + + /** + * Test #2 for <code>getEncoded()</code> method <br> + * Assertion: returns the ASN.1 encoding of this object <br> + * Test preconditions: test object created using ctor which takes algorithm + * name and encrypted data as a parameters <br> + * Expected: equivalent encoded form (without alg params) must be returned + * + * @throws IOException + */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "IOException checking missed.", + targets = { + @TestTarget( + methodName = "getEncoded", + methodArgs = {} + ) + }) + public final void testGetEncoded02() throws IOException { + boolean performed = false; + for (int i = 0; i < EncryptedPrivateKeyInfoData.algName0.length; i++) { + try { + EncryptedPrivateKeyInfo epki = new EncryptedPrivateKeyInfo( + EncryptedPrivateKeyInfoData.algName0[i][0], + EncryptedPrivateKeyInfoData.encryptedData); + + // check that method under test returns + // valid encoded form + byte[] refEnc = EncryptedPrivateKeyInfoData + .getValidEncryptedPrivateKeyInfoEncoding( + EncryptedPrivateKeyInfoData.algName0[i][0], + false); + // System.out.println(Array.toString(refEnc, " ")); + byte[] actEnc = epki.getEncoded(); + // System.out.println(Array.toString(actEnc, " ")); + assertTrue(Arrays.equals(refEnc, actEnc)); + + performed = true; + } catch (NoSuchAlgorithmException allowedFailure) { + } + } + assertTrue("Test not performed", performed); + } + + /** + * Test #3 for <code>getEncoded()</code> method <br> + * Assertion: returns the ASN.1 encoding of this object <br> + * Test preconditions: test object created using ctor which takes algorithm + * name and encrypted data as a parameters <br> + * Expected: equivalent encoded form (without alg params) must be returned + * + * @throws IOException + */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "IOException checking missed.", + targets = { + @TestTarget( + methodName = "getEncoded", + methodArgs = {} + ) + }) + public final void testGetEncoded03() throws IOException { + boolean performed = false; + for (int i = 0; i < EncryptedPrivateKeyInfoData.algName0.length; i++) { + try { + AlgorithmParameters ap = AlgorithmParameters + .getInstance(EncryptedPrivateKeyInfoData.algName0[i][0]); + // use pregenerated AlgorithmParameters encodings + ap.init(EncryptedPrivateKeyInfoData.getParametersEncoding( + EncryptedPrivateKeyInfoData.algName0[i][0])); + + EncryptedPrivateKeyInfo epki = new EncryptedPrivateKeyInfo(ap, + EncryptedPrivateKeyInfoData.encryptedData); + + // check that method under test returns + // valid encoded form + assertTrue(Arrays.equals( + EncryptedPrivateKeyInfoData + .getValidEncryptedPrivateKeyInfoEncoding( + EncryptedPrivateKeyInfoData.algName0[i][0]), + epki.getEncoded())); + + performed = true; + } catch (NoSuchAlgorithmException allowedFailure) { + } + } + assertTrue("Test not performed", performed); + } + + /** + * Test #4 for <code>getEncoded()</code> method <br> + * Assertion: returns a new array each time this method is called <br> + * Test preconditions: test object created using ctor which takes algorithm + * name and encrypted data as a parameters <br> + * Expected: several refs to byte array returned by the method under test + * must be different + * + * @throws IOException + */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "IOException checking missed.", + targets = { + @TestTarget( + methodName = "getEncoded", + methodArgs = {} + ) + }) + public final void testGetEncoded04() throws IOException { + boolean performed = false; + for (int i = 0; i < EncryptedPrivateKeyInfoData.algName0.length; i++) { + try { + EncryptedPrivateKeyInfo epki = new EncryptedPrivateKeyInfo( + EncryptedPrivateKeyInfoData.algName0[i][0], + EncryptedPrivateKeyInfoData.encryptedData); + + // check that method under test returns + // new array each time + byte[] ec1 = epki.getEncoded(); + byte[] ec2 = epki.getEncoded(); + byte[] ec3 = epki.getEncoded(); + assertNotSame(ec1, ec2); + assertNotSame(ec2, ec3); + assertNotSame(ec1, ec3); + + performed = true; + } catch (NoSuchAlgorithmException allowedFailure) { + } + } + assertTrue("Test not performed", performed); + } + +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "This is a complete subset of tests for getKeySpec method.", + targets = { + @TestTarget( + methodName = "getKeySpec", + methodArgs = {javax.crypto.Cipher.class} + ) + }) + public final void testGetKeySpecCipher01() { + boolean performed = false; + for (int i = 0; i < EncryptedPrivateKeyInfoData.algName0.length; i++) { + try { + EncryptedPrivateKeyInfo epki = new EncryptedPrivateKeyInfo( + EncryptedPrivateKeyInfoData.algName0[i][0], + EncryptedPrivateKeyInfoData.encryptedData); + + try { + + // check that method under test throws NPE + epki.getKeySpec((Cipher) null); + fail(getName() + "NullPointerException has not been thrown"); + + } catch (NullPointerException ok) { + } catch (InvalidKeySpecException e) { + fail(getName() + "Unexpected exception: " + e); + } + + performed = true; + } catch (NoSuchAlgorithmException allowedFailure) { + } + } + assertTrue("Test not performed", performed); + } + + /** + * Encrypted data contains valid PKCS8 key info encoding + */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "This is a complete subset of tests for getKeySpec method.", + targets = { + @TestTarget( + methodName = "getKeySpec", + methodArgs = {javax.crypto.Cipher.class} + ) + }) + public final void test_ROUNDTRIP_GetKeySpecCipher01() { + boolean performed = false; + + for (int i = 0; i < algName.length; i++) { + try { + // generate test data + TestDataGenerator g = new TestDataGenerator(algName[i][0], + algName[i][1], privateKeyInfo, null); + + // create test object + EncryptedPrivateKeyInfo epki; + if (g.ap() == null) { + epki = new EncryptedPrivateKeyInfo(algName[i][0], g.ct()); + } else { + epki = new EncryptedPrivateKeyInfo(g.ap(), g.ct()); + } + + // call methods under test + try { + + PKCS8EncodedKeySpec eks = epki.getKeySpec(g.c()); + + if (!Arrays.equals(privateKeyInfo, eks.getEncoded())) { + fail(algName[i][0] + " != " + algName[i][1]); + } + } catch (InvalidKeySpecException e) { + fail(algName[i][0] + ", " + algName[i][1] + e + "\n"); + } + performed = true; + + } catch (TestDataGenerator.AllowedFailure allowedFailure) { + } catch (NoSuchAlgorithmException allowed) { + } + } + assertTrue("Test not performed", performed); + } + + /** + * Encrypted data contains invalid PKCS8 key info encoding + */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "This is a complete subset of tests for getKeySpec method.", + targets = { + @TestTarget( + methodName = "getKeySpec", + methodArgs = {javax.crypto.Cipher.class} + ) + }) + public final void test_ROUNDTRIP_GetKeySpecCipher02() { + boolean performed = false; + for (int i = 0; i < algName.length; i++) { + try { + // generate test data + TestDataGenerator g = new TestDataGenerator(algName[i][0], + algName[i][1], privateKeyInfoDamaged, null); + + // create test object + EncryptedPrivateKeyInfo epki; + if (g.ap() == null) { + epki = new EncryptedPrivateKeyInfo(algName[i][0], g.ct()); + } else { + epki = new EncryptedPrivateKeyInfo(g.ap(), g.ct()); + } + + // call methods under test + try { + epki.getKeySpec(g.c()); + + // must not get here because decrypted data does + // not represent valid PKCS8 encoding + fail(algName[i][0] + ", " + algName[i][1]); + } catch (InvalidKeySpecException ok) { + } + + performed = true; + } catch (TestDataGenerator.AllowedFailure allowedFailure) { + } catch (NoSuchAlgorithmException allowedFailure) { + } + } + assertTrue("Test not performed", performed); + } + +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "Subset does not checks NoSuchAlgorithmException", + targets = { + @TestTarget( + methodName = "getKeySpec", + methodArgs = {java.security.Key.class} + ) + }) + public final void testGetKeySpecKey01() { + boolean performed = false; + for (int i = 0; i < EncryptedPrivateKeyInfoData.algName0.length; i++) { + try { + EncryptedPrivateKeyInfo epki = new EncryptedPrivateKeyInfo( + EncryptedPrivateKeyInfoData.algName0[i][0], + EncryptedPrivateKeyInfoData.encryptedData); + + try { + + // check that method under test throws NPE + epki.getKeySpec((Key) null); + fail(getName() + "NullPointerException has not been thrown"); + + } catch (NullPointerException ok) { + } catch (InvalidKeyException e) { + fail(getName() + "Unexpected exception: " + e); + } + + performed = true; + } catch (NoSuchAlgorithmException allowedFailure) { + } + } + assertTrue("Test not performed", performed); + } + + /** + * Encrypted data contains valid PKCS8 key info encoding + */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "Subset does not checks NoSuchAlgorithmException", + targets = { + @TestTarget( + methodName = "getKeySpec", + methodArgs = {java.security.Key.class} + ) + }) + public final void test_ROUNDTRIP_GetKeySpecKey01() { + boolean performed = false; + for (int i = 0; i < algName.length; i++) { + try { + // generate test data + TestDataGenerator g = new TestDataGenerator(algName[i][0], + algName[i][1], privateKeyInfo, null); + + // create test object + EncryptedPrivateKeyInfo epki; + if (g.ap() == null) { + epki = new EncryptedPrivateKeyInfo(algName[i][0], g.ct()); + } else { + epki = new EncryptedPrivateKeyInfo(g.ap(), g.ct()); + } + + try { + PKCS8EncodedKeySpec eks = epki + .getKeySpec(g.pubK() == null ? g.k() : g.pubK()); + + if (!Arrays.equals(privateKeyInfo, eks.getEncoded())) { + fail(algName[i][0] + " != " + algName[i][1]); + } + } catch (InvalidKeyException e) { + fail(algName[i][0] + ", " + algName[i][1] + ": " + e); + } + + performed = true; + } catch (TestDataGenerator.AllowedFailure allowedFailure) { + } catch (NoSuchAlgorithmException allowedFailure) { + } + } + assertTrue("Test not performed", performed); + } + + /** + * Encrypted data contains invalid PKCS8 key info encoding + */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "Subset does not checks NoSuchAlgorithmException", + targets = { + @TestTarget( + methodName = "getKeySpec", + methodArgs = {java.security.Key.class} + ) + }) + public final void test_ROUNDTRIP_GetKeySpecKey02() { + boolean performed = false; + for (int i = 0; i < algName.length; i++) { + try { + // generate test data + TestDataGenerator g = new TestDataGenerator(algName[i][0], + algName[i][1], privateKeyInfoDamaged, null); + + // create test object + EncryptedPrivateKeyInfo epki; + if (g.ap() == null) { + epki = new EncryptedPrivateKeyInfo(algName[i][0], g.ct()); + } else { + epki = new EncryptedPrivateKeyInfo(g.ap(), g.ct()); + } + + try { + epki.getKeySpec(g.pubK() == null ? g.k() : g.pubK()); + fail(algName[i][0] + ", " + algName[i][1]); + } catch (InvalidKeyException e) { + } + + performed = true; + } catch (TestDataGenerator.AllowedFailure allowedFailure) { + } catch (NoSuchAlgorithmException allowedFailure) { + } + } + assertTrue("Test not performed", performed); + } + +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "In subset missed NoSuchProviderException & NoSuchAlgorithmException checking", + targets = { + @TestTarget( + methodName = "getKeySpec", + methodArgs = {java.security.Key.class, java.lang.String.class} + ) + }) + public final void testGetKeySpecKeyString01() throws Exception { + boolean performed = false; + for (int i = 0; i < EncryptedPrivateKeyInfoData.algName0.length; i++) { + try { + EncryptedPrivateKeyInfo epki = new EncryptedPrivateKeyInfo( + EncryptedPrivateKeyInfoData.algName0[i][0], + EncryptedPrivateKeyInfoData.encryptedData); + + try { + + // check that method under test throws NPE + epki.getKeySpec((Key) null, "SomeProviderName"); + fail(getName() + "NullPointerException has not been thrown"); + + } catch (NullPointerException ok) { + } + + try { + + // check that method under test throws NPE + epki.getKeySpec(new Key() { + public String getAlgorithm() { + return "alg"; + } + + public String getFormat() { + return "fmt"; + } + + public byte[] getEncoded() { + return new byte[] {}; + } + }, (String) null); + + fail(getName() + "NullPointerException has not been thrown"); + + } catch (NullPointerException ok) { + } + + performed = true; + } catch (NoSuchAlgorithmException allowedFailure) { + } + } + assertTrue("Test not performed", performed); + } + + /** + * Encrypted data contains valid PKCS8 key info encoding + */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "In subset missed NoSuchProviderException & NoSuchAlgorithmException checking", + targets = { + @TestTarget( + methodName = "getKeySpec", + methodArgs = {java.security.Key.class, java.lang.String.class} + ) + }) + public final void test_ROUNDTRIP_GetKeySpecKeyString01() throws Exception { + boolean performed = false; + for (int i = 0; i < algName.length; i++) { + for (int l = 0; l < provider.length; l++) { + if (provider[l] == null) { + continue; + } + TestDataGenerator g; + try { + // generate test data + g = new TestDataGenerator(algName[i][0], algName[i][1], + privateKeyInfo, provider[l]); + } catch (TestDataGenerator.AllowedFailure allowedFailure) { + continue; + } + + try { + // create test object + EncryptedPrivateKeyInfo epki; + if (g.ap() == null) { + epki = new EncryptedPrivateKeyInfo(algName[i][0], g + .ct()); + } else { + epki = new EncryptedPrivateKeyInfo(g.ap(), g.ct()); + } + try { + + PKCS8EncodedKeySpec eks = epki.getKeySpec( + g.pubK() == null ? g.k() : g.pubK(), + provider[l].getName()); + + if (!Arrays.equals(privateKeyInfo, eks.getEncoded())) { + fail(algName[i][0] + " != " + algName[i][1]); + } + } catch (InvalidKeyException e) { + fail(algName[i][0] + ", " + algName[i][1] + ": " + e); + } + + performed = true; + } catch (NoSuchAlgorithmException allowedFailure) { + } + } + } + assertTrue("Test not performed", performed); + } + + /** + * Encrypted data contains invalid PKCS8 key info encoding + */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "In subset missed NoSuchProviderException & NoSuchAlgorithmException checking", + targets = { + @TestTarget( + methodName = "getKeySpec", + methodArgs = {java.security.Key.class, java.lang.String.class} + ) + }) + public final void test_ROUNDTRIP_GetKeySpecKeyString02() throws Exception { + boolean performed = false; + for (int i = 0; i < algName.length; i++) { + for (int l = 0; l < provider.length; l++) { + if (provider[l] == null) { + continue; + } + TestDataGenerator g; + try { + // generate test data + g = new TestDataGenerator(algName[i][0], algName[i][1], + privateKeyInfoDamaged, provider[l]); + } catch (TestDataGenerator.AllowedFailure allowedFailure) { + continue; + } + + try { + // create test object + EncryptedPrivateKeyInfo epki; + if (g.ap() == null) { + epki = new EncryptedPrivateKeyInfo(algName[i][0], g + .ct()); + } else { + epki = new EncryptedPrivateKeyInfo(g.ap(), g.ct()); + } + + try { + + epki.getKeySpec(g.pubK() == null ? g.k() : g.pubK(), + provider[l].getName()); + + fail(algName[i][0] + ", " + algName[i][1]); + + } catch (InvalidKeyException e) { + } + + performed = true; + } catch (NoSuchAlgorithmException allowedFailure) { + } + } + } + assertTrue("Test not performed", performed); + } + +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "In subset missed NoSuchAlgorithmException checking", + targets = { + @TestTarget( + methodName = "getKeySpec", + methodArgs = {java.security.Key.class, java.security.Provider.class} + ) + }) + public final void testGetKeySpecKeyProvider01() throws Exception { + boolean performed = false; + + for (int i = 0; i < EncryptedPrivateKeyInfoData.algName0.length; i++) { + try { + EncryptedPrivateKeyInfo epki = new EncryptedPrivateKeyInfo( + EncryptedPrivateKeyInfoData.algName0[i][0], + EncryptedPrivateKeyInfoData.encryptedData); + + try { + + // check that method under test throws NPE + epki.getKeySpec((Key) null, (Provider) null); + fail(getName() + "NullPointerException has not been thrown"); + } catch (NullPointerException ok) { + } + + try { + + // check that method under test throws NPE + epki.getKeySpec(new Key() { + public String getAlgorithm() { + return "alg"; + } + + public String getFormat() { + return "fmt"; + } + + public byte[] getEncoded() { + return new byte[] {}; + } + }, (Provider) null); + + fail(getName() + "NullPointerException has not been thrown"); + } catch (NullPointerException ok) { + } + + performed = true; + } catch (NoSuchAlgorithmException allowedFailure) { + } + } + assertTrue("Test not performed", performed); + } + + /** + * Encrypted data contains valid PKCS8 key info encoding + */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "In subset missed NoSuchAlgorithmException checking", + targets = { + @TestTarget( + methodName = "getKeySpec", + methodArgs = {java.security.Key.class, java.security.Provider.class} + ) + }) + public final void test_ROUNDTRIP_GetKeySpecKeyProvider01() { + boolean performed = false; + + for (int i = 0; i < algName.length; i++) { + for (int l = 0; l < provider.length; l++) { + if (provider[l] == null) { + continue; + } + TestDataGenerator g; + try { + // generate test data + g = new TestDataGenerator(algName[i][0], algName[i][1], + privateKeyInfo, provider[l]); + } catch (TestDataGenerator.AllowedFailure allowedFailure) { + continue; + } + try { + // create test object + EncryptedPrivateKeyInfo epki; + if (g.ap() == null) { + epki = new EncryptedPrivateKeyInfo(algName[i][0], g + .ct()); + } else { + epki = new EncryptedPrivateKeyInfo(g.ap(), g.ct()); + } + try { + + PKCS8EncodedKeySpec eks = epki.getKeySpec( + g.pubK() == null ? g.k() : g.pubK(), + provider[l]); + + if (!Arrays.equals(privateKeyInfo, eks.getEncoded())) { + fail(algName[i][0] + " != " + algName[i][1]); + } + } catch (InvalidKeyException e) { + fail(algName[i][0] + ", " + algName[i][1] + ": " + e); + } + performed = true; + + } catch (NoSuchAlgorithmException allowedFailure) { + } + } + } + assertTrue("Test not performed", performed); + } + + /** + * Encrypted data contains invalid PKCS8 key info encoding + */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "In subset missed NoSuchAlgorithmException checking", + targets = { + @TestTarget( + methodName = "getKeySpec", + methodArgs = {java.security.Key.class, java.security.Provider.class} + ) + }) + public final void test_ROUNDTRIP_GetKeySpecKeyProvider02() { + boolean performed = false; + + for (int i = 0; i < algName.length; i++) { + for (int l = 0; l < provider.length; l++) { + if (provider[l] == null) { + continue; + } + TestDataGenerator g; + try { + // generate test data + g = new TestDataGenerator(algName[i][0], algName[i][1], + privateKeyInfoDamaged, provider[l]); + } catch (TestDataGenerator.AllowedFailure allowedFailure) { + continue; + } + + try { + // create test object + EncryptedPrivateKeyInfo epki; + if (g.ap() == null) { + epki = new EncryptedPrivateKeyInfo(algName[i][0], g + .ct()); + } else { + epki = new EncryptedPrivateKeyInfo(g.ap(), g.ct()); + } + try { + + epki.getKeySpec(g.pubK() == null ? g.k() : g.pubK(), + provider[l]); + + fail(algName[i][0] + ", " + algName[i][1]); + + } catch (InvalidKeyException e) { + } + performed = true; + } catch (NoSuchAlgorithmException allowedFailure) { + } + } + } + assertTrue("Test not performed", performed); + } + + public static class TestDataGenerator { + + public static class AllowedFailure extends Exception { + AllowedFailure(String msg) { + super(msg); + } + } + + private Cipher c = null; + + private Key k = null, pubK = null; + + private AlgorithmParameters ap = null; + + byte[] ct; + + public TestDataGenerator(String algName, String transformation, + byte[] privateKeyInfo, Provider provider) throws AllowedFailure { + try { + c = (provider == null) ? Cipher + .getInstance(transformation != null ? transformation + : algName) : Cipher.getInstance( + transformation != null ? transformation : algName, + provider); + } catch (NoSuchAlgorithmException e) { + throw new AllowedFailure(e.getMessage()); + } catch (NoSuchPaddingException e) { + throw new AllowedFailure(e.getMessage()); + } + + try { + KeyGenerator kg = (provider == null) ? KeyGenerator + .getInstance(algName) : KeyGenerator.getInstance( + algName, provider); + k = kg.generateKey(); + } catch (NoSuchAlgorithmException e) { + } + + if (k == null) { + try { + KeyPairGenerator kpg = (provider == null) ? KeyPairGenerator + .getInstance(algName) + : KeyPairGenerator.getInstance(algName, provider); + KeyPair kp = kpg.genKeyPair(); + k = kp.getPrivate(); + pubK = kp.getPublic(); + } catch (NoSuchAlgorithmException e) { + } + } + + PBEParameterSpec pbeParamSpec = null; + if (k == null) { + try { + pbeParamSpec = new PBEParameterSpec(new byte[] { 1, 2, 3, + 4, 5, 6, 7, 8 }, 10); + SecretKeyFactory skf = (provider == null) ? SecretKeyFactory + .getInstance(algName) + : SecretKeyFactory.getInstance(algName, provider); + PBEKeySpec ks = new PBEKeySpec("12345678".toCharArray()); + try { + k = skf.generateSecret(ks); + } catch (InvalidKeySpecException e) { + throw new AllowedFailure(e.getMessage()); + } + + } catch (NoSuchAlgorithmException e) { + throw new AllowedFailure(e.getMessage()); + } + } + + try { + if (pbeParamSpec == null) { + c.init(Cipher.ENCRYPT_MODE, k); + } else { + c.init(Cipher.ENCRYPT_MODE, k, pbeParamSpec); + } + } catch (InvalidKeyException e) { + throw new AllowedFailure(e.getMessage()); + } catch (SecurityException e) { + throw new AllowedFailure(e.getMessage()); + } catch (InvalidAlgorithmParameterException e) { + throw new AllowedFailure(e.getMessage()); + } + + ap = c.getParameters(); + + try { + ct = c.doFinal(privateKeyInfo); + } catch (IllegalStateException e) { + throw new AllowedFailure(e.getMessage()); + } catch (IllegalBlockSizeException e) { + throw new AllowedFailure(e.getMessage()); + } catch (BadPaddingException e) { + throw new AllowedFailure(e.getMessage()); + } catch (RuntimeException e) { + throw new AllowedFailure(e.getMessage()); + } + + try { + // try to convert pbeParamSpec->ap + if (pbeParamSpec != null) { + try { + ap = (provider == null) ? AlgorithmParameters + .getInstance(algName) : AlgorithmParameters + .getInstance(algName, provider); + ap.init(pbeParamSpec); + pbeParamSpec = null; + } catch (NoSuchAlgorithmException e) { + // couldn't convert + throw new AllowedFailure(e.getMessage()); + } catch (InvalidParameterSpecException e) { + // couldn't convert + throw new AllowedFailure(e.getMessage()); + } + } + + if (ap == null) { + c.init(Cipher.DECRYPT_MODE, pubK == null ? k : pubK); + } else { + c.init(Cipher.DECRYPT_MODE, pubK == null ? k : pubK, ap); + } + + } catch (InvalidKeyException e) { + throw new AllowedFailure(e.getMessage()); + } catch (SecurityException e) { + throw new AllowedFailure(e.getMessage()); + } catch (InvalidAlgorithmParameterException e) { + throw new AllowedFailure(e.getMessage()); + } + } + + public Key k() { + return k; + } + + public Key pubK() { + return pubK; + } + + public Cipher c() { + return c; + } + + public byte[] ct() { + return ct; + } + + public AlgorithmParameters ap() { + return ap; + } + } + + // valid PrivateKeyInfo encoding + private static final byte[] privateKeyInfo = { (byte) 0x30, (byte) 0x82, + (byte) 0x02, (byte) 0x77, (byte) 0x02, (byte) 0x01, (byte) 0x00, + (byte) 0x30, (byte) 0x0d, (byte) 0x06, (byte) 0x09, (byte) 0x2a, + (byte) 0x86, (byte) 0x48, (byte) 0x86, (byte) 0xf7, (byte) 0x0d, + (byte) 0x01, (byte) 0x01, (byte) 0x01, (byte) 0x05, (byte) 0x00, + (byte) 0x04, (byte) 0x82, (byte) 0x02, (byte) 0x61, (byte) 0x30, + (byte) 0x82, (byte) 0x02, (byte) 0x5d, (byte) 0x02, (byte) 0x01, + (byte) 0x00, (byte) 0x02, (byte) 0x81, (byte) 0x81, (byte) 0x00, + (byte) 0xb2, (byte) 0x4a, (byte) 0x9b, (byte) 0x5b, (byte) 0xba, + (byte) 0x01, (byte) 0xc0, (byte) 0xcd, (byte) 0x65, (byte) 0x09, + (byte) 0x63, (byte) 0x70, (byte) 0x0b, (byte) 0x5a, (byte) 0x1b, + (byte) 0x92, (byte) 0x08, (byte) 0xf8, (byte) 0x55, (byte) 0x5e, + (byte) 0x7c, (byte) 0x1b, (byte) 0x50, (byte) 0x17, (byte) 0xec, + (byte) 0x44, (byte) 0x4c, (byte) 0x58, (byte) 0x42, (byte) 0x2b, + (byte) 0x41, (byte) 0x09, (byte) 0x59, (byte) 0xf2, (byte) 0xe1, + (byte) 0x5d, (byte) 0x43, (byte) 0x71, (byte) 0x4d, (byte) 0x92, + (byte) 0x03, (byte) 0x1d, (byte) 0xb6, (byte) 0x6c, (byte) 0x7f, + (byte) 0x5d, (byte) 0x48, (byte) 0xcd, (byte) 0x17, (byte) 0xec, + (byte) 0xd7, (byte) 0x4c, (byte) 0x39, (byte) 0xb1, (byte) 0x7b, + (byte) 0xe2, (byte) 0xbf, (byte) 0x96, (byte) 0x77, (byte) 0xbe, + (byte) 0xd0, (byte) 0xa0, (byte) 0xf0, (byte) 0x2d, (byte) 0x6b, + (byte) 0x24, (byte) 0xaa, (byte) 0x14, (byte) 0xba, (byte) 0x82, + (byte) 0x79, (byte) 0x10, (byte) 0x9b, (byte) 0x16, (byte) 0x68, + (byte) 0x47, (byte) 0x81, (byte) 0x54, (byte) 0xa2, (byte) 0xfa, + (byte) 0x91, (byte) 0x9e, (byte) 0x0a, (byte) 0x2a, (byte) 0x53, + (byte) 0xa6, (byte) 0xe7, (byte) 0x9e, (byte) 0x7d, (byte) 0x29, + (byte) 0x33, (byte) 0xd8, (byte) 0x05, (byte) 0xfc, (byte) 0x02, + (byte) 0x3f, (byte) 0xbd, (byte) 0xc7, (byte) 0x6e, (byte) 0xed, + (byte) 0xaa, (byte) 0x30, (byte) 0x6c, (byte) 0x5f, (byte) 0x52, + (byte) 0xed, (byte) 0x35, (byte) 0x65, (byte) 0x4b, (byte) 0x0e, + (byte) 0xc8, (byte) 0xa7, (byte) 0x12, (byte) 0x10, (byte) 0x56, + (byte) 0x37, (byte) 0xaf, (byte) 0x11, (byte) 0xfa, (byte) 0x21, + (byte) 0x0e, (byte) 0x99, (byte) 0xff, (byte) 0xfa, (byte) 0x8c, + (byte) 0x65, (byte) 0x8e, (byte) 0x6d, (byte) 0x02, (byte) 0x03, + (byte) 0x01, (byte) 0x00, (byte) 0x01, (byte) 0x02, (byte) 0x81, + (byte) 0x80, (byte) 0x78, (byte) 0x41, (byte) 0x72, (byte) 0x40, + (byte) 0x90, (byte) 0x59, (byte) 0x96, (byte) 0x5d, (byte) 0xf3, + (byte) 0x84, (byte) 0x3d, (byte) 0x99, (byte) 0xd9, (byte) 0x4e, + (byte) 0x51, (byte) 0xc2, (byte) 0x52, (byte) 0x62, (byte) 0x8d, + (byte) 0xd2, (byte) 0x49, (byte) 0x0b, (byte) 0x73, (byte) 0x1e, + (byte) 0x6f, (byte) 0xb2, (byte) 0x31, (byte) 0x7c, (byte) 0x66, + (byte) 0x45, (byte) 0x1e, (byte) 0x7c, (byte) 0xdc, (byte) 0x3a, + (byte) 0xc2, (byte) 0x5f, (byte) 0x51, (byte) 0x9a, (byte) 0x1e, + (byte) 0xa4, (byte) 0x19, (byte) 0x8d, (byte) 0xf4, (byte) 0xf9, + (byte) 0x81, (byte) 0x7e, (byte) 0xbe, (byte) 0x17, (byte) 0xf7, + (byte) 0xc7, (byte) 0x3c, (byte) 0x00, (byte) 0xa1, (byte) 0xf9, + (byte) 0x60, (byte) 0x82, (byte) 0x34, (byte) 0x8f, (byte) 0x9c, + (byte) 0xfd, (byte) 0x0b, (byte) 0x63, (byte) 0x42, (byte) 0x1b, + (byte) 0x7f, (byte) 0x45, (byte) 0xf1, (byte) 0x31, (byte) 0xc3, + (byte) 0x63, (byte) 0x47, (byte) 0x5c, (byte) 0xc1, (byte) 0xb2, + (byte) 0x5f, (byte) 0x57, (byte) 0xee, (byte) 0x02, (byte) 0x9f, + (byte) 0x5e, (byte) 0x08, (byte) 0x48, (byte) 0xba, (byte) 0x74, + (byte) 0xba, (byte) 0x81, (byte) 0xb7, (byte) 0x30, (byte) 0xac, + (byte) 0x4c, (byte) 0x01, (byte) 0x35, (byte) 0xce, (byte) 0x46, + (byte) 0x47, (byte) 0x8c, (byte) 0xe4, (byte) 0x62, (byte) 0x36, + (byte) 0x1a, (byte) 0x65, (byte) 0x0e, (byte) 0x33, (byte) 0x56, + (byte) 0xf9, (byte) 0xb7, (byte) 0xa0, (byte) 0xc4, (byte) 0xb6, + (byte) 0x82, (byte) 0x55, (byte) 0x7d, (byte) 0x36, (byte) 0x55, + (byte) 0xc0, (byte) 0x52, (byte) 0x5e, (byte) 0x35, (byte) 0x54, + (byte) 0xbd, (byte) 0x97, (byte) 0x01, (byte) 0x00, (byte) 0xbf, + (byte) 0x10, (byte) 0xdc, (byte) 0x1b, (byte) 0x51, (byte) 0x02, + (byte) 0x41, (byte) 0x00, (byte) 0xe7, (byte) 0x68, (byte) 0x03, + (byte) 0x3e, (byte) 0x21, (byte) 0x64, (byte) 0x68, (byte) 0x24, + (byte) 0x7b, (byte) 0xd0, (byte) 0x31, (byte) 0xa0, (byte) 0xa2, + (byte) 0xd9, (byte) 0x87, (byte) 0x6d, (byte) 0x79, (byte) 0x81, + (byte) 0x8f, (byte) 0x8f, (byte) 0x2d, (byte) 0x7a, (byte) 0x95, + (byte) 0x2e, (byte) 0x55, (byte) 0x9f, (byte) 0xd7, (byte) 0x86, + (byte) 0x29, (byte) 0x93, (byte) 0xbd, (byte) 0x04, (byte) 0x7e, + (byte) 0x4f, (byte) 0xdb, (byte) 0x56, (byte) 0xf1, (byte) 0x75, + (byte) 0xd0, (byte) 0x4b, (byte) 0x00, (byte) 0x3a, (byte) 0xe0, + (byte) 0x26, (byte) 0xf6, (byte) 0xab, (byte) 0x9e, (byte) 0x0b, + (byte) 0x2a, (byte) 0xf4, (byte) 0xa8, (byte) 0xd7, (byte) 0xff, + (byte) 0xbe, (byte) 0x01, (byte) 0xeb, (byte) 0x9b, (byte) 0x81, + (byte) 0xc7, (byte) 0x5f, (byte) 0x02, (byte) 0x73, (byte) 0xe1, + (byte) 0x2b, (byte) 0x02, (byte) 0x41, (byte) 0x00, (byte) 0xc5, + (byte) 0x3d, (byte) 0x78, (byte) 0xab, (byte) 0xe6, (byte) 0xab, + (byte) 0x3e, (byte) 0x29, (byte) 0xfd, (byte) 0x98, (byte) 0xd0, + (byte) 0xa4, (byte) 0x3e, (byte) 0x58, (byte) 0xee, (byte) 0x48, + (byte) 0x45, (byte) 0xa3, (byte) 0x66, (byte) 0xac, (byte) 0xe9, + (byte) 0x4d, (byte) 0xbd, (byte) 0x60, (byte) 0xea, (byte) 0x24, + (byte) 0xff, (byte) 0xed, (byte) 0x0c, (byte) 0x67, (byte) 0xc5, + (byte) 0xfd, (byte) 0x36, (byte) 0x28, (byte) 0xea, (byte) 0x74, + (byte) 0x88, (byte) 0xd1, (byte) 0xd1, (byte) 0xad, (byte) 0x58, + (byte) 0xd7, (byte) 0xf0, (byte) 0x67, (byte) 0x20, (byte) 0xc1, + (byte) 0xe3, (byte) 0xb3, (byte) 0xdb, (byte) 0x52, (byte) 0xad, + (byte) 0xf3, (byte) 0xc4, (byte) 0x21, (byte) 0xd8, (byte) 0x8c, + (byte) 0x4c, (byte) 0x41, (byte) 0x27, (byte) 0xdb, (byte) 0xd0, + (byte) 0x35, (byte) 0x92, (byte) 0xc7, (byte) 0x02, (byte) 0x41, + (byte) 0x00, (byte) 0xe0, (byte) 0x99, (byte) 0x42, (byte) 0xb4, + (byte) 0x76, (byte) 0x02, (byte) 0x97, (byte) 0x55, (byte) 0xf9, + (byte) 0xda, (byte) 0x3b, (byte) 0xa0, (byte) 0xd7, (byte) 0x0e, + (byte) 0xdc, (byte) 0xf4, (byte) 0x33, (byte) 0x7f, (byte) 0xbd, + (byte) 0xcf, (byte) 0xd0, (byte) 0xeb, (byte) 0x6e, (byte) 0x89, + (byte) 0xf7, (byte) 0x4f, (byte) 0x5a, (byte) 0x07, (byte) 0x7c, + (byte) 0xa9, (byte) 0x49, (byte) 0x47, (byte) 0x68, (byte) 0x35, + (byte) 0xa8, (byte) 0x05, (byte) 0x3d, (byte) 0xfd, (byte) 0x04, + (byte) 0x7b, (byte) 0x17, (byte) 0x31, (byte) 0x0d, (byte) 0xc8, + (byte) 0xa3, (byte) 0x98, (byte) 0x34, (byte) 0xa0, (byte) 0x50, + (byte) 0x44, (byte) 0x00, (byte) 0xf1, (byte) 0x0c, (byte) 0xe6, + (byte) 0xe5, (byte) 0xc4, (byte) 0x41, (byte) 0x3d, (byte) 0xf8, + (byte) 0x3d, (byte) 0x4e, (byte) 0x0b, (byte) 0x1c, (byte) 0xdb, + (byte) 0x02, (byte) 0x41, (byte) 0x00, (byte) 0x82, (byte) 0x9b, + (byte) 0x8a, (byte) 0xfd, (byte) 0xa1, (byte) 0x98, (byte) 0x41, + (byte) 0x68, (byte) 0xc2, (byte) 0xd1, (byte) 0xdf, (byte) 0x4e, + (byte) 0xf3, (byte) 0x2e, (byte) 0x26, (byte) 0x53, (byte) 0x5b, + (byte) 0x31, (byte) 0xb1, (byte) 0x7a, (byte) 0xcc, (byte) 0x5e, + (byte) 0xbb, (byte) 0x09, (byte) 0xa2, (byte) 0xe2, (byte) 0x6f, + (byte) 0x4a, (byte) 0x04, (byte) 0x0d, (byte) 0xef, (byte) 0x90, + (byte) 0x15, (byte) 0xbe, (byte) 0x10, (byte) 0x4a, (byte) 0xac, + (byte) 0x92, (byte) 0xeb, (byte) 0xda, (byte) 0x72, (byte) 0xdb, + (byte) 0x43, (byte) 0x08, (byte) 0xb7, (byte) 0x2b, (byte) 0x4c, + (byte) 0xe1, (byte) 0xbb, (byte) 0x58, (byte) 0xcb, (byte) 0x71, + (byte) 0x80, (byte) 0xad, (byte) 0xbc, (byte) 0xdc, (byte) 0x62, + (byte) 0x5e, (byte) 0x3e, (byte) 0xcb, (byte) 0x92, (byte) 0xda, + (byte) 0xf6, (byte) 0xdf, (byte) 0x02, (byte) 0x40, (byte) 0x4d, + (byte) 0x81, (byte) 0x90, (byte) 0xc5, (byte) 0x77, (byte) 0x30, + (byte) 0xb7, (byte) 0x29, (byte) 0x00, (byte) 0xa8, (byte) 0xf1, + (byte) 0xb4, (byte) 0xae, (byte) 0x52, (byte) 0x63, (byte) 0x00, + (byte) 0xb2, (byte) 0x2d, (byte) 0x3e, (byte) 0x7d, (byte) 0xd6, + (byte) 0x4d, (byte) 0xf9, (byte) 0x8a, (byte) 0xc1, (byte) 0xb1, + (byte) 0x98, (byte) 0x89, (byte) 0x52, (byte) 0x40, (byte) 0x14, + (byte) 0x1b, (byte) 0x0e, (byte) 0x61, (byte) 0x8f, (byte) 0xf4, + (byte) 0xbe, (byte) 0x59, (byte) 0x79, (byte) 0x79, (byte) 0x95, + (byte) 0x19, (byte) 0x5c, (byte) 0x51, (byte) 0x08, (byte) 0x66, + (byte) 0xc1, (byte) 0x42, (byte) 0x30, (byte) 0xb3, (byte) 0x7a, + (byte) 0x86, (byte) 0x9f, (byte) 0x3e, (byte) 0xf5, (byte) 0x19, + (byte) 0xa3, (byte) 0xae, (byte) 0x64, (byte) 0x69, (byte) 0x14, + (byte) 0x07, (byte) 0x50, (byte) 0x97, }; + + // valid PrivateKeyInfo encoding (Damaged) + private static final byte[] privateKeyInfoDamaged = { (byte) 0x30, + (byte) 0x82, (byte) 0x02, (byte) 0x77, (byte) 0x02, (byte) 0x01, + (byte) 0x00, (byte) 0x30, (byte) 0x0d, (byte) 0x06, (byte) 0x09, + (byte) 0x2a, (byte) 0x86, (byte) 0x48, (byte) 0x86, (byte) 0xf7, + (byte) 0x0d, (byte) 0x01, (byte) 0x01, (byte) 0x01, (byte) 0x05, + (byte) 0x00, (byte) 0x04, // private key octet str + (byte) 0x82, (byte) 0x02, (byte) 0x62, // Damage: l=460->461 + // (0x61->0x62) + (byte) 0x30, (byte) 0x82, (byte) 0x02, (byte) 0x5d, (byte) 0x02, + (byte) 0x01, (byte) 0x00, (byte) 0x02, (byte) 0x81, (byte) 0x81, + (byte) 0x00, (byte) 0xb2, (byte) 0x4a, (byte) 0x9b, (byte) 0x5b, + (byte) 0xba, (byte) 0x01, (byte) 0xc0, (byte) 0xcd, (byte) 0x65, + (byte) 0x09, (byte) 0x63, (byte) 0x70, (byte) 0x0b, (byte) 0x5a, + (byte) 0x1b, (byte) 0x92, (byte) 0x08, (byte) 0xf8, (byte) 0x55, + (byte) 0x5e, (byte) 0x7c, (byte) 0x1b, (byte) 0x50, (byte) 0x17, + (byte) 0xec, (byte) 0x44, (byte) 0x4c, (byte) 0x58, (byte) 0x42, + (byte) 0x2b, (byte) 0x41, (byte) 0x09, (byte) 0x59, (byte) 0xf2, + (byte) 0xe1, (byte) 0x5d, (byte) 0x43, (byte) 0x71, (byte) 0x4d, + (byte) 0x92, (byte) 0x03, (byte) 0x1d, (byte) 0xb6, (byte) 0x6c, + (byte) 0x7f, (byte) 0x5d, (byte) 0x48, (byte) 0xcd, (byte) 0x17, + (byte) 0xec, (byte) 0xd7, (byte) 0x4c, (byte) 0x39, (byte) 0xb1, + (byte) 0x7b, (byte) 0xe2, (byte) 0xbf, (byte) 0x96, (byte) 0x77, + (byte) 0xbe, (byte) 0xd0, (byte) 0xa0, (byte) 0xf0, (byte) 0x2d, + (byte) 0x6b, (byte) 0x24, (byte) 0xaa, (byte) 0x14, (byte) 0xba, + (byte) 0x82, (byte) 0x79, (byte) 0x10, (byte) 0x9b, (byte) 0x16, + (byte) 0x68, (byte) 0x47, (byte) 0x81, (byte) 0x54, (byte) 0xa2, + (byte) 0xfa, (byte) 0x91, (byte) 0x9e, (byte) 0x0a, (byte) 0x2a, + (byte) 0x53, (byte) 0xa6, (byte) 0xe7, (byte) 0x9e, (byte) 0x7d, + (byte) 0x29, (byte) 0x33, (byte) 0xd8, (byte) 0x05, (byte) 0xfc, + (byte) 0x02, (byte) 0x3f, (byte) 0xbd, (byte) 0xc7, (byte) 0x6e, + (byte) 0xed, (byte) 0xaa, (byte) 0x30, (byte) 0x6c, (byte) 0x5f, + (byte) 0x52, (byte) 0xed, (byte) 0x35, (byte) 0x65, (byte) 0x4b, + (byte) 0x0e, (byte) 0xc8, (byte) 0xa7, (byte) 0x12, (byte) 0x10, + (byte) 0x56, (byte) 0x37, (byte) 0xaf, (byte) 0x11, (byte) 0xfa, + (byte) 0x21, (byte) 0x0e, (byte) 0x99, (byte) 0xff, (byte) 0xfa, + (byte) 0x8c, (byte) 0x65, (byte) 0x8e, (byte) 0x6d, (byte) 0x02, + (byte) 0x03, (byte) 0x01, (byte) 0x00, (byte) 0x01, (byte) 0x02, + (byte) 0x81, (byte) 0x80, (byte) 0x78, (byte) 0x41, (byte) 0x72, + (byte) 0x40, (byte) 0x90, (byte) 0x59, (byte) 0x96, (byte) 0x5d, + (byte) 0xf3, (byte) 0x84, (byte) 0x3d, (byte) 0x99, (byte) 0xd9, + (byte) 0x4e, (byte) 0x51, (byte) 0xc2, (byte) 0x52, (byte) 0x62, + (byte) 0x8d, (byte) 0xd2, (byte) 0x49, (byte) 0x0b, (byte) 0x73, + (byte) 0x1e, (byte) 0x6f, (byte) 0xb2, (byte) 0x31, (byte) 0x7c, + (byte) 0x66, (byte) 0x45, (byte) 0x1e, (byte) 0x7c, (byte) 0xdc, + (byte) 0x3a, (byte) 0xc2, (byte) 0x5f, (byte) 0x51, (byte) 0x9a, + (byte) 0x1e, (byte) 0xa4, (byte) 0x19, (byte) 0x8d, (byte) 0xf4, + (byte) 0xf9, (byte) 0x81, (byte) 0x7e, (byte) 0xbe, (byte) 0x17, + (byte) 0xf7, (byte) 0xc7, (byte) 0x3c, (byte) 0x00, (byte) 0xa1, + (byte) 0xf9, (byte) 0x60, (byte) 0x82, (byte) 0x34, (byte) 0x8f, + (byte) 0x9c, (byte) 0xfd, (byte) 0x0b, (byte) 0x63, (byte) 0x42, + (byte) 0x1b, (byte) 0x7f, (byte) 0x45, (byte) 0xf1, (byte) 0x31, + (byte) 0xc3, (byte) 0x63, (byte) 0x47, (byte) 0x5c, (byte) 0xc1, + (byte) 0xb2, (byte) 0x5f, (byte) 0x57, (byte) 0xee, (byte) 0x02, + (byte) 0x9f, (byte) 0x5e, (byte) 0x08, (byte) 0x48, (byte) 0xba, + (byte) 0x74, (byte) 0xba, (byte) 0x81, (byte) 0xb7, (byte) 0x30, + (byte) 0xac, (byte) 0x4c, (byte) 0x01, (byte) 0x35, (byte) 0xce, + (byte) 0x46, (byte) 0x47, (byte) 0x8c, (byte) 0xe4, (byte) 0x62, + (byte) 0x36, (byte) 0x1a, (byte) 0x65, (byte) 0x0e, (byte) 0x33, + (byte) 0x56, (byte) 0xf9, (byte) 0xb7, (byte) 0xa0, (byte) 0xc4, + (byte) 0xb6, (byte) 0x82, (byte) 0x55, (byte) 0x7d, (byte) 0x36, + (byte) 0x55, (byte) 0xc0, (byte) 0x52, (byte) 0x5e, (byte) 0x35, + (byte) 0x54, (byte) 0xbd, (byte) 0x97, (byte) 0x01, (byte) 0x00, + (byte) 0xbf, (byte) 0x10, (byte) 0xdc, (byte) 0x1b, (byte) 0x51, + (byte) 0x02, (byte) 0x41, (byte) 0x00, (byte) 0xe7, (byte) 0x68, + (byte) 0x03, (byte) 0x3e, (byte) 0x21, (byte) 0x64, (byte) 0x68, + (byte) 0x24, (byte) 0x7b, (byte) 0xd0, (byte) 0x31, (byte) 0xa0, + (byte) 0xa2, (byte) 0xd9, (byte) 0x87, (byte) 0x6d, (byte) 0x79, + (byte) 0x81, (byte) 0x8f, (byte) 0x8f, (byte) 0x2d, (byte) 0x7a, + (byte) 0x95, (byte) 0x2e, (byte) 0x55, (byte) 0x9f, (byte) 0xd7, + (byte) 0x86, (byte) 0x29, (byte) 0x93, (byte) 0xbd, (byte) 0x04, + (byte) 0x7e, (byte) 0x4f, (byte) 0xdb, (byte) 0x56, (byte) 0xf1, + (byte) 0x75, (byte) 0xd0, (byte) 0x4b, (byte) 0x00, (byte) 0x3a, + (byte) 0xe0, (byte) 0x26, (byte) 0xf6, (byte) 0xab, (byte) 0x9e, + (byte) 0x0b, (byte) 0x2a, (byte) 0xf4, (byte) 0xa8, (byte) 0xd7, + (byte) 0xff, (byte) 0xbe, (byte) 0x01, (byte) 0xeb, (byte) 0x9b, + (byte) 0x81, (byte) 0xc7, (byte) 0x5f, (byte) 0x02, (byte) 0x73, + (byte) 0xe1, (byte) 0x2b, (byte) 0x02, (byte) 0x41, (byte) 0x00, + (byte) 0xc5, (byte) 0x3d, (byte) 0x78, (byte) 0xab, (byte) 0xe6, + (byte) 0xab, (byte) 0x3e, (byte) 0x29, (byte) 0xfd, // 88 + (byte) 0x98, (byte) 0xd0, (byte) 0xa4, (byte) 0x3e, (byte) 0x58, + (byte) 0xee, (byte) 0x48, (byte) 0x45, (byte) 0xa3, (byte) 0x66, + (byte) 0xac, (byte) 0xe9, (byte) 0x4d, (byte) 0xbd, (byte) 0x60, + (byte) 0xea, (byte) 0x24, (byte) 0xff, (byte) 0xed, (byte) 0x0c, + (byte) 0x67, (byte) 0xc5, (byte) 0xfd, (byte) 0x36, (byte) 0x28, + (byte) 0xea, (byte) 0x74, (byte) 0x88, (byte) 0xd1, (byte) 0xd1, + (byte) 0xad, (byte) 0x58, (byte) 0xd7, (byte) 0xf0, (byte) 0x67, + (byte) 0x20, (byte) 0xc1, (byte) 0xe3, (byte) 0xb3, (byte) 0xdb, + (byte) 0x52, (byte) 0xad, (byte) 0xf3, (byte) 0xc4, (byte) 0x21, + (byte) 0xd8, (byte) 0x8c, (byte) 0x4c, (byte) 0x41, (byte) 0x27, + (byte) 0xdb, (byte) 0xd0, (byte) 0x35, (byte) 0x92, (byte) 0xc7, + (byte) 0x02, (byte) 0x41, (byte) 0x00, (byte) 0xe0, (byte) 0x99, + (byte) 0x42, (byte) 0xb4, (byte) 0x76, (byte) 0x02, (byte) 0x97, + (byte) 0x55, (byte) 0xf9, (byte) 0xda, (byte) 0x3b, (byte) 0xa0, + (byte) 0xd7, (byte) 0x0e, (byte) 0xdc, (byte) 0xf4, (byte) 0x33, + (byte) 0x7f, (byte) 0xbd, (byte) 0xcf, (byte) 0xd0, (byte) 0xeb, + (byte) 0x6e, (byte) 0x89, (byte) 0xf7, (byte) 0x4f, (byte) 0x5a, + (byte) 0x07, (byte) 0x7c, (byte) 0xa9, (byte) 0x49, (byte) 0x47, + (byte) 0x68, (byte) 0x35, (byte) 0xa8, (byte) 0x05, (byte) 0x3d, + (byte) 0xfd, (byte) 0x04, (byte) 0x7b, (byte) 0x17, (byte) 0x31, + (byte) 0x0d, (byte) 0xc8, (byte) 0xa3, (byte) 0x98, (byte) 0x34, + (byte) 0xa0, (byte) 0x50, (byte) 0x44, (byte) 0x00, (byte) 0xf1, + (byte) 0x0c, (byte) 0xe6, (byte) 0xe5, (byte) 0xc4, (byte) 0x41, + (byte) 0x3d, (byte) 0xf8, (byte) 0x3d, (byte) 0x4e, (byte) 0x0b, // 118 + (byte) 0x1c, (byte) 0xdb, (byte) 0x02, (byte) 0x41, (byte) 0x00, + (byte) 0x82, (byte) 0x9b, (byte) 0x8a, (byte) 0xfd, (byte) 0xa1, + (byte) 0x98, (byte) 0x41, (byte) 0x68, (byte) 0xc2, (byte) 0xd1, + (byte) 0xdf, (byte) 0x4e, (byte) 0xf3, (byte) 0x2e, (byte) 0x26, + (byte) 0x53, (byte) 0x5b, (byte) 0x31, (byte) 0xb1, (byte) 0x7a, + (byte) 0xcc, (byte) 0x5e, (byte) 0xbb, (byte) 0x09, (byte) 0xa2, + (byte) 0xe2, (byte) 0x6f, (byte) 0x4a, (byte) 0x04, (byte) 0x0d, + (byte) 0xef, (byte) 0x90, (byte) 0x15, (byte) 0xbe, (byte) 0x10, + (byte) 0x4a, (byte) 0xac, (byte) 0x92, (byte) 0xeb, (byte) 0xda, + (byte) 0x72, (byte) 0xdb, (byte) 0x43, (byte) 0x08, (byte) 0xb7, + (byte) 0x2b, (byte) 0x4c, (byte) 0xe1, (byte) 0xbb, (byte) 0x58, + (byte) 0xcb, (byte) 0x71, (byte) 0x80, (byte) 0xad, (byte) 0xbc, + (byte) 0xdc, (byte) 0x62, (byte) 0x5e, (byte) 0x3e, (byte) 0xcb, + (byte) 0x92, (byte) 0xda, (byte) 0xf6, (byte) 0xdf, (byte) 0x02, + (byte) 0x40, (byte) 0x4d, (byte) 0x81, (byte) 0x90, (byte) 0xc5, + (byte) 0x77, (byte) 0x30, (byte) 0xb7, (byte) 0x29, (byte) 0x00, + (byte) 0xa8, (byte) 0xf1, (byte) 0xb4, (byte) 0xae, (byte) 0x52, + (byte) 0x63, (byte) 0x00, (byte) 0xb2, // 140 + (byte) 0x2d, (byte) 0x3e, (byte) 0x7d, (byte) 0xd6, (byte) 0x4d, + (byte) 0xf9, (byte) 0x8a, (byte) 0xc1, (byte) 0xb1, (byte) 0x98, + (byte) 0x89, (byte) 0x52, (byte) 0x40, (byte) 0x14, (byte) 0x1b, + (byte) 0x0e, (byte) 0x61, (byte) 0x8f, (byte) 0xf4, (byte) 0xbe, + (byte) 0x59, (byte) 0x79, (byte) 0x79, (byte) 0x95, (byte) 0x19, + (byte) 0x5c, (byte) 0x51, (byte) 0x08, (byte) 0x66, (byte) 0xc1, + (byte) 0x42, (byte) 0x30, (byte) 0xb3, (byte) 0x7a, (byte) 0x86, + (byte) 0x9f, (byte) 0x3e, (byte) 0xf5, (byte) 0x19, (byte) 0xa3, // 150 + (byte) 0xae, (byte) 0x64, (byte) 0x69, (byte) 0x14, (byte) 0x07, + (byte) 0x50, (byte) 0x97, }; +} diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/ExemptionMechanismExceptionTest.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/ExemptionMechanismExceptionTest.java new file mode 100644 index 0000000..0f8a372 --- /dev/null +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/ExemptionMechanismExceptionTest.java @@ -0,0 +1,146 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Vera Y. Petrashkova +* @version $Revision$ +*/ + +package org.apache.harmony.crypto.tests.javax.crypto; + +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + +import javax.crypto.ExemptionMechanismException; + +import junit.framework.TestCase; + + +@TestTargetClass(ExemptionMechanismException.class) +/** + * Tests for <code>ExemptionMechanismException</code> class constructors and + * methods. + * + */ +public class ExemptionMechanismExceptionTest extends TestCase { + + public static void main(String[] args) { + } + + /** + * Constructor for ExemptionMechanismExceptionTests. + * + * @param arg0 + */ + public ExemptionMechanismExceptionTest(String arg0) { + super(arg0); + } + + static String[] msgs = { + "", + "Check new message", + "Check new message Check new message Check new message Check new message Check new message" }; + + static Throwable tCause = new Throwable("Throwable for exception"); + + static String createErr(Exception tE, Exception eE) { + return "ExemptionMechanismException: ".concat(tE.toString()).concat( + " is not equal to caught exception: ").concat(eE.toString()); + } + + /** + * Test for <code>ExemptionMechanismException()</code> constructor + * Assertion: constructs ExemptionMechanismException with no detail message + */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "ExemptionMechanismException", + methodArgs = {} + ) + }) + public void testExemptionMechanismException01() { + ExemptionMechanismException tE = new ExemptionMechanismException(); + assertNull("getMessage() must return null.", tE.getMessage()); + assertNull("getCause() must return null", tE.getCause()); + try { + throw tE; + } catch (Exception e) { + assertTrue(createErr(tE, e), tE.equals(e)); + } + } + + /** + * Test for <code>ExemptionMechanismException(String)</code> constructor + * Assertion: constructs ExemptionMechanismException with detail message + * msg. Parameter <code>msg</code> is not null. + */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "ExemptionMechanismException", + methodArgs = {java.lang.String.class} + ) + }) + public void testExemptionMechanismException02() { + ExemptionMechanismException tE; + for (int i = 0; i < msgs.length; i++) { + tE = new ExemptionMechanismException(msgs[i]); + assertEquals("getMessage() must return: ".concat(msgs[i]), tE + .getMessage(), msgs[i]); + assertNull("getCause() must return null", tE.getCause()); + try { + throw tE; + } catch (Exception e) { + assertTrue(createErr(tE, e), tE.equals(e)); + } + } + } + + /** + * Test for <code>ExemptionMechanismException(String)</code> constructor + * Assertion: constructs ExemptionMechanismException when <code>msg</code> + * is null + */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "ExemptionMechanismException", + methodArgs = {java.lang.String.class} + ) + }) + public void testExemptionMechanismException03() { + String msg = null; + ExemptionMechanismException tE = new ExemptionMechanismException(msg); + assertNull("getMessage() must return null.", tE.getMessage()); + assertNull("getCause() must return null", tE.getCause()); + try { + throw tE; + } catch (Exception e) { + assertTrue(createErr(tE, e), tE.equals(e)); + } + } + +} diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/ExemptionMechanismSpiTest.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/ExemptionMechanismSpiTest.java new file mode 100644 index 0000000..e528258 --- /dev/null +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/ExemptionMechanismSpiTest.java @@ -0,0 +1,161 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Vera Y. Petrashkova +* @version $Revision$ +*/ + +package org.apache.harmony.crypto.tests.javax.crypto; + +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + +import java.security.AlgorithmParameters; +import java.security.InvalidAlgorithmParameterException; +import java.security.InvalidKeyException; +import java.security.Key; +import java.security.spec.AlgorithmParameterSpec; +import javax.crypto.ExemptionMechanismException; +import javax.crypto.ShortBufferException; +import javax.crypto.ExemptionMechanismSpi; +import org.apache.harmony.crypto.tests.support.MyExemptionMechanismSpi; + +import junit.framework.TestCase; + + +@TestTargetClass(ExemptionMechanismSpi.class) +/** + * Tests for <code>ExemptionMechanismSpi</code> class constructors and + * methods. + * + */ +public class ExemptionMechanismSpiTest extends TestCase { +class Mock_ExemptionMechanismSpi extends MyExemptionMechanismSpi{ + + @Override + protected byte[] engineGenExemptionBlob() throws ExemptionMechanismException { + return super.engineGenExemptionBlob(); + } + + @Override + protected int engineGenExemptionBlob(byte[] output, int outputOffset) throws ShortBufferException, ExemptionMechanismException { + return super.engineGenExemptionBlob(output, outputOffset); + } + + @Override + protected int engineGetOutputSize(int inputLen) { + return super.engineGetOutputSize(inputLen); + } + + @Override + protected void engineInit(Key key) throws InvalidKeyException, ExemptionMechanismException { + super.engineInit(key); + + } + + @Override + protected void engineInit(Key key, AlgorithmParameterSpec params) throws InvalidKeyException, InvalidAlgorithmParameterException, ExemptionMechanismException { + super.engineInit(key, params); + + } + + @Override + protected void engineInit(Key key, AlgorithmParameters params) throws InvalidKeyException, InvalidAlgorithmParameterException, ExemptionMechanismException { + super.engineInit(key, params); + + } + +} + + /** + * Constructor for ExemptionMechanismSpiTests. + * + * @param arg0 + */ + public ExemptionMechanismSpiTest(String arg0) { + super(arg0); + } + + /** + * Test for <code>ExemptionMechanismSpi</code> constructor Assertion: + * constructs ExemptionMechanismSpi + */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "ExemptionMechanismSpi", + methodArgs = {} + ) + }) + public void testExemptionMechanismSpi01() + throws ExemptionMechanismException, + ShortBufferException, InvalidKeyException, + InvalidAlgorithmParameterException { + Mock_ExemptionMechanismSpi emSpi = new Mock_ExemptionMechanismSpi(){}; + int len = MyExemptionMechanismSpi.getLength(); + byte [] bbRes = emSpi.engineGenExemptionBlob(); + assertEquals("Incorrect length", bbRes.length, len); + assertEquals("Incorrect result", + emSpi.engineGenExemptionBlob(new byte[1], len), len); + assertEquals("Incorrect output size", 10, emSpi.engineGetOutputSize(100)); + Key key = null; + AlgorithmParameters params = null; + AlgorithmParameterSpec parSpec = null; + try { + emSpi.engineInit(key); + fail("InvalidKeyException must be thrown"); + } catch (InvalidKeyException e) { + } + try { + emSpi.engineInit(key, params); + fail("InvalidKeyException must be thrown"); + } catch (InvalidKeyException e) { + } + try { + emSpi.engineInit(key, parSpec); + fail("InvalidKeyException must be thrown"); + } catch (InvalidKeyException e) { + } + key = ((MyExemptionMechanismSpi)emSpi).new tmp1Key("Proba", new byte[0]); + try { + emSpi.engineInit(key); + fail("ExemptionMechanismException must be thrown"); + } catch (ExemptionMechanismException e) { + } + try { + emSpi.engineInit(key, params); + fail("ExemptionMechanismException must be thrown"); + } catch (ExemptionMechanismException e) { + } + try { + emSpi.engineInit(key, parSpec); + fail("ExemptionMechanismException must be thrown"); + } catch (ExemptionMechanismException e) { + } + key = ((MyExemptionMechanismSpi)emSpi).new tmpKey("Proba", new byte[0]); + emSpi.engineInit(key); + emSpi.engineInit(key, params); + emSpi.engineInit(key, parSpec); + + assertEquals("Incorrect result", 10, emSpi.engineGetOutputSize(100)); + } +} diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/ExemptionMechanismTest.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/ExemptionMechanismTest.java new file mode 100644 index 0000000..4c36900 --- /dev/null +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/ExemptionMechanismTest.java @@ -0,0 +1,201 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.harmony.crypto.tests.javax.crypto; + +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + +import java.security.InvalidKeyException; +import java.security.Key; +import java.security.NoSuchProviderException; +import java.security.Provider; + +import javax.crypto.ExemptionMechanism; +import javax.crypto.ExemptionMechanismSpi; + +import org.apache.harmony.crypto.tests.support.MyExemptionMechanismSpi; +import org.apache.harmony.crypto.tests.support.MyExemptionMechanismSpi.tmpKey; +import org.apache.harmony.security.tests.support.SpiEngUtils; + +import junit.framework.TestCase; + +@TestTargetClass(ExemptionMechanism.class) +/** + * Tests for <code>ExemptionMechanism</code> class constructors and methods + * + */ + +public class ExemptionMechanismTest extends TestCase { + + private static final String srvExemptionMechanism = "ExemptionMechanism"; + + private static final String defaultAlg = "EMech"; + + private static final String ExemptionMechanismProviderClass = "org.apache.harmony.crypto.tests.support.MyExemptionMechanismSpi"; + + /** + * Test for <code>ExemptionMechanism</code> constructor + * Assertion: creates new object using provider and mechanism name + */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "ExemptionMechanism", + methodArgs = {javax.crypto.ExemptionMechanismSpi.class, java.security.Provider.class, java.lang.String.class} + ) + }) + public void testExemptionMechanism() throws Exception { + Provider mProv = (new SpiEngUtils()).new MyProvider("MyExMechProvider", + "Provider for ExemptionMechanism testing", + srvExemptionMechanism.concat(".").concat(defaultAlg), + ExemptionMechanismProviderClass); + + ExemptionMechanismSpi spi = new MyExemptionMechanismSpi(); + + ExemptionMechanism em = new ExemptionMechanism(spi, mProv, defaultAlg) {}; + assertEquals("Incorrect provider", em.getProvider(), mProv); + assertEquals("Incorrect algorithm", em.getName(), defaultAlg); + try { + em.init(null); + fail("InvalidKeyException must be thrown"); + } catch (InvalidKeyException e) {} + + try { + em.getOutputSize(100); + fail("IllegalStateException must be thrown"); + } catch (IllegalStateException e) {} + + + em = new ExemptionMechanism(null, null, null) {}; + assertNull("Incorrect mechanism", em.getName()); + assertNull("Incorrect provider", em.getProvider()); + try { + em.init(null); + fail("NullPointerException must be thrown"); + } catch (NullPointerException e) {} + try { + em.getOutputSize(100); + fail("IllegalStateException must be thrown"); + } catch (IllegalStateException e) {} + } + + /** + * @tests javax/crypto/ExemptionMechanism#getInstance(String algorithm, String provider) + * Checks exception order + */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "Regression test.", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {java.lang.String.class, java.lang.String.class} + ) + }) + public void testGetInstance() throws Exception { + //Regression for HARMONY-762 + try { + ExemptionMechanism.getInstance((String) null, "aaa"); + fail("NoSuchProviderException must be thrown"); + } catch (NoSuchProviderException pe) { + //expected + } + } + + /** + * Test for <code>isCryptoAllowed(Key key)</code> method + */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "Regression test.", + targets = { + @TestTarget( + methodName = "isCryptoAllowed", + methodArgs = {java.security.Key.class} + ) + }) + public void testIsCryptoAllowed() throws Exception { + + //Regression for HARMONY-1029 + Provider mProv = (new SpiEngUtils()).new MyProvider("MyExMechProvider", + "Provider for ExemptionMechanism testing", + srvExemptionMechanism.concat(".").concat(defaultAlg), + ExemptionMechanismProviderClass); + + ExemptionMechanism em = new ExemptionMechanism( + new MyExemptionMechanismSpi(), mProv, defaultAlg) { + }; + + Key key = new MyExemptionMechanismSpi().new tmpKey("Proba", new byte[0]); + + assertFalse(em.isCryptoAllowed(key)); + + em.init(key); + assertFalse(em.isCryptoAllowed(key)); + + em.genExemptionBlob(); + assertTrue(em.isCryptoAllowed(key)); + + Key key1 = new MyExemptionMechanismSpi().new tmpKey("Proba", + new byte[] { 1 }); + assertFalse(em.isCryptoAllowed(key1)); + + em.init(key1); + assertFalse(em.isCryptoAllowed(key)); + } + + /** + * Test for <code>genExemptionBlob((byte[] output, int outputOffset)</code> method + */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "Regression test", + targets = { + @TestTarget( + methodName = "genExemptionBlob", + methodArgs = {byte[].class, int.class} + ) + }) + public void testGenExemptionBlob() throws Exception { + + //Regression for HARMONY-1029 + Provider mProv = (new SpiEngUtils()).new MyProvider("MyExMechProvider", + "Provider for ExemptionMechanism testing", + srvExemptionMechanism.concat(".").concat(defaultAlg), + ExemptionMechanismProviderClass); + + ExemptionMechanism em = new ExemptionMechanism( + new MyExemptionMechanismSpi(), mProv, defaultAlg) { + }; + + Key key = new MyExemptionMechanismSpi().new tmpKey("Proba", new byte[0]); + + em.init(key); + // ExemptionMechanism doesn't check parameters + // it is a responsibility of ExemptionMechanismSpi + em.genExemptionBlob(null, 0); + em.genExemptionBlob(new byte[0], 0); + em.genExemptionBlob(new byte[10], -5); + + } + +} diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/IllegalBlockSizeExceptionTest.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/IllegalBlockSizeExceptionTest.java new file mode 100644 index 0000000..5ec8321 --- /dev/null +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/IllegalBlockSizeExceptionTest.java @@ -0,0 +1,125 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Vera Y. Petrashkova +* @version $Revision$ +*/ + +package org.apache.harmony.crypto.tests.javax.crypto; + +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + +import javax.crypto.IllegalBlockSizeException; + +import junit.framework.TestCase; + + +@TestTargetClass(IllegalBlockSizeException.class) +/** + * Tests for <code>IllegalBlockSizeException</code> class constructors and + * methods. + * + */ +public class IllegalBlockSizeExceptionTest extends TestCase { + + public static void main(String[] args) { + } + + /** + * Constructor for IllegalBlockSizeExceptionTests. + * + * @param arg0 + */ + public IllegalBlockSizeExceptionTest(String arg0) { + super(arg0); + } + + static String[] msgs = { + "", + "Check new message", + "Check new message Check new message Check new message Check new message Check new message" }; + + static Throwable tCause = new Throwable("Throwable for exception"); + + /** + * Test for <code>IllegalBlockSizeException()</code> constructor + * Assertion: constructs IllegalBlockSizeException with no detail message + */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "IllegalBlockSizeException", + methodArgs = {} + ) + }) + public void testIllegalBlockSizeException01() { + IllegalBlockSizeException tE = new IllegalBlockSizeException(); + assertNull("getMessage() must return null.", tE.getMessage()); + assertNull("getCause() must return null", tE.getCause()); + } + + /** + * Test for <code>IllegalBlockSizeException(String)</code> constructor + * Assertion: constructs IllegalBlockSizeException with detail message msg. + * Parameter <code>msg</code> is not null. + */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "IllegalBlockSizeException", + methodArgs = {java.lang.String.class} + ) + }) + public void testIllegalBlockSizeException02() { + IllegalBlockSizeException tE; + for (int i = 0; i < msgs.length; i++) { + tE = new IllegalBlockSizeException(msgs[i]); + assertEquals("getMessage() must return: ".concat(msgs[i]), tE + .getMessage(), msgs[i]); + assertNull("getCause() must return null", tE.getCause()); + } + } + + /** + * Test for <code>IllegalBlockSizeException(String)</code> constructor + * Assertion: constructs IllegalBlockSizeException when <code>msg</code> + * is null + */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "IllegalBlockSizeException", + methodArgs = {java.lang.String.class} + ) + }) + public void testIllegalBlockSizeException03() { + String msg = null; + IllegalBlockSizeException tE = new IllegalBlockSizeException(msg); + assertNull("getMessage() must return null.", tE.getMessage()); + assertNull("getCause() must return null", tE.getCause()); + } +} diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/KeyAgreementSpiTest.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/KeyAgreementSpiTest.java new file mode 100644 index 0000000..cc34674 --- /dev/null +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/KeyAgreementSpiTest.java @@ -0,0 +1,142 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Vera Y. Petrashkova +* @version $Revision$ +*/ + +package org.apache.harmony.crypto.tests.javax.crypto; + +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + +import java.security.InvalidAlgorithmParameterException; +import java.security.InvalidKeyException; +import java.security.Key; +import java.security.NoSuchAlgorithmException; +import java.security.SecureRandom; +import java.security.spec.AlgorithmParameterSpec; + +import javax.crypto.SecretKey; +import javax.crypto.ShortBufferException; +import javax.crypto.KeyAgreementSpi; + +import org.apache.harmony.crypto.tests.support.MyKeyAgreementSpi; + +import junit.framework.TestCase; + +@TestTargetClass(KeyAgreementSpi.class) +/** + * Tests for <code>KeyAgreementSpi</code> class constructors and methods. + * + */ + +public class KeyAgreementSpiTest extends TestCase { + class Mock_KeyAgreementSpi extends MyKeyAgreementSpi { + + @Override + protected Key engineDoPhase(Key key, boolean lastPhase) throws InvalidKeyException, IllegalStateException { + return super.engineDoPhase(key, lastPhase); + } + + @Override + protected byte[] engineGenerateSecret() throws IllegalStateException { + return super.engineGenerateSecret(); + } + + @Override + protected SecretKey engineGenerateSecret(String algorithm) throws IllegalStateException, NoSuchAlgorithmException, InvalidKeyException { + return super.engineGenerateSecret(algorithm); + } + + @Override + protected int engineGenerateSecret(byte[] sharedSecret, int offset) throws IllegalStateException, ShortBufferException { + return super.engineGenerateSecret(sharedSecret, offset); + } + + @Override + protected void engineInit(Key key, SecureRandom random) throws InvalidKeyException { + super.engineInit(key, random); + } + + @Override + protected void engineInit(Key key, AlgorithmParameterSpec params, SecureRandom random) throws InvalidKeyException, InvalidAlgorithmParameterException { + super.engineInit(key, params, random); + } + + } + /** + * Constructor for KeyAgreementSpiTests. + * + * @param arg0 + */ + public KeyAgreementSpiTest(String arg0) { + super(arg0); + } + + /** + * Test for <code>KeyAgreementSpi</code> constructor Assertion: constructs + * KeyAgreementSpi + */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "KeyAgreementSpi", + methodArgs = {} + ) + }) + public void testKeyAgreementSpi01() throws InvalidKeyException, + ShortBufferException, NoSuchAlgorithmException, + InvalidAlgorithmParameterException { + Mock_KeyAgreementSpi kaSpi = new Mock_KeyAgreementSpi(); + + assertNull("Not null result", kaSpi.engineDoPhase(null, true)); + try { + kaSpi.engineDoPhase(null, false); + fail("IllegalStateException must be thrown"); + } catch (IllegalStateException e) { + } + byte[] bb = kaSpi.engineGenerateSecret(); + assertEquals("Length is not 0", bb.length, 0); + assertEquals("Returned integer is not 0", + kaSpi.engineGenerateSecret(new byte[1], 10), + -1); + assertNull("Not null result", kaSpi.engineGenerateSecret("aaa")); + try { + kaSpi.engineGenerateSecret(""); + fail("NoSuchAlgorithmException must be thrown"); + } catch (NoSuchAlgorithmException e) { + } + Key key = null; + try { + kaSpi.engineInit(key, new SecureRandom()); + fail("IllegalArgumentException must be thrown"); + } catch (IllegalArgumentException e) { + } + AlgorithmParameterSpec params = null; + try { + kaSpi.engineInit(key, params, new SecureRandom()); + fail("IllegalArgumentException must be thrown"); + } catch (IllegalArgumentException e) { + } + } +} diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/KeyAgreementTest.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/KeyAgreementTest.java new file mode 100644 index 0000000..baed6e8 --- /dev/null +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/KeyAgreementTest.java @@ -0,0 +1,715 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Vera Y. Petrashkova +* @version $Revision$ +*/ + +package org.apache.harmony.crypto.tests.javax.crypto; + +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + +import java.math.BigInteger; +import java.security.InvalidAlgorithmParameterException; +import java.security.InvalidKeyException; +import java.security.NoSuchAlgorithmException; +import java.security.NoSuchProviderException; +import java.security.PrivateKey; +import java.security.Provider; +import java.security.PublicKey; +import java.security.SecureRandom; +import java.security.spec.AlgorithmParameterSpec; +import java.security.spec.DSAParameterSpec; + +import javax.crypto.KeyAgreement; +import javax.crypto.KeyAgreementSpi; +import javax.crypto.interfaces.DHPrivateKey; +import javax.crypto.spec.DHParameterSpec; + +import org.apache.harmony.crypto.tests.support.MyKeyAgreementSpi; +import org.apache.harmony.security.tests.support.SpiEngUtils; +import org.apache.harmony.security.tests.support.TestKeyPair; + +import junit.framework.TestCase; + + +@TestTargetClass(KeyAgreement.class) +/** + * Tests for KeyAgreement constructor and methods + * + */ + +public class KeyAgreementTest extends TestCase { + + public static final String srvKeyAgreement = "KeyAgreement"; + + private static String defaultAlgorithm = "DH"; + + private static String defaultProviderName = null; + + private static Provider defaultProvider = null; + + private static boolean DEFSupported = false; + + private static final String NotSupportMsg = "There is no suitable provider for KeyAgreement"; + + private static final String[] invalidValues = SpiEngUtils.invalidValues; + + private static String[] validValues = { "DH", "dH", + "Dh", "dh" }; + + private static PrivateKey privKey = null; + + private static PublicKey publKey = null; + + private static boolean initKeys = false; + + static { + defaultProvider = SpiEngUtils.isSupport(defaultAlgorithm, + srvKeyAgreement); + DEFSupported = (defaultProvider != null); + defaultProviderName = (DEFSupported ? defaultProvider.getName() : null); + } + + private void createKeys() throws Exception { + if (!initKeys) { + TestKeyPair tkp = new TestKeyPair(defaultAlgorithm); + privKey = tkp.getPrivate(); + publKey = tkp.getPublic(); + initKeys = true; + } + + } + + private KeyAgreement[] createKAs() throws Exception { + if (!DEFSupported) { + fail(NotSupportMsg); + } + + KeyAgreement[] ka = new KeyAgreement[3]; + ka[0] = KeyAgreement.getInstance(defaultAlgorithm); + ka[1] = KeyAgreement.getInstance(defaultAlgorithm, defaultProvider); + ka[2] = KeyAgreement.getInstance(defaultAlgorithm, + defaultProviderName); + return ka; + } + + public static String getDefAlg() { + return defaultAlgorithm; + } + + /** + * Test for <code> getInstance(String algorithm) </code> method Assertions: + * throws NullPointerException when algorithm is null throws + * NoSuchAlgorithmException when algorithm isnot available + */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "This is a complete subset of tests for getInstance method.", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {java.lang.String.class} + ) + }) + public void testGetInstanceString01() throws NoSuchAlgorithmException { + try { + KeyAgreement.getInstance(null); + fail("NullPointerException or NoSuchAlgorithmException should be thrown if algorithm is null"); + } catch (NullPointerException e) { + } catch (NoSuchAlgorithmException e) { + } + for (int i = 0; i < invalidValues.length; i++) { + try { + KeyAgreement.getInstance(invalidValues[i]); + fail("NoSuchAlgorithmException must be thrown"); + } catch (NoSuchAlgorithmException e) { + } + } + } + + /** + * Test for <code> getInstance(String algorithm) </code> method Assertions: + * returns KeyAgreement object + */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "This is a complete subset of tests for getInstance method.", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {java.lang.String.class} + ) + }) + public void testGetInstanceString02() throws NoSuchAlgorithmException { + if (!DEFSupported) { + fail(NotSupportMsg); + return; + } + KeyAgreement keyA; + for (int i = 0; i < validValues.length; i++) { + keyA = KeyAgreement.getInstance(validValues[i]); + assertEquals("Incorrect algorithm", keyA.getAlgorithm(), + validValues[i]); + } + } + + /** + * Test for <code> getInstance(String algorithm, String provider)</code> + * method Assertions: throws NullPointerException when algorithm is null + * throws NoSuchAlgorithmException when algorithm is not available + */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "This is a complete subset of tests for getInstance method.", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {java.lang.String.class, java.lang.String.class} + ) + }) + public void testGetInstanceStringString01() + throws NoSuchAlgorithmException, IllegalArgumentException, + NoSuchProviderException { + if (!DEFSupported) { + fail(NotSupportMsg); + return; + } + try { + KeyAgreement.getInstance(null, defaultProviderName); + fail("NullPointerException or NoSuchAlgorithmException should be thrown if algorithm is null"); + } catch (NullPointerException e) { + } catch (NoSuchAlgorithmException e) { + } + for (int i = 0; i < invalidValues.length; i++) { + try { + KeyAgreement.getInstance(invalidValues[i], defaultProviderName); + fail("NoSuchAlgorithmException must be thrown"); + } catch (NoSuchAlgorithmException e) { + } + } + } + + /** + * Test for <code> getInstance(String algorithm, String provider)</code> + * method Assertions: throws IllegalArgumentException when provider is null + * or empty throws NoSuchProviderException when provider has not be + * configured + */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "This is a complete subset of tests for getInstance method.", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {java.lang.String.class, java.lang.String.class} + ) + }) + public void testGetInstanceStringString02() + throws IllegalArgumentException, NoSuchAlgorithmException, + NoSuchProviderException { + if (!DEFSupported) { + fail(NotSupportMsg); + return; + } + String provider = null; + for (int i = 0; i < validValues.length; i++) { + try { + KeyAgreement.getInstance(validValues[i], provider); + fail("IllegalArgumentException must be thrown when provider is null"); + } catch (IllegalArgumentException e) { + } + try { + KeyAgreement.getInstance(validValues[i], ""); + fail("IllegalArgumentException must be thrown when provider is empty"); + } catch (IllegalArgumentException e) { + } + for (int j = 1; j < invalidValues.length; j++) { + try { + KeyAgreement.getInstance(validValues[i], invalidValues[j]); + fail("NoSuchProviderException must be thrown (algorithm: " + .concat(validValues[i]).concat(" provider: ") + .concat(invalidValues[j]).concat(")")); + } catch (NoSuchProviderException e) { + } + } + } + } + + /** + * Test for <code> getInstance(String algorithm, String provider)</code> + * method Assertions: returns KeyAgreement object + */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "This is a complete subset of tests for getInstance method.", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {java.lang.String.class, java.lang.String.class} + ) + }) + public void testGetInstanceStringString03() + throws IllegalArgumentException, NoSuchAlgorithmException, + NoSuchProviderException { + if (!DEFSupported) { + fail(NotSupportMsg); + return; + } + KeyAgreement keyA; + for (int i = 0; i < validValues.length; i++) { + keyA = KeyAgreement + .getInstance(validValues[i], defaultProviderName); + assertEquals("Incorrect algorithm", keyA.getAlgorithm(), + validValues[i]); + assertEquals("Incorrect provider", keyA.getProvider().getName(), + defaultProviderName); + } + } + + /** + * Test for <code> getInstance(String algorithm, Provider provider)</code> + * method Assertions: throws NullPointerException when algorithm is null + * throws NoSuchAlgorithmException when algorithm isnot available + */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "This is a complete subset of tests for getInstance method.", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {java.lang.String.class, java.security.Provider.class} + ) + }) + public void testGetInstanceStringProvider01() + throws NoSuchAlgorithmException, IllegalArgumentException { + if (!DEFSupported) { + fail(NotSupportMsg); + return; + } + try { + KeyAgreement.getInstance(null, defaultProvider); + fail("NullPointerException or NoSuchAlgorithmException should be thrown if algorithm is null"); + } catch (NullPointerException e) { + } catch (NoSuchAlgorithmException e) { + } + for (int i = 0; i < invalidValues.length; i++) { + try { + KeyAgreement.getInstance(invalidValues[i], defaultProvider); + fail("NoSuchAlgorithmException must be thrown"); + } catch (NoSuchAlgorithmException e) { + } + } + } + + /** + * Test for <code> getInstance(String algorithm, Provider provider)</code> + * method Assertions: throws IllegalArgumentException when provider is null + */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "This is a complete subset of tests for getInstance method.", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {java.lang.String.class, java.security.Provider.class} + ) + }) + public void testGetInstanceStringProvider02() + throws NoSuchAlgorithmException, IllegalArgumentException { + if (!DEFSupported) { + fail(NotSupportMsg); + return; + } + Provider provider = null; + for (int i = 0; i < invalidValues.length; i++) { + try { + KeyAgreement.getInstance(invalidValues[i], provider); + fail("IllegalArgumentException must be thrown"); + } catch (IllegalArgumentException e) { + } + } + } + + /** + * Test for <code> getInstance(String algorithm, Provider provider)</code> + * method Assertions: returns KeyAgreement object + */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "This is a complete subset of tests for getInstance method.", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {java.lang.String.class, java.security.Provider.class} + ) + }) + public void testGetInstanceStringProvider03() + throws IllegalArgumentException, NoSuchAlgorithmException { + if (!DEFSupported) { + fail(NotSupportMsg); + return; + } + KeyAgreement keyA; + for (int i = 0; i < validValues.length; i++) { + keyA = KeyAgreement.getInstance(validValues[i], defaultProvider); + assertEquals("Incorrect algorithm", keyA.getAlgorithm(), + validValues[i]); + assertEquals("Incorrect provider", keyA.getProvider(), + defaultProvider); + } + } + + /** + * Test for the methods: <code>init(Key key)</code> + * <code>generateSecret()</code> + * <code>generateSecret(byte[] sharedsecret, int offset)</code> + * <code>generateSecret(String algorithm)</code> + * Assertions: initializes KeyAgreement; returns sharedSecret; puts + * sharedsecret in buffer and return numbers of bytes; returns SecretKey + * object + */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Checks functionality only.", + targets = { + @TestTarget( + methodName = "init", + methodArgs = {java.security.Key.class} + ), @TestTarget( + methodName = "generateSecret", + methodArgs = {} + ), @TestTarget( + methodName = "generateSecret", + methodArgs = {byte[].class, int.class} + ), @TestTarget( + methodName = "generateSecret", + methodArgs = {java.lang.String.class} + ) + }) + public void testGenerateSecret03() throws Exception { + if (!DEFSupported) { + fail(NotSupportMsg); + return; + } + createKeys(); + KeyAgreement[] kAgs = createKAs(); + + byte[] bb; + byte[] bb1 = new byte[10]; + for (int i = 0; i < kAgs.length; i++) { + kAgs[i].init(privKey); + kAgs[i].doPhase(publKey, true); + bb = kAgs[i].generateSecret(); + kAgs[i].init(privKey); + kAgs[i].doPhase(publKey, true); + bb1 = new byte[bb.length + 10]; + kAgs[i].generateSecret(bb1, 9); + kAgs[i].init(privKey); + kAgs[i].doPhase(publKey, true); + kAgs[i].generateSecret("DES"); + } + } + + /** + * Test for <code>doPhase(Key key, boolean lastPhase)</code> method + * Assertion: throws InvalidKeyException if key is not appropriate + */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "Checks InvalidKeyException.", + targets = { + @TestTarget( + methodName = "doPhase", + methodArgs = {java.security.Key.class, boolean.class} + ) + }) + public void testDoPhase() throws Exception { + if (!DEFSupported) { + fail(NotSupportMsg); + return; + } + createKeys(); + KeyAgreement[] kAgs = createKAs(); + + for (int i = 0; i < kAgs.length; i++) { + kAgs[i].init(privKey); + try { + kAgs[i].doPhase(privKey, false); + fail("InvalidKeyException must be throw"); + } catch (InvalidKeyException e) { + } + + try { + kAgs[i].doPhase(privKey, true); + fail("InvalidKeyException must be throw"); + } catch (InvalidKeyException e) { + } + } + } + + /** + * Test for the methods <code>init(Key key)</code> + * <code>init(Key key, SecureRandom random)</code> + * <code>init(Key key, AlgorithmParameterSpec params)</code> + * <code>init(Key key, AlgorithmParameterSpec params, SecureRandom random)</code> + * Assertion: throws InvalidKeyException when key is inappropriate + */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Checks InvalidKeyException.", + targets = { + @TestTarget( + methodName = "init", + methodArgs = {java.security.Key.class} + ), @TestTarget( + methodName = "init", + methodArgs = {java.security.Key.class, java.security.spec.AlgorithmParameterSpec.class} + ), @TestTarget( + methodName = "init", + methodArgs = {java.security.Key.class, java.security.spec.AlgorithmParameterSpec.class, java.security.SecureRandom.class} + ), @TestTarget( + methodName = "init", + methodArgs = {java.security.Key.class, java.security.SecureRandom.class} + ) + }) + public void testInit01() throws Exception { + if (!DEFSupported) { + fail(NotSupportMsg); + return; + } + createKeys(); + KeyAgreement[] kAgs = createKAs(); + + SecureRandom random = null; + AlgorithmParameterSpec aps = null; + DHParameterSpec dhPs = new DHParameterSpec(new BigInteger("56"), + new BigInteger("56")); + for (int i = 0; i < kAgs.length; i++) { + try { + kAgs[i].init(publKey); + fail("InvalidKeyException must be throw"); + } catch (InvalidKeyException e) { + } + try { + kAgs[i].init(publKey, new SecureRandom()); + fail("InvalidKeyException must be throw"); + } catch (InvalidKeyException e) { + } + try { + kAgs[i].init(publKey, random); + fail("InvalidKeyException must be throw"); + } catch (InvalidKeyException e) { + } + try { + kAgs[i].init(publKey, dhPs); + fail("InvalidKeyException must be throw"); + } catch (InvalidKeyException e) { + } + try { + kAgs[i].init(publKey, aps); + fail("InvalidKeyException must be throw"); + } catch (InvalidKeyException e) { + } + try { + kAgs[i].init(publKey, dhPs, new SecureRandom()); + fail("InvalidKeyException must be throw"); + } catch (InvalidKeyException e) { + } + } + } + + /** + * Test for the methods + * <code>init(Key key, AlgorithmParameterSpec params)</code> + * <code>init(Key key, AlgorithmParameterSpec params, SecureRandom random)</code> + * Assertion: throws AlgorithmParameterException when params are + * inappropriate + */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Checks InvalidAlgorithmParameterException." + + "This is a complete subset of tests for exceptions checking for init methods group", + targets = { + @TestTarget( + methodName = "init", + methodArgs = {java.security.Key.class, java.security.spec.AlgorithmParameterSpec.class} + ), @TestTarget( + methodName = "init", + methodArgs = {java.security.Key.class, java.security.spec.AlgorithmParameterSpec.class, java.security.SecureRandom.class} + ) + }) + public void testInit02() throws Exception { + if (!DEFSupported) { + fail(NotSupportMsg); + return; + } + createKeys(); + KeyAgreement[] kAgs = createKAs(); + + SecureRandom random = null; + DSAParameterSpec dsa = new DSAParameterSpec(new BigInteger("56"), + new BigInteger("56"), new BigInteger("56")); + for (int i = 0; i < kAgs.length; i++) { + try { + kAgs[i].init(privKey, dsa); + fail("InvalidAlgorithmParameterException or InvalidKeyException must be throw"); + } catch (InvalidAlgorithmParameterException e) { + } catch (InvalidKeyException e) { + } + try { + kAgs[i].init(privKey, dsa, new SecureRandom()); + fail("InvalidAlgorithmParameterException or InvalidKeyException must be throw"); + } catch (InvalidAlgorithmParameterException e) { + } catch (InvalidKeyException e) { + } + try { + kAgs[i].init(privKey, dsa, random); + fail("InvalidAlgorithmParameterException or InvalidKeyException must be throw"); + } catch (InvalidAlgorithmParameterException e) { + } catch (InvalidKeyException e) { + } + } + } + + /** + * Test for the methods: <code>init(Key key)</code> + * <code>init(Key key, SecureRandom random)</code> + * <code>generateSecret()</code> + * Assertions: initializes KeyAgreement and returns byte array + */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Checks functionality.", + targets = { + @TestTarget( + methodName = "init", + methodArgs = {java.security.Key.class} + ), @TestTarget( + methodName = "init", + methodArgs = {java.security.Key.class, java.security.SecureRandom.class} + ), @TestTarget( + methodName = "generateSecret", + methodArgs = {} + ) + }) + public void testInit03() throws Exception { + if (!DEFSupported) { + fail(NotSupportMsg); + return; + } + createKeys(); + KeyAgreement[] kAgs = createKAs(); + + byte[] bbRes1; + byte[] bbRes2; + byte[] bbRes3; + SecureRandom randomNull = null; + SecureRandom random = new SecureRandom(); + for (int i = 0; i < kAgs.length; i++) { + kAgs[i].init(privKey); + kAgs[i].doPhase(publKey, true); + bbRes1 = kAgs[i].generateSecret(); + kAgs[i].init(privKey, random); + kAgs[i].doPhase(publKey, true); + bbRes2 = kAgs[i].generateSecret(); + assertEquals("Incorrect byte array length", bbRes1.length, + bbRes2.length); + for (int j = 0; j < bbRes1.length; j++) { + assertEquals("Incorrect byte (index: ".concat( + Integer.toString(i)).concat(")"), bbRes1[j], bbRes2[j]); + } + kAgs[i].init(privKey, randomNull); + kAgs[i].doPhase(publKey, true); + bbRes3 = kAgs[i].generateSecret(); + assertEquals("Incorrect byte array length", bbRes1.length, + bbRes3.length); + for (int j = 0; j < bbRes1.length; j++) { + assertEquals("Incorrect byte (index: ".concat( + Integer.toString(i)).concat(")"), bbRes1[j], bbRes3[j]); + } + } + } + + /** + * Test for the methods: + * <code>init(Key key, AlgorithmParameterSpec params)</code> + * <code>init(Key key, AlgorithmParameterSpec params, SecureRandom random)</code> + * <code>generateSecret()</code> + * Assertions: initializes KeyAgreement and returns byte array + */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "Checks functionality.", + targets = { + @TestTarget( + methodName = "init", + methodArgs = {java.security.Key.class, java.security.spec.AlgorithmParameterSpec.class} + ), @TestTarget( + methodName = "init", + methodArgs = {java.security.Key.class, java.security.spec.AlgorithmParameterSpec.class, java.security.SecureRandom.class} + ), @TestTarget( + methodName = "generateSecret", + methodArgs = {} + ) +}) + public void testInit04() throws Exception, + InvalidAlgorithmParameterException { + if (!DEFSupported) { + fail(NotSupportMsg); + return; + } + createKeys(); + KeyAgreement[] kAgs = createKAs(); + + DHParameterSpec dhPs = ((DHPrivateKey) privKey).getParams(); + + byte[] bbRes1; + byte[] bbRes2; + byte[] bbRes3; + SecureRandom randomNull = null; + SecureRandom random = new SecureRandom(); + for (int i = 0; i < kAgs.length; i++) { + kAgs[i].init(privKey, dhPs); + kAgs[i].doPhase(publKey, true); + bbRes1 = kAgs[i].generateSecret(); + kAgs[i].init(privKey, dhPs, random); + kAgs[i].doPhase(publKey, true); + bbRes2 = kAgs[i].generateSecret(); + assertEquals("Incorrect byte array length", bbRes1.length, + bbRes2.length); + for (int j = 0; j < bbRes1.length; j++) { + assertEquals("Incorrect byte (index: ".concat( + Integer.toString(i)).concat(")"), bbRes1[j], bbRes2[j]); + } + kAgs[i].init(privKey, dhPs, randomNull); + kAgs[i].doPhase(publKey, true); + bbRes3 = kAgs[i].generateSecret(); + assertEquals("Incorrect byte array length", bbRes1.length, + bbRes3.length); + for (int j = 0; j < bbRes1.length; j++) { + assertEquals("Incorrect byte (index: ".concat( + Integer.toString(i)).concat(")"), bbRes1[j], bbRes3[j]); + } + } + } + +} diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/KeyGeneratorSpiTest.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/KeyGeneratorSpiTest.java new file mode 100644 index 0000000..f5c3f23 --- /dev/null +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/KeyGeneratorSpiTest.java @@ -0,0 +1,118 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Vera Y. Petrashkova +* @version $Revision$ +*/ + +package org.apache.harmony.crypto.tests.javax.crypto; + +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + +import java.security.InvalidAlgorithmParameterException; +import java.security.SecureRandom; +import java.security.spec.AlgorithmParameterSpec; +import javax.crypto.KeyGeneratorSpi; +import javax.crypto.SecretKey; + +import org.apache.harmony.crypto.tests.support.MyKeyGeneratorSpi; + +import junit.framework.TestCase; + +@TestTargetClass(KeyGeneratorSpi.class) +/** + * Tests for <code>KeyGeneratorSpi</code> class constructors and methods. + * + */ + +public class KeyGeneratorSpiTest extends TestCase { +class Mock_KeyGeneratorSpi extends MyKeyGeneratorSpi { + + @Override + protected SecretKey engineGenerateKey() { + return super.engineGenerateKey(); + } + + @Override + protected void engineInit(SecureRandom random) { + super.engineInit(random); + } + + @Override + protected void engineInit(AlgorithmParameterSpec params, SecureRandom random) throws InvalidAlgorithmParameterException { + super.engineInit(params, random); + } + + @Override + protected void engineInit(int keysize, SecureRandom random) { + super.engineInit(keysize, random); + } + +} + /** + * Constructor for KeyGeneratorSpiTests. + * + * @param arg0 + */ + public KeyGeneratorSpiTest(String arg0) { + super(arg0); + } + + /** + * Test for <code>KeyGeneratorSpi</code> constructor Assertion: constructs + * KeyGeneratorSpi + */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "KeyGeneratorSpi", + methodArgs = {} + ) + }) + public void testKeyGeneratorSpi01() throws InvalidAlgorithmParameterException { + Mock_KeyGeneratorSpi kgSpi = new Mock_KeyGeneratorSpi(); + assertNull("Not null result", kgSpi.engineGenerateKey()); + try { + kgSpi.engineInit(77, new SecureRandom()); + fail("IllegalArgumentException must be thrown"); + } catch (IllegalArgumentException e) { + } + try { + kgSpi.engineInit(new SecureRandom()); + fail("IllegalArgumentException must be thrown"); + } catch (IllegalArgumentException e) { + } + AlgorithmParameterSpec aps = null; + try { + kgSpi.engineInit(aps, new SecureRandom()); + fail("InvalidAlgorithmParameterException must be thrown when parameter is null"); + } catch (InvalidAlgorithmParameterException e) { + } + aps = new APSpecSpi(); + kgSpi.engineInit(aps, new SecureRandom()); + } + +} +class APSpecSpi implements AlgorithmParameterSpec { + +} diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/KeyGeneratorTest.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/KeyGeneratorTest.java new file mode 100644 index 0000000..e7b1985 --- /dev/null +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/KeyGeneratorTest.java @@ -0,0 +1,565 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Vera Y. Petrashkova +* @version $Revision$ +*/ + +package org.apache.harmony.crypto.tests.javax.crypto; + +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + +import java.security.InvalidAlgorithmParameterException; +import java.security.InvalidParameterException; +import java.security.NoSuchAlgorithmException; +import java.security.NoSuchProviderException; +import java.security.Provider; +import java.security.SecureRandom; +import java.security.spec.AlgorithmParameterSpec; + +import javax.crypto.KeyGenerator; +import javax.crypto.KeyGeneratorSpi; +import javax.crypto.SecretKey; + +import org.apache.harmony.crypto.tests.support.MyKeyGeneratorSpi; +import org.apache.harmony.security.tests.support.SpiEngUtils; + +import junit.framework.TestCase; + + +@TestTargetClass(KeyGenerator.class) +/** + * Tests for KeyGenerator constructor and methods + * + */ + +public class KeyGeneratorTest extends TestCase { + + public static final String srvKeyGenerator = "KeyGenerator"; + + public static final String validAlgorithmsKeyGenerator [] = + {"DESede", "DES", "Blowfish", "AES", "HmacMD5"}; + + private static final int [] validKeySizes = { 168, 56, 56, 256, 56}; + + private static int defaultKeySize = -1; + + private static String defaultAlgorithm = null; + + private static String defaultProviderName = null; + + private static Provider defaultProvider = null; + + private static boolean DEFSupported = false; + + private static final String NotSupportMsg = "There is no suitable provider for KeyGenerator"; + + private static final String[] invalidValues = SpiEngUtils.invalidValues; + + private static String[] validValues = new String[3]; + + static { + for (int i = 0; i < validAlgorithmsKeyGenerator.length; i++) { + defaultProvider = SpiEngUtils.isSupport(validAlgorithmsKeyGenerator[i], + srvKeyGenerator); + DEFSupported = (defaultProvider != null); + if (DEFSupported) { + defaultAlgorithm = validAlgorithmsKeyGenerator[i]; + defaultKeySize = validKeySizes[i]; + defaultProviderName = defaultProvider.getName(); + validValues[0] = defaultAlgorithm; + validValues[1] = defaultAlgorithm.toUpperCase(); + validValues[2] = defaultAlgorithm.toLowerCase(); + break; + } + } + } + + private KeyGenerator[] createKGs() throws Exception { + if (!DEFSupported) { + fail(NotSupportMsg); + } + + KeyGenerator [] kg = new KeyGenerator[3]; + kg[0] = KeyGenerator.getInstance(defaultAlgorithm); + kg[1] = KeyGenerator.getInstance(defaultAlgorithm, defaultProvider); + kg[2] = KeyGenerator.getInstance(defaultAlgorithm, defaultProviderName); + return kg; + } + + + /** + * Test for <code>KeyGenerator</code> constructor Assertion: returns + * KeyGenerator object + */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "KeyGenerator", + methodArgs = {javax.crypto.KeyGeneratorSpi.class, java.security.Provider.class, java.lang.String.class} + ) + }) + public void testKeyGenerator() throws NoSuchAlgorithmException, + InvalidAlgorithmParameterException { + if (!DEFSupported) { + fail(NotSupportMsg); + return; + } + KeyGeneratorSpi spi = new MyKeyGeneratorSpi(); + KeyGenerator keyG = new myKeyGenerator(spi, defaultProvider, + defaultAlgorithm); + assertEquals("Incorrect algorithm", keyG.getAlgorithm(), + defaultAlgorithm); + assertEquals("Incorrect provider", keyG.getProvider(), defaultProvider); + AlgorithmParameterSpec params = null; + int keysize = 0; + try { + keyG.init(params, null); + fail("InvalidAlgorithmParameterException must be thrown"); + } catch (InvalidAlgorithmParameterException e) { + } + try { + keyG.init(keysize, null); + fail("IllegalArgumentException must be thrown"); + } catch (IllegalArgumentException e) { + } + keyG = new myKeyGenerator(null, null, null); + assertNull("Algorithm must be null", keyG.getAlgorithm()); + assertNull("Provider must be null", keyG.getProvider()); + + try { + keyG.init(params, null); + fail("NullPointerException must be thrown"); + } catch (NullPointerException e) { + } + try { + keyG.init(keysize, null); + fail("NullPointerException or InvalidParameterException must be thrown"); + } catch (InvalidParameterException e) { + } catch (NullPointerException e) { + } + } + + /* + * Test for <code> getInstance(String algorithm) </code> method Assertions: + * throws NullPointerException when algorithm is null throws + * NoSuchAlgorithmException when algorithm isnot available + */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "This is a complete subset of tests for getInstance method.", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {java.lang.String.class} + ) + }) + public void testGetInstanceString01() throws NoSuchAlgorithmException { + try { + KeyGenerator.getInstance(null); + fail("NullPointerException or NoSuchAlgorithmException should be thrown if algorithm is null"); + } catch (NullPointerException e) { + } catch (NoSuchAlgorithmException e) { + } + for (int i = 0; i < invalidValues.length; i++) { + try { + KeyGenerator.getInstance(invalidValues[i]); + fail("NoSuchAlgorithmException should be thrown"); + } catch (NoSuchAlgorithmException e) { + } + } + } + + /* + * Test for <code> getInstance(String algorithm) </code> method + * Assertions: returns KeyGenerator object + */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "This is a complete subset of tests for getInstance method.", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {java.lang.String.class} + ) + }) + public void testGetInstanceString02() throws NoSuchAlgorithmException { + if (!DEFSupported) { + fail(NotSupportMsg); + return; + } + KeyGenerator keyG; + for (int i = 0; i < validValues.length; i++) { + keyG = KeyGenerator.getInstance(validValues[i]); + assertEquals("Incorrect algorithm", keyG.getAlgorithm(), validValues[i]); + } + } + + /* + * Test for <code> getInstance(String algorithm, String provider)</code> method + * Assertions: + * throws NullPointerException when algorithm is null + * throws NoSuchAlgorithmException when algorithm isnot available + */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "This is a complete subset of tests for getInstance method.", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {java.lang.String.class, java.lang.String.class} + ) + }) + public void testGetInstanceStringString01() throws + NoSuchAlgorithmException, IllegalArgumentException, + NoSuchProviderException { + if (!DEFSupported) { + fail(NotSupportMsg); + return; + } + try { + KeyGenerator.getInstance(null, defaultProviderName); + fail("NullPointerException or NoSuchAlgorithmException should be thrown if algorithm is null"); + } catch (NullPointerException e) { + } catch (NoSuchAlgorithmException e) { + } + for (int i = 0; i < invalidValues.length; i++) { + try { + KeyGenerator.getInstance(invalidValues[i], defaultProviderName); + fail("NoSuchAlgorithmException must be thrown"); + } catch (NoSuchAlgorithmException e) { + } + } + } + + /* + * Test for <code> getInstance(String algorithm, String provider)</code> method + * Assertions: + * throws IllegalArgumentException when provider is null or empty + * throws NoSuchProviderException when provider has not be configured + */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "This is a complete subset of tests for getInstance method.", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {java.lang.String.class, java.lang.String.class} + ) + }) + public void testGetInstanceStringString02() throws IllegalArgumentException, + NoSuchAlgorithmException, NoSuchProviderException { + if (!DEFSupported) { + fail(NotSupportMsg); + return; + } + String provider = null; + for (int i = 0; i < validValues.length; i++) { + try { + KeyGenerator.getInstance(validValues[i], provider); + fail("IllegalArgumentException must be thrown when provider is null"); + } catch (IllegalArgumentException e) { + } + try { + KeyGenerator.getInstance(validValues[i], ""); + fail("IllegalArgumentException must be thrown when provider is empty"); + } catch (IllegalArgumentException e) { + } + for (int j = 1; j < invalidValues.length; j++) { + try { + KeyGenerator.getInstance(validValues[i], invalidValues[j]); + fail("NoSuchProviderException must be thrown (algorithm: " + .concat(validValues[i]).concat(" provider: ") + .concat(invalidValues[j]).concat(")")); + } catch (NoSuchProviderException e) { + } + } + } + } + + /* + * Test for <code> getInstance(String algorithm, String provider)</code> method + * Assertions: returns KeyGenerator object + */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "This is a complete subset of tests for getInstance method.", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {java.lang.String.class, java.lang.String.class} + ) + }) + public void testGetInstanceStringString03() throws IllegalArgumentException, + NoSuchAlgorithmException, NoSuchProviderException { + if (!DEFSupported) { + fail(NotSupportMsg); + return; + } + KeyGenerator keyG; + for (int i = 0; i < validValues.length; i++) { + keyG = KeyGenerator.getInstance(validValues[i], defaultProviderName); + assertEquals("Incorrect algorithm", keyG.getAlgorithm(), validValues[i]); + assertEquals("Incorrect provider", keyG.getProvider().getName(), defaultProviderName); + } + } + + /* + * Test for <code> getInstance(String algorithm, Provider provider)</code> method + * Assertions: + * throws NullPointerException when algorithm is null + * throws NoSuchAlgorithmException when algorithm isnot available + */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "This is a complete subset of tests for getInstance method.", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {java.lang.String.class, java.security.Provider.class} + ) + }) + public void testGetInstanceStringProvider01() throws NoSuchAlgorithmException, + IllegalArgumentException { + if (!DEFSupported) { + fail(NotSupportMsg); + return; + } + try { + KeyGenerator.getInstance(null, defaultProvider); + fail("NullPointerException or NoSuchAlgorithmException should be thrown if algorithm is null"); + } catch (NullPointerException e) { + } catch (NoSuchAlgorithmException e) { + } + for (int i = 0; i < invalidValues.length; i++) { + try { + KeyGenerator.getInstance(invalidValues[i], defaultProvider); + fail("NoSuchAlgorithmException must be thrown"); + } catch (NoSuchAlgorithmException e) { + } + } + } + /* + * Test for <code> getInstance(String algorithm, Provider provider)</code> method + * Assertions: + * throws IllegalArgumentException when provider is null + */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "This is a complete subset of tests for getInstance method.", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {java.lang.String.class, java.security.Provider.class} + ) + }) + public void testGetInstanceStringProvider02() throws NoSuchAlgorithmException, + IllegalArgumentException { + if (!DEFSupported) { + fail(NotSupportMsg); + return; + } + Provider provider = null; + for (int i = 0; i < invalidValues.length; i++) { + try { + KeyGenerator.getInstance(invalidValues[i], provider); + fail("IllegalArgumentException must be thrown"); + } catch (IllegalArgumentException e) { + } + } + } + + /* + * Test for <code> getInstance(String algorithm, Provider provider)</code> method + * Assertions: returns KeyGenerator object + */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "This is a complete subset of tests for getInstance method.", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {java.lang.String.class, java.security.Provider.class} + ) + }) + public void testGetInstanceStringProvider03() throws IllegalArgumentException, + NoSuchAlgorithmException { + if (!DEFSupported) { + fail(NotSupportMsg); + return; + } + KeyGenerator keyA; + for (int i = 0; i < validValues.length; i++) { + keyA = KeyGenerator.getInstance(validValues[i], defaultProvider); + assertEquals("Incorrect algorithm", keyA.getAlgorithm(), validValues[i]); + assertEquals("Incorrect provider", keyA.getProvider(), defaultProvider); + } + } + + /* + * Test for <code>init(int keysize)</code> and + * <code>init(int keysize, SecureRandom random)</code> methods + * Assertion: throws InvalidParameterException if keysize is wrong + * + */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "Checks exceptions only", + targets = { + @TestTarget( + methodName = "init", + methodArgs = {int.class} + ),@TestTarget( + methodName = "init", + methodArgs = {int.class, java.security.SecureRandom.class} + ) + }) + public void testInitKey() throws Exception { + if (!DEFSupported) { + fail(NotSupportMsg); + return; + } + if (defaultAlgorithm + .equals(validAlgorithmsKeyGenerator[validAlgorithmsKeyGenerator.length - 1])) { + return; + } + int[] size = { Integer.MIN_VALUE, -1, 0, Integer.MAX_VALUE }; + KeyGenerator[] kgs = createKGs(); + SecureRandom random = new SecureRandom(); + + for (int i = 0; i < kgs.length; i++) { + for (int j = 0; j < size.length; j++) { + try { + kgs[i].init(size[j]); + } catch (InvalidParameterException ignore) { + } + + try { + kgs[i].init(size[j], random); + } catch (InvalidParameterException ignore) { + } + } + } + } + + /* + * Test for <code>init(AlgorithmParameterSpec params)</code> and + * <code>init(AlgorithmParameterSpec params, SecureRandom random)</code> methods + * Assertion: throws InvalidAlgorithmParameterException when params is null + */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "Checks exceptions only", + targets = { + @TestTarget( + methodName = "init", + methodArgs = {java.security.spec.AlgorithmParameterSpec.class} + ), @TestTarget( + methodName = "init", + methodArgs = {java.security.spec.AlgorithmParameterSpec.class, java.security.SecureRandom.class} + ) + }) + public void testInitParams() throws Exception { + if (!DEFSupported) { + fail(NotSupportMsg); + return; + } + KeyGenerator [] kgs = createKGs(); + AlgorithmParameterSpec aps = null; + + for (int i = 0; i < kgs.length; i++) { + try { + kgs[i].init(aps); + fail("InvalidAlgorithmParameterException must be thrown"); + } catch (InvalidAlgorithmParameterException e) { + } + try { + kgs[i].init(aps, new SecureRandom()); + fail("InvalidAlgorithmParameterException must be thrown"); + } catch (InvalidAlgorithmParameterException e) { + } + } + } + + /* + * Test for <code>generateKey()</code> and + * <code>init(SecureRandom random)</code> methods + * <code>init(int keysize, SecureRandom random)</code> methods + * <code>init(int keysize)</code> methods + * <code>init(AlgorithmParameterSpec params, SecureRandom random)</code> methods + * <code>init(AlgorithmParameterSpec params)</code> methods + * Assertions: + * initializes KeyGenerator; + * returns SecretKey object + * + */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "generateKey", + methodArgs = {} + ) + }) + public void testGenerateKey() throws Exception { + if (!DEFSupported) { + fail(NotSupportMsg); + return; + } + SecretKey sKey; + String dAl = defaultAlgorithm.toUpperCase(); + + KeyGenerator[] kgs = createKGs(); + + for (int i = 0; i < kgs.length; i++) { + sKey = kgs[i].generateKey(); + assertEquals("Incorrect algorithm", sKey.getAlgorithm() + .toUpperCase(), dAl); + kgs[i].init(new SecureRandom()); + sKey = kgs[i].generateKey(); + assertEquals("Incorrect algorithm", sKey.getAlgorithm() + .toUpperCase(), dAl); + kgs[i].init(defaultKeySize); + sKey = kgs[i].generateKey(); + assertEquals("Incorrect algorithm", sKey.getAlgorithm() + .toUpperCase(), dAl); + kgs[i].init(defaultKeySize, new SecureRandom()); + sKey = kgs[i].generateKey(); + assertEquals("Incorrect algorithm", sKey.getAlgorithm() + .toUpperCase(), dAl); + } + } + +} + +/** + * Additional class for KeyGenerator constructor verification + */ +class myKeyGenerator extends KeyGenerator { + + public myKeyGenerator(KeyGeneratorSpi keyAgreeSpi, Provider provider, + String algorithm) { + super(keyAgreeSpi, provider, algorithm); + } +} diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/MacSpiTest.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/MacSpiTest.java new file mode 100644 index 0000000..f5ecfdf --- /dev/null +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/MacSpiTest.java @@ -0,0 +1,285 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Vera Y. Petrashkova +* @version $Revision$ +*/ + +package org.apache.harmony.crypto.tests.javax.crypto; + +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + +import java.nio.ByteBuffer; +import java.security.InvalidAlgorithmParameterException; +import java.security.InvalidKeyException; +import java.security.Key; +import java.security.spec.AlgorithmParameterSpec; + +import javax.crypto.spec.SecretKeySpec; +import javax.crypto.MacSpi; + +import org.apache.harmony.crypto.tests.support.MyMacSpi; + +import junit.framework.TestCase; + + +@TestTargetClass(MacSpi.class) +/** + * Tests for <code>MacSpi</code> class constructors and methods. + * + */ + +public class MacSpiTest extends TestCase { +class Mock_MacSpi extends MyMacSpi { + + @Override + protected byte[] engineDoFinal() { + return super.engineDoFinal(); + } + + @Override + protected int engineGetMacLength() { + return super.engineGetMacLength(); + } + + @Override + protected void engineInit(Key key, AlgorithmParameterSpec params) throws InvalidKeyException, InvalidAlgorithmParameterException { + super.engineInit(key, params); + } + + @Override + protected void engineReset() { + super.engineReset(); + } + + @Override + protected void engineUpdate(byte input) { + super.engineUpdate(input); + } + + @Override + protected void engineUpdate(byte[] input, int offset, int len) { + super.engineUpdate(input, offset, len); + } + +} + +class Mock_MacSpi1 extends MyMacSpi1 { + + @Override + protected byte[] engineDoFinal() { + return super.engineDoFinal(); + } + + @Override + protected int engineGetMacLength() { + return super.engineGetMacLength(); + } + + @Override + protected void engineInit(Key key, AlgorithmParameterSpec params) throws InvalidKeyException, InvalidAlgorithmParameterException { + super.engineInit(key, params); + } + + @Override + protected void engineReset() { + super.engineReset(); + } + + @Override + protected void engineUpdate(byte input) { + super.engineUpdate(input); + } + + @Override + protected void engineUpdate(byte[] input, int offset, int len) { + super.engineUpdate(input, offset, len); + } + + protected void engineUpdate(ByteBuffer input) { + super.engineUpdate(input); + } + +} + + +class Mock_MacSpi2 extends MyMacSpi2 { + + @Override + protected byte[] engineDoFinal() { + return super.engineDoFinal(); + } + + @Override + protected int engineGetMacLength() { + return super.engineGetMacLength(); + } + + @Override + protected void engineInit(Key key, AlgorithmParameterSpec params) throws InvalidKeyException, InvalidAlgorithmParameterException { + super.engineInit(key, params); + } + + @Override + protected void engineReset() { + super.engineReset(); + } + + @Override + protected void engineUpdate(byte input) { + super.engineUpdate(input); + } + + @Override + protected void engineUpdate(byte[] input, int offset, int len) { + super.engineUpdate(input, offset, len); + } + + protected void engineUpdate(ByteBuffer input) { + super.engineUpdate(input); + } + +} + + +/** + * Constructor for MacSpiTests. + * + * @param arg0 + */ + public MacSpiTest(String arg0) { + super(arg0); + } + + /** + * Test for <code>MacSpi</code> constructor + * Assertion: constructs MacSpi + */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "All others methods are abstract.", + targets = { + @TestTarget( + methodName = "MacSpi", + methodArgs = {} + ), @TestTarget( + methodName = "engineUpdate", + methodArgs = {java.nio.ByteBuffer.class} + ), @TestTarget( + methodName = "clone", + methodArgs = {} + ) + }) + public void testMacSpiTests01() throws Exception { + Mock_MacSpi mSpi = new Mock_MacSpi(); + + byte [] bb1 = {(byte)1, (byte)2, (byte)3, (byte)4, (byte)5}; + SecretKeySpec sks = new SecretKeySpec(bb1, "SHA1"); + + assertEquals("Incorrect MacLength", mSpi.engineGetMacLength(), 0); + + try { + mSpi.engineInit(null, null); + fail("IllegalArgumentException must be thrown"); + } catch (IllegalArgumentException e) { + } + + mSpi.engineInit(sks, null); + + byte[] bb = mSpi.engineDoFinal(); + assertEquals(bb.length, 0); + try { + mSpi.clone(); + fail("CloneNotSupportedException was not thrown as expected"); + } catch (CloneNotSupportedException e) { + } + + Mock_MacSpi1 mSpi1 = new Mock_MacSpi1(); + mSpi1.clone(); + + byte [] bbb = new byte[10]; + for (int i = 0; i < bbb.length; i++) { + bbb[i] = (byte)i; + } + try { + mSpi1.engineInit(null, null); + fail("IllegalArgumentException must be thrown"); + } catch (IllegalArgumentException e) { + } + mSpi1.engineInit(sks, null); + + ByteBuffer byteBuf = ByteBuffer.allocate(10); + byteBuf.put(bbb); + byteBuf.position(5); + int beforeUp = byteBuf.remaining(); + mSpi1.engineUpdate(byteBuf); + bb = mSpi1.engineDoFinal(); + assertEquals("Incorrect result of engineDoFinal", bb.length, beforeUp); + + Mock_MacSpi2 mSpi2 = new Mock_MacSpi2(); + + mSpi2.engineInit(null, null); + mSpi2.engineInit(sks, null); + + try { + mSpi2.clone(); + } catch (CloneNotSupportedException e) { + } + + byte [] bbuf = {(byte)5, (byte)4, (byte)3, (byte)2, (byte)1}; + byteBuf = ByteBuffer.allocate(5); + byteBuf.put(bbuf); + byteBuf.position(5); + if (!byteBuf.hasRemaining()) { + mSpi2.engineUpdate(byteBuf); + } + } +} + + +class MyMacSpi1 extends MyMacSpi { + public Object clone() throws CloneNotSupportedException { + return new MyMacSpi1(); + } +} + +class MyMacSpi2 extends MacSpi { + protected int engineGetMacLength() { + return 0; + } + + protected void engineInit(Key key, AlgorithmParameterSpec params) + throws InvalidKeyException, InvalidAlgorithmParameterException { + } + + protected void engineUpdate(byte input) { + } + + protected void engineUpdate(byte[] input, int offset, int len) { + } + + protected byte[] engineDoFinal() { + return new byte[0]; + } + + protected void engineReset() { + } +} diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/MacTest.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/MacTest.java new file mode 100644 index 0000000..84f663c --- /dev/null +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/MacTest.java @@ -0,0 +1,1046 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Vera Y. Petrashkova +* @version $Revision$ +*/ + +package org.apache.harmony.crypto.tests.javax.crypto; + +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + +import java.nio.ByteBuffer; +import java.security.InvalidAlgorithmParameterException; +import java.security.InvalidKeyException; +import java.security.NoSuchAlgorithmException; +import java.security.NoSuchProviderException; +import java.security.Provider; + +import javax.crypto.Mac; +import javax.crypto.MacSpi; +import javax.crypto.ShortBufferException; +import javax.crypto.spec.DHGenParameterSpec; + +import javax.crypto.spec.SecretKeySpec; + +import org.apache.harmony.crypto.tests.support.MyMacSpi; +import org.apache.harmony.security.tests.support.SpiEngUtils; + +import junit.framework.TestCase; + +import junit.framework.Test; +import junit.framework.TestSuite; + +@TestTargetClass(Mac.class) +/** + * Tests for Mac class constructors and methods + * + */ + +public class MacTest extends TestCase { + + public static final String srvMac = "Mac"; + + private static String defaultAlgorithm = null; + + private static String defaultProviderName = null; + + private static Provider defaultProvider = null; + + private static boolean DEFSupported = false; + + private static final String NotSupportedMsg = "There is no suitable provider for Mac"; + + private static final String[] invalidValues = SpiEngUtils.invalidValues; + + private static String[] validValues = new String[3]; + + public static final String validAlgorithmsMac [] = + {"HmacSHA1", "HmacMD5", "HmacSHA256", "HmacSHA384", "HmacSHA512"}; + + + static { + for (int i = 0; i < validAlgorithmsMac.length; i++) { + defaultProvider = SpiEngUtils.isSupport(validAlgorithmsMac[i], + srvMac); + DEFSupported = (defaultProvider != null); + if (DEFSupported) { + defaultAlgorithm = validAlgorithmsMac[i]; + defaultProviderName = defaultProvider.getName(); + validValues[0] = defaultAlgorithm; + validValues[1] = defaultAlgorithm.toUpperCase(); + validValues[2] = defaultAlgorithm.toLowerCase(); + break; + } + } + } + + private Mac [] createMacs() { + if (!DEFSupported) { + fail(NotSupportedMsg); + return null; + } + try { + Mac m [] = new Mac[3]; + m[0] = Mac.getInstance(defaultAlgorithm); + m[1] = Mac.getInstance(defaultAlgorithm, defaultProvider); + m[2] = Mac.getInstance(defaultAlgorithm, defaultProviderName); + return m; + } catch (Exception e) { + return null; + } + } + + /** + * Test for <code>getInstance(String algorithm)</code> method + * Assertion: + * throws NullPointerException when algorithm is null + * throws NoSuchAlgorithmException when algorithm is not available + */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "This is a complete subset of tests for getInstance method.", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {java.lang.String.class} + ) + }) + public void testMac01() { + try { + Mac.getInstance(null); + fail("NullPointerException or NoSuchAlgorithmException should be thrown when algorithm is null"); + } catch (NullPointerException e) { + } catch (NoSuchAlgorithmException e) { + } + for (int i = 0; i < invalidValues.length; i++) { + try { + Mac.getInstance(invalidValues[i]); + fail("NoSuchAlgorithmException must be thrown when algorithm is not available: " + .concat(invalidValues[i])); + } catch (NoSuchAlgorithmException e) { + } + } + } + + /** + * Test for <code>getInstance(String algorithm)</code> method + * Assertion: returns Mac object + */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "This is a complete subset of tests for getInstance method.", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {java.lang.String.class} + ) + }) + public void testMac02() throws NoSuchAlgorithmException { + if (!DEFSupported) { + fail(NotSupportedMsg); + return; + } + Mac mac; + for (int i = 0; i < validValues.length; i++) { + mac = Mac.getInstance(validValues[i]); + assertEquals("Incorrect algorithm", mac.getAlgorithm(), validValues[i]); + } + } + /** + * Test for <code>getInstance(String algorithm, String provider)</code> method + * Assertion: + * throws IllegalArgumentException when provider is null or empty + * throws NoSuchProviderException when provider is not available + */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "This is a complete subset of tests for getInstance method.", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {java.lang.String.class, java.lang.String.class} + ) + }) + public void testMac03() throws NoSuchAlgorithmException, NoSuchProviderException { + if (!DEFSupported) { + fail(NotSupportedMsg); + return; + } + String provider = null; + for (int i = 0; i < validValues.length; i++) { + try { + Mac.getInstance(validValues[i], provider); + fail("IllegalArgumentException must be thrown when provider is null"); + } catch (IllegalArgumentException e) { + } + try { + Mac.getInstance(validValues[i], ""); + fail("IllegalArgumentException must be thrown when provider is empty"); + } catch (IllegalArgumentException e) { + } + for (int j = 1; j < invalidValues.length; j++) { + try { + Mac.getInstance(validValues[i], invalidValues[j]); + fail("NoSuchProviderException must be thrown (algorithm: " + .concat(validValues[i]).concat(" provider: ") + .concat(invalidValues[j]).concat(")")); + } catch (NoSuchProviderException e) { + } + } + } + } + + /** + * Test for <code>getInstance(String algorithm, String provider)</code> method + * Assertion: + * throws NullPointerException when algorithm is null + * throws NoSuchAlgorithmException when algorithm is not available + */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "This is a complete subset of tests for getInstance method.", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {java.lang.String.class, java.lang.String.class} + ) + }) + public void testMac04() throws NoSuchAlgorithmException, + IllegalArgumentException, NoSuchProviderException { + if (!DEFSupported) { + fail(NotSupportedMsg); + return; + } + try { + Mac.getInstance(null, defaultProviderName); + fail("NullPointerException or NoSuchAlgorithmException should be thrown when algorithm is null"); + } catch (NullPointerException e) { + } catch (NoSuchAlgorithmException e) { + } + for (int i = 0; i < invalidValues.length; i++) { + try { + Mac.getInstance(invalidValues[i], defaultProviderName); + fail("NoSuchAlgorithmException must be throws when algorithm is not available: " + .concat(invalidValues[i])); + } catch( NoSuchAlgorithmException e) { + } + } + } + /** + * Test for <code>getInstance(String algorithm, String provider)</code> method + * Assertion: returns Mac object + */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "This is a complete subset of tests for getInstance method.", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {java.lang.String.class, java.lang.String.class} + ) + }) + public void testMac05() throws NoSuchAlgorithmException, NoSuchProviderException, + IllegalArgumentException { + if (!DEFSupported) { + fail(NotSupportedMsg); + return; + } + Mac mac; + for (int i = 0; i < validValues.length; i++) { + mac = Mac.getInstance(validValues[i], defaultProviderName); + assertEquals("Incorrect algorithm", mac.getAlgorithm(), validValues[i]); + assertEquals("Incorrect provider", mac.getProvider().getName(), + defaultProviderName); + } + } + + /** + * Test for <code>getInstance(String algorithm, Provider provider)</code> method + * Assertion: throws IllegalArgumentException when provider is null + */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "This is a complete subset of tests for getInstance method.", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {java.lang.String.class, java.security.Provider.class} + ) + }) + public void testMac06() throws NoSuchAlgorithmException, NoSuchProviderException { + if (!DEFSupported) { + fail(NotSupportedMsg); + return; + } + Provider provider = null; + for (int i = 0; i < validValues.length; i++) { + try { + Mac.getInstance(validValues[i], provider); + fail("IllegalArgumentException must be thrown when provider is null"); + } catch (IllegalArgumentException e) { + } + } + } + /** + * Test for <code>getInstance(String algorithm, Provider provider)</code> method + * Assertion: + * throws NullPointerException when algorithm is null + * throws NoSuchAlgorithmException when algorithm is not available + */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "This is a complete subset of tests for getInstance method.", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {java.lang.String.class, java.security.Provider.class} + ) + }) + public void testMac07() throws NoSuchAlgorithmException, + NoSuchProviderException, IllegalArgumentException { + if (!DEFSupported) { + fail(NotSupportedMsg); + return; + } + try { + Mac.getInstance(null, defaultProvider); + fail("NullPointerException or NoSuchAlgorithmException should be thrown when algorithm is null"); + } catch (NullPointerException e) { + } catch (NoSuchAlgorithmException e) { + } + for (int i = 0; i < invalidValues.length; i++) { + try { + Mac.getInstance(invalidValues[i], defaultProvider); + fail("NoSuchAlgorithmException must be thrown when algorithm is not available: " + .concat(invalidValues[i])); + } catch (NoSuchAlgorithmException e) { + } + } + } + + /** + * Test for <code>getInstance(String algorithm, Provider provider)</code> method + * Assertion: returns Mac object + */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "This is a complete subset of tests for getInstance method.", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {java.lang.String.class, java.security.Provider.class} + ) + }) + public void testMac08() throws NoSuchAlgorithmException, NoSuchProviderException, + IllegalArgumentException { + if (!DEFSupported) { + fail(NotSupportedMsg); + return; + } + Mac mac; + for (int i = 0; i < validValues.length; i++) { + mac = Mac.getInstance(validValues[i], defaultProvider); + assertEquals("Incorrect algorithm", mac.getAlgorithm(), validValues[i]); + assertEquals("Incorrect provider", mac.getProvider(), defaultProvider); + } + } + /** + * Test for <code>update</code> and <code>doFinal</code> methods + * Assertion: throws IllegalStateException when Mac is not initialized + */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "Checks IllegalStateException only but for all methods." + + " Not enough for doFinal(byte[] output, int outOffset) - it can throw ShortBufferException", + targets = { + @TestTarget( + methodName = "doFinal", + methodArgs = {} + ),@TestTarget( + methodName = "doFinal", + methodArgs = {byte[].class} + ),@TestTarget( + methodName = "doFinal", + methodArgs = {byte[].class, int.class} + ),@TestTarget( + methodName = "update", + methodArgs = {byte.class} + ),@TestTarget( + methodName = "update", + methodArgs = {byte[].class} + ),@TestTarget( + methodName = "update", + methodArgs = {byte[].class, int.class, int.class} + ),@TestTarget( + methodName = "update", + methodArgs = {java.nio.ByteBuffer.class} + ) + }) + public void testMac09() throws NoSuchAlgorithmException, NoSuchProviderException, IllegalArgumentException, ShortBufferException { + if (!DEFSupported) { + fail(NotSupportedMsg); + return; + } + Mac [] macs = createMacs(); + assertNotNull("Mac objects were not created", macs); + byte [] buf = new byte[10]; + ByteBuffer bBuf = ByteBuffer.wrap(buf, 0, 10); + for (int i = 0; i < macs.length; i++) { + try { + macs[i].update((byte)0); + fail("IllegalStateException must be thrown"); + } catch (IllegalStateException e) { + } + try { + macs[i].update(buf); + fail("IllegalStateException must be thrown"); + } catch (IllegalStateException e) { + } + try { + macs[i].update(buf, 0, 3); + fail("IllegalStateException must be thrown"); + } catch (IllegalStateException e) { + } + try { + macs[i].update(bBuf); + fail("IllegalStateException must be thrown"); + } catch (IllegalStateException e) { + } + try { + macs[i].doFinal(); + fail("IllegalStateException must be thrown"); + } catch (IllegalStateException e) { + } + try { + macs[i].doFinal(new byte[10]); + fail("IllegalStateException must be thrown"); + } catch (IllegalStateException e) { + } + try { + macs[i].doFinal(new byte[10], 0); + fail("IllegalStateException must be thrown"); + } catch (IllegalStateException e) { + } + } + } + /** + * Test for <code>doFinal(byte[] output, int outOffset)</code> method + * Assertion: + * throws ShotBufferException when outOffset is negative or + * outOffset >= output.length or when given buffer is small + */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "Checks ShortBufferException", + targets = { + @TestTarget( + methodName = "doFinal", + methodArgs = {byte[].class, int.class} + ) + }) + public void testMac10() throws NoSuchAlgorithmException, + NoSuchProviderException, IllegalArgumentException, + IllegalStateException, InvalidKeyException { + if (!DEFSupported) { + fail(NotSupportedMsg); + return; + } + Mac[] macs = createMacs(); + assertNotNull("Mac objects were not created", macs); + byte[] b = { (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0 }; + byte[] byteA = new byte[b.length]; + SecretKeySpec sks = new SecretKeySpec(b, "SHA1"); + for (int i = 0; i < macs.length; i++) { + macs[i].init(sks); + try { + macs[i].doFinal(null, 10); + fail("ShortBufferException must be thrown"); + } catch (ShortBufferException e) { + } + try { + macs[i].doFinal(byteA, -4); + fail("ShortBufferException must be thrown"); + } catch (ShortBufferException e) { + } + try { + macs[i].doFinal(byteA, 10); + fail("ShortBufferException must be thrown"); + } catch (ShortBufferException e) { + } + try { + macs[i].doFinal(new byte[1], 0); + fail("ShortBufferException must be thrown"); + } catch (ShortBufferException e) { + } + byte[] res = macs[i].doFinal(); + try { + macs[i].doFinal(new byte[res.length - 1], 0); + fail("ShortBufferException must be thrown"); + } catch (ShortBufferException e) { + } + } + } + + /** + * Test for <code>doFinal(byte[] output, int outOffset)</code> and + * <code>doFinal()</code> methods Assertion: Mac result is stored in + * output buffer + */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "Checks functionality.", + targets = { + @TestTarget( + methodName = "doFinal", + methodArgs = {} + ),@TestTarget( + methodName = "doFinal", + methodArgs = {byte[].class, int.class} + ) + }) + public void testMac11() throws NoSuchAlgorithmException, NoSuchProviderException, + IllegalArgumentException, IllegalStateException, + InvalidKeyException, ShortBufferException { + if (!DEFSupported) { + fail(NotSupportedMsg); + return; + } + Mac [] macs = createMacs(); + assertNotNull("Mac objects were not created", macs); + byte [] b = {(byte)0, (byte)0, (byte)0, (byte)0, (byte)0}; + SecretKeySpec scs = new SecretKeySpec(b, "SHA1"); + for (int i = 0; i < macs.length; i++) { + macs[i].init(scs); + byte [] res1 = macs[i].doFinal(); + byte [] res2 = new byte[res1.length + 10]; + macs[i].doFinal(res2, 0); + for (int j = 0; j < res1.length; j++) { + assertEquals("Not equals byte number: " + .concat(Integer.toString(j)), res1[j], res2[j]); + } + } + } + /** + * Test for <code>doFinal(byte[] input)</code> method + * Assertion: update Mac and returns result + */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "Checks functionality.", + targets = { + @TestTarget( + methodName = "doFinal", + methodArgs = {} + ), @TestTarget( + methodName = "doFinal", + methodArgs = {byte[].class} + ) + }) + public void testMac12() throws NoSuchAlgorithmException, NoSuchProviderException, + IllegalArgumentException, IllegalStateException, + InvalidKeyException { + if (!DEFSupported) { + fail(NotSupportedMsg); + return; + } + Mac [] macs = createMacs(); + assertNotNull("Mac objects were not created", macs); + byte [] b = {(byte)0, (byte)0, (byte)0, (byte)0, (byte)0}; + byte [] upd = {(byte)5, (byte)4, (byte)3, (byte)2, (byte)1, (byte)0}; + SecretKeySpec scs = new SecretKeySpec(b, "SHA1"); + for (int i = 0; i < macs.length; i++) { + macs[i].init(scs); + byte [] res1 = macs[i].doFinal(); + byte [] res2 = macs[i].doFinal(); + assertEquals("Results are not the same", res1.length, res2.length); + for(int t = 0; t < res1.length; t++) { + assertEquals("Results are not the same", res1[t], res2[t]); + } + res2 = macs[i].doFinal(upd); + macs[i].update(upd); + res1 = macs[i].doFinal(); + assertEquals("Results are not the same", res1.length, res2.length); + for(int t = 0; t < res1.length; t++) { + assertEquals("Results are not the same", res1[t], res2[t]); + } + } + } + + /** + * Test for <code>update(byte[] input, int outset, int len)</code> method + * Assertion: throws IllegalArgumentException when offset or len is negative, + * offset + len >= input.length + */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "Checks IllegalArgumentException", + targets = { + @TestTarget( + methodName = "update", + methodArgs = {byte[].class, int.class, int.class} + ) + }) + public void testMac13() throws NoSuchAlgorithmException, + NoSuchProviderException, IllegalArgumentException, IllegalStateException, + InvalidKeyException { + if (!DEFSupported) { + fail(NotSupportedMsg); + return; + } + Mac [] macs = createMacs(); + assertNotNull("Mac objects were not created", macs); + byte [] b = {(byte)0, (byte)0, (byte)0, (byte)0, (byte)0}; + SecretKeySpec scs = new SecretKeySpec(b, "SHA1"); + for (int i = 0; i < macs.length; i++) { + macs[i].init(scs); + try { + macs[i].update(b, -10, b.length); + fail("IllegalArgumentException must be thrown"); + } catch (IllegalArgumentException e) { + } + try { + macs[i].update(b, 0, -10); + fail("IllegalArgumentException must be thrown"); + } catch (IllegalArgumentException e) { + } + try { + macs[i].update(b, 0, b.length + 1); + fail("IllegalArgumentException must be thrown"); + } catch (IllegalArgumentException e) { + } + try { + macs[i].update(b, b.length - 1, 2); + fail("IllegalArgumentException must be thrown"); + } catch (IllegalArgumentException e) { + } + } + } + /** + * Test for <code>update(byte[] input, int outset, int len)</code> and + * <code>update(byte[] input</code> + * methods + * Assertion: updates Mac + */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "Checks functionality.", + targets = { + @TestTarget( + methodName = "update", + methodArgs = {byte.class} + ),@TestTarget( + methodName = "update", + methodArgs = {byte[].class, int.class, int.class} + ) + }) + public void testMac14() throws NoSuchAlgorithmException, + NoSuchProviderException, IllegalArgumentException, IllegalStateException, + InvalidKeyException { + if (!DEFSupported) { + fail(NotSupportedMsg); + return; + } + Mac [] macs = createMacs(); + assertNotNull("Mac objects were not created", macs); + byte [] b = {(byte)0, (byte)0, (byte)0, (byte)0, (byte)0}; + byte [] upd1 = {(byte)0, (byte)1, (byte)5, (byte)4, (byte)3, (byte)2}; + byte [] upd2 = {(byte)5, (byte)4, (byte)3, (byte)2}; + byte [] res1; + byte [] res2; + SecretKeySpec scs = new SecretKeySpec(b, "SHA1"); + for (int i = 0; i < macs.length; i++) { + macs[i].init(scs); + macs[i].update(upd1, 2, 4); + res1 = macs[i].doFinal(); + macs[i].init(scs); + macs[i].update(upd2); + res2 = macs[i].doFinal(); + assertEquals("Results are not the same", res1.length, res2.length); + for(int t = 0; t < res1.length; t++) { + assertEquals("Results are not the same", res1[t], res2[t]); + } + macs[i].init(scs); + macs[i].update((byte)5); + res1 = macs[i].doFinal(); + macs[i].init(scs); + macs[i].update(upd1,2,1); + res2 = macs[i].doFinal(); + assertEquals("Results are not the same", res1.length, res2.length); + for(int t = 0; t < res1.length; t++) { + assertEquals("Results are not the same", res1[t], res2[t]); + } + } + } + /** + * Test for <code>clone()</code> method + * Assertion: returns Mac object or throws CloneNotSupportedException + */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "clone", + methodArgs = {} + ) + }) + public void testMacClone() throws NoSuchAlgorithmException, CloneNotSupportedException { + if (!DEFSupported) { + fail(NotSupportedMsg); + return; + } + Mac [] macs = createMacs(); + assertNotNull("Mac objects were not created", macs); + for (int i = 0; i < macs.length; i++) { + try { + Mac mac1 = (Mac) macs[i].clone(); + assertEquals(mac1.getAlgorithm(), macs[i].getAlgorithm()); + assertEquals(mac1.getProvider(), macs[i].getProvider()); + assertFalse(macs[i].equals(mac1)); + } catch (CloneNotSupportedException e) { + } + } + } + /** + * Test for + * <code>init(Key key, AlgorithmParameterSpec params)</code> + * <code>init(Key key)</code> + * methods + * Assertion: throws InvalidKeyException and InvalidAlgorithmParameterException + * when parameters are not appropriate + */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "Checks exceptions", + targets = { + @TestTarget( + methodName = "init", + methodArgs = {java.security.Key.class} + ),@TestTarget( + methodName = "init", + methodArgs = {java.security.Key.class, java.security.spec.AlgorithmParameterSpec.class} + ) + }) + public void testInit() throws NoSuchAlgorithmException, NoSuchProviderException, + IllegalArgumentException, IllegalStateException, InvalidAlgorithmParameterException, + InvalidKeyException { + if (!DEFSupported) { + fail(NotSupportedMsg); + return; + } + Mac [] macs = createMacs(); + assertNotNull("Mac objects were not created", macs); + byte [] b = {(byte)1, (byte)2, (byte)3, (byte)4, (byte)5}; + SecretKeySpec sks = new SecretKeySpec(b, "SHA1"); + DHGenParameterSpec algPS = new DHGenParameterSpec(1, 2); + + for (int i = 0; i < macs.length; i++) { + try { + macs[i].init(sks, algPS); + fail("init(..) accepts incorrect AlgorithmParameterSpec parameter"); + } catch (InvalidAlgorithmParameterException e) { + } + + try { + macs[i].init(null, null); + fail("InvalidKeyException must be thrown"); + } catch (InvalidKeyException e) { + } + + try { + macs[i].init(null); + fail("InvalidKeyException must be thrown"); + } catch (InvalidKeyException e) { + } + } + } + + /** + * Test for <code>update(ByteBuffer input)</code> + * <code>update(byte[] input, int offset, int len)</code> + * methods + * Assertion: processes Mac; if input is null then do nothing + */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "Checks functionality", + targets = { + @TestTarget( + methodName = "update", + methodArgs = {byte[].class, int.class, int.class} + ),@TestTarget( + methodName = "update", + methodArgs = {java.nio.ByteBuffer.class} + ) + }) + public void testUpdateByteBuffer01() throws NoSuchAlgorithmException, NoSuchProviderException, + IllegalArgumentException, IllegalStateException, InvalidAlgorithmParameterException, + InvalidKeyException { + if (!DEFSupported) { + fail(NotSupportedMsg); + return; + } + Mac [] macs = createMacs(); + assertNotNull("Mac objects were not created", macs); + byte [] bb = {(byte)1, (byte)2, (byte)3, (byte)4, (byte)5}; + SecretKeySpec sks = new SecretKeySpec(bb, "SHA1"); + ByteBuffer byteNull = null; + ByteBuffer byteBuff = ByteBuffer.allocate(0); + byte [] bb1; + byte [] bb2; + for (int i = 0; i < macs.length; i++) { + macs[i].init(sks); + bb1 = macs[i].doFinal(); + try { + macs[i].update(byteNull); + fail("IllegalArgumentException must be thrown because buffer is null"); + } catch (IllegalArgumentException e) { + } + macs[i].update(byteBuff); + bb2 = macs[i].doFinal(); + for (int t = 0; t < bb1.length; t++) { + assertEquals("Incorrect doFinal result", bb1[t], bb2[t]); + } + macs[i].init(sks); + bb1 = macs[i].doFinal(); + macs[i].update(null, 0, 0); + bb2 = macs[i].doFinal(); + for (int t = 0; t < bb1.length; t++) { + assertEquals("Incorrect doFinal result", bb1[t], bb2[t]); + } + } + } + /** + * Test for <code>update(ByteBuffer input)</code> + * <code>update(byte[] input, int offset, int len)</code> + * methods + * Assertion: processes Mac + */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "Checks functionality", + targets = { + @TestTarget( + methodName = "update", + methodArgs = {java.nio.ByteBuffer.class} + ),@TestTarget( + methodName = "update", + methodArgs = {byte[].class, int.class, int.class} + ) + }) + public void testUpdateByteBuffer02() throws NoSuchAlgorithmException, NoSuchProviderException, + IllegalArgumentException, IllegalStateException, InvalidAlgorithmParameterException, + InvalidKeyException { + if (!DEFSupported) { + fail(NotSupportedMsg); + return; + } + Mac [] macs = createMacs(); + assertNotNull("Mac objects were not created", macs); + byte [] bb = {(byte)1, (byte)2, (byte)3, (byte)4, (byte)5}; + SecretKeySpec sks = new SecretKeySpec(bb, "SHA1"); + byte [] bbuf = {(byte)5, (byte)4, (byte)3, (byte)2, (byte)1}; + ByteBuffer byteBuf; + byte [] bb1; + byte [] bb2; + for (int i = 0; i < macs.length; i++) { + byteBuf = ByteBuffer.allocate(5); + byteBuf.put(bbuf); + byteBuf.position(2); + macs[i].init(sks); + macs[i].update(byteBuf); + bb1 = macs[i].doFinal(); + + macs[i].init(sks); + macs[i].update(bbuf, 2, 3); + bb2 = macs[i].doFinal(); + for (int t = 0; t < bb1.length; t++) { + assertEquals("Incorrect doFinal result", bb1[t], bb2[t]); + } + } + } + /** + * Test for <code>clone()</code> method + * Assertion: clone if provider is clo + */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "clone", + methodArgs = {} + ) + }) + public void testClone() { + if (!DEFSupported) { + fail(NotSupportedMsg); + return; + } + Mac [] macs = createMacs(); + assertNotNull("Mac objects were not created", macs); + Mac res; + for (int i = 0; i < macs.length; i++) { + try { + res = (Mac)macs[i].clone(); + assertTrue("Object should not be equals", !macs[i].equals(res)); + assertEquals("Incorrect class", macs[i].getClass(), res.getClass()); + } catch (CloneNotSupportedException e) { + } + } + } + /** + * Test for <code>getMacLength()</code> method + * Assertion: return Mac length + */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getMacLength", + methodArgs = {} + ) + }) + public void testGetMacLength() { + if (!DEFSupported) { + fail(NotSupportedMsg); + return; + } + Mac [] macs = createMacs(); + assertNotNull("Mac objects were not created", macs); + for (int i = 0; i < macs.length; i++) { + assertTrue("Length should be positive", (macs[i].getMacLength() >= 0)); + } + } + + /** + * Test for <code>reset()</code> method + * Assertion: return Mac length + */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "reset", + methodArgs = {} + ) + }) + public void testReset() throws InvalidKeyException { + if (!DEFSupported) { + fail(NotSupportedMsg); + return; + } + Mac [] macs = createMacs(); + assertNotNull("Mac objects were not created", macs); + byte [] bb = {(byte)1, (byte)2, (byte)3, (byte)4, (byte)5}; + SecretKeySpec sks = new SecretKeySpec(bb, "SHA1"); + byte [] bbuf = {(byte)5, (byte)4, (byte)3, (byte)2, (byte)1}; + byte [] bb1; + byte [] bb2; + for (int i = 0; i < macs.length; i++) { + macs[i].init(sks); + bb1 = macs[i].doFinal(); + macs[i].reset(); + bb2 = macs[i].doFinal(); + assertEquals("incorrect result",bb1.length, bb2.length); + for (int t = 0; t < bb1.length; t++) { + assertEquals("Incorrect doFinal result", bb1[t], bb2[t]); + } + macs[i].reset(); + macs[i].update(bbuf); + bb1 = macs[i].doFinal(); + macs[i].reset(); + macs[i].update(bbuf, 0, bbuf.length); + bb2 = macs[i].doFinal(); + assertEquals("incorrect result",bb1.length, bb2.length); + for (int t = 0; t < bb1.length; t++) { + assertEquals("Incorrect doFinal result", bb1[t], bb2[t]); + } + } + } + /** + * Test for <code>Mac</code> constructor + * Assertion: returns Mac object + */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "Mac", + methodArgs = {javax.crypto.MacSpi.class, java.security.Provider.class, java.lang.String.class} + ) + }) + public void testMacConstructor() throws NoSuchAlgorithmException, + InvalidKeyException, InvalidAlgorithmParameterException { + if (!DEFSupported) { + fail(NotSupportedMsg); + return; + } + MacSpi spi = new MyMacSpi(); + Mac mac = new myMac(spi, defaultProvider, defaultAlgorithm); + assertEquals("Incorrect algorithm", mac.getAlgorithm(), + defaultAlgorithm); + assertEquals("Incorrect provider", mac.getProvider(), defaultProvider); + try { + mac.init(null, null); + fail("Exception should be thrown because init(..) uses incorrect parameters"); + } catch (Exception e) { + } + assertEquals("Invalid mac length", mac.getMacLength(), 0); + + mac = new myMac(null, null, null); + assertNull("Algorithm must be null", mac.getAlgorithm()); + assertNull("Provider must be null", mac.getProvider()); + try { + mac.init(null, null); + fail("Exception should be thrown because init(..) uses incorrect parameters"); + } catch (Exception e) { + } + try { + mac.getMacLength(); + fail("NullPointerException must be thrown"); + } catch (NullPointerException e) { + } + } + + public static Test suite() { + return new TestSuite(MacTest.class); + } + + public static void main(String args[]) { + junit.textui.TestRunner.run(suite()); + + } +} +/** + * Additional class for Mac constructor verification + */ +class myMac extends Mac { + + public myMac(MacSpi macSpi, Provider provider, + String algorithm) { + super(macSpi, provider, algorithm); + } +} diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/NoSuchPaddingExceptionTest.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/NoSuchPaddingExceptionTest.java new file mode 100644 index 0000000..88b1bda --- /dev/null +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/NoSuchPaddingExceptionTest.java @@ -0,0 +1,125 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Vera Y. Petrashkova +* @version $Revision$ +*/ + +package org.apache.harmony.crypto.tests.javax.crypto; + +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + +import javax.crypto.NoSuchPaddingException; + +import junit.framework.TestCase; + + +@TestTargetClass(NoSuchPaddingException.class) +/** + * Tests for <code>NoSuchPaddingException</code> class constructors and + * methods. + * + */ +public class NoSuchPaddingExceptionTest extends TestCase { + + public static void main(String[] args) { + } + + /** + * Constructor for NoSuchPaddingExceptionTests. + * + * @param arg0 + */ + public NoSuchPaddingExceptionTest(String arg0) { + super(arg0); + } + + static String[] msgs = { + "", + "Check new message", + "Check new message Check new message Check new message Check new message Check new message" }; + + static Throwable tCause = new Throwable("Throwable for exception"); + + /** + * Test for <code>NoSuchPaddingException()</code> constructor Assertion: + * constructs NoSuchPaddingException with no detail message + */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "NoSuchPaddingException", + methodArgs = {} + ) + }) + public void testNoSuchPaddingException01() { + NoSuchPaddingException tE = new NoSuchPaddingException(); + assertNull("getMessage() must return null.", tE.getMessage()); + assertNull("getCause() must return null", tE.getCause()); + } + + /** + * Test for <code>NoSuchPaddingException(String)</code> constructor + * Assertion: constructs NoSuchPaddingException with detail message msg. + * Parameter <code>msg</code> is not null. + */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "NoSuchPaddingException", + methodArgs = {java.lang.String.class} + ) + }) + public void testNoSuchPaddingException02() { + NoSuchPaddingException tE; + for (int i = 0; i < msgs.length; i++) { + tE = new NoSuchPaddingException(msgs[i]); + assertEquals("getMessage() must return: ".concat(msgs[i]), tE + .getMessage(), msgs[i]); + assertNull("getCause() must return null", tE.getCause()); + } + } + + /** + * Test for <code>NoSuchPaddingException(String)</code> constructor + * Assertion: constructs NoSuchPaddingException when <code>msg</code> is + * null + */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "NoSuchPaddingException", + methodArgs = {java.lang.String.class} + ) + }) + public void testNoSuchPaddingException03() { + String msg = null; + NoSuchPaddingException tE = new NoSuchPaddingException(msg); + assertNull("getMessage() must return null.", tE.getMessage()); + assertNull("getCause() must return null", tE.getCause()); + } +} diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/NullCipherTest.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/NullCipherTest.java new file mode 100644 index 0000000..aea4b3f --- /dev/null +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/NullCipherTest.java @@ -0,0 +1,489 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Boris V. Kuznetsov +* @version $Revision$ +*/ + +package org.apache.harmony.crypto.tests.javax.crypto; + +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + +import java.security.SecureRandom; +import java.util.Arrays; + +import javax.crypto.Cipher; +import javax.crypto.NullCipher; +import javax.crypto.spec.SecretKeySpec; + +import junit.framework.TestCase; + +@TestTargetClass(NullCipher.class) +/** + * + * Tests for NullCipher + */ +public class NullCipherTest extends TestCase { + + private Cipher c; + + protected void setUp() throws Exception { + super.setUp(); + c = new NullCipher(); + } + +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "Class checks inherited methods.", + targets = { + @TestTarget( + methodName = "getAlgorithm", + methodArgs = {} + ) + }) + public void testGetAlgorithm() { + c.getAlgorithm(); + } + +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "Checks inherited method from Cipher.", + targets = { + @TestTarget( + methodName = "getBlockSize", + methodArgs = {} + ) + }) + public void testGetBlockSize() { + assertEquals("Incorrect BlockSize", 1, c.getBlockSize()); + } + +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "IllegalStateException checking missed. Checks inherited method from Cipher.", + targets = { + @TestTarget( + methodName = "getOutputSize", + methodArgs = {int.class} + ) + }) + public void testGetOutputSize() { + assertEquals("Incorrect OutputSize", 111, c.getOutputSize(111)); + } + +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "Checks inherited method from Cipher.", + targets = { + @TestTarget( + methodName = "getIV", + methodArgs = {} + ) + }) + public void testGetIV() { + assertTrue("Incorrect IV", Arrays.equals(c.getIV(), new byte[8])); + } + +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "Checks inherited method from Cipher.", + targets = { + @TestTarget( + methodName = "getParameters", + methodArgs = {} + ) + }) + public void testGetParameters() { + assertNull("Incorrect Parameters", c.getParameters()); + } + +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "Checks inherited method from Cipher.", + targets = { + @TestTarget( + methodName = "getExemptionMechanism", + methodArgs = {} + ) + }) + public void testGetExemptionMechanism() { + assertNull("Incorrect ExemptionMechanism", c.getExemptionMechanism()); + } + + /* + * Class under test for void init(int, Key) + */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "InvalidKeyException checking missed. Checks inherited method from Cipher.", + targets = { + @TestTarget( + methodName = "init", + methodArgs = {int.class, java.security.Key.class} + ) + }) + public void testInitintKey() throws Exception { + c.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(new byte[1], "algorithm")); + + } + + /* + * Class under test for void init(int, Key, SecureRandom) + */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "InvalidKeyException checking missed. Checks inherited method from Cipher.", + targets = { + @TestTarget( + methodName = "init", + methodArgs = {int.class, java.security.Key.class, java.security.SecureRandom.class} + ) + }) + public void testInitintKeySecureRandom() throws Exception { + c.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(new byte[1], + "algorithm"), new SecureRandom()); + } + + /* + * Class under test for void init(int, Key, AlgorithmParameterSpec) + */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "Exceptions checking missed. Checks inherited method from Cipher.", + targets = { + @TestTarget( + methodName = "init", + methodArgs = {int.class, java.security.Key.class, java.security.spec.AlgorithmParameterSpec.class} + ) + }) + public void testInitintKeyAlgorithmParameterSpec() throws Exception { + class myAlgorithmParameterSpec implements java.security.spec.AlgorithmParameterSpec {} + c.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(new byte[1], + "algorithm"), new myAlgorithmParameterSpec()); + } + + /* + * Class under test for byte[] update(byte[]) + */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "IllegalStateException checking missed. Checks inherited method from Cipher.", + targets = { + @TestTarget( + methodName = "update", + methodArgs = {byte[].class} + ) + }) + public void testUpdatebyteArray() throws Exception { + byte [] b = {1, 2, 3, 4, 5}; + byte [] r = c.update(b); + assertEquals("different length", b.length, r.length); + assertTrue("different content", Arrays.equals(b, r)); + } + + /* + * Class under test for byte[] update(byte[], int, int) + */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "IllegalStateException checking missed. Checks inherited method from Cipher.", + targets = { + @TestTarget( + methodName = "update", + methodArgs = {byte[].class, int.class, int.class} + ) + }) + public void testUpdatebyteArrayintint() throws Exception { + byte [] b = {1, 2, 3, 4, 5}; + byte [] r = c.update(b, 0, 5); + assertEquals("different length", b.length, r.length); + assertTrue("different content", Arrays.equals(b, r)); + + r = c.update(b, 1, 3); + assertEquals("different length", 3, r.length); + for (int i = 0; i < 3; i++) { + assertEquals("different content", b[i + 1], r[i]); + } + } + + /* + * Class under test for int update(byte[], int, int, byte[]) + */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "Exceptions checking missed. Checks inherited method from Cipher.", + targets = { + @TestTarget( + methodName = "update", + methodArgs = {byte[].class, int.class, int.class, byte[].class} + ) + }) + public void testUpdatebyteArrayintintbyteArray() throws Exception { + byte [] b = {1, 2, 3, 4, 5}; + byte [] r = new byte[5]; + c.update(b, 0, 5, r); + assertTrue("different content", Arrays.equals(b, r)); + } + + /* + * Class under test for int update(byte[], int, int, byte[], int) + */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "Exceptions checking missed. Checks inherited method from Cipher.", + targets = { + @TestTarget( + methodName = "update", + methodArgs = {byte[].class, int.class, int.class, byte[].class, int.class} + ) + }) + public void testUpdatebyteArrayintintbyteArrayint() throws Exception { + byte [] b = {1, 2, 3, 4, 5}; + byte [] r = new byte[5]; + c.update(b, 0, 5, r, 0); + assertTrue("different content", Arrays.equals(b, r)); + } + + /* + * Class under test for byte[] doFinal() + */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "Exceptions checking missed. Checks inherited method from Cipher.", + targets = { + @TestTarget( + methodName = "doFinal", + methodArgs = {} + ) + }) + public void testDoFinal() throws Exception { + assertNull("doFinal failed", c.doFinal()); + } + + /* + * Class under test for int doFinal(byte[], int) + */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "Exceptions checking missed. Checks inherited method from Cipher.", + targets = { + @TestTarget( + methodName = "doFinal", + methodArgs = {byte[].class, int.class} + ) + }) + public void testDoFinalbyteArrayint() throws Exception { + byte [] r = new byte[5]; + assertEquals("doFinal failed", 0, c.doFinal(r, 0)); + } + + /* + * Class under test for byte[] doFinal(byte[]) + */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "Exceptions checking missed. Checks inherited method from Cipher.", + targets = { + @TestTarget( + methodName = "doFinal", + methodArgs = {byte[].class} + ) + }) + public void testDoFinalbyteArray() throws Exception { + byte [] b = {1, 2, 3, 4, 5}; + byte [] r = null; + r = c.doFinal(b); + assertEquals("different length", b.length, r.length); + assertTrue("different content", Arrays.equals(b, r)); + } + + /* + * Class under test for byte[] doFinal(byte[], int, int) + */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "Exceptions checking missed. Checks inherited method from Cipher.", + targets = { + @TestTarget( + methodName = "doFinal", + methodArgs = {byte[].class, int.class, int.class} + ) + }) + public void testDoFinalbyteArrayintint() throws Exception { + byte [] b = {1, 2, 3, 4, 5}; + byte [] r = null; + r = c.doFinal(b, 0, 5); + assertEquals("different length", b.length, r.length); + assertTrue("different content", Arrays.equals(b, r)); + + r = c.doFinal(b, 1, 3); + assertEquals("different length", 3, r.length); + for (int i = 0; i < 3; i++) { + assertEquals("different content", b[i + 1], r[i]); + } + } + + /* + * Class under test for byte[] update(byte[], int, int) + */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "Exceptions checking missed. Checks inherited method from Cipher.", + targets = { + @TestTarget( + methodName = "update", + methodArgs = {byte[].class, int.class, int.class} + ) + }) + public void testUpdatebyteArrayintint2() { + //Regression for HARMONY-758 + try { + new NullCipher().update(new byte[1], 1, Integer.MAX_VALUE); + fail("Expected IllegalArgumentException was not thrown"); + } catch (IllegalArgumentException e) { + } + } + + /* + * Class under test for int doFinal(byte[], int, int, byte[]) + */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "Exceptions checking missed. Checks inherited method from Cipher.", + targets = { + @TestTarget( + methodName = "doFinal", + methodArgs = {byte[].class, int.class, int.class, byte[].class} + ) + }) + public void testDoFinalbyteArrayintintbyteArray() throws Exception { + byte [] b = {1, 2, 3, 4, 5}; + byte [] r = new byte[5]; + c.doFinal(b, 0, 5, r); + assertTrue("different content", Arrays.equals(b, r)); + } + + /* + * Class under test for int doFinal(byte[], int, int, byte[]) + */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "Exceptions checking missed. Checks inherited method from Cipher.", + targets = { + @TestTarget( + methodName = "doFinal", + methodArgs = {byte[].class, int.class, int.class, byte[].class} + ) + }) + public void testDoFinalbyteArrayintintbyteArray2() throws Exception { + //Regression for HARMONY-758 + try { + new NullCipher().update(new byte[1], 1, Integer.MAX_VALUE, + new byte[1]); + fail("Expected IllegalArgumentException was not thrown"); + } catch (IllegalArgumentException e) { + } + } + + /* + * Class under test for int doFinal(byte[], int, int, byte[]) + */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "Exceptions checking missed. Checks inherited method from Cipher.", + targets = { + @TestTarget( + methodName = "doFinal", + methodArgs = {byte[].class, int.class, int.class, byte[].class} + ) + }) + public void _testDoFinalbyteArrayintintbyteArray3() throws Exception { + //Regression for HARMONY-758 + try { + new NullCipher().update(new byte[1], 0, 1, new byte[0]); + fail("Expected ArrayIndexOutOfBoundsException was not thrown"); + } catch (ArrayIndexOutOfBoundsException e) { + } + } + + /* + * Class under test for int doFinal(byte[], int, int, byte[], int) + */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "Exceptions checking missed. Checks inherited method from Cipher.", + targets = { + @TestTarget( + methodName = "doFinal", + methodArgs = {byte[].class, int.class, int.class, byte[].class, int.class} + ) + }) + public void testDoFinalbyteArrayintintbyteArrayint() throws Exception { + byte [] b = {1, 2, 3, 4, 5}; + byte [] r = new byte[5]; + c.doFinal(b, 0, 5, r, 0); + assertTrue("different content", Arrays.equals(b, r)); + } + + /* + * Class under test for int doFinal(byte[], int, int, byte[], int) + */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "Exceptions checking missed. Checks inherited method from Cipher.", + targets = { + @TestTarget( + methodName = "doFinal", + methodArgs = {byte[].class, int.class, int.class, byte[].class, int.class} + ) + }) + public void testDoFinalbyteArrayintintbyteArrayint2() throws Exception { + //Regression for HARMONY-758 + try { + new NullCipher().update(new byte[1], 1, Integer.MAX_VALUE, + new byte[1], 0); + fail("Expected IllegalArgumentException was not thrown"); + } catch (IllegalArgumentException e) { + } + } + + /* + * Class under test for int doFinal(byte[], int, int, byte[], int) + */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "Exceptions checking missed. Checks inherited method from Cipher.", + targets = { + @TestTarget( + methodName = "doFinal", + methodArgs = {byte[].class, int.class, int.class, byte[].class, int.class} + ) + }) + public void _testDoFinalbyteArrayintintbyteArrayint3() throws Exception { + //Regression for HARMONY-758 + try { + new NullCipher().update(new byte[1], 0, 1, + new byte[0], 0); + fail("Expected ArrayIndexOutOfBoundsException was not thrown"); + } catch (ArrayIndexOutOfBoundsException e) { + } + } +} diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/SealedObjectTest.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/SealedObjectTest.java new file mode 100644 index 0000000..67dcc23 --- /dev/null +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/SealedObjectTest.java @@ -0,0 +1,307 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to You under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +/** + * @author Alexander Y. Kleymenov + * @version $Revision$ + */ + +package org.apache.harmony.crypto.tests.javax.crypto; + +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.Serializable; +import java.security.Key; +import java.util.Arrays; +import javax.crypto.Cipher; +import javax.crypto.IllegalBlockSizeException; +import javax.crypto.KeyGenerator; +import javax.crypto.NullCipher; +import javax.crypto.SealedObject; +import javax.crypto.spec.IvParameterSpec; +import javax.crypto.spec.SecretKeySpec; + +import junit.framework.TestCase; + +@TestTargetClass(SealedObject.class) +/** + */ +public class SealedObjectTest extends TestCase { + class Mock_SealedObject extends SealedObject { + public Mock_SealedObject(Serializable object, Cipher c) + throws IOException, IllegalBlockSizeException { + super(object, c); + } + + public byte[] get_encodedParams() { + return super.encodedParams; + } + + } + + /** + * readObject(ObjectInputStream s) method testing. Tests if the + * serialization/deserialization works correctly: object is serialized, + * deserialized, the content od deserialized object equals to the content of + * initial object. + */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "!Serialization", + methodArgs = {} + ) + }) + public void testReadObject() throws Exception { + String secret = "secret string"; + SealedObject so = new SealedObject(secret, new NullCipher()); + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + ObjectOutputStream oos = new ObjectOutputStream(bos); + oos.writeObject(so); + + ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream( + bos.toByteArray())); + + SealedObject so_des = (SealedObject) ois.readObject(); + assertEquals("The secret content of deserialized object " + + "should be equal to the secret content of initial object", + secret, so_des.getObject(new NullCipher())); + assertEquals("The value returned by getAlgorithm() method of " + + "deserialized object should be equal to the value returned " + + "by getAlgorithm() method of initial object", so + .getAlgorithm(), so_des.getAlgorithm()); + } + + /** + * SealedObject(Serializable object, Cipher c) method testing. Tests if the + * NullPointerException is thrown in the case of null cipher. + */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "Functionality checked in testSealedObject2, missed IOException & IllegalBlockSizeException checking", + targets = { + @TestTarget( + methodName = "SealedObject", + methodArgs = {java.io.Serializable.class, javax.crypto.Cipher.class} + ) + }) + public void testSealedObject1() throws Exception { + String secret = "secret string"; + try { + new SealedObject(secret, null); + fail("NullPointerException should be thrown in the case " + + "of null cipher."); + } catch (NullPointerException e) { + } + } + + /** + * SealedObject(SealedObject so) method testing. Tests if the + * NullPointerException is thrown in the case of null SealedObject. + */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "SealedObject", + methodArgs = {javax.crypto.SealedObject.class} + ) + }) + public void testSealedObject2() throws Exception { + try { + new SealedObject(null) {}; + fail("NullPointerException should be thrown in the case " + + "of null SealedObject."); + } catch (NullPointerException e) { + } + + String secret = "secret string"; + Cipher cipher = new NullCipher(); + SealedObject so1 = new SealedObject(secret, cipher); + SealedObject so2 = new SealedObject(so1) {}; + + assertEquals("The secret content of the object should equals " + + "to the secret content of initial object.", secret, so2 + .getObject(cipher)); + assertEquals("The algorithm which was used to seal the object " + + "should be the same as the algorithm used to seal the " + + "initial object", so1.getAlgorithm(), so2.getAlgorithm()); + } + + /** + * getAlgorithm() method testing. Tests if the returned value equals to the + * corresponding value of Cipher object. + */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getAlgorithm", + methodArgs = {} + ) + }) + public void testGetAlgorithm() throws Exception { + String secret = "secret string"; + String algorithm = "DES"; + KeyGenerator kg = KeyGenerator.getInstance(algorithm); + Key key = kg.generateKey(); + + Cipher cipher = Cipher.getInstance(algorithm); + cipher.init(Cipher.ENCRYPT_MODE, key); + SealedObject so = new SealedObject(secret, cipher); + + assertEquals("The algorithm name should be the same as used " + + "in cipher.", algorithm, so.getAlgorithm()); + } + + /** + * getObject(Key key) method testing. Tests if the object sealed with + * encryption algorithm and specified parameters can be retrieved by + * specifying the cryptographic key. + */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "Exceptions checking missed.", + targets = { + @TestTarget( + methodName = "getObject", + methodArgs = {java.security.Key.class} + ) + }) + public void testGetObject1() throws Exception { + KeyGenerator kg = KeyGenerator.getInstance("DES"); + Key key = kg.generateKey(); + + IvParameterSpec ips = new IvParameterSpec(new byte[] { + 1, 2, 3, 4, 5, 6, 7, 8}); + + Cipher cipher = Cipher.getInstance("DES/CBC/PKCS5Padding"); + cipher.init(Cipher.ENCRYPT_MODE, key, ips); + + String secret = "secret string"; + Mock_SealedObject so = new Mock_SealedObject(secret, cipher); + + assertEquals("The returned object does not equals to the " + + "original object.", secret, so.getObject(key)); + + assertTrue("The encodedParams field of SealedObject object " + + "should contain the encoded algorithm parameters.", Arrays + .equals(so.get_encodedParams(), cipher.getParameters() + .getEncoded())); + } + + /** + * getObject(Cipher c) method testing. Tests if the proper exception is + * thrown in the case of incorrect input parameters and if the object sealed + * with encryption algorithm and specified parameters can be retrieved by + * specifying the initialized Cipher object. + */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "Exceptions checking missed.", + targets = { + @TestTarget( + methodName = "getObject", + methodArgs = {javax.crypto.Cipher.class} + ) + }) + public void testGetObject2() throws Exception { + try { + new SealedObject("secret string", new NullCipher()) + .getObject((Cipher) null); + fail("NullPointerException should be thrown in the case of " + + "null cipher."); + } catch (NullPointerException e) { + } + + KeyGenerator kg = KeyGenerator.getInstance("DES"); + Key key = kg.generateKey(); + + IvParameterSpec ips = new IvParameterSpec(new byte[] { + 1, 2, 3, 4, 5, 6, 7, 8}); + + Cipher cipher = Cipher.getInstance("DES/CBC/PKCS5Padding"); + cipher.init(Cipher.ENCRYPT_MODE, key, ips); + + String secret = "secret string"; + SealedObject so = new SealedObject(secret, cipher); + + cipher.init(Cipher.DECRYPT_MODE, key, ips); + assertEquals("The returned object does not equals to the " + + "original object.", secret, so.getObject(cipher)); + } + + /** + * getObject(Key key, String provider) method testing. Tests if the proper + * exception is thrown in the case of incorrect input parameters and if the + * object sealed with encryption algorithm can be retrieved by specifying + * the cryptographic key and provider name. + */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "Exceptions checking missed.", + targets = { + @TestTarget( + methodName = "getObject", + methodArgs = {java.security.Key.class, java.lang.String.class} + ) + }) + public void testGetObject3() throws Exception { + try { + new SealedObject("secret string", new NullCipher()).getObject( + new SecretKeySpec(new byte[] {0, 0, 0}, "algorithm"), null); + fail("IllegalArgumentException should be thrown in the case of " + + "null provider."); + } catch (IllegalArgumentException e) { + } + + try { + new SealedObject("secret string", new NullCipher()).getObject( + new SecretKeySpec(new byte[] {0, 0, 0}, "algorithm"), ""); + fail("IllegalArgumentException should be thrown in the case of " + + "empty provider."); + } catch (IllegalArgumentException e) { + } + + KeyGenerator kg = KeyGenerator.getInstance("DES"); + Key key = kg.generateKey(); + + Cipher cipher = Cipher.getInstance("DES"); + String provider = cipher.getProvider().getName(); + cipher.init(Cipher.ENCRYPT_MODE, key); + + String secret = "secret string"; + SealedObject so = new SealedObject(secret, cipher); + + cipher.init(Cipher.DECRYPT_MODE, key); + assertEquals("The returned object does not equals to the " + + "original object.", secret, so.getObject(key, provider)); + } + +} diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/SecretKeyFactorySpiTest.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/SecretKeyFactorySpiTest.java new file mode 100644 index 0000000..5a2ae23 --- /dev/null +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/SecretKeyFactorySpiTest.java @@ -0,0 +1,100 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Vera Y. Petrashkova +* @version $Revision$ +*/ + +package org.apache.harmony.crypto.tests.javax.crypto; + +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + +import java.security.InvalidKeyException; +import java.security.spec.InvalidKeySpecException; +import java.security.spec.KeySpec; +import javax.crypto.SecretKeyFactorySpi; +import javax.crypto.SecretKey; +import org.apache.harmony.crypto.tests.support.MySecretKeyFactorySpi; + +import junit.framework.TestCase; + + +/** + * Tests for <code>SecretKeyFactorySpi</code> class constructors and methods. + * + */ + +@TestTargetClass(SecretKeyFactorySpi.class) +public class SecretKeyFactorySpiTest extends TestCase { + class Mock_SecretKeyFactorySpi extends MySecretKeyFactorySpi { + + @Override + protected SecretKey engineGenerateSecret(KeySpec keySpec) throws InvalidKeySpecException { + return super.engineGenerateSecret(keySpec); + } + + @Override + protected KeySpec engineGetKeySpec(SecretKey key, Class keySpec) throws InvalidKeySpecException { + return super.engineGetKeySpec(key, keySpec); + } + + @Override + protected SecretKey engineTranslateKey(SecretKey key) throws InvalidKeyException { + return super.engineTranslateKey(key); + } + + } + + /** + * Constructor for SecretKeyfactorySpiTests. + * + * @param arg0 + */ + public SecretKeyFactorySpiTest(String arg0) { + super(arg0); + } + + /** + * + * Test for <code>SecretKeyFactorySpi</code> constructor Assertion: + * constructs SecretKeyFactorySpi + */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "SecretKeyFactorySpi", + methodArgs = {} + ) + }) + public void testSecretKeyFactorySpi01() throws InvalidKeyException, + InvalidKeySpecException { + Mock_SecretKeyFactorySpi skfSpi = new Mock_SecretKeyFactorySpi(); + SecretKey sk = null; + assertNull("Not null result", skfSpi.engineTranslateKey(sk)); + + KeySpec kspec = null; + assertNull("Not null result", skfSpi.engineGenerateSecret(kspec)); + + assertNull("Not null result", skfSpi.engineGetKeySpec(sk, null)); + } +} diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/SecretKeyFactoryTest.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/SecretKeyFactoryTest.java new file mode 100644 index 0000000..f3b8d31 --- /dev/null +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/SecretKeyFactoryTest.java @@ -0,0 +1,524 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Vera Y. Petrashkova +* @version $Revision$ +*/ + +package org.apache.harmony.crypto.tests.javax.crypto; + +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + +import java.security.InvalidKeyException; +import java.security.NoSuchAlgorithmException; +import java.security.NoSuchProviderException; +import java.security.Provider; +import java.security.spec.InvalidKeySpecException; +import java.security.spec.KeySpec; + +import javax.crypto.SecretKey; +import javax.crypto.SecretKeyFactory; +import javax.crypto.SecretKeyFactorySpi; +import javax.crypto.spec.DESKeySpec; +import javax.crypto.spec.DESedeKeySpec; +import javax.crypto.spec.SecretKeySpec; + +import org.apache.harmony.crypto.tests.support.MySecretKeyFactorySpi; +import org.apache.harmony.security.tests.support.SpiEngUtils; + +import junit.framework.TestCase; + +@TestTargetClass(SecretKeyFactory.class) +/** + * Tests for <code>SecretKeyFactory</code> class constructors and methods. + * + */ + +public class SecretKeyFactoryTest extends TestCase { + + public static final String srvSecretKeyFactory = "SecretKeyFactory"; + + private static String defaultAlgorithm1 = "DESede"; + private static String defaultAlgorithm2 = "DES"; + + public static String defaultAlgorithm = null; + + private static String defaultProviderName = null; + + private static Provider defaultProvider = null; + + private static final String[] invalidValues = SpiEngUtils.invalidValues; + + public static final String[] validValues = new String[2]; + private static boolean DEFSupported = false; + + private static final String NotSupportMsg = "Default algorithm is not supported"; + + static { + defaultProvider = SpiEngUtils.isSupport(defaultAlgorithm1, + srvSecretKeyFactory); + DEFSupported = (defaultProvider != null); + if (DEFSupported) { + defaultAlgorithm = defaultAlgorithm1; + validValues[0] = defaultAlgorithm.toUpperCase(); + validValues[1] = defaultAlgorithm.toLowerCase(); + defaultProviderName = defaultProvider.getName(); + } else { + defaultProvider = SpiEngUtils.isSupport(defaultAlgorithm2, + srvSecretKeyFactory); + DEFSupported = (defaultProvider != null); + if (DEFSupported) { + defaultAlgorithm = defaultAlgorithm2; + validValues[0] = defaultAlgorithm.toUpperCase(); + validValues[2] = defaultAlgorithm.toLowerCase(); + defaultProviderName = defaultProvider.getName(); + } else { + defaultAlgorithm = null; + defaultProviderName = null; + defaultProvider = null; + } + } + } + + protected SecretKeyFactory[] createSKFac() { + if (!DEFSupported) { + fail(defaultAlgorithm + " algorithm is not supported"); + return null; + } + SecretKeyFactory[] skF = new SecretKeyFactory[3]; + try { + skF[0] = SecretKeyFactory.getInstance(defaultAlgorithm); + skF[1] = SecretKeyFactory.getInstance(defaultAlgorithm, + defaultProvider); + skF[2] = SecretKeyFactory.getInstance(defaultAlgorithm, + defaultProviderName); + return skF; + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } + + /** + * Test for <code>SecretKeyFactory</code> constructor + * Assertion: returns SecretKeyFactory object + */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "SecretKeyFactory", + methodArgs = {javax.crypto.SecretKeyFactorySpi.class, java.security.Provider.class, java.lang.String.class} + ) + }) + public void testSecretKeyFactory01() throws NoSuchAlgorithmException, + InvalidKeySpecException, InvalidKeyException { + if (!DEFSupported) { + fail(NotSupportMsg); + return; + } + SecretKeyFactorySpi spi = new MySecretKeyFactorySpi(); + SecretKeyFactory secKF = new mySecretKeyFactory(spi, defaultProvider, + defaultAlgorithm); + assertEquals("Incorrect algorithm", secKF.getAlgorithm(), + defaultAlgorithm); + assertEquals("Incorrect provider", secKF.getProvider(), defaultProvider); + assertNull("Incorrect result", secKF.generateSecret(null)); + assertNull("Incorrect result", secKF.getKeySpec(null, null)); + assertNull("Incorrect result", secKF.translateKey(null)); + secKF = new mySecretKeyFactory(null, null, null); + assertNull("Algorithm must be null", secKF.getAlgorithm()); + assertNull("Provider must be null", secKF.getProvider()); + try { + secKF.translateKey(null); + fail("NullPointerException must be thrown"); + } catch (NullPointerException e) { + } + } + + /** + * Test for <code>getInstance(String algorithm)</code> method + * Assertions: + * throws NullPointerException when algorithm is null; + * throws NoSuchAlgorithmException when algorithm has invalid value + */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "This is a complete subset of tests for getInstance method.", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {java.lang.String.class} + ) + }) + public void testSecretKeyFactory02() throws NoSuchAlgorithmException { + try { + SecretKeyFactory.getInstance(null); + fail("NullPointerException or NoSuchAlgorithmException should be thrown if algorithm is null"); + } catch (NullPointerException e) { + } catch (NoSuchAlgorithmException e) { + } + for (int i = 0; i < invalidValues.length; i++) { + try { + SecretKeyFactory.getInstance(invalidValues[i]); + fail("NoSuchAlgorithmException was not thrown as expected"); + } catch (NoSuchAlgorithmException e) { + } + } + } + + /** + * Test for <code>getInstance(String algorithm)</code> method + * Assertion: returns SecretKeyObject + */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "This is a complete subset of tests for getInstance method.", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {java.lang.String.class} + ) + }) + public void testSecretKeyFactory03() throws NoSuchAlgorithmException { + if (!DEFSupported) { + fail(NotSupportMsg); + return; + } + for (int i = 0; i < validValues.length; i++) { + SecretKeyFactory secKF = SecretKeyFactory + .getInstance(validValues[i]); + assertEquals("Incorrect algorithm", secKF.getAlgorithm(), + validValues[i]); + } + } + + /** + * Test for <code>getInstance(String algorithm, String provider)</code> + * method + * Assertion: + * throws NullPointerException when algorithm is null; + * throws NoSuchAlgorithmException when algorithm is invalid + */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "This is a complete subset of tests for getInstance method.", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {java.lang.String.class, java.lang.String.class} + ) + }) + public void testSecretKeyFactory04() throws NoSuchAlgorithmException, + NoSuchProviderException { + if (!DEFSupported) { + fail(NotSupportMsg); + return; + } + try { + SecretKeyFactory.getInstance(null, defaultProviderName); + fail("NullPointerException or NoSuchAlgorithmException should be thrown if algorithm is null"); + } catch (NullPointerException e) { + } catch (NoSuchAlgorithmException e) { + } + for (int i = 0; i < invalidValues.length; i++) { + try { + SecretKeyFactory.getInstance(invalidValues[i], + defaultProviderName); + fail("NoSuchAlgorithmException was not thrown as expected (algorithm: " + .concat(invalidValues[i]).concat(")")); + } catch (NoSuchAlgorithmException e) { + } + } + } + + /** + * Test for <code>getInstance(String algorithm, String provider)</code> + * method + * Assertion: + * throws IllegalArgumentException when provider is null or empty; + * throws NoSuchProviderException when provider has invalid value + */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "This is a complete subset of tests for getInstance method.", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {java.lang.String.class, java.lang.String.class} + ) + }) + public void testSecretKeyFactory05() throws NoSuchAlgorithmException, + NoSuchProviderException { + if (!DEFSupported) { + fail(NotSupportMsg); + return; + } + String prov = null; + for (int i = 0; i < validValues.length; i++) { + try { + SecretKeyFactory.getInstance(validValues[i], prov); + fail("IllegalArgumentException was not thrown as expected (algorithm: " + .concat(validValues[i]).concat(" provider: null")); + } catch (IllegalArgumentException e) { + } + try { + SecretKeyFactory.getInstance(validValues[i], ""); + fail("IllegalArgumentException was not thrown as expected (algorithm: " + .concat(validValues[i]).concat(" provider: empty")); + } catch (IllegalArgumentException e) { + } + for (int j = 1; j < invalidValues.length; j++) { + try { + SecretKeyFactory.getInstance(validValues[i], + invalidValues[j]); + fail("NoSuchProviderException was not thrown as expected (algorithm: " + .concat(validValues[i]).concat(" provider: ") + .concat(invalidValues[j]).concat(")")); + } catch (NoSuchProviderException e) { + } + } + } + } + + /** + * Test for <code>getInstance(String algorithm, String provider)</code> + * method + * Assertion: returns SecretKeyFactory object + */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "This is a complete subset of tests for getInstance method.", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {java.lang.String.class, java.lang.String.class} + ) + }) + public void testSecretKeyFactory06() throws NoSuchProviderException, + NoSuchAlgorithmException { + if (!DEFSupported) { + fail(NotSupportMsg); + return; + } + for (int i = 0; i < validValues.length; i++) { + SecretKeyFactory secKF = SecretKeyFactory.getInstance( + validValues[i], defaultProviderName); + assertEquals("Incorrect algorithm", secKF.getAlgorithm(), + validValues[i]); + assertEquals("Incorrect provider", secKF.getProvider().getName(), + defaultProviderName); + } + } + + /** + * Test for <code>getInstance(String algorithm, Provider provider)</code> + * method + * Assertion: throws NullPointerException when algorithm is null; + * throws NoSuchAlgorithmException when algorithm is invalid + */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "This is a complete subset of tests for getInstance method.", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {java.lang.String.class, java.security.Provider.class} + ) + }) + public void testSecretKeyFactory07() throws NoSuchAlgorithmException { + if (!DEFSupported) { + fail(NotSupportMsg); + return; + } + try { + SecretKeyFactory.getInstance(null, defaultProvider); + fail("NullPointerException or NoSuchAlgorithmException should be thrown if algorithm is null"); + } catch (NullPointerException e) { + } catch (NoSuchAlgorithmException e) { + } + for (int i = 0; i < invalidValues.length; i++) { + try { + SecretKeyFactory.getInstance(invalidValues[i], defaultProvider); + fail("NoSuchAlgorithmException was not thrown as expected (algorithm: " + .concat(invalidValues[i]).concat(")")); + } catch (NoSuchAlgorithmException e) { + } + } + } + + /** + * Test for <code>getInstance(String algorithm, Provider provider)</code> + * method + * Assertion: throws IllegalArgumentException when provider is null + */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "This is a complete subset of tests for getInstance method.", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {java.lang.String.class, java.security.Provider.class} + ) + }) + public void testSecretKeyFactory08() throws NoSuchAlgorithmException { + if (!DEFSupported) { + fail(NotSupportMsg); + return; + } + Provider prov = null; + for (int i = 0; i < validValues.length; i++) { + try { + SecretKeyFactory.getInstance(validValues[i], prov); + fail("IllegalArgumentException was not thrown as expected (provider is null, algorithm: " + .concat(validValues[i]).concat(")")); + } catch (IllegalArgumentException e) { + } + } + } + + /** + * Test for <code>getInstance(String algorithm, Provider provider)</code> + * method + * Assertion: returns SecretKeyFactory object + */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "This is a complete subset of tests for getInstance method.", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {java.lang.String.class, java.security.Provider.class} + ) + }) + public void testSecretKeyFactory09() throws NoSuchAlgorithmException { + if (!DEFSupported) { + fail(NotSupportMsg); + return; + } + for (int i = 0; i < validValues.length; i++) { + SecretKeyFactory secKF = SecretKeyFactory.getInstance( + validValues[i], defaultProvider); + assertEquals("Incorrect algorithm", secKF.getAlgorithm(), + validValues[i]); + assertEquals("Incorrect provider", secKF.getProvider(), + defaultProvider); + } + } + + /** + * Test for <code>generateSecret(KeySpec keySpec)</code> and + * <code>getKeySpec(SecretKey key, Class keySpec) + * methods + * Assertion: + * throw InvalidKeySpecException if parameter is inappropriate + */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "Tis test is checking two methods.", + targets = { + @TestTarget( + methodName = "generateSecret", + methodArgs = {java.security.spec.KeySpec.class} + ), @TestTarget( + methodName = "getKeySpec", + methodArgs = {javax.crypto.SecretKey.class, java.lang.Class.class} + ) + }) + public void testSecretKeyFactory10() throws InvalidKeyException, + InvalidKeySpecException { + if (!DEFSupported) { + fail(NotSupportMsg); + return; + } + byte[] bb = new byte[24]; + KeySpec ks = (defaultAlgorithm.equals(defaultAlgorithm2) ? (KeySpec)new DESKeySpec(bb) : + (KeySpec)new DESedeKeySpec(bb)); + KeySpec rks = null; + SecretKeySpec secKeySpec = new SecretKeySpec(bb, defaultAlgorithm); + SecretKey secKey = null; + SecretKeyFactory[] skF = createSKFac(); + assertNotNull("SecretKeyFactory object were not created", skF); + for (int i = 0; i < skF.length; i++) { + try { + skF[i].generateSecret(null); + fail("generateSecret(null): InvalidKeySpecException must be thrown"); + } catch (InvalidKeySpecException e) { + } + + secKey = skF[i].generateSecret(ks); + try { + skF[i].getKeySpec(null, null); + fail("getKeySpec(null,null): InvalidKeySpecException must be thrown"); + } catch (InvalidKeySpecException e) { + } + try { + skF[i].getKeySpec(null, ks.getClass()); + fail("getKeySpec(null, Class): InvalidKeySpecException must be thrown"); + } catch (InvalidKeySpecException e) { + } + try { + skF[i].getKeySpec(secKey, null); + fail("getKeySpec(secKey, null): NullPointerException or InvalidKeySpecException must be thrown"); + } catch (InvalidKeySpecException e) { + // Expected + } catch (NullPointerException e) { + // Expected + } + + try { + Class c; + if (defaultAlgorithm.equals(defaultAlgorithm2)) { + c = DESedeKeySpec.class; + } else { + c = DESKeySpec.class; + } + skF[i].getKeySpec(secKeySpec, c); + fail("getKeySpec(secKey, Class): InvalidKeySpecException must be thrown"); + } catch (InvalidKeySpecException e) { + } + rks = skF[i].getKeySpec(secKeySpec, ks.getClass()); + if (defaultAlgorithm.equals(defaultAlgorithm1)) { + assertTrue("Incorrect getKeySpec() result 1", + rks instanceof DESedeKeySpec); + } else { + assertTrue("Incorrect getKeySpec() result 1", + rks instanceof DESKeySpec); + } + + rks = skF[i].getKeySpec(secKey, ks.getClass()); + if (defaultAlgorithm.equals(defaultAlgorithm1)) { + assertTrue("Incorrect getKeySpec() result 2", + rks instanceof DESedeKeySpec); + } else { + assertTrue("Incorrect getKeySpec() result 2", + rks instanceof DESKeySpec); + } + } + } +} + +class mySecretKeyFactory extends SecretKeyFactory { + public mySecretKeyFactory(SecretKeyFactorySpi spi, Provider prov, String alg) { + super(spi, prov, alg); + } +} diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/SecretKeyTest.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/SecretKeyTest.java new file mode 100644 index 0000000..638c6f9 --- /dev/null +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/SecretKeyTest.java @@ -0,0 +1,84 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Vera Y. Petrashkova +* @version $Revision$ +*/ + +package org.apache.harmony.crypto.tests.javax.crypto; + +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + +import javax.crypto.SecretKey; + +import junit.framework.TestCase; + + +@TestTargetClass(SecretKey.class) +/** + * Tests for <code>SecretKey</code> class field + * + */ +public class SecretKeyTest extends TestCase { + + /** + * Constructor for SecretKeyTest. + * + * @param arg0 + */ + public SecretKeyTest(String arg0) { + super(arg0); + } + + /** + * Test for <code>serialVersionUID</code> field + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "!Constants", + methodArgs = {} + ) + }) + public void testField() { + checkSecretKey sk = new checkSecretKey(); + assertEquals("Incorrect serialVersionUID", + sk.getSerVerUID(), //SecretKey.serialVersionUID + -4795878709595146952L); + } + + public class checkSecretKey implements SecretKey { + public String getAlgorithm() { + return "SecretKey"; + } + public String getFormat() { + return "Format"; + } + public byte[] getEncoded() { + return new byte[0]; + } + public long getSerVerUID() { + return serialVersionUID; + } + } +} diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/ShortBufferExceptionTest.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/ShortBufferExceptionTest.java new file mode 100644 index 0000000..35ba2c5 --- /dev/null +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/ShortBufferExceptionTest.java @@ -0,0 +1,123 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Vera Y. Petrashkova +* @version $Revision$ +*/ + +package org.apache.harmony.crypto.tests.javax.crypto; + +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + +import javax.crypto.ShortBufferException; + +import junit.framework.TestCase; + +@TestTargetClass(ShortBufferException.class) +/** + * Tests for <code>ShortBufferException</code> class constructors and methods. + * + */ +public class ShortBufferExceptionTest extends TestCase { + + public static void main(String[] args) { + } + + /** + * Constructor for ShortBufferExceptionTests. + * + * @param arg0 + */ + public ShortBufferExceptionTest(String arg0) { + super(arg0); + } + + static String[] msgs = { + "", + "Check new message", + "Check new message Check new message Check new message Check new message Check new message" }; + + static Throwable tCause = new Throwable("Throwable for exception"); + + /** + * Test for <code>ShortBufferException()</code> constructor Assertion: + * constructs ShortBufferException with no detail message + */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "ShortBufferException", + methodArgs = {} + ) + }) + public void testShortBufferException01() { + ShortBufferException tE = new ShortBufferException(); + assertNull("getMessage() must return null.", tE.getMessage()); + assertNull("getCause() must return null", tE.getCause()); + } + + /** + * Test for <code>ShortBufferException(String)</code> constructor + * Assertion: constructs ShortBufferException with detail message msg. + * Parameter <code>msg</code> is not null. + */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "ShortBufferException", + methodArgs = {java.lang.String.class} + ) + }) + public void testShortBufferException02() { + ShortBufferException tE; + for (int i = 0; i < msgs.length; i++) { + tE = new ShortBufferException(msgs[i]); + assertEquals("getMessage() must return: ".concat(msgs[i]), tE + .getMessage(), msgs[i]); + assertNull("getCause() must return null", tE.getCause()); + } + } + + /** + * Test for <code>ShortBufferException(String)</code> constructor + * Assertion: constructs ShortBufferException when <code>msg</code> is + * null + */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "ShortBufferException", + methodArgs = {java.lang.String.class} + ) + }) + public void testShortBufferException03() { + String msg = null; + ShortBufferException tE = new ShortBufferException(msg); + assertNull("getMessage() must return null.", tE.getMessage()); + assertNull("getCause() must return null", tE.getCause()); + } +} diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/interfaces/AllTests.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/interfaces/AllTests.java new file mode 100644 index 0000000..bca63e6 --- /dev/null +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/interfaces/AllTests.java @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2007 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.harmony.crypto.tests.javax.crypto.interfaces; + +import junit.framework.Test; +import junit.framework.TestSuite; + +/** + * This is autogenerated source file. Includes tests for package org.apache.harmony.crypto.tests.javax.crypto.interfaces; + */ + +public class AllTests { + + public static void main(String[] args) { + junit.textui.TestRunner.run(AllTests.suite()); + } + + public static Test suite() { + TestSuite suite = new TestSuite("All tests for package org.apache.harmony.crypto.tests.javax.crypto.interfaces;"); + // $JUnit-BEGIN$ + + suite.addTestSuite(DHPrivateKeyTest.class); + suite.addTestSuite(DHPublicKeyTest.class); + suite.addTestSuite(PBEKeyTest.class); + + // $JUnit-END$ + return suite; + } +} diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/interfaces/DHPrivateKeyTest.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/interfaces/DHPrivateKeyTest.java new file mode 100644 index 0000000..3c65d24 --- /dev/null +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/interfaces/DHPrivateKeyTest.java @@ -0,0 +1,78 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Vera Y. Petrashkova +* @version $Revision$ +*/ + +package org.apache.harmony.crypto.tests.javax.crypto.interfaces; + +import javax.crypto.interfaces.DHPrivateKey; +import javax.crypto.spec.DHParameterSpec; + +import junit.framework.TestCase; + +import java.math.BigInteger; + + +/** + * Tests for <code>DHPrivateKey</code> class field + * + */ +public class DHPrivateKeyTest extends TestCase { + + /** + * Constructor for DHPrivateKey. + * + * @param arg0 + */ + public DHPrivateKeyTest(String arg0) { + super(arg0); + } + + /** + * Test for <code>serialVersionUID</code> field + */ + public void testField() { + checkDHPrivateKey key = new checkDHPrivateKey(); + assertEquals("Incorrect serialVersionUID", + key.getSerVerUID(), //DHPrivateKey.serialVersionUID + 2211791113380396553L); + } + + public class checkDHPrivateKey implements DHPrivateKey { + public String getAlgorithm() { + return "SecretKey"; + } + public String getFormat() { + return "Format"; + } + public byte[] getEncoded() { + return new byte[0]; + } + public long getSerVerUID() { + return serialVersionUID; + } + public BigInteger getX() { + return null; + } + public DHParameterSpec getParams() { + return null; + } + } +} diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/interfaces/DHPublicKeyTest.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/interfaces/DHPublicKeyTest.java new file mode 100644 index 0000000..b5121ee --- /dev/null +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/interfaces/DHPublicKeyTest.java @@ -0,0 +1,80 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Vera Y. Petrashkova +* @version $Revision$ +*/ + +package org.apache.harmony.crypto.tests.javax.crypto.interfaces; + +import java.math.BigInteger; + +import javax.crypto.interfaces.DHPublicKey; +import javax.crypto.spec.DHParameterSpec; + +import junit.framework.TestCase; + + +/** + * Tests for <code>DHPublicKey</code> class field + * + */ +public class DHPublicKeyTest extends TestCase { + + public static void main(String[] args) { + } + + /** + * Constructor for DHPublicKey. + * + * @param arg0 + */ + public DHPublicKeyTest(String arg0) { + super(arg0); + } + + /** + * Test for <code>serialVersionUID</code> field + */ + public void testField() { + checkDHPublicKey key = new checkDHPublicKey(); + assertEquals("Incorrect serialVersionUID", + key.getSerVerUID(), //DHPublicKey.serialVersionUID + -6628103563352519193L); + } + public class checkDHPublicKey implements DHPublicKey { + public String getAlgorithm() { + return "SecretKey"; + } + public String getFormat() { + return "Format"; + } + public byte[] getEncoded() { + return new byte[0]; + } + public long getSerVerUID() { + return serialVersionUID; + } + public BigInteger getY() { + return null; + } + public DHParameterSpec getParams() { + return null; + } + } +} diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/interfaces/PBEKeyTest.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/interfaces/PBEKeyTest.java new file mode 100644 index 0000000..5e0c21c --- /dev/null +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/interfaces/PBEKeyTest.java @@ -0,0 +1,83 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Vera Y. Petrashkova +* @version $Revision$ +*/ + +package org.apache.harmony.crypto.tests.javax.crypto.interfaces; + +import java.math.BigInteger; + +import javax.crypto.interfaces.PBEKey; + +import junit.framework.TestCase; + + +/** + * Tests for <code>PBEKey</code> class field + * + */ +public class PBEKeyTest extends TestCase { + + + /** + * Constructor for PBEKey. + * + * @param arg0 + */ + public PBEKeyTest(String arg0) { + super(arg0); + } + + /** + * Test for <code>serialVersionUID</code> field + */ + public void testField() { + checkPBEKey key = new checkPBEKey(); + assertEquals("Incorrect serialVersionUID", + key.getSerVerUID(), //PBEKey.serialVersionUID + -1430015993304333921L); + } + public class checkPBEKey implements PBEKey { + public String getAlgorithm() { + return "SecretKey"; + } + public String getFormat() { + return "Format"; + } + public byte[] getEncoded() { + return new byte[0]; + } + public long getSerVerUID() { + return serialVersionUID; + } + public BigInteger getY() { + return null; + } + public int getIterationCount() { + return 0; + } + public byte[] getSalt() { + return new byte[0]; + } + public char[] getPassword() { + return new char[0]; + } + } +} diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/serialization/AllTests.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/serialization/AllTests.java new file mode 100644 index 0000000..5bfa13f --- /dev/null +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/serialization/AllTests.java @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2007 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.harmony.crypto.tests.javax.crypto.serialization; + +import junit.framework.Test; +import junit.framework.TestSuite; + +/** + * This is autogenerated source file. Includes tests for package org.apache.harmony.crypto.tests.javax.crypto.serialization; + */ + +public class AllTests { + + public static void main(String[] args) { + junit.textui.TestRunner.run(AllTests.suite()); + } + + public static Test suite() { + TestSuite suite = new TestSuite("All tests for package org.apache.harmony.crypto.tests.javax.crypto.serialization;"); + // $JUnit-BEGIN$ + + suite.addTestSuite(BadPaddingExceptionTest.class); + suite.addTestSuite(ExemptionMechanismExceptionTest.class); + suite.addTestSuite(IllegalBlockSizeExceptionTest.class); + suite.addTestSuite(NoSuchPaddingExceptionTest.class); + suite.addTestSuite(ShortBufferExceptionTest.class); + + // $JUnit-END$ + return suite; + } +} diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/serialization/BadPaddingExceptionTest.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/serialization/BadPaddingExceptionTest.java new file mode 100644 index 0000000..2f632ae --- /dev/null +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/serialization/BadPaddingExceptionTest.java @@ -0,0 +1,49 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Vera Y. Petrashkova +* @version $Revision$ +*/ + +package org.apache.harmony.crypto.tests.javax.crypto.serialization; + +import javax.crypto.BadPaddingException; + +import org.apache.harmony.testframework.serialization.SerializationTest; + + +/** + * Test for BadPaddingException serialization + * + */ + +public class BadPaddingExceptionTest extends SerializationTest { + + public static String[] msgs = { + "New message", + "Long message for Exception. Long message for Exception. Long message for Exception." }; + + protected Object[] getData() { + return new Object[] { new BadPaddingException(), + new BadPaddingException(null), new BadPaddingException(msgs[1]) }; + } + + public static void main(String[] args) { + junit.textui.TestRunner.run(BadPaddingExceptionTest.class); + } +} diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/serialization/ExemptionMechanismExceptionTest.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/serialization/ExemptionMechanismExceptionTest.java new file mode 100644 index 0000000..7fd8cd0 --- /dev/null +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/serialization/ExemptionMechanismExceptionTest.java @@ -0,0 +1,49 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Vera Y. Petrashkova +* @version $Revision$ +*/ + +package org.apache.harmony.crypto.tests.javax.crypto.serialization; + +import javax.crypto.ExemptionMechanismException; + +import org.apache.harmony.testframework.serialization.SerializationTest; + + +/** + * Test for ExemptionMechanismException serialization + * + */ + +public class ExemptionMechanismExceptionTest extends SerializationTest { + + public static String[] msgs = { + "New message", + "Long message for Exception. Long message for Exception. Long message for Exception." }; + + protected Object[] getData() { + return new Object[] { new ExemptionMechanismException(), + new ExemptionMechanismException(null), new ExemptionMechanismException(msgs[1]) }; + } + + public static void main(String[] args) { + junit.textui.TestRunner.run(ExemptionMechanismExceptionTest.class); + } +} diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/serialization/IllegalBlockSizeExceptionTest.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/serialization/IllegalBlockSizeExceptionTest.java new file mode 100644 index 0000000..2cc1daa --- /dev/null +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/serialization/IllegalBlockSizeExceptionTest.java @@ -0,0 +1,49 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Vera Y. Petrashkova +* @version $Revision$ +*/ + +package org.apache.harmony.crypto.tests.javax.crypto.serialization; + +import javax.crypto.IllegalBlockSizeException; + +import org.apache.harmony.testframework.serialization.SerializationTest; + + +/** + * Test for IllegalBlockSizeException serialization + * + */ + +public class IllegalBlockSizeExceptionTest extends SerializationTest { + + public static String[] msgs = { + "New message", + "Long message for Exception. Long message for Exception. Long message for Exception." }; + + protected Object[] getData() { + return new Object[] { new IllegalBlockSizeException(), + new IllegalBlockSizeException(null), new IllegalBlockSizeException(msgs[1]) }; + } + + public static void main(String[] args) { + junit.textui.TestRunner.run(IllegalBlockSizeExceptionTest.class); + } +} diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/serialization/NoSuchPaddingExceptionTest.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/serialization/NoSuchPaddingExceptionTest.java new file mode 100644 index 0000000..475bd2f --- /dev/null +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/serialization/NoSuchPaddingExceptionTest.java @@ -0,0 +1,49 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Vera Y. Petrashkova +* @version $Revision$ +*/ + +package org.apache.harmony.crypto.tests.javax.crypto.serialization; + +import javax.crypto.NoSuchPaddingException; + +import org.apache.harmony.testframework.serialization.SerializationTest; + + +/** + * Test for NuSuchPaddingException serialization + * + */ + +public class NoSuchPaddingExceptionTest extends SerializationTest { + + public static String[] msgs = { + "New message", + "Long message for Exception. Long message for Exception. Long message for Exception." }; + + protected Object[] getData() { + return new Object[] { new NoSuchPaddingException(), + new NoSuchPaddingException(null), new NoSuchPaddingException(msgs[1]) }; + } + + public static void main(String[] args) { + junit.textui.TestRunner.run(NoSuchPaddingExceptionTest.class); + } +} diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/serialization/ShortBufferExceptionTest.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/serialization/ShortBufferExceptionTest.java new file mode 100644 index 0000000..ab696e8 --- /dev/null +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/serialization/ShortBufferExceptionTest.java @@ -0,0 +1,49 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Vera Y. Petrashkova +* @version $Revision$ +*/ + +package org.apache.harmony.crypto.tests.javax.crypto.serialization; + +import javax.crypto.ShortBufferException; + +import org.apache.harmony.testframework.serialization.SerializationTest; + + +/** + * Test for ShortBufferException serialization + * + */ + +public class ShortBufferExceptionTest extends SerializationTest { + + public static String[] msgs = { + "New message", + "Long message for Exception. Long message for Exception. Long message for Exception." }; + + protected Object[] getData() { + return new Object[] { new ShortBufferException(), + new ShortBufferException(null), new ShortBufferException(msgs[1]) }; + } + + public static void main(String[] args) { + junit.textui.TestRunner.run(ShortBufferExceptionTest.class); + } +} diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/AllTests.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/AllTests.java new file mode 100644 index 0000000..1afd486 --- /dev/null +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/AllTests.java @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2007 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.harmony.crypto.tests.javax.crypto.spec; + +import junit.framework.Test; +import junit.framework.TestSuite; + +/** + * This is autogenerated source file. Includes tests for package org.apache.harmony.crypto.tests.javax.crypto.spec; + */ + +public class AllTests { + + public static void main(String[] args) { + junit.textui.TestRunner.run(AllTests.suite()); + } + + public static Test suite() { + TestSuite suite = new TestSuite("All tests for package org.apache.harmony.crypto.tests.javax.crypto.spec;"); + // $JUnit-BEGIN$ + + suite.addTestSuite(DESKeySpecTest.class); + suite.addTestSuite(DESedeKeySpecTest.class); + suite.addTestSuite(DHGenParameterSpecTest.class); + suite.addTestSuite(DHParameterSpecTest.class); + suite.addTestSuite(DHPrivateKeySpecTest.class); + suite.addTestSuite(DHPublicKeySpecTest.class); + suite.addTestSuite(IvParameterSpecTest.class); + suite.addTestSuite(OAEPParameterSpecTest.class); + suite.addTestSuite(PBEKeySpecTest.class); + suite.addTestSuite(PBEParameterSpecTest.class); + suite.addTestSuite(PSourceTest.class); + suite.addTestSuite(RC2ParameterSpecTest.class); + suite.addTestSuite(RC5ParameterSpecTest.class); + suite.addTestSuite(SecretKeySpecTest.class); + + // $JUnit-END$ + return suite; + } +} diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/DESKeySpecTest.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/DESKeySpecTest.java new file mode 100644 index 0000000..706104f --- /dev/null +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/DESKeySpecTest.java @@ -0,0 +1,339 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** +* @author Alexander Y. Kleymenov +* @version $Revision$ +*/ + +package org.apache.harmony.crypto.tests.javax.crypto.spec; + +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + +import java.lang.NullPointerException; +import java.security.InvalidKeyException; +import java.util.Arrays; + +import javax.crypto.spec.DESKeySpec; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +@TestTargetClass(DESKeySpec.class) +/** + */ + +public class DESKeySpecTest extends TestCase { + + // DES weak and semi-weak keys + // Got from: + // FIP PUB 74 + // FEDERAL INFORMATION PROCESSING STANDARDS PUBLICATION 1981 + // GUIDELINES FOR IMPLEMENTING AND USING THE NBS DATA ENCRYPTION STANDARD + // http://www.dice.ucl.ac.be/crypto/standards/fips/fip74/fip74-1.pdf + private static final byte[][] semiweaks = { + {(byte) 0xE0, (byte) 0x01, (byte) 0xE0, (byte) 0x01, + (byte) 0xF1, (byte) 0x01, (byte) 0xF1, (byte) 0x01}, + + {(byte) 0x01, (byte) 0xE0, (byte) 0x01, (byte) 0xE0, + (byte) 0x01, (byte) 0xF1, (byte) 0x01, (byte) 0xF1}, + + {(byte) 0xFE, (byte) 0x1F, (byte) 0xFE, (byte) 0x1F, + (byte) 0xFE, (byte) 0x0E, (byte) 0xFE, (byte) 0x0E}, + + {(byte) 0x1F, (byte) 0xFE, (byte) 0x1F, (byte) 0xFE, + (byte) 0x0E, (byte) 0xFE, (byte) 0x0E, (byte) 0xFE}, + + {(byte) 0xE0, (byte) 0x1F, (byte) 0xE0, (byte) 0x1F, + (byte) 0xF1, (byte) 0x0E, (byte) 0xF1, (byte) 0x0E}, + + {(byte) 0x1F, (byte) 0xE0, (byte) 0x1F, (byte) 0xE0, + (byte) 0x0E, (byte) 0xF1, (byte) 0x0E, (byte) 0xF1}, + + {(byte) 0x01, (byte) 0xFE, (byte) 0x01, (byte) 0xFE, + (byte) 0x01, (byte) 0xFE, (byte) 0x01, (byte) 0xFE}, + + {(byte) 0xFE, (byte) 0x01, (byte) 0xFE, (byte) 0x01, + (byte) 0xFE, (byte) 0x01, (byte) 0xFE, (byte) 0x01}, + + {(byte) 0x01, (byte) 0x1F, (byte) 0x01, (byte) 0x1F, + (byte) 0x01, (byte) 0x0E, (byte) 0x01, (byte) 0x0E}, + + {(byte) 0x1F, (byte) 0x01, (byte) 0x1F, (byte) 0x01, + (byte) 0x0E, (byte) 0x01, (byte) 0x0E, (byte) 0x01}, + + {(byte) 0xE0, (byte) 0xFE, (byte) 0xE0, (byte) 0xFE, + (byte) 0xF1, (byte) 0xFE, (byte) 0xF1, (byte) 0xFE}, + + {(byte) 0xFE, (byte) 0xE0, (byte) 0xFE, (byte) 0xE0, + (byte) 0xFE, (byte) 0xF1, (byte) 0xFE, (byte) 0xF1}, + + {(byte) 0x01, (byte) 0x01, (byte) 0x01, (byte) 0x01, + (byte) 0x01, (byte) 0x01, (byte) 0x01, (byte) 0x01}, + + {(byte) 0xFE, (byte) 0xFE, (byte) 0xFE, (byte) 0xFE, + (byte) 0xFE, (byte) 0xFE, (byte) 0xFE, (byte) 0xFE}, + + {(byte) 0xE0, (byte) 0xE0, (byte) 0xE0, (byte) 0xE0, + (byte) 0xF1, (byte) 0xF1, (byte) 0xF1, (byte) 0xF1}, + + {(byte) 0x1F, (byte) 0x1F, (byte) 0x1F, (byte) 0x1F, + (byte) 0x0E, (byte) 0x0E, (byte) 0x0E, (byte) 0x0E}, + }; + + /* DES not weak or semi-weak keys */ + private static final byte[][] notsemiweaks = { + {(byte) 0x1f, (byte) 0x1f, (byte) 0x1f, (byte) 0x1f, + (byte) 0x1f, (byte) 0x1f, (byte) 0x1f, (byte) 0x1f}, + + {(byte) 0xe0, (byte) 0xe0, (byte) 0xe0, (byte) 0xe0, + (byte) 0xe0, (byte) 0xe0, (byte) 0xe0, (byte) 0xe0} + }; + /** + * Constructors testing. Tests behavior of each of two constructors + * in the cases of: null array, short array, normal array. + */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "Checks both constructors.", + targets = { + @TestTarget( + methodName = "DESKeySpec", + methodArgs = {byte[].class} + ), @TestTarget( + methodName = "DESKeySpec", + methodArgs = {byte[].class, int.class} + ) + }) + public void testDESKeySpec() { + try { + new DESKeySpec((byte []) null); + fail("Should raise an NullPointerException " + + "in case of null byte array."); + } catch (NullPointerException e) { + } catch (InvalidKeyException e) { + fail("Should raise an NullPointerException " + + "in case of null byte array."); + } + try { + new DESKeySpec(new byte [] {1, 2, 3}); + fail("Should raise an InvalidKeyException on a short byte array."); + } catch (NullPointerException e) { + fail("Unexpected NullPointerException was thrown."); + } catch (InvalidKeyException e) { + } + try { + new DESKeySpec(new byte[] {1, 2, 3, 4, 5, 6, 7, 8}); + } catch (NullPointerException e) { + fail("Unexpected NullPointerException was thrown."); + } catch (InvalidKeyException e) { + fail("Unexpected InvalidKeyException was thrown."); + } + try { + new DESKeySpec((byte []) null, 1); + fail("Should raise an NullPointerException " + + "in case of null byte array."); + } catch (NullPointerException e) { + } catch (InvalidKeyException e) { + fail("Should raise an NullPointerException " + + "in case of null byte array."); + } + try { + new DESKeySpec(new byte [] {1, 2, 3, 4, 5, 6, 7, 8}, 1); + fail("Should raise an InvalidKeyException on a short byte array."); + } catch (NullPointerException e) { + fail("Unexpected NullPointerException was thrown."); + } catch (InvalidKeyException e) { + } + try { + new DESKeySpec(new byte[] {1, 2, 3, 4, 5, 6, 7, 8, 9}, 1); + } catch (NullPointerException e) { + fail("Unexpected NullPointerException was thrown."); + } catch (InvalidKeyException e) { + fail("Unexpected InvalidKeyException was thrown."); + } + } + + /** + * getKey() method testing. Checks that modification of returned key + * does not affect the internal key. Also test check an equality of + * the key with the key specified in the constructor. The object under + * the test is created by different constructors. + */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getKey", + methodArgs = {} + ) + }) + public void testGetKey() { + byte[] key = {1, 2, 3, 4, 5, 6, 7, 8}; + DESKeySpec ks; + try { + ks = new DESKeySpec(key); + } catch (InvalidKeyException e) { + fail("InvalidKeyException should not be thrown."); + return; + } + byte[] res = ks.getKey(); + assertTrue("The returned array should be equal to the specified " + + "in constructor.", Arrays.equals(key, res)); + res[0] += 1; + assertFalse("The modification of returned key should not affect" + + "the underlying key.", key[0] == res[0]); + + byte[] key1 = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0}; + try { + ks = new DESKeySpec(key1, 2); + } catch (InvalidKeyException e) { + fail("InvalidKeyException should not be thrown."); + return; + } + res = ks.getKey(); + assertNotSame("The returned array should not be the same object " + + "as specified in a constructor.", key1, res); + byte[] exp = new byte[8]; + System.arraycopy(key1, 2, exp, 0, 8); + assertTrue("The returned array should be equal to the specified " + + "in constructor.", Arrays.equals(exp, res)); + } + + /** + * isParityAdjusted(byte[] key, offset) method testing. Tests if the + * method throws appropriate exceptions on incorrect byte array, if + * it returns false on the key which is not parity adjusted, and if + * it returns true on parity adjusted key. + */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "isParityAdjusted", + methodArgs = {byte[].class, int.class} + ) + }) + public void testIsParityAdjusted() { + try { + DESKeySpec.isParityAdjusted(null, 1); + fail("Should raise an InvalidKeyException " + + "in case of null byte array."); + } catch (NullPointerException e) { + fail("Unexpected NullPointerException was thrown."); + } catch (InvalidKeyException e) { + } + + byte[] key = {1, 2, 3, 4, 5, 6, 7, 8}; + try { + DESKeySpec.isParityAdjusted(key, 1); + fail("Should raise an InvalidKeyException " + + "in case of short byte array."); + } catch (NullPointerException e) { + fail("Unexpected NullPointerException was thrown."); + } catch (InvalidKeyException e) { + } + + byte[] key_not_pa = {1, 2, 3, 4, 5, 6, 7, 8}; + try { + assertFalse("Method returns true when false is expected.", + DESKeySpec.isParityAdjusted(key_not_pa, 0)); + } catch (NullPointerException e) { + fail("Unexpected NullPointerException was thrown."); + } catch (InvalidKeyException e) { + fail("Unexpected InvalidKeyException was thrown."); + } + + byte[] key_pa = {(byte) 128, (byte) 131, (byte) 133, (byte) 134, + (byte) 137, (byte) 138, (byte) 140, (byte) 143}; + try { + assertTrue("Method returns false when true is expected.", + DESKeySpec.isParityAdjusted(key_pa, 0)); + } catch (NullPointerException e) { + fail("Unexpected NullPointerException was thrown."); + } catch (InvalidKeyException e) { + fail("Unexpected InvalidKeyException was thrown."); + } + } + + /** + * isWeak(byte[] key, int offset) method testing. Tests if the + * method throws appropriate exceptions on incorrect byte array, if + * it returns true on weak or semi-weak keys, and if it returns + * false on other keys. + */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "isWeak", + methodArgs = {byte[].class, int.class} + ) + }) + public void testIsWeak() { + try { + DESKeySpec.isWeak(null, 1); + fail("Should raise an InvalidKeyException " + + "in case of null byte array."); + } catch (NullPointerException e) { + fail("Unexpected NullPointerException was thrown."); + } catch (InvalidKeyException e) { + } + + byte[] key = {1, 2, 3, 4, 5, 6, 7, 8}; + try { + DESKeySpec.isWeak(key, 1); + fail("Should raise an InvalidKeyException " + + "in case of short byte array."); + } catch (NullPointerException e) { + fail("Unexpected NullPointerException was thrown."); + } catch (InvalidKeyException e) { + } + + for (int i=0; i<semiweaks.length; i++) { + try { + assertTrue("Method returns false when true is expected", + DESKeySpec.isWeak(semiweaks[i], 0)); + } catch (InvalidKeyException e) { + fail("Unexpected InvalidKeyException was thrown."); + } + } + for (int i=0; i<notsemiweaks.length; i++) { + try { + assertFalse("Method returns true when false is expected", + DESKeySpec.isWeak(notsemiweaks[i], 0)); + } catch (InvalidKeyException e) { + fail("Unexpected InvalidKeyException was thrown."); + } + } + } + + public static Test suite() { + return new TestSuite(DESKeySpecTest.class); + } + + public static void main(String args[]) { + junit.textui.TestRunner.run(suite()); + } +} + diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/DESedeKeySpecTest.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/DESedeKeySpecTest.java new file mode 100644 index 0000000..038e3fc --- /dev/null +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/DESedeKeySpecTest.java @@ -0,0 +1,238 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Alexander Y. Kleymenov +* @version $Revision$ +*/ + +package org.apache.harmony.crypto.tests.javax.crypto.spec; + +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + +import java.lang.NullPointerException; +import java.security.InvalidKeyException; +import java.util.Arrays; + +import javax.crypto.spec.DESedeKeySpec; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +@TestTargetClass(DESedeKeySpec.class) +/** + */ + +public class DESedeKeySpecTest extends TestCase { + + /** + * Constructors testing. Tests behavior of each of two constructors + * in the cases of: null array, short array, normal array. + */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "Checks both constructors.", + targets = { + @TestTarget( + methodName = "DESedeKeySpec", + methodArgs = {byte[].class} + ), @TestTarget( + methodName = "DESedeKeySpec", + methodArgs = {byte[].class, int.class} + ) + }) + public void testDESedeKeySpec() { + try { + new DESedeKeySpec((byte []) null); + fail("Should raise an NullPointerException " + + "in case of null byte array."); + } catch (NullPointerException e) { + } catch (InvalidKeyException e) { + fail("Should raise an NullPointerException " + + "in case of null byte array."); + } + try { + new DESedeKeySpec(new byte [] {1, 2, 3}); + fail("Should raise an InvalidKeyException on a short byte array."); + } catch (NullPointerException e) { + fail("Unexpected NullPointerException was thrown."); + } catch (InvalidKeyException e) { + } + try { + new DESedeKeySpec(new byte[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 0, + 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, + 1, 2, 3, 4}); + } catch (NullPointerException e) { + fail("Unexpected NullPointerException was thrown."); + } catch (InvalidKeyException e) { + fail("Unexpected InvalidKeyException was thrown."); + } + try { + new DESedeKeySpec((byte []) null, 1); + fail("Should raise an NullPointerException " + + "in case of null byte array."); + } catch (NullPointerException e) { + } catch (InvalidKeyException e) { + fail("Should raise an NullPointerException " + + "in case of null byte array."); + } + try { + new DESedeKeySpec(new byte [] {1, 2, 3, 4, 5, 6, 7, 8, 9, 0, + 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, + 1, 2, 3, 4}, 1); + fail("Should raise an InvalidKeyException on a short byte array."); + } catch (NullPointerException e) { + fail("Unexpected NullPointerException was thrown."); + } catch (InvalidKeyException e) { + } + try { + new DESedeKeySpec(new byte[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 0, + 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, + 1, 2, 3, 4, 5}, 1); + } catch (NullPointerException e) { + fail("Unexpected NullPointerException was thrown."); + } catch (InvalidKeyException e) { + fail("Unexpected InvalidKeyException was thrown."); + } + } + + /** + * getKey() method testing. Checks that modification of returned key + * does not affect the internal key. Also test check an equality of + * the key with the key specified in the constructor. The object under + * the test is created by different constructors. + */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getKey", + methodArgs = {} + ) + }) + public void testGetKey() { + byte[] key = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, + 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2}; + DESedeKeySpec ks; + try { + ks = new DESedeKeySpec(key); + } catch (InvalidKeyException e) { + fail("InvalidKeyException should not be thrown."); + return; + } + byte[] res = ks.getKey(); + assertTrue("The returned array should be equal to the specified " + + "in constructor.", Arrays.equals(key, res)); + res[0] += 1; + assertFalse("The modification of returned key should not affect" + + "the underlying key.", key[0] == res[0]); + + byte[] key1 = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, + 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3}; + try { + ks = new DESedeKeySpec(key1, 2); + } catch (InvalidKeyException e) { + fail("InvalidKeyException should not be thrown."); + return; + } + res = ks.getKey(); + assertNotSame("The returned array should not be the same object " + + "as specified in a constructor.", key1, res); + byte[] exp = new byte[24]; + System.arraycopy(key1, 2, exp, 0, 24); + assertTrue("The returned array should be equal to the specified " + + "in constructor.", Arrays.equals(exp, res)); + } + + /** + * isParityAdjusted(byte[] key, offset) method testing. Tests if the + * method throws appropriate exceptions on incorrect byte array, if + * it returns false on the key which is not parity adjusted, and if + * it returns true on parity adjusted key. + */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "isParityAdjusted", + methodArgs = {byte[].class, int.class} + ) + }) + public void testIsParityAdjusted() { + try { + DESedeKeySpec.isParityAdjusted(null, 1); + fail("Should raise an NullPointerException " + + "in case of null byte array."); + } catch (NullPointerException e) { + } catch (InvalidKeyException e) { + fail("Should raise an NullPointerException " + + "in case of null byte array."); + } + + byte[] key = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0, + 1, 2, 3, 4, 5, 6, 7, 8, 9, 0}; + try { + DESedeKeySpec.isParityAdjusted(key, 1); + fail("Should raise an InvalidKeyException " + + "in case of short byte array."); + } catch (NullPointerException e) { + fail("Unexpected NullPointerException was thrown."); + } catch (InvalidKeyException e) { + } + + byte[] key_not_pa = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, + 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2}; + try { + assertFalse("Method returns true when false is expected.", + DESedeKeySpec.isParityAdjusted(key_not_pa, 0)); + } catch (NullPointerException e) { + fail("Unexpected NullPointerException was thrown."); + } catch (InvalidKeyException e) { + fail("Unexpected InvalidKeyException was thrown."); + } + + byte[] key_pa = {(byte) 128, (byte) 131, (byte) 133, (byte) 134, + (byte) 137, (byte) 138, (byte) 140, (byte) 143, + (byte) 145, (byte) 146, (byte) 148, (byte) 151, + (byte) 152, (byte) 155, (byte) 157, (byte) 158, + (byte) 161, (byte) 162, (byte) 164, (byte) 167, + (byte) 168, (byte) 171, (byte) 173, (byte) 174}; + try { + assertTrue("Method returns false when true is expected.", + DESedeKeySpec.isParityAdjusted(key_pa, 0)); + } catch (NullPointerException e) { + fail("Unexpected NullPointerException was thrown."); + } catch (InvalidKeyException e) { + fail("Unexpected InvalidKeyException was thrown."); + } + } + + public static Test suite() { + return new TestSuite(DESedeKeySpecTest.class); + } + + public static void main(String args[]) { + junit.textui.TestRunner.run(suite()); + } +} + diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/DHGenParameterSpecTest.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/DHGenParameterSpecTest.java new file mode 100644 index 0000000..2f379c3 --- /dev/null +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/DHGenParameterSpecTest.java @@ -0,0 +1,87 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Alexander Y. Kleymenov +* @version $Revision$ +*/ + +package org.apache.harmony.crypto.tests.javax.crypto.spec; + +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + +import java.lang.Integer; + +import javax.crypto.spec.DHGenParameterSpec; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +@TestTargetClass(DHGenParameterSpec.class) +/** + */ + +public class DHGenParameterSpecTest extends TestCase { + + /** + * DHGenParameterSpec class testing. Tests the equivalence of + * parameters specified in the constructor with the values returned + * by getters. + */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "All functionality tested in one method. Probably it should be divided into several tests.", + targets = { + @TestTarget( + methodName = "DHGenParameterSpec", + methodArgs = {int.class, int.class} + ), @TestTarget( + methodName = "getExponentSize", + methodArgs = {} + ), @TestTarget( + methodName = "getPrimeSize", + methodArgs = {} + ) + }) + public void testDHGenParameterSpec() { + int[] primes = {Integer.MIN_VALUE, -1, 0, 1, Integer.MAX_VALUE}; + int[] exponents = {Integer.MIN_VALUE, -1, 0, 1, Integer.MAX_VALUE}; + for (int i=0; i<primes.length; i++) { + DHGenParameterSpec ps = new DHGenParameterSpec(primes[i], + exponents[i]); + assertEquals("The value returned by getPrimeSize() must be " + + "equal to the value specified in the constructor", + ps.getPrimeSize(), primes[i]); + assertEquals("The value returned by getExponentSize() must be " + + "equal to the value specified in the constructor", + ps.getPrimeSize(), exponents[i]); + } + } + + public static Test suite() { + return new TestSuite(DHGenParameterSpecTest.class); + } + + public static void main(String[] args) { + junit.textui.TestRunner.run(suite()); + } +} + diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/DHParameterSpecTest.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/DHParameterSpecTest.java new file mode 100644 index 0000000..0ffd340 --- /dev/null +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/DHParameterSpecTest.java @@ -0,0 +1,108 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Alexander Y. Kleymenov +* @version $Revision$ +*/ + +package org.apache.harmony.crypto.tests.javax.crypto.spec; + +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + +import java.lang.Integer; +import java.math.BigInteger; + +import javax.crypto.spec.DHParameterSpec; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +@TestTargetClass(DHParameterSpec.class) +/** + */ + +public class DHParameterSpecTest extends TestCase { + + /** + * DHParameterSpec class testing. Tests the equivalence of parameters + * specified in the constructor with the values returned by getters. + * The tested object is created by different constructors. + */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "All functionality tested in one method. Probably it should be divided into several tests.", + targets = { + @TestTarget( + methodName = "DHParameterSpec", + methodArgs = {java.math.BigInteger.class, java.math.BigInteger.class} + ), @TestTarget( + methodName = "DHParameterSpec", + methodArgs = {java.math.BigInteger.class, java.math.BigInteger.class, int.class} + ), @TestTarget( + methodName = "getG", + methodArgs = {} + ), @TestTarget( + methodName = "getL", + methodArgs = {} + ), @TestTarget( + methodName = "getP", + methodArgs = {} + ) + }) + public void testDHParameterSpec() { + BigInteger[] ps = {new BigInteger("-1000000000000"), BigInteger.ZERO, + BigInteger.ONE, new BigInteger("1000000000000")}; + BigInteger[] gs = {new BigInteger("-1000000000000"), BigInteger.ZERO, + BigInteger.ONE, new BigInteger("1000000000000")}; + int[] ls = {Integer.MIN_VALUE, 0, 1, Integer.MAX_VALUE}; + for (int i=0; i<ps.length; i++) { + DHParameterSpec dhps = new DHParameterSpec(ps[i], gs[i]); + assertEquals("The value returned by getP() must be " + + "equal to the value specified in the constructor", + dhps.getP(), ps[i]); + assertEquals("The value returned by getG() must be " + + "equal to the value specified in the constructor", + dhps.getG(), gs[i]); + } + for (int i=0; i<ps.length; i++) { + DHParameterSpec dhps = new DHParameterSpec(ps[i], gs[i], ls[i]); + assertEquals("The value returned by getP() must be " + + "equal to the value specified in the constructor", + dhps.getP(), ps[i]); + assertEquals("The value returned by getG() must be " + + "equal to the value specified in the constructor", + dhps.getG(), gs[i]); + assertEquals("The value returned by getL() must be " + + "equal to the value specified in the constructor", + dhps.getL(), ls[i]); + } + } + + public static Test suite() { + return new TestSuite(DHParameterSpecTest.class); + } + + public static void main(String[] args) { + junit.textui.TestRunner.run(suite()); + } +} + diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/DHPrivateKeySpecTest.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/DHPrivateKeySpecTest.java new file mode 100644 index 0000000..783032e --- /dev/null +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/DHPrivateKeySpecTest.java @@ -0,0 +1,95 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Alexander Y. Kleymenov +* @version $Revision$ +*/ + +package org.apache.harmony.crypto.tests.javax.crypto.spec; + +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + +import java.math.BigInteger; + +import javax.crypto.spec.DHPrivateKeySpec; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +@TestTargetClass(DHPrivateKeySpec.class) +/** + */ + +public class DHPrivateKeySpecTest extends TestCase { + + /** + * DHPrivateKeySpec class testing. Tests the equivalence of parameters + * specified in the constructor with the values returned by getters. + */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "All functionality tested in one method. Probably it should be divided into several tests.", + targets = { + @TestTarget( + methodName = "DHPrivateKeySpec", + methodArgs = {java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class} + ), @TestTarget( + methodName = "getG", + methodArgs = {} + ), @TestTarget( + methodName = "getP", + methodArgs = {} + ), @TestTarget( + methodName = "getX", + methodArgs = {} + ) + }) + public void testDHPrivateKeySpec() { + BigInteger[] xs = {new BigInteger("-1000000000000"), BigInteger.ZERO, + BigInteger.ONE, new BigInteger("1000000000000")}; + BigInteger[] ps = {new BigInteger("-1000000000000"), BigInteger.ZERO, + BigInteger.ONE, new BigInteger("1000000000000")}; + BigInteger[] gs = {new BigInteger("-1000000000000"), BigInteger.ZERO, + BigInteger.ONE, new BigInteger("1000000000000")}; + for (int i=0; i<ps.length; i++) { + DHPrivateKeySpec dhpks = new DHPrivateKeySpec(xs[i], ps[i], gs[i]); + assertEquals("The value returned by getX() must be " + + "equal to the value specified in the constructor", + dhpks.getX(), xs[i]); + assertEquals("The value returned by getP() must be " + + "equal to the value specified in the constructor", + dhpks.getP(), ps[i]); + assertEquals("The value returned by getG() must be " + + "equal to the value specified in the constructor", + dhpks.getG(), gs[i]); + } + } + + public static Test suite() { + return new TestSuite(DHPrivateKeySpecTest.class); + } + + public static void main(String[] args) { + junit.textui.TestRunner.run(suite()); + } +} + diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/DHPublicKeySpecTest.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/DHPublicKeySpecTest.java new file mode 100644 index 0000000..24b4cdc --- /dev/null +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/DHPublicKeySpecTest.java @@ -0,0 +1,95 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Alexander Y. Kleymenov +* @version $Revision$ +*/ + +package org.apache.harmony.crypto.tests.javax.crypto.spec; + +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + +import java.math.BigInteger; + +import javax.crypto.spec.DHPublicKeySpec; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +@TestTargetClass(DHPublicKeySpec.class) +/** + */ + +public class DHPublicKeySpecTest extends TestCase { + + /** + * DHPublicKeySpec class testing. Tests the equivalence of parameters + * specified in the constructor with the values returned by getters. + */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "All functionality tested in one method. Probably it should be divided into several tests.", + targets = { + @TestTarget( + methodName = "DHPublicKeySpec", + methodArgs = {java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class} + ), @TestTarget( + methodName = "getG", + methodArgs = {} + ), @TestTarget( + methodName = "getP", + methodArgs = {} + ), @TestTarget( + methodName = "getY", + methodArgs = {} + ) + }) + public void testDHPrivateKeySpec() { + BigInteger[] ys = {new BigInteger("-1000000000000"), BigInteger.ZERO, + BigInteger.ONE, new BigInteger("1000000000000")}; + BigInteger[] ps = {new BigInteger("-1000000000000"), BigInteger.ZERO, + BigInteger.ONE, new BigInteger("1000000000000")}; + BigInteger[] gs = {new BigInteger("-1000000000000"), BigInteger.ZERO, + BigInteger.ONE, new BigInteger("1000000000000")}; + for (int i=0; i<ps.length; i++) { + DHPublicKeySpec dhpks = new DHPublicKeySpec(ys[i], ps[i], gs[i]); + assertEquals("The value returned by getY() must be " + + "equal to the value specified in the constructor", + dhpks.getY(), ys[i]); + assertEquals("The value returned by getP() must be " + + "equal to the value specified in the constructor", + dhpks.getP(), ps[i]); + assertEquals("The value returned by getG() must be " + + "equal to the value specified in the constructor", + dhpks.getG(), gs[i]); + } + } + + public static Test suite() { + return new TestSuite(DHPublicKeySpecTest.class); + } + + public static void main(String[] args) { + junit.textui.TestRunner.run(suite()); + } +} + diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/IvParameterSpecTest.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/IvParameterSpecTest.java new file mode 100644 index 0000000..4d5be6b --- /dev/null +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/IvParameterSpecTest.java @@ -0,0 +1,177 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Alexander Y. Kleymenov +* @version $Revision$ +*/ + +package org.apache.harmony.crypto.tests.javax.crypto.spec; + +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + +import java.lang.NullPointerException; +import java.lang.IllegalArgumentException; +import java.lang.ArrayIndexOutOfBoundsException; + +import javax.crypto.spec.IvParameterSpec; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +@TestTargetClass(IvParameterSpec.class) +/** + */ + +public class IvParameterSpecTest extends TestCase { + + /** + * IvParameterSpec(byte[] iv) constructor testing. Checks that + * NullPointerException is thrown in the case of null input + * array and that input array is copied during initialization. + */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "IvParameterSpec", + methodArgs = {byte[].class} + ) + }) + public void testIvParameterSpec1() { + try { + new IvParameterSpec(null); + fail("Should raise an NullPointerException " + + "in the case of null byte array."); + } catch(NullPointerException e) { + } + + byte[] iv = new byte[] {1, 2, 3, 4, 5}; + IvParameterSpec ivps = new IvParameterSpec(iv); + iv[0] ++; + assertFalse("The change of input array's content should not cause " + + "the change of internal array", iv[0] == ivps.getIV()[0]); + } + + /** + * IvParameterSpec(byte[] iv) constructor testing. Checks that + * NullPointerException is thrown in the case of null input + * array and that input array is copied during initialization. + */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "IvParameterSpec", + methodArgs = {byte[].class, int.class, int.class} + ) + }) + public void testIvParameterSpec2() { + try { + new IvParameterSpec(null, 1, 1); + fail("Should raise an IllegalArgumentException " + + "in the case of null byte array."); + } catch(ArrayIndexOutOfBoundsException e) { + fail("Unexpected ArrayIndexOutOfBoundsException was thrown"); + } catch(IllegalArgumentException e) { + } catch(NullPointerException e) { + fail("Unexpected NullPointerException was thrown"); + } + + try { + new IvParameterSpec(new byte[] {1, 2, 3}, 2, 2); + fail("Should raise an IllegalArgumentException " + + "if (iv.length - offset < len)."); + } catch(ArrayIndexOutOfBoundsException e) { + fail("Unexpected ArrayIndexOutOfBoundsException was thrown"); + } catch(IllegalArgumentException e) { + } catch(NullPointerException e) { + fail("Unexpected NullPointerException was thrown"); + } + + try { + new IvParameterSpec(new byte[] {1, 2, 3}, -1, 1); + fail("Should raise an ArrayIndexOutOfBoundsException " + + "if offset index bytes outside the iv."); + } catch(ArrayIndexOutOfBoundsException e) { + } catch(IllegalArgumentException e) { + fail("Unexpected IllegalArgumentException was thrown"); + } catch(NullPointerException e) { + fail("Unexpected NullPointerException was thrown"); + } + + /* TODO: DRL fail with java.lang.NegativeArraySizeException + try { + new IvParameterSpec(new byte[] {1, 2, 3}, 1, -2); + fail("Should raise an ArrayIndexOutOfBoundsException " + + "if len index bytes outside the iv."); + } catch(ArrayIndexOutOfBoundsException e) { + } catch(IllegalArgumentException e) { + fail("Unexpected IllegalArgumentException was thrown"); + } catch(NullPointerException e) { + fail("Unexpected NullPointerException was thrown"); + } + */ + + byte[] iv = new byte[] {1, 2, 3, 4, 5}; + IvParameterSpec ivps = new IvParameterSpec(iv, 0, iv.length); + iv[0] ++; + assertFalse("The change of input array's content should not cause " + + "the change of internal array", iv[0] == ivps.getIV()[0]); + + //Regression for HARMONY-1089 + try { + new IvParameterSpec(new byte[2], 2, -1); + fail("ArrayIndexOutOfBoundsException expected"); + } catch (ArrayIndexOutOfBoundsException e) { + //expected + } + } + +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getIV", + methodArgs = {} + ) + }) + public void testGetIV() { + byte[] iv = new byte[] {1, 2, 3, 4, 5}; + IvParameterSpec ivps = new IvParameterSpec(iv); + iv = ivps.getIV(); + iv[0] ++; + assertFalse("The change of returned array should not cause " + + "the change of internal array", iv[0] == ivps.getIV()[0]); + } + + public static Test suite() { + return new TestSuite(IvParameterSpecTest.class); + } + + public static void main(String[] args) { + junit.textui.TestRunner.run(suite()); + } +} + diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/OAEPParameterSpecTest.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/OAEPParameterSpecTest.java new file mode 100644 index 0000000..43e38c6 --- /dev/null +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/OAEPParameterSpecTest.java @@ -0,0 +1,217 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Alexander Y. Kleymenov +* @version $Revision$ +*/ + +package org.apache.harmony.crypto.tests.javax.crypto.spec; + +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + +import java.security.spec.MGF1ParameterSpec; +import java.security.spec.AlgorithmParameterSpec; + +import javax.crypto.spec.OAEPParameterSpec; +import javax.crypto.spec.PSource; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +@TestTargetClass(OAEPParameterSpec.class) +/** + */ + +public class OAEPParameterSpecTest extends TestCase { + + /** + * OAEPParameterSpec(String mdName, String mgfName, AlgorithmParameterSpec + * mgfSpec, PSource pSrc) method testing. Tests that NullPointerException + * is thrown in the case of inappropriate constructor parameters and checks + * the value of DEFAULT field. + */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "OAEPParameterSpec", + methodArgs = {java.lang.String.class, java.lang.String.class, java.security.spec.AlgorithmParameterSpec.class, javax.crypto.spec.PSource.class} + ) + }) + public void testOAEPParameterSpec() { + // using init values for OAEPParameterSpec.DEFAULT + String mdName = "SHA-1"; + String mgfName = "MGF1"; + AlgorithmParameterSpec mgfSpec = MGF1ParameterSpec.SHA1; + PSource pSrc = PSource.PSpecified.DEFAULT; + + try { + new OAEPParameterSpec(null, mgfName, mgfSpec, pSrc); + fail("NullPointerException should be thrown in the case of " + + "null mdName."); + } catch (NullPointerException e) { + } + + try { + new OAEPParameterSpec(mdName, null, mgfSpec, pSrc); + fail("NullPointerException should be thrown in the case of " + + "null mgfName."); + } catch (NullPointerException e) { + } + + try { + new OAEPParameterSpec(mdName, mgfName, mgfSpec, null); + fail("NullPointerException should be thrown in the case of " + + "null pSrc."); + } catch (NullPointerException e) { + } + + assertTrue("The message digest algorithm name of " + + "OAEPParameterSpec.DEFAULT field should be " + mdName, + OAEPParameterSpec.DEFAULT.getDigestAlgorithm().equals(mdName)); + + assertTrue("The mask generation function algorithm name of " + + "OAEPParameterSpec.DEFAULT field should be " + mgfName, + OAEPParameterSpec.DEFAULT.getMGFAlgorithm().equals(mgfName)); + + assertTrue("The mask generation function parameters of " + + "OAEPParameterSpec.DEFAULT field should be the same object " + + "as MGF1ParameterSpec.SHA1", + OAEPParameterSpec.DEFAULT.getMGFParameters() + == MGF1ParameterSpec.SHA1); + assertTrue("The source of the encoding input P of " + + "OAEPParameterSpec.DEFAULT field should be the same object " + + "PSource.PSpecified.DEFAULT", + OAEPParameterSpec.DEFAULT.getPSource() + == PSource.PSpecified.DEFAULT); + } + + /** + * getDigestAlgorithm() method testing. + */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getDigestAlgorithm", + methodArgs = {} + ) + }) + public void testGetDigestAlgorithm() { + String mdName = "SHA-1"; + String mgfName = "MGF1"; + AlgorithmParameterSpec mgfSpec = MGF1ParameterSpec.SHA1; + PSource pSrc = PSource.PSpecified.DEFAULT; + + OAEPParameterSpec ps = new OAEPParameterSpec(mdName, mgfName, + mgfSpec, pSrc); + assertTrue("The returned value does not equal to the " + + "value specified in the constructor.", + ps.getDigestAlgorithm().equals(mdName)); + } + + /** + * getMGFAlgorithm() method testing. + */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getMGFAlgorithm", + methodArgs = {} + ) + }) + public void testGetMGFAlgorithm() { + String mdName = "SHA-1"; + String mgfName = "MGF1"; + AlgorithmParameterSpec mgfSpec = MGF1ParameterSpec.SHA1; + PSource pSrc = PSource.PSpecified.DEFAULT; + + OAEPParameterSpec ps = new OAEPParameterSpec(mdName, mgfName, + mgfSpec, pSrc); + assertTrue("The returned value does not equal to the " + + "value specified in the constructor.", + ps.getMGFAlgorithm().equals(mgfName)); + } + + /** + * getMGFParameters() method testing. + */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getMGFParameters", + methodArgs = {} + ) + }) + public void testGetMGFParameters() { + String mdName = "SHA-1"; + String mgfName = "MGF1"; + AlgorithmParameterSpec mgfSpec = MGF1ParameterSpec.SHA1; + PSource pSrc = PSource.PSpecified.DEFAULT; + + OAEPParameterSpec ps = new OAEPParameterSpec(mdName, mgfName, + mgfSpec, pSrc); + assertTrue("The returned value does not equal to the " + + "value specified in the constructor.", + ps.getMGFParameters() == mgfSpec); + } + + /** + * getPSource() method testing. + */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getPSource", + methodArgs = {} + ) + }) + public void testGetPSource() { + String mdName = "SHA-1"; + String mgfName = "MGF1"; + AlgorithmParameterSpec mgfSpec = MGF1ParameterSpec.SHA1; + PSource pSrc = PSource.PSpecified.DEFAULT; + + OAEPParameterSpec ps = new OAEPParameterSpec(mdName, mgfName, + mgfSpec, pSrc); + assertTrue("The returned value does not equal to the " + + "value specified in the constructor.", + ps.getPSource() == pSrc); + } + + public static Test suite() { + return new TestSuite(OAEPParameterSpecTest.class); + } + + public static void main(String[] args) { + junit.textui.TestRunner.run(suite()); + } +} + diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/PBEKeySpecTest.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/PBEKeySpecTest.java new file mode 100644 index 0000000..7aba77f --- /dev/null +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/PBEKeySpecTest.java @@ -0,0 +1,388 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Alexander Y. Kleymenov +* @version $Revision$ +*/ + +package org.apache.harmony.crypto.tests.javax.crypto.spec; + +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + +import java.util.Arrays; + +import javax.crypto.spec.PBEKeySpec; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +@TestTargetClass(PBEKeySpec.class) +/** + */ + +public class PBEKeySpecTest extends TestCase { + + /** + * PBEKeySpec(char[] password) method testing. Tests the behavior of + * the method in the case of null input char array and tests that input + * array is copied during the object initialization. + */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "PBEKeySpec", + methodArgs = {char[].class} + ) + }) + public void testPBEKeySpec1() { + try { + PBEKeySpec pbeks = new PBEKeySpec(null); + assertTrue("An empty char[] should be used in case of null " + + "char array.", pbeks.getPassword().length == 0); + } catch (NullPointerException e) { + fail("Unexpected NullPointerException was thrown."); + } + + char[] password = new char[] {'1', '2', '3', '4', '5'}; + PBEKeySpec pbeks = new PBEKeySpec(password); + password[0] ++; + assertFalse("The change of password specified in the constructor " + + "should not cause the change of internal array.", + password[0] == pbeks.getPassword()[0]); + } + + /** + * PBEKeySpec(char[] password, byte[] salt, int iterationCount, int + * keyLength) method testing. Tests the behavior of the method in the case + * of inappropriate parameters and checks that array objects specified as + * a parameters are copied during the object initialization. + */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "PBEKeySpec", + methodArgs = {char[].class, byte[].class, int.class, int.class} + ) + }) + public void testPBEKeySpec2() { + char[] password = new char[] {'1', '2', '3', '4', '5'}; + byte[] salt = new byte[] {1, 2, 3, 4, 5}; + int iterationCount = 10; + int keyLength = 10; + + try { + PBEKeySpec pbeks = new PBEKeySpec(null, salt, + iterationCount, keyLength); + assertTrue("An empty char[] should be used in case of null input " + + "char array.", pbeks.getPassword().length == 0); + } catch (IllegalArgumentException e) { + fail("Unexpected IllegalArgumentException was thrown."); + } catch (NullPointerException e) { + fail("Unexpected NullPointerException was thrown."); + } + + try { + new PBEKeySpec(password, null, iterationCount, keyLength); + fail("A NullPointerException should be was thrown " + + "in the case of null salt."); + } catch (IllegalArgumentException e) { + fail("Unexpected IllegalArgumentException was thrown."); + } catch (NullPointerException e) { + } + + try { + new PBEKeySpec(password, new byte [0], iterationCount, keyLength); + fail("An IllegalArgumentException should be thrown " + + "in the case of empty salt."); + } catch (IllegalArgumentException e) { + } + + try { + new PBEKeySpec(password, salt, -1, keyLength); + fail("An IllegalArgumentException should be thrown " + + "in the case of negative iterationCount."); + } catch (IllegalArgumentException e) { + } + + try { + new PBEKeySpec(password, salt, iterationCount, -1); + fail("An IllegalArgumentException should be thrown " + + "in the case of negative keyLength."); + } catch (IllegalArgumentException e) { + } + + try { + new PBEKeySpec(password, salt, 0, keyLength); + fail("An IllegalArgumentException should be thrown " + + "in the case of zero iterationCount."); + } catch (IllegalArgumentException e) { + } + + try { + new PBEKeySpec(password, salt, iterationCount, 0); + fail("An IllegalArgumentException should be thrown " + + "in the case of zero keyLength."); + } catch (IllegalArgumentException e) { + } + + PBEKeySpec pbeks = new PBEKeySpec(password, salt, + iterationCount, keyLength); + password[0] ++; + assertFalse("The change of password specified in the constructor " + + "should not cause the change of internal array.", + password[0] == pbeks.getPassword()[0]); + salt[0] ++; + assertFalse("The change of salt specified in the constructor " + + " should not cause the change of internal array.", + salt[0] == pbeks.getSalt()[0]); + } + + /** + * PBEKeySpec(char[] password, byte[] salt, int iterationCount) method + * testing. Tests the behavior of the method in the case + * of inappropriate parameters and checks that array objects specified as + * a parameters are copied during the object initialization. + */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "PBEKeySpec", + methodArgs = {char[].class, byte[].class, int.class} + ) + }) + public void testPBEKeySpec3() { + char[] password = new char[] {'1', '2', '3', '4', '5'}; + byte[] salt = new byte[] {1, 2, 3, 4, 5}; + int iterationCount = 10; + + try { + PBEKeySpec pbeks = new PBEKeySpec(null, salt, iterationCount); + assertTrue("An empty char[] should be used in case of null input " + + "char array.", pbeks.getPassword().length == 0); + } catch (IllegalArgumentException e) { + fail("Unexpected IllegalArgumentException was thrown."); + } catch (NullPointerException e) { + fail("Unexpected NullPointerException was thrown."); + } + + try { + new PBEKeySpec(password, null, iterationCount); + fail("A NullPointerException should be was thrown " + + "in the case of null salt."); + } catch (IllegalArgumentException e) { + fail("Unexpected IllegalArgumentException was thrown."); + } catch (NullPointerException e) { + } + + try { + new PBEKeySpec(password, new byte [0], + iterationCount); + fail("An IllegalArgumentException should be thrown " + + "in the case of empty salt."); + } catch (IllegalArgumentException e) { + } + + try { + new PBEKeySpec(password, salt, -1); + fail("An IllegalArgumentException should be thrown " + + "in the case of negative iterationCount."); + } catch (IllegalArgumentException e) { + } + + try { + new PBEKeySpec(password, salt, 0); + fail("An IllegalArgumentException should be thrown " + + "in the case of zero iterationCount."); + } catch (IllegalArgumentException e) { + } + + PBEKeySpec pbeks = new PBEKeySpec(password, salt, iterationCount); + password[0] ++; + assertFalse("The change of password specified in the constructor " + + "should not cause the change of internal array.", + password[0] == pbeks.getPassword()[0]); + salt[0] ++; + assertFalse("The change of salt specified in the constructor " + + " should not cause the change of internal array.", + salt[0] == pbeks.getSalt()[0]); + } + + /** + * clearPassword() method testing. Tests that internal copy of password + * is cleared after the method call. + */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "clearPassword", + methodArgs = {} + ) + }) + public void testClearPassword() { + char[] password = new char[] {'1', '2', '3', '4', '5'}; + PBEKeySpec pbeks = new PBEKeySpec(password); + pbeks.clearPassword(); + try { + pbeks.getPassword(); + fail("An IllegalStateException should be was thrown " + + "after the clearing the password."); + } catch (IllegalStateException e) { + } + } + + /** + * getPassword() method testing. Tests that returned password is equal + * to the password specified in the constructor and that the change of + * returned array does not cause the change of internal array. + */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "Exception was checked in testClearPassword() method.", + targets = { + @TestTarget( + methodName = "getPassword", + methodArgs = {} + ) + }) + public void testGetPassword() { + char[] password = new char[] {'1', '2', '3', '4', '5'}; + PBEKeySpec pbeks = new PBEKeySpec(password); + char[] result = pbeks.getPassword(); + if (! Arrays.equals(password, result)) { + fail("The returned password is not equal to the specified " + + "in the constructor."); + } + result[0] ++; + assertFalse("The change of returned by getPassword() method password " + + "should not cause the change of internal array.", + result[0] == pbeks.getPassword()[0]); + } + + /** + * getSalt() method testing. Tests that returned salt is equal + * to the salt specified in the constructor and that the change of + * returned array does not cause the change of internal array. + * Also it checks that the method returns null if salt is not + * specified. + */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getSalt", + methodArgs = {} + ) + }) + public void testGetSalt() { + char[] password = new char[] {'1', '2', '3', '4', '5'}; + byte[] salt = new byte[] {1, 2, 3, 4, 5}; + int iterationCount = 10; + PBEKeySpec pbeks = new PBEKeySpec(password, salt, iterationCount); + byte[] result = pbeks.getSalt(); + if (! Arrays.equals(salt, result)) { + fail("The returned salt is not equal to the specified " + + "in the constructor."); + } + result[0] ++; + assertFalse("The change of returned by getSalt() method salt" + + "should not cause the change of internal array.", + result[0] == pbeks.getSalt()[0]); + pbeks = new PBEKeySpec(password); + assertNull("The getSalt() method should return null if the salt " + + "is not specified.", pbeks.getSalt()); + } + + /** + * getIterationCount() method testing. Tests that returned value is equal + * to the value specified in the constructor. + * Also it checks that the method returns 0 if iterationCount is not + * specified. + */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getIterationCount", + methodArgs = {} + ) + }) + public void testGetIterationCount() { + char[] password = new char[] {'1', '2', '3', '4', '5'}; + byte[] salt = new byte[] {1, 2, 3, 4, 5}; + int iterationCount = 10; + PBEKeySpec pbeks = new PBEKeySpec(password, salt, iterationCount); + assertTrue("The returned iterationCount is not equal to the specified " + + "in the constructor.", + pbeks.getIterationCount() == iterationCount); + pbeks = new PBEKeySpec(password); + assertTrue("The getIterationCount() method should return 0 " + + "if the iterationCount is not specified.", + pbeks.getIterationCount() == 0); + } + + /** + * getKeyLength() method testing. + */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getKeyLength", + methodArgs = {} + ) + }) + public void testGetKeyLength() { + char[] password = new char[] {'1', '2', '3', '4', '5'}; + byte[] salt = new byte[] {1, 2, 3, 4, 5}; + int iterationCount = 10; + int keyLength = 10; + PBEKeySpec pbeks = new PBEKeySpec(password, salt, + iterationCount, keyLength); + assertTrue("The returned keyLength is not equal to the value specified " + + "in the constructor.", + pbeks.getKeyLength() == keyLength); + pbeks = new PBEKeySpec(password); + assertTrue("The getKeyLength() method should return 0 " + + "if the keyLength is not specified.", + pbeks.getKeyLength() == 0); + } + + public static Test suite() { + return new TestSuite(PBEKeySpecTest.class); + } + + public static void main(String[] args) { + junit.textui.TestRunner.run(suite()); + } +} + diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/PBEParameterSpecTest.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/PBEParameterSpecTest.java new file mode 100644 index 0000000..d627d12 --- /dev/null +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/PBEParameterSpecTest.java @@ -0,0 +1,135 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Alexander Y. Kleymenov +* @version $Revision$ +*/ + +package org.apache.harmony.crypto.tests.javax.crypto.spec; + +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + +import java.util.Arrays; + +import javax.crypto.spec.PBEParameterSpec; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +@TestTargetClass(PBEParameterSpec.class) +/** + */ + +public class PBEParameterSpecTest extends TestCase { + + /** + * PBEParameterSpec(byte[] salt, int iterationCount) method testing. + * Tests the behavior of the method in the case of null input array + * and tests that input array is copied during the object initialization. + */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "PBEParameterSpec", + methodArgs = {byte[].class, int.class} + ) + }) + public void testPBEParameterSpec() { + byte[] salt = {1, 2, 3, 4, 5}; + int iterationCount = 10; + + try { + new PBEParameterSpec(null, iterationCount); + fail("A NullPointerException should be was thrown " + + "in the case of null salt."); + } catch (NullPointerException e) { + } + + PBEParameterSpec pbeps = new PBEParameterSpec(salt, iterationCount); + salt[0] ++; + assertFalse("The change of salt specified in the constructor " + + "should not cause the change of internal array.", + salt[0] == pbeps.getSalt()[0]); + } + + /** + * getSalt() method testing. Tests that returned salt is equal + * to the salt specified in the constructor and that the change of + * returned array does not cause the change of internal array. + */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getSalt", + methodArgs = {} + ) + }) + public void testGetSalt() { + byte[] salt = new byte[] {1, 2, 3, 4, 5}; + int iterationCount = 10; + PBEParameterSpec pbeps = new PBEParameterSpec(salt, iterationCount); + byte[] result = pbeps.getSalt(); + if (! Arrays.equals(salt, result)) { + fail("The returned salt is not equal to the specified " + + "in the constructor."); + } + result[0] ++; + assertFalse("The change of returned by getSalt() method salt" + + "should not cause the change of internal array.", + result[0] == pbeps.getSalt()[0]); + } + + /** + * getIterationCount() method testing. Tests that returned value is equal + * to the value specified in the constructor. + */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getIterationCount", + methodArgs = {} + ) + }) + public void testGetIterationCount() { + byte[] salt = new byte[] {1, 2, 3, 4, 5}; + int iterationCount = 10; + PBEParameterSpec pbeps = new PBEParameterSpec(salt, iterationCount); + assertTrue("The returned iterationCount is not equal to the specified " + + "in the constructor.", + pbeps.getIterationCount() == iterationCount); + } + + public static Test suite() { + return new TestSuite(PBEParameterSpecTest.class); + } + + public static void main(String[] args) { + junit.textui.TestRunner.run(suite()); + } +} + diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/PSourceTest.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/PSourceTest.java new file mode 100644 index 0000000..6c13cfd --- /dev/null +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/PSourceTest.java @@ -0,0 +1,141 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @author Alexander Y. Kleymenov + * @version $Revision$ + */ + +package org.apache.harmony.crypto.tests.javax.crypto.spec; + +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + +import java.util.Arrays; +import javax.crypto.spec.PSource; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +@TestTargetClass(PSource.class) +/** + */ +public class PSourceTest extends TestCase { + + /** + * PSpecified(byte[] p) method testing. Tests that NullPointerException + * is thrown in the case of null p array. Also it checks the value of + * DEFAULT field, and that input p array is copied to protect against + * subsequent modification. + */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "Nested class.", + targets = { + @TestTarget( + methodName = "PSource.PSpecified", + methodArgs = {} + ) + }) + public void testPSpecified() { + try { + new PSource.PSpecified(null); + fail("NullPointerException should be thrown in the case of " + + "null p array."); + } catch (NullPointerException e) { + } + + assertEquals("The PSource.PSpecified DEFAULT value should be byte[0]", + 0, PSource.PSpecified.DEFAULT.getValue().length); + + byte[] p = new byte[] {1, 2, 3, 4, 5}; + PSource.PSpecified ps = new PSource.PSpecified(p); + p[0]++; + assertFalse("The change of p specified in the constructor " + + "should not cause the change of internal array.", p[0] == ps + .getValue()[0]); + } + + /** + * getValue() method testing. Tests that returned array is equal to the + * array specified in the constructor. Checks that modification + * of returned array does not affect the internal array. + */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "!Constants", + methodArgs = {} + ) + }) + public void testGetValue() { + byte[] p = new byte[] {1, 2, 3, 4, 5}; + + PSource.PSpecified ps = new PSource.PSpecified(p); + byte[] result = ps.getValue(); + if (!Arrays.equals(p, result)) { + fail("The returned array does not equal to the specified " + + "in the constructor."); + } + result[0]++; + assertFalse("The change of returned by getValue() array " + + "should not cause the change of internal array.", + result[0] == ps.getValue()[0]); + } + + + /** + * PSource(String pSrcName) method testing. Tests that returned value is + * equal to the value specified in the constructor. + */ + @TestInfo(level = TestLevel.PARTIAL_OK, purpose = "Checks NullPointerException", targets = {@TestTarget(methodName = "PSource", methodArgs = {java.lang.String.class})}) + public void testPSource() { + try { + new PSource(null) {}; + fail("NullPointerException should be thrown in the case of " + + "null pSrcName."); + } catch (NullPointerException e) { + } + } + + /** + * getAlgorithm() method testing. Tests that returned value is + * equal to the value specified in the constructor. + */ + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + @TestTarget(methodName = "getAlgorithm", methodArgs = {}), + @TestTarget(methodName = "PSource", methodArgs = {java.lang.String.class})}) + public void testGetAlgorithm() { + String pSrcName = "pSrcName"; + PSource ps = new PSource(pSrcName) {}; + assertTrue("The returned value is not equal to the value specified " + + "in constructor", pSrcName.equals(ps.getAlgorithm())); + } + + public static Test suite() { + return new TestSuite(PSourceTest.class); + } + + public static void main(String[] args) { + junit.textui.TestRunner.run(suite()); + } +} diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/RC2ParameterSpecTest.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/RC2ParameterSpecTest.java new file mode 100644 index 0000000..38b11b0 --- /dev/null +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/RC2ParameterSpecTest.java @@ -0,0 +1,265 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Alexander Y. Kleymenov +* @version $Revision$ +*/ + +package org.apache.harmony.crypto.tests.javax.crypto.spec; + +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + +import java.lang.IllegalArgumentException; +import java.util.Arrays; + +import javax.crypto.spec.RC2ParameterSpec; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +@TestTargetClass(RC2ParameterSpec.class) +/** + */ + +public class RC2ParameterSpecTest extends TestCase { + + /** + * RC2ParameterSpec(int effectiveKeyBits, byte[] iv) method testing. + * Tests that IllegalArgumentException is thrown in the case of + * inappropriate constructor parameters and that input iv array is + * copied to protect against subsequent modification. + */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "RC2ParameterSpec", + methodArgs = {int.class, byte[].class} + ) + }) + public void testRC2ParameterSpec1() { + int effectiveKeyBits = 10; + byte[] iv = {1, 2, 3, 4, 5, 6, 7, 8}; + + try { + new RC2ParameterSpec(effectiveKeyBits, null); + fail("An IllegalArgumentException should be thrown " + + "in the case of null iv."); + } catch (IllegalArgumentException e) { + } + + try { + new RC2ParameterSpec(effectiveKeyBits, new byte[] {1, 2, 3, 4, 5}); + fail("An IllegalArgumentException should be thrown " + + "in the case of short iv."); + } catch (IllegalArgumentException e) { + } + + RC2ParameterSpec ps = new RC2ParameterSpec(effectiveKeyBits, iv); + iv[0] ++; + assertFalse("The change of iv specified in the constructor " + + "should not cause the change of internal array.", + iv[0] == ps.getIV()[0]); + } + + /** + * RC2ParameterSpec(int effectiveKeyBits, byte[] iv, int offset) method + * testing. Tests that IllegalArgumentException is thrown in the case of + * inappropriate constructor parameters and that input iv array is + * copied to protect against subsequent modification. + */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "RC2ParameterSpec", + methodArgs = {int.class, byte[].class, int.class} + ) + }) + public void testRC2ParameterSpec2() { + int effectiveKeyBits = 10; + byte[] iv = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0}; + int offset = 2; + + try { + new RC2ParameterSpec(effectiveKeyBits, null, offset); + fail("An IllegalArgumentException should be thrown " + + "in the case of null iv."); + } catch (IllegalArgumentException e) { + } + + try { + new RC2ParameterSpec(effectiveKeyBits, iv, 4); + fail("An IllegalArgumentException should be thrown " + + "in the case of short iv."); + } catch (IllegalArgumentException e) { + } + + RC2ParameterSpec ps = new RC2ParameterSpec(effectiveKeyBits, iv, offset); + iv[offset] ++; + assertFalse("The change of iv specified in the constructor " + + "should not cause the change of internal array.", + iv[offset] == ps.getIV()[0]); + } + + /** + * getEffectiveKeyBits() method testing. Tests that returned value is + * equal to the value specified in the constructor. + */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getEffectiveKeyBits", + methodArgs = {} + ) + }) + public void testGetEffectiveKeyBits() { + int effectiveKeyBits = 10; + byte[] iv = {1, 2, 3, 4, 5, 6, 7, 8}; + + RC2ParameterSpec ps = new RC2ParameterSpec(effectiveKeyBits, iv); + assertTrue("The returned effectiveKeyBits value is not equal to the " + + "value specified in the constructor.", + effectiveKeyBits == ps.getEffectiveKeyBits()); + } + + /** + * getIV() method testing. Tests that returned array is equal to the + * array specified in the constructor. Checks that modification + * of returned array does not affect the internal array. Also it checks + * that getIV() method returns null if iv is not specified. + */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getIV", + methodArgs = {} + ) + }) + public void testGetIV() { + int effectiveKeyBits = 10; + byte[] iv = new byte[] {1, 2, 3, 4, 5, 6, 7, 8}; + + RC2ParameterSpec ps = new RC2ParameterSpec(effectiveKeyBits, iv); + byte[] result = ps.getIV(); + if (! Arrays.equals(iv, result)) { + fail("The returned iv is not equal to the specified " + + "in the constructor."); + } + result[0] ++; + assertFalse("The change of returned by getIV() method iv " + + "should not cause the change of internal array.", + result[0] == ps.getIV()[0]); + ps = new RC2ParameterSpec(effectiveKeyBits); + assertNull("The getIV() method should return null if the parameter " + + "set does not contain iv.", ps.getIV()); + } + + /** + * equals(Object obj) method testing. Tests the correctness of equal + * operation: it should be reflexive, symmetric, transitive, consistent + * and should be false on null object. + */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "equals", + methodArgs = {java.lang.Object.class} + ) + }) + public void testEquals() { + int effectiveKeyBits = 10; + byte[] iv = new byte[] {1, 2, 3, 4, 5, 6, 7, 8}; + + RC2ParameterSpec ps1 = new RC2ParameterSpec(effectiveKeyBits, iv); + RC2ParameterSpec ps2 = new RC2ParameterSpec(effectiveKeyBits, iv); + RC2ParameterSpec ps3 = new RC2ParameterSpec(10, + new byte[] {1, 2, 3, 4, 5, 6, 7, 8, 9}); + + // checking for reflexive law: + assertTrue("The equivalence relation should be reflexive.", + ps1.equals(ps1)); + + assertTrue("Objects built on the same parameters should be equal.", + ps1.equals(ps2)); + // checking for symmetric law: + assertTrue("The equivalence relation should be symmetric.", + ps2.equals(ps1)); + + assertTrue("Objects built on the equal parameters should be equal.", + ps2.equals(ps3)); + + // checking for transitive law: + assertTrue("The equivalence relation should be transitive.", + ps1.equals(ps3)); + + assertFalse("Should return not be equal to null object.", + ps1.equals(null)); + + ps2 = new RC2ParameterSpec(11, iv); + assertFalse("Objects should not be equal.", ps1.equals(ps2)); + + ps2 = new RC2ParameterSpec(11, new byte[] {9, 8, 7, 6, 5, 4, 3, 2, 1}); + assertFalse("Objects should not be equal.", ps1.equals(ps2)); + } + + /** + * hashCode() method testing. Tests that for equal objects hash codes + * are equal. + */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "hashCode", + methodArgs = {} + ) + }) + public void testHashCode() { + int effectiveKeyBits = 0; + byte[] iv = new byte[] {1, 2, 3, 4, 5, 6, 7, 8}; + + RC2ParameterSpec ps1 = new RC2ParameterSpec(effectiveKeyBits, iv); + RC2ParameterSpec ps2 = new RC2ParameterSpec(effectiveKeyBits, iv); + + assertTrue("Equal objects should have the same hash codes.", + ps1.hashCode() == ps2.hashCode()); + } + + public static Test suite() { + return new TestSuite(RC2ParameterSpecTest.class); + } + + public static void main(String[] args) { + junit.textui.TestRunner.run(suite()); + } +} + diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/RC5ParameterSpecTest.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/RC5ParameterSpecTest.java new file mode 100644 index 0000000..caf047f --- /dev/null +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/RC5ParameterSpecTest.java @@ -0,0 +1,365 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Alexander Y. Kleymenov +* @version $Revision$ +*/ + +package org.apache.harmony.crypto.tests.javax.crypto.spec; + +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + +import java.util.Arrays; + +import javax.crypto.spec.RC5ParameterSpec; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +@TestTargetClass(RC5ParameterSpec.class) +/** + */ + +public class RC5ParameterSpecTest extends TestCase { + + /** + * RC5ParameterSpec(int version, int rounds, int wordSize, byte[] iv) method + * testing. Tests that IllegalArgumentException is thrown in the case of + * inappropriate constructor parameters and that input iv array is + * copied to protect against subsequent modification. + */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "RC5ParameterSpec", + methodArgs = {int.class, int.class, int.class, byte[].class} + ) + }) + public void testRC5ParameterSpec1() { + int version = 1; + int rounds = 5; + int wordSize = 16; + byte[] iv = {1, 2, 3, 4}; + + try { + new RC5ParameterSpec(version, rounds, wordSize, null); + fail("An IllegalArgumentException should be thrown " + + "in the case of null iv."); + } catch (IllegalArgumentException e) { + } + + try { + new RC5ParameterSpec(version, rounds, wordSize+8, iv); + fail("An IllegalArgumentException should be thrown " + + "in the case of short iv."); + } catch (IllegalArgumentException e) { + } + + try { + new RC5ParameterSpec(version, rounds, wordSize, new byte[] {1, 2, 3}); + fail("An IllegalArgumentException should be thrown " + + "in the case of short iv."); + } catch (IllegalArgumentException e) { + } + + RC5ParameterSpec ps = new RC5ParameterSpec(version, rounds, + wordSize, iv); + iv[0] ++; + assertFalse("The change of iv specified in the constructor " + + "should not cause the change of internal array.", + iv[0] == ps.getIV()[0]); + } + + /** + * RC5ParameterSpec(int version, int rounds, int wordSize, byte[] iv, int + * offset) method testing. Tests that IllegalArgumentException is thrown in + * the case of inappropriate constructor parameters and that input iv array + * is copied to protect against subsequent modification. + */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "RC5ParameterSpec", + methodArgs = {int.class, int.class, int.class, byte[].class, int.class} + ) + }) + public void testRC5ParameterSpec2() { + int version = 1; + int rounds = 5; + int wordSize = 16; + byte[] iv = {1, 2, 3, 4, 5, 6}; + int offset = 2; + + try { + new RC5ParameterSpec(version, rounds, wordSize, null, offset); + fail("An IllegalArgumentException should be thrown " + + "in the case of null iv."); + } catch (IllegalArgumentException e) { + } + + try { + new RC5ParameterSpec(version, rounds, wordSize+8, iv, offset); + fail("An IllegalArgumentException should be thrown " + + "in the case of short iv."); + } catch (IllegalArgumentException e) { + } + + try { + new RC5ParameterSpec(version, rounds, wordSize, iv, offset+1); + fail("An IllegalArgumentException should be thrown " + + "in the case of short iv."); + } catch (IllegalArgumentException e) { + } + + try { + new RC5ParameterSpec(version, rounds, wordSize, new byte[] { 1, 2, + 3, 4 }, offset); + fail("An IllegalArgumentException should be thrown " + + "in the case of short iv."); + } catch (IllegalArgumentException e) { + } + + RC5ParameterSpec ps = new RC5ParameterSpec(version, rounds, wordSize, + iv, offset); + iv[offset] ++; + assertFalse("The change of iv specified in the constructor " + + "should not cause the change of internal array.", + iv[offset] == ps.getIV()[0]); + + // Regression test for HARMONY-1077 + try { + new RC5ParameterSpec(0, 9, 77, new byte[] { 2 }, -100); + fail("ArrayIndexOutOfBoundsException expected"); + } catch (ArrayIndexOutOfBoundsException e) { + // expected + } + } + + /** + * getVersion() method testing. Tests that returned value is + * equal to the value specified in the constructor. + */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getVersion", + methodArgs = {} + ) + }) + public void testGetVersion() { + int version = 1; + int rounds = 5; + int wordSize = 16; + + RC5ParameterSpec ps = new RC5ParameterSpec(version, rounds, wordSize); + assertTrue("The returned version value should be equal to the " + + "value specified in the constructor.", + ps.getVersion() == version); + } + + /** + * getRounds() method testing. Tests that returned value is + * equal to the value specified in the constructor. + */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getRounds", + methodArgs = {} + ) + }) + public void testGetRounds() { + int version = 1; + int rounds = 5; + int wordSize = 16; + + RC5ParameterSpec ps = new RC5ParameterSpec(version, rounds, wordSize); + assertTrue("The returned rounds value should be equal to the " + + "value specified in the constructor.", + ps.getRounds() == rounds); + } + + /** + * getWordSize() method testing. Tests that returned value is + * equal to the value specified in the constructor. + */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getWordSize", + methodArgs = {} + ) + }) + public void testGetWordSize() { + int version = 1; + int rounds = 5; + int wordSize = 16; + + RC5ParameterSpec ps = new RC5ParameterSpec(version, rounds, wordSize); + assertTrue("The returned wordSize value should be equal to the " + + "value specified in the constructor.", + ps.getWordSize() == wordSize); + } + + /** + * getIV() method testing. Tests that returned array is equal to the + * array specified in the constructor. Checks that modification + * of returned array does not affect the internal array. Also it checks + * that getIV() method returns null if iv is not specified. + */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getIV", + methodArgs = {} + ) + }) + public void testGetIV() { + int version = 1; + int rounds = 5; + int wordSize = 16; + byte[] iv = {1, 2, 3, 4}; + + RC5ParameterSpec ps = new RC5ParameterSpec(version, rounds, + wordSize, iv); + byte[] result = ps.getIV(); + if (! Arrays.equals(iv, result)) { + fail("The returned iv is not equal to the specified " + + "in the constructor."); + } + result[0] ++; + assertFalse("The change of returned by getIV() method iv " + + "should not cause the change of internal array.", + result[0] == ps.getIV()[0]); + ps = new RC5ParameterSpec(version, rounds, wordSize); + assertNull("The getIV() method should return null if the parameter " + + "set does not contain IV.", ps.getIV()); + } + + /** + * equals(Object obj) method testing. Tests the correctness of equal + * operation: it should be reflexive, symmetric, transitive, consistent + * and should be false on null object. + */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "equals", + methodArgs = {java.lang.Object.class} + ) + }) + public void testEquals() { + int version = 1; + int rounds = 5; + int wordSize = 16; + byte[] iv = {1, 2, 3, 4, 5, 6}; + + RC5ParameterSpec ps1 = new RC5ParameterSpec(version, rounds, + wordSize, iv); + RC5ParameterSpec ps2 = new RC5ParameterSpec(version, rounds, + wordSize, iv); + RC5ParameterSpec ps3 = new RC5ParameterSpec(version, rounds, wordSize, + new byte[] {1, 2, 3, 4}); + // checking for reflexive law: + assertTrue("The equivalence relation should be reflexive.", + ps1.equals(ps1)); + + assertTrue("Objects built on the same parameters should be equal.", + ps1.equals(ps2)); + // checking for symmetric law: + assertTrue("The equivalence relation should be symmetric.", + ps2.equals(ps1)); + + assertTrue("Objects built on the equal parameters should be equal.", + ps2.equals(ps3)); + + // checking for transitive law: + assertTrue("The equivalence relation should be transitive.", + ps1.equals(ps3)); + + assertFalse("Should return not be equal to null object.", + ps1.equals(null)); + + ps2 = new RC5ParameterSpec(version+1, rounds, wordSize, iv); + assertFalse("Objects should not be equal.", ps1.equals(ps2)); + + ps2 = new RC5ParameterSpec(version, rounds+1, wordSize, iv); + assertFalse("Objects should not be equal.", ps1.equals(ps2)); + + ps2 = new RC5ParameterSpec(version, rounds, wordSize/2, iv); + assertFalse("Objects should not be equal.", ps1.equals(ps2)); + + ps2 = new RC5ParameterSpec(version, rounds, wordSize, + new byte[] {4, 3, 2, 1}); + assertFalse("Objects should not be equal.", ps1.equals(ps2)); + } + + /** + * hashCode() method testing. Tests that for equal objects hash codes + * are equal. + */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "hashCode", + methodArgs = {} + ) + }) + public void testHashCode() { + int version = 1; + int rounds = 5; + int wordSize = 16; + byte[] iv = {1, 2, 3, 4, 5, 6}; + + RC5ParameterSpec ps1 = new RC5ParameterSpec(version, rounds, + wordSize, iv); + RC5ParameterSpec ps2 = new RC5ParameterSpec(version, rounds, + wordSize, iv); + assertTrue("Equal objects should have the same hash codes.", + ps1.hashCode() == ps2.hashCode()); + } + + public static Test suite() { + return new TestSuite(RC5ParameterSpecTest.class); + } + + public static void main(String[] args) { + junit.textui.TestRunner.run(suite()); + } +} + diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/SecretKeySpecTest.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/SecretKeySpecTest.java new file mode 100644 index 0000000..61371aa --- /dev/null +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/SecretKeySpecTest.java @@ -0,0 +1,330 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Alexander Y. Kleymenov +* @version $Revision$ +*/ + +package org.apache.harmony.crypto.tests.javax.crypto.spec; + +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + +import java.util.Arrays; + +import javax.crypto.spec.SecretKeySpec; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +@TestTargetClass(SecretKeySpec.class) +/** + */ + +public class SecretKeySpecTest extends TestCase { + + /** + * SecretKeySpec(byte[] key, String algorithm) method testing. Tests that + * IllegalArgumentException is thrown in the case of inappropriate + * constructor parameters and that input iv array is + * copied to protect against subsequent modification. + */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "SecretKeySpec", + methodArgs = {byte[].class, java.lang.String.class} + ) + }) + public void testSecretKeySpec1() { + byte[] key = new byte[] {1, 2, 3, 4, 5}; + String algorithm = "Algorithm"; + + try { + new SecretKeySpec(new byte[] {}, algorithm); + fail("An IllegalArgumentException should be thrown " + + "in the case of empty key."); + } catch (IllegalArgumentException e) { + } + + try { + new SecretKeySpec(null, algorithm); + fail("An IllegalArgumentException should be thrown " + + "in the case of null key."); + } catch (IllegalArgumentException e) { + } + + try { + new SecretKeySpec(key, null); + fail("An IllegalArgumentException should be thrown " + + "in the case of null algorithm."); + } catch (IllegalArgumentException e) { + } + + SecretKeySpec ks = new SecretKeySpec(key, algorithm); + key[0] ++; + assertFalse("The change of key specified in the constructor " + + "should not cause the change of internal array.", + key[0] == ks.getEncoded()[0]); + } + + /** + * SecretKeySpec(byte[] key, int offset, int len, String algorithm) method + * testing. Tests that IllegalArgumentException is thrown in + * the case of inappropriate constructor parameters and that input iv array + * is copied to protect against subsequent modification. + */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "SecretKeySpec", + methodArgs = {byte[].class, int.class, int.class, java.lang.String.class} + ) + }) + public void _testSecretKeySpec2() { + byte[] key = new byte[] {1, 2, 3, 4, 5}; + int offset = 1; + int len = 4; + String algorithm = "Algorithm"; + + try { + new SecretKeySpec(new byte[] {}, 0, 0, algorithm); + fail("An IllegalArgumentException should be thrown " + + "in the case of empty key."); + } catch (IllegalArgumentException e) { + } + + try { + new SecretKeySpec(null, 0, 0, algorithm); + fail("An IllegalArgumentException should be thrown " + + "in the case of null key."); + } catch (IllegalArgumentException e) { + } + + try { + new SecretKeySpec(key, offset, len, null); + fail("An IllegalArgumentException should be thrown " + + "in the case of short key algorithm."); + } catch (IllegalArgumentException e) { + } + + try { + new SecretKeySpec(key, offset, key.length, algorithm); + fail("An IllegalArgumentException should be thrown " + + "in the case of null key."); + } catch (IllegalArgumentException e) { + } + + try { + new SecretKeySpec(key, -1, key.length, algorithm); + fail("An IllegalArgumentException should be thrown " + + "in the case of null key."); + } catch (IllegalArgumentException e) { + fail("Not expected IllegalArgumentException was thrown."); + } catch (ArrayIndexOutOfBoundsException e) { + } + + try { + new SecretKeySpec(key, offset, len, null); + fail("An IllegalArgumentException should be thrown " + + "in the case of null algorithm."); + } catch (IllegalArgumentException e) { + } + + SecretKeySpec ks = new SecretKeySpec(key, algorithm); + key[offset] ++; + assertFalse("The change of key specified in the constructor " + + "should not cause the change of internal array.", + key[offset] == ks.getEncoded()[0]); + + // Regression test for HARMONY-1077 + try { + new SecretKeySpec(new byte[] { 2 }, 4, -100, "CCC"); + fail("ArrayIndexOutOfBoundsException expected"); + } catch (ArrayIndexOutOfBoundsException e) { + //expected + } + } + + /** + * getAlgorithm() method testing. Tests that returned value is + * equal to the value specified in the constructor. + */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getAlgorithm", + methodArgs = {} + ) + }) + public void testGetAlgorithm() { + byte[] key = new byte[] {1, 2, 3, 4, 5}; + String algorithm = "Algorithm"; + + SecretKeySpec ks = new SecretKeySpec(key, algorithm); + assertEquals("The returned value does not equal to the " + + "value specified in the constructor.", + algorithm, ks.getAlgorithm()); + } + + /** + * getFormat() method testing. Tests that returned value is "RAW". + */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getFormat", + methodArgs = {} + ) + }) + public void testGetFormat() { + byte[] key = new byte[] {1, 2, 3, 4, 5}; + String algorithm = "Algorithm"; + + SecretKeySpec ks = new SecretKeySpec(key, algorithm); + assertTrue("The returned value is not \"RAW\".", + ks.getFormat() == "RAW"); + } + + /** + * getEncoded() method testing. Tests that returned array is equal to the + * array specified in the constructor. Checks that modification + * of returned array does not affect the internal array. + */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getEncoded", + methodArgs = {} + ) + }) + public void testGetEncoded() { + byte[] key = new byte[] {1, 2, 3, 4, 5}; + String algorithm = "Algorithm"; + + SecretKeySpec ks = new SecretKeySpec(key, algorithm); + byte[] result = ks.getEncoded(); + if (! Arrays.equals(key, result)) { + fail("The returned key does not equal to the specified " + + "in the constructor."); + } + result[0] ++; + assertFalse("The change of returned by getEncoded() method key " + + "should not cause the change of internal array.", + result[0] == ks.getEncoded()[0]); + + // Regression for HARMONY-78 + int offset = 1; + int len = 4; + SecretKeySpec sks = new SecretKeySpec(key, offset, len, algorithm); + assertEquals("Key length is incorrect", len, sks.getEncoded().length); + } + + /** + * hashCode() method testing. Tests that for equal objects hash codes + * are equal. + */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "hashCode", + methodArgs = {} + ) + }) + public void testHashCode() { + byte[] key = new byte[] {1, 2, 3, 4, 5}; + String algorithm = "Algorithm"; + + SecretKeySpec ks1 = new SecretKeySpec(key, algorithm); + SecretKeySpec ks2 = new SecretKeySpec(key, algorithm); + assertTrue("Equal objects should have the same hash codes.", + ks1.hashCode() == ks2.hashCode()); + } + + /** + * equals(Object obj) method testing. Tests the correctness of equal + * operation: it should be reflexive, symmetric, transitive, consistent + * and should be false on null object. + */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "equals", + methodArgs = {java.lang.Object.class} + ) + }) + public void testEquals() { + byte[] key = new byte[] {1, 2, 3, 4, 5}; + String algorithm = "Algorithm"; + + SecretKeySpec ks1 = new SecretKeySpec(key, algorithm); + SecretKeySpec ks2 = new SecretKeySpec(key, algorithm); + SecretKeySpec ks3 = new SecretKeySpec(key, algorithm); + + // checking for reflexive law: + assertTrue("The equivalence relation should be reflexive.", + ks1.equals(ks1)); + + assertTrue("Objects built on the same parameters should be equal.", + ks1.equals(ks2)); + // checking for symmetric law: + assertTrue("The equivalence relation should be symmetric.", + ks2.equals(ks1)); + + assertTrue("Objects built on the equal parameters should be equal.", + ks2.equals(ks3)); + // checking for transitive law: + assertTrue("The equivalence relation should be transitive.", + ks1.equals(ks3)); + + assertFalse("Should not be equal to null object.", + ks1.equals(null)); + + ks2 = new SecretKeySpec(new byte[] {1}, algorithm); + assertFalse("Objects should not be equal.", ks1.equals(ks2)); + + ks2 = new SecretKeySpec(key, "Another Algorithm"); + assertFalse("Objects should not be equal.", ks1.equals(ks2)); + } + + public static Test suite() { + return new TestSuite(SecretKeySpecTest.class); + } + + public static void main(String[] args) { + junit.textui.TestRunner.run(suite()); + } +} + diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/support/EncryptedPrivateKeyInfoData.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/support/EncryptedPrivateKeyInfoData.java new file mode 100644 index 0000000..7ca0e6a --- /dev/null +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/support/EncryptedPrivateKeyInfoData.java @@ -0,0 +1,1229 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.harmony.crypto.tests.support; + +import java.security.NoSuchAlgorithmException; +import java.util.HashMap; + +/** + * + * Support class for EncryptedPrivateKeyInfo_ImplTest and EncryptedPrivateKeyInfo_Test + * + * All binary data for these tests were generated using + * BEA JRockit j2sdk1.4.2_04 (http://www.bea.com) with + * security providers list extended by Bouncy Castle's one + * (http://www.bouncycastle.org) + */ +public class EncryptedPrivateKeyInfoData { + + + /** + * "valid" encoding for DSA with alg params + */ + private static final byte[] dsaEncryptedPrivateKeyInfo = new byte[] { + (byte) 0x30, (byte) 0x82, (byte) 0x05, (byte) 0x33, (byte) 0x30, + (byte) 0x82, (byte) 0x01, (byte) 0x2b, (byte) 0x06, (byte) 0x07, + (byte) 0x2a, (byte) 0x86, (byte) 0x48, (byte) 0xce, (byte) 0x38, + (byte) 0x04, (byte) 0x01, (byte) 0x30, (byte) 0x82, (byte) 0x01, + (byte) 0x1e, (byte) 0x02, (byte) 0x81, (byte) 0x81, (byte) 0x00, + (byte) 0x9f, (byte) 0x5e, (byte) 0x76, (byte) 0x19, (byte) 0x59, + (byte) 0xd8, (byte) 0xf7, (byte) 0x6b, (byte) 0x91, (byte) 0x6d, + (byte) 0x15, (byte) 0x7e, (byte) 0x14, (byte) 0x27, (byte) 0x25, + (byte) 0x6e, (byte) 0x59, (byte) 0x2c, (byte) 0xec, (byte) 0x21, + (byte) 0x7a, (byte) 0xb7, (byte) 0xd4, (byte) 0xf4, (byte) 0xa0, + (byte) 0x26, (byte) 0x4e, (byte) 0x72, (byte) 0x29, (byte) 0x18, + (byte) 0x4a, (byte) 0x1c, (byte) 0x9a, (byte) 0xc9, (byte) 0xcd, + (byte) 0x85, (byte) 0x1b, (byte) 0x39, (byte) 0x41, (byte) 0x9e, + (byte) 0x58, (byte) 0x16, (byte) 0xeb, (byte) 0x20, (byte) 0x84, + (byte) 0x28, (byte) 0x2a, (byte) 0xb9, (byte) 0xce, (byte) 0xc7, + (byte) 0x6d, (byte) 0x74, (byte) 0x99, (byte) 0xfe, (byte) 0xa5, + (byte) 0xe8, (byte) 0x66, (byte) 0xe1, (byte) 0x48, (byte) 0xdd, + (byte) 0x2e, (byte) 0xcf, (byte) 0xfe, (byte) 0xb9, (byte) 0x6a, + (byte) 0x8e, (byte) 0x12, (byte) 0x4b, (byte) 0xa4, (byte) 0xa8, + (byte) 0x87, (byte) 0xd7, (byte) 0xab, (byte) 0x26, (byte) 0xd6, + (byte) 0xc3, (byte) 0xd1, (byte) 0x3b, (byte) 0x95, (byte) 0xc4, + (byte) 0x97, (byte) 0x2c, (byte) 0xdc, (byte) 0xab, (byte) 0x5d, + (byte) 0xf5, (byte) 0x55, (byte) 0xae, (byte) 0x58, (byte) 0x68, + (byte) 0x84, (byte) 0x41, (byte) 0x99, (byte) 0x1b, (byte) 0xd3, + (byte) 0xd0, (byte) 0xd9, (byte) 0xd3, (byte) 0xdd, (byte) 0xf5, + (byte) 0x48, (byte) 0x04, (byte) 0xa2, (byte) 0x92, (byte) 0x61, + (byte) 0xf8, (byte) 0xb1, (byte) 0xe6, (byte) 0x24, (byte) 0x65, + (byte) 0x8f, (byte) 0xa4, (byte) 0x97, (byte) 0x40, (byte) 0x1d, + (byte) 0x3f, (byte) 0x2b, (byte) 0x85, (byte) 0x00, (byte) 0xd5, + (byte) 0xcb, (byte) 0x8d, (byte) 0x66, (byte) 0x9a, (byte) 0xac, + (byte) 0x7b, (byte) 0x5f, (byte) 0xc7, (byte) 0x02, (byte) 0x15, + (byte) 0x00, (byte) 0x9a, (byte) 0xfb, (byte) 0x6f, (byte) 0x72, + (byte) 0x15, (byte) 0x01, (byte) 0x03, (byte) 0x16, (byte) 0x2a, + (byte) 0xd6, (byte) 0xca, (byte) 0x60, (byte) 0x10, (byte) 0x47, + (byte) 0xde, (byte) 0x4b, (byte) 0x0f, (byte) 0xd6, (byte) 0x73, + (byte) 0x37, (byte) 0x02, (byte) 0x81, (byte) 0x80, (byte) 0x5d, + (byte) 0x51, (byte) 0x28, (byte) 0x64, (byte) 0xb2, (byte) 0x2b, + (byte) 0xeb, (byte) 0x85, (byte) 0xb4, (byte) 0x14, (byte) 0x0d, + (byte) 0xad, (byte) 0xec, (byte) 0xc8, (byte) 0x1f, (byte) 0x96, + (byte) 0x1e, (byte) 0x6a, (byte) 0x52, (byte) 0xd4, (byte) 0x0b, + (byte) 0x69, (byte) 0xb0, (byte) 0x33, (byte) 0xa1, (byte) 0xd1, + (byte) 0xbc, (byte) 0x64, (byte) 0xd6, (byte) 0x64, (byte) 0xef, + (byte) 0x2c, (byte) 0x89, (byte) 0xc7, (byte) 0x39, (byte) 0x75, + (byte) 0x87, (byte) 0x82, (byte) 0x61, (byte) 0xbe, (byte) 0xd1, + (byte) 0xcd, (byte) 0x70, (byte) 0x41, (byte) 0x85, (byte) 0x99, + (byte) 0x55, (byte) 0x75, (byte) 0x6f, (byte) 0x16, (byte) 0xc0, + (byte) 0x40, (byte) 0xf1, (byte) 0x0c, (byte) 0x78, (byte) 0x1f, + (byte) 0xe8, (byte) 0x63, (byte) 0x5d, (byte) 0xfa, (byte) 0x37, + (byte) 0xc1, (byte) 0xce, (byte) 0x97, (byte) 0x76, (byte) 0xa5, + (byte) 0x48, (byte) 0x5b, (byte) 0x88, (byte) 0xe4, (byte) 0xd5, + (byte) 0xb8, (byte) 0x06, (byte) 0xf5, (byte) 0x7f, (byte) 0x92, + (byte) 0xda, (byte) 0x99, (byte) 0xa5, (byte) 0x5a, (byte) 0x64, + (byte) 0xc9, (byte) 0x30, (byte) 0x2c, (byte) 0x77, (byte) 0x58, + (byte) 0x60, (byte) 0xa6, (byte) 0x35, (byte) 0x1d, (byte) 0x71, + (byte) 0xfb, (byte) 0x49, (byte) 0x24, (byte) 0x6c, (byte) 0x34, + (byte) 0x29, (byte) 0xa0, (byte) 0x47, (byte) 0xf1, (byte) 0x14, + (byte) 0xad, (byte) 0xc2, (byte) 0x85, (byte) 0x41, (byte) 0xdd, + (byte) 0x2c, (byte) 0x78, (byte) 0x2a, (byte) 0x5a, (byte) 0x24, + (byte) 0x7f, (byte) 0x19, (byte) 0xf4, (byte) 0x0a, (byte) 0x2e, + (byte) 0x1d, (byte) 0x92, (byte) 0x80, (byte) 0xe5, (byte) 0xe4, + (byte) 0x05, (byte) 0x28, (byte) 0x48, (byte) 0x5c, // 38 + (byte) 0x34, (byte) 0xc8, (byte) 0x22, (byte) 0x04, (byte) 0x82, + (byte) 0x04, (byte) 0x00, (byte) 0x00, // + (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x04, (byte) 0x05, + (byte) 0x06, (byte) 0x07, (byte) 0x08, (byte) 0x09, (byte) 0x0a, + (byte) 0x0b, (byte) 0x0c, (byte) 0x0d, (byte) 0x0e, (byte) 0x0f, + (byte) 0x10, (byte) 0x11, (byte) 0x12, (byte) 0x13, (byte) 0x14, + (byte) 0x15, (byte) 0x16, (byte) 0x17, (byte) 0x18, (byte) 0x19, + (byte) 0x1a, (byte) 0x1b, (byte) 0x1c, (byte) 0x1d, (byte) 0x1e, + (byte) 0x1f, (byte) 0x20, (byte) 0x21, (byte) 0x22, (byte) 0x23, + (byte) 0x24, (byte) 0x25, (byte) 0x26, (byte) 0x27, (byte) 0x28, + (byte) 0x29, (byte) 0x2a, (byte) 0x2b, (byte) 0x2c, (byte) 0x2d, + (byte) 0x2e, (byte) 0x2f, (byte) 0x30, (byte) 0x31, (byte) 0x32, + (byte) 0x33, (byte) 0x34, (byte) 0x35, (byte) 0x36, (byte) 0x37, + (byte) 0x38, (byte) 0x39, (byte) 0x3a, (byte) 0x3b, (byte) 0x3c, + (byte) 0x3d, (byte) 0x3e, (byte) 0x3f, (byte) 0x40, (byte) 0x41, + (byte) 0x42, (byte) 0x43, (byte) 0x44, (byte) 0x45, (byte) 0x46, + (byte) 0x47, (byte) 0x48, (byte) 0x49, (byte) 0x4a, (byte) 0x4b, + (byte) 0x4c, (byte) 0x4d, (byte) 0x4e, (byte) 0x4f, (byte) 0x50, + (byte) 0x51, (byte) 0x52, (byte) 0x53, (byte) 0x54, (byte) 0x55, + (byte) 0x56, (byte) 0x57, (byte) 0x58, (byte) 0x59, (byte) 0x5a, + (byte) 0x5b, (byte) 0x5c, (byte) 0x5d, (byte) 0x5e, (byte) 0x5f, + (byte) 0x60, (byte) 0x61, (byte) 0x62, (byte) 0x63, (byte) 0x64, + (byte) 0x65, (byte) 0x66, (byte) 0x67, (byte) 0x68, (byte) 0x69, + (byte) 0x6a, (byte) 0x6b, (byte) 0x6c, (byte) 0x6d, (byte) 0x6e, + (byte) 0x6f, (byte) 0x70, (byte) 0x71, (byte) 0x72, (byte) 0x73, + (byte) 0x74, (byte) 0x75, (byte) 0x76, (byte) 0x77, (byte) 0x78, + (byte) 0x79, (byte) 0x7a, (byte) 0x7b, (byte) 0x7c, (byte) 0x7d, + (byte) 0x7e, (byte) 0x7f, (byte) 0x80, (byte) 0x81, (byte) 0x82, + (byte) 0x83, (byte) 0x84, (byte) 0x85, (byte) 0x86, (byte) 0x87, + (byte) 0x88, (byte) 0x89, (byte) 0x8a, (byte) 0x8b, (byte) 0x8c, + (byte) 0x8d, (byte) 0x8e, (byte) 0x8f, (byte) 0x90, (byte) 0x91, + (byte) 0x92, (byte) 0x93, (byte) 0x94, (byte) 0x95, (byte) 0x96, + (byte) 0x97, (byte) 0x98, (byte) 0x99, (byte) 0x9a, (byte) 0x9b, + (byte) 0x9c, (byte) 0x9d, (byte) 0x9e, (byte) 0x9f, (byte) 0xa0, + (byte) 0xa1, (byte) 0xa2, (byte) 0xa3, (byte) 0xa4, (byte) 0xa5, + (byte) 0xa6, (byte) 0xa7, (byte) 0xa8, (byte) 0xa9, (byte) 0xaa, + (byte) 0xab, (byte) 0xac, (byte) 0xad, (byte) 0xae, (byte) 0xaf, + (byte) 0xb0, (byte) 0xb1, (byte) 0xb2, (byte) 0xb3, (byte) 0xb4, + (byte) 0xb5, (byte) 0xb6, (byte) 0xb7, (byte) 0xb8, (byte) 0xb9, + (byte) 0xba, (byte) 0xbb, (byte) 0xbc, (byte) 0xbd, (byte) 0xbe, + (byte) 0xbf, (byte) 0xc0, (byte) 0xc1, (byte) 0xc2, (byte) 0xc3, + (byte) 0xc4, (byte) 0xc5, (byte) 0xc6, (byte) 0xc7, (byte) 0xc8, + (byte) 0xc9, (byte) 0xca, (byte) 0xcb, (byte) 0xcc, (byte) 0xcd, + (byte) 0xce, (byte) 0xcf, (byte) 0xd0, (byte) 0xd1, (byte) 0xd2, + (byte) 0xd3, (byte) 0xd4, (byte) 0xd5, (byte) 0xd6, (byte) 0xd7, + (byte) 0xd8, (byte) 0xd9, (byte) 0xda, (byte) 0xdb, (byte) 0xdc, + (byte) 0xdd, (byte) 0xde, (byte) 0xdf, (byte) 0xe0, (byte) 0xe1, + (byte) 0xe2, (byte) 0xe3, (byte) 0xe4, (byte) 0xe5, (byte) 0xe6, + (byte) 0xe7, (byte) 0xe8, (byte) 0xe9, (byte) 0xea, (byte) 0xeb, + (byte) 0xec, (byte) 0xed, (byte) 0xee, (byte) 0xef, (byte) 0xf0, + (byte) 0xf1, (byte) 0xf2, (byte) 0xf3, (byte) 0xf4, (byte) 0xf5, + (byte) 0xf6, (byte) 0xf7, (byte) 0xf8, (byte) 0xf9, (byte) 0xfa, + (byte) 0xfb, (byte) 0xfc, (byte) 0xfd, (byte) 0xfe, (byte) 0xff, + (byte) 0x00, (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x04, + (byte) 0x05, (byte) 0x06, (byte) 0x07, (byte) 0x08, (byte) 0x09, + (byte) 0x0a, (byte) 0x0b, (byte) 0x0c, (byte) 0x0d, (byte) 0x0e, + (byte) 0x0f, (byte) 0x10, (byte) 0x11, (byte) 0x12, (byte) 0x13, + (byte) 0x14, (byte) 0x15, (byte) 0x16, (byte) 0x17, (byte) 0x18, + (byte) 0x19, (byte) 0x1a, (byte) 0x1b, (byte) 0x1c, (byte) 0x1d, + (byte) 0x1e, (byte) 0x1f, (byte) 0x20, (byte) 0x21, (byte) 0x22, + (byte) 0x23, (byte) 0x24, (byte) 0x25, (byte) 0x26, (byte) 0x27, + (byte) 0x28, (byte) 0x29, (byte) 0x2a, (byte) 0x2b, (byte) 0x2c, + (byte) 0x2d, (byte) 0x2e, (byte) 0x2f, (byte) 0x30, (byte) 0x31, + (byte) 0x32, (byte) 0x33, (byte) 0x34, (byte) 0x35, (byte) 0x36, + (byte) 0x37, (byte) 0x38, (byte) 0x39, (byte) 0x3a, (byte) 0x3b, + (byte) 0x3c, (byte) 0x3d, (byte) 0x3e, (byte) 0x3f, (byte) 0x40, + (byte) 0x41, (byte) 0x42, (byte) 0x43, (byte) 0x44, (byte) 0x45, + (byte) 0x46, (byte) 0x47, (byte) 0x48, (byte) 0x49, (byte) 0x4a, + (byte) 0x4b, (byte) 0x4c, (byte) 0x4d, (byte) 0x4e, (byte) 0x4f, + (byte) 0x50, (byte) 0x51, (byte) 0x52, (byte) 0x53, (byte) 0x54, + (byte) 0x55, (byte) 0x56, (byte) 0x57, (byte) 0x58, (byte) 0x59, + (byte) 0x5a, (byte) 0x5b, (byte) 0x5c, (byte) 0x5d, (byte) 0x5e, + (byte) 0x5f, (byte) 0x60, (byte) 0x61, (byte) 0x62, (byte) 0x63, + (byte) 0x64, (byte) 0x65, (byte) 0x66, (byte) 0x67, (byte) 0x68, + (byte) 0x69, (byte) 0x6a, (byte) 0x6b, (byte) 0x6c, (byte) 0x6d, + (byte) 0x6e, (byte) 0x6f, (byte) 0x70, (byte) 0x71, (byte) 0x72, + (byte) 0x73, (byte) 0x74, (byte) 0x75, (byte) 0x76, (byte) 0x77, + (byte) 0x78, (byte) 0x79, (byte) 0x7a, (byte) 0x7b, (byte) 0x7c, + (byte) 0x7d, (byte) 0x7e, (byte) 0x7f, (byte) 0x80, (byte) 0x81, + (byte) 0x82, (byte) 0x83, (byte) 0x84, (byte) 0x85, (byte) 0x86, + (byte) 0x87, (byte) 0x88, (byte) 0x89, (byte) 0x8a, (byte) 0x8b, + (byte) 0x8c, (byte) 0x8d, (byte) 0x8e, (byte) 0x8f, (byte) 0x90, + (byte) 0x91, (byte) 0x92, (byte) 0x93, (byte) 0x94, (byte) 0x95, + (byte) 0x96, (byte) 0x97, (byte) 0x98, (byte) 0x99, (byte) 0x9a, + (byte) 0x9b, (byte) 0x9c, (byte) 0x9d, (byte) 0x9e, (byte) 0x9f, + (byte) 0xa0, (byte) 0xa1, (byte) 0xa2, (byte) 0xa3, (byte) 0xa4, + (byte) 0xa5, (byte) 0xa6, (byte) 0xa7, (byte) 0xa8, (byte) 0xa9, + (byte) 0xaa, (byte) 0xab, (byte) 0xac, (byte) 0xad, (byte) 0xae, + (byte) 0xaf, (byte) 0xb0, (byte) 0xb1, (byte) 0xb2, (byte) 0xb3, + (byte) 0xb4, (byte) 0xb5, (byte) 0xb6, (byte) 0xb7, (byte) 0xb8, + (byte) 0xb9, (byte) 0xba, (byte) 0xbb, (byte) 0xbc, (byte) 0xbd, + (byte) 0xbe, (byte) 0xbf, (byte) 0xc0, (byte) 0xc1, (byte) 0xc2, + (byte) 0xc3, (byte) 0xc4, (byte) 0xc5, (byte) 0xc6, (byte) 0xc7, + (byte) 0xc8, (byte) 0xc9, (byte) 0xca, (byte) 0xcb, (byte) 0xcc, + (byte) 0xcd, (byte) 0xce, (byte) 0xcf, (byte) 0xd0, (byte) 0xd1, + (byte) 0xd2, (byte) 0xd3, (byte) 0xd4, (byte) 0xd5, (byte) 0xd6, + (byte) 0xd7, (byte) 0xd8, (byte) 0xd9, (byte) 0xda, (byte) 0xdb, + (byte) 0xdc, (byte) 0xdd, (byte) 0xde, (byte) 0xdf, (byte) 0xe0, + (byte) 0xe1, (byte) 0xe2, (byte) 0xe3, (byte) 0xe4, (byte) 0xe5, + (byte) 0xe6, (byte) 0xe7, (byte) 0xe8, (byte) 0xe9, (byte) 0xea, + (byte) 0xeb, (byte) 0xec, (byte) 0xed, (byte) 0xee, (byte) 0xef, + (byte) 0xf0, (byte) 0xf1, (byte) 0xf2, (byte) 0xf3, (byte) 0xf4, + (byte) 0xf5, (byte) 0xf6, (byte) 0xf7, (byte) 0xf8, (byte) 0xf9, + (byte) 0xfa, (byte) 0xfb, (byte) 0xfc, (byte) 0xfd, (byte) 0xfe, + (byte) 0xff, (byte) 0x00, (byte) 0x01, (byte) 0x02, (byte) 0x03, + (byte) 0x04, (byte) 0x05, (byte) 0x06, (byte) 0x07, (byte) 0x08, + (byte) 0x09, (byte) 0x0a, (byte) 0x0b, (byte) 0x0c, (byte) 0x0d, + (byte) 0x0e, (byte) 0x0f, (byte) 0x10, (byte) 0x11, (byte) 0x12, + (byte) 0x13, (byte) 0x14, (byte) 0x15, (byte) 0x16, (byte) 0x17, + (byte) 0x18, (byte) 0x19, (byte) 0x1a, (byte) 0x1b, (byte) 0x1c, + (byte) 0x1d, (byte) 0x1e, (byte) 0x1f, (byte) 0x20, (byte) 0x21, + (byte) 0x22, (byte) 0x23, (byte) 0x24, (byte) 0x25, (byte) 0x26, + (byte) 0x27, (byte) 0x28, (byte) 0x29, (byte) 0x2a, (byte) 0x2b, + (byte) 0x2c, (byte) 0x2d, (byte) 0x2e, (byte) 0x2f, (byte) 0x30, + (byte) 0x31, (byte) 0x32, (byte) 0x33, (byte) 0x34, (byte) 0x35, + (byte) 0x36, (byte) 0x37, (byte) 0x38, (byte) 0x39, (byte) 0x3a, + (byte) 0x3b, (byte) 0x3c, (byte) 0x3d, (byte) 0x3e, (byte) 0x3f, + (byte) 0x40, (byte) 0x41, (byte) 0x42, (byte) 0x43, (byte) 0x44, + (byte) 0x45, (byte) 0x46, (byte) 0x47, (byte) 0x48, (byte) 0x49, + (byte) 0x4a, (byte) 0x4b, (byte) 0x4c, (byte) 0x4d, (byte) 0x4e, + (byte) 0x4f, (byte) 0x50, (byte) 0x51, (byte) 0x52, (byte) 0x53, + (byte) 0x54, (byte) 0x55, (byte) 0x56, (byte) 0x57, (byte) 0x58, + (byte) 0x59, (byte) 0x5a, (byte) 0x5b, (byte) 0x5c, (byte) 0x5d, + (byte) 0x5e, (byte) 0x5f, (byte) 0x60, (byte) 0x61, (byte) 0x62, + (byte) 0x63, (byte) 0x64, (byte) 0x65, (byte) 0x66, (byte) 0x67, + (byte) 0x68, (byte) 0x69, (byte) 0x6a, (byte) 0x6b, (byte) 0x6c, + (byte) 0x6d, (byte) 0x6e, (byte) 0x6f, (byte) 0x70, (byte) 0x71, + (byte) 0x72, (byte) 0x73, (byte) 0x74, (byte) 0x75, (byte) 0x76, + (byte) 0x77, (byte) 0x78, (byte) 0x79, (byte) 0x7a, (byte) 0x7b, + (byte) 0x7c, (byte) 0x7d, (byte) 0x7e, (byte) 0x7f, (byte) 0x80, + (byte) 0x81, (byte) 0x82, (byte) 0x83, (byte) 0x84, (byte) 0x85, + (byte) 0x86, (byte) 0x87, (byte) 0x88, (byte) 0x89, (byte) 0x8a, + (byte) 0x8b, (byte) 0x8c, (byte) 0x8d, (byte) 0x8e, (byte) 0x8f, + (byte) 0x90, (byte) 0x91, (byte) 0x92, (byte) 0x93, (byte) 0x94, + (byte) 0x95, (byte) 0x96, (byte) 0x97, (byte) 0x98, (byte) 0x99, + (byte) 0x9a, (byte) 0x9b, (byte) 0x9c, (byte) 0x9d, (byte) 0x9e, + (byte) 0x9f, (byte) 0xa0, (byte) 0xa1, (byte) 0xa2, (byte) 0xa3, + (byte) 0xa4, (byte) 0xa5, (byte) 0xa6, (byte) 0xa7, (byte) 0xa8, + (byte) 0xa9, (byte) 0xaa, (byte) 0xab, (byte) 0xac, (byte) 0xad, + (byte) 0xae, (byte) 0xaf, (byte) 0xb0, (byte) 0xb1, (byte) 0xb2, + (byte) 0xb3, (byte) 0xb4, (byte) 0xb5, (byte) 0xb6, (byte) 0xb7, + (byte) 0xb8, (byte) 0xb9, (byte) 0xba, (byte) 0xbb, (byte) 0xbc, + (byte) 0xbd, (byte) 0xbe, (byte) 0xbf, (byte) 0xc0, (byte) 0xc1, + (byte) 0xc2, (byte) 0xc3, (byte) 0xc4, (byte) 0xc5, (byte) 0xc6, + (byte) 0xc7, (byte) 0xc8, (byte) 0xc9, (byte) 0xca, (byte) 0xcb, + (byte) 0xcc, (byte) 0xcd, (byte) 0xce, (byte) 0xcf, (byte) 0xd0, + (byte) 0xd1, (byte) 0xd2, (byte) 0xd3, (byte) 0xd4, (byte) 0xd5, + (byte) 0xd6, (byte) 0xd7, (byte) 0xd8, (byte) 0xd9, (byte) 0xda, + (byte) 0xdb, (byte) 0xdc, (byte) 0xdd, (byte) 0xde, (byte) 0xdf, + (byte) 0xe0, (byte) 0xe1, (byte) 0xe2, (byte) 0xe3, (byte) 0xe4, + (byte) 0xe5, (byte) 0xe6, (byte) 0xe7, (byte) 0xe8, (byte) 0xe9, + (byte) 0xea, (byte) 0xeb, (byte) 0xec, (byte) 0xed, (byte) 0xee, + (byte) 0xef, (byte) 0xf0, (byte) 0xf1, (byte) 0xf2, (byte) 0xf3, + (byte) 0xf4, (byte) 0xf5, (byte) 0xf6, (byte) 0xf7, (byte) 0xf8, + (byte) 0xf9, (byte) 0xfa, (byte) 0xfb, (byte) 0xfc, (byte) 0xfd, + (byte) 0xfe, (byte) 0xff, (byte) 0x00, (byte) 0x01, (byte) 0x02, + (byte) 0x03, (byte) 0x04, (byte) 0x05, (byte) 0x06, (byte) 0x07, + (byte) 0x08, (byte) 0x09, (byte) 0x0a, (byte) 0x0b, (byte) 0x0c, + (byte) 0x0d, (byte) 0x0e, (byte) 0x0f, (byte) 0x10, (byte) 0x11, + (byte) 0x12, (byte) 0x13, (byte) 0x14, (byte) 0x15, (byte) 0x16, + (byte) 0x17, (byte) 0x18, (byte) 0x19, (byte) 0x1a, (byte) 0x1b, + (byte) 0x1c, (byte) 0x1d, (byte) 0x1e, (byte) 0x1f, (byte) 0x20, + (byte) 0x21, (byte) 0x22, (byte) 0x23, (byte) 0x24, (byte) 0x25, + (byte) 0x26, (byte) 0x27, (byte) 0x28, (byte) 0x29, (byte) 0x2a, + (byte) 0x2b, (byte) 0x2c, (byte) 0x2d, (byte) 0x2e, (byte) 0x2f, + (byte) 0x30, (byte) 0x31, (byte) 0x32, (byte) 0x33, (byte) 0x34, + (byte) 0x35, (byte) 0x36, (byte) 0x37, (byte) 0x38, (byte) 0x39, + (byte) 0x3a, (byte) 0x3b, (byte) 0x3c, (byte) 0x3d, (byte) 0x3e, + (byte) 0x3f, (byte) 0x40, (byte) 0x41, (byte) 0x42, (byte) 0x43, + (byte) 0x44, (byte) 0x45, (byte) 0x46, (byte) 0x47, (byte) 0x48, + (byte) 0x49, (byte) 0x4a, (byte) 0x4b, (byte) 0x4c, (byte) 0x4d, + (byte) 0x4e, (byte) 0x4f, (byte) 0x50, (byte) 0x51, (byte) 0x52, + (byte) 0x53, (byte) 0x54, (byte) 0x55, (byte) 0x56, (byte) 0x57, + (byte) 0x58, (byte) 0x59, (byte) 0x5a, (byte) 0x5b, (byte) 0x5c, + (byte) 0x5d, (byte) 0x5e, (byte) 0x5f, (byte) 0x60, (byte) 0x61, + (byte) 0x62, (byte) 0x63, (byte) 0x64, (byte) 0x65, (byte) 0x66, + (byte) 0x67, (byte) 0x68, (byte) 0x69, (byte) 0x6a, (byte) 0x6b, + (byte) 0x6c, (byte) 0x6d, (byte) 0x6e, (byte) 0x6f, (byte) 0x70, + (byte) 0x71, (byte) 0x72, (byte) 0x73, (byte) 0x74, (byte) 0x75, + (byte) 0x76, (byte) 0x77, (byte) 0x78, (byte) 0x79, (byte) 0x7a, + (byte) 0x7b, (byte) 0x7c, (byte) 0x7d, (byte) 0x7e, (byte) 0x7f, + (byte) 0x80, (byte) 0x81, (byte) 0x82, (byte) 0x83, (byte) 0x84, + (byte) 0x85, (byte) 0x86, (byte) 0x87, (byte) 0x88, (byte) 0x89, + (byte) 0x8a, (byte) 0x8b, (byte) 0x8c, (byte) 0x8d, (byte) 0x8e, + (byte) 0x8f, (byte) 0x90, (byte) 0x91, (byte) 0x92, (byte) 0x93, + (byte) 0x94, (byte) 0x95, (byte) 0x96, (byte) 0x97, (byte) 0x98, + (byte) 0x99, (byte) 0x9a, (byte) 0x9b, (byte) 0x9c, (byte) 0x9d, + (byte) 0x9e, (byte) 0x9f, (byte) 0xa0, (byte) 0xa1, (byte) 0xa2, + (byte) 0xa3, (byte) 0xa4, (byte) 0xa5, (byte) 0xa6, (byte) 0xa7, + (byte) 0xa8, (byte) 0xa9, (byte) 0xaa, (byte) 0xab, (byte) 0xac, + (byte) 0xad, (byte) 0xae, (byte) 0xaf, (byte) 0xb0, (byte) 0xb1, + (byte) 0xb2, (byte) 0xb3, (byte) 0xb4, (byte) 0xb5, (byte) 0xb6, + (byte) 0xb7, (byte) 0xb8, (byte) 0xb9, (byte) 0xba, (byte) 0xbb, + (byte) 0xbc, (byte) 0xbd, (byte) 0xbe, (byte) 0xbf, (byte) 0xc0, + (byte) 0xc1, (byte) 0xc2, (byte) 0xc3, (byte) 0xc4, (byte) 0xc5, + (byte) 0xc6, (byte) 0xc7, (byte) 0xc8, (byte) 0xc9, (byte) 0xca, + (byte) 0xcb, (byte) 0xcc, (byte) 0xcd, (byte) 0xce, (byte) 0xcf, + (byte) 0xd0, (byte) 0xd1, (byte) 0xd2, (byte) 0xd3, (byte) 0xd4, + (byte) 0xd5, (byte) 0xd6, (byte) 0xd7, (byte) 0xd8, (byte) 0xd9, + (byte) 0xda, (byte) 0xdb, (byte) 0xdc, (byte) 0xdd, (byte) 0xde, + (byte) 0xdf, (byte) 0xe0, (byte) 0xe1, (byte) 0xe2, (byte) 0xe3, + (byte) 0xe4, (byte) 0xe5, (byte) 0xe6, (byte) 0xe7, (byte) 0xe8, + (byte) 0xe9, (byte) 0xea, (byte) 0xeb, (byte) 0xec, (byte) 0xed, + (byte) 0xee, (byte) 0xef, (byte) 0xf0, (byte) 0xf1, (byte) 0xf2, + (byte) 0xf3, (byte) 0xf4, (byte) 0xf5, (byte) 0xf6, (byte) 0xf7, + (byte) 0xf8, (byte) 0xf9, (byte) 0xfa, (byte) 0xfb, (byte) 0xfc, + (byte) 0xfd, (byte) 0xfe, (byte) 0xff }; + + /** + * "valid" encoding for DSA - no alg params + */ + private static final byte[] dsaEncryptedPrivateKeyInfoNP = new byte[] { + (byte) 0x30, (byte) 0x82, (byte) 0x04, (byte) 0x11, (byte) 0x30, + (byte) 0x0b, (byte) 0x06, (byte) 0x07, (byte) 0x2a, (byte) 0x86, + (byte) 0x48, (byte) 0xce, (byte) 0x38, (byte) 0x04, (byte) 0x01, + (byte) 0x05, (byte) 0x00, (byte) 0x04, (byte) 0x82, (byte) 0x04, + (byte) 0x00, (byte) 0x00, (byte) 0x01, (byte) 0x02, (byte) 0x03, + (byte) 0x04, (byte) 0x05, (byte) 0x06, (byte) 0x07, (byte) 0x08, + (byte) 0x09, (byte) 0x0a, (byte) 0x0b, (byte) 0x0c, (byte) 0x0d, + (byte) 0x0e, (byte) 0x0f, (byte) 0x10, (byte) 0x11, (byte) 0x12, + (byte) 0x13, (byte) 0x14, (byte) 0x15, (byte) 0x16, (byte) 0x17, + (byte) 0x18, (byte) 0x19, (byte) 0x1a, (byte) 0x1b, (byte) 0x1c, + (byte) 0x1d, (byte) 0x1e, (byte) 0x1f, (byte) 0x20, (byte) 0x21, + (byte) 0x22, (byte) 0x23, (byte) 0x24, (byte) 0x25, (byte) 0x26, + (byte) 0x27, (byte) 0x28, (byte) 0x29, (byte) 0x2a, (byte) 0x2b, + (byte) 0x2c, (byte) 0x2d, (byte) 0x2e, (byte) 0x2f, (byte) 0x30, + (byte) 0x31, (byte) 0x32, (byte) 0x33, (byte) 0x34, (byte) 0x35, + (byte) 0x36, (byte) 0x37, (byte) 0x38, (byte) 0x39, (byte) 0x3a, + (byte) 0x3b, (byte) 0x3c, (byte) 0x3d, (byte) 0x3e, (byte) 0x3f, + (byte) 0x40, (byte) 0x41, (byte) 0x42, (byte) 0x43, (byte) 0x44, + (byte) 0x45, (byte) 0x46, (byte) 0x47, (byte) 0x48, (byte) 0x49, + (byte) 0x4a, (byte) 0x4b, (byte) 0x4c, (byte) 0x4d, (byte) 0x4e, + (byte) 0x4f, (byte) 0x50, (byte) 0x51, (byte) 0x52, (byte) 0x53, + (byte) 0x54, (byte) 0x55, (byte) 0x56, (byte) 0x57, (byte) 0x58, + (byte) 0x59, (byte) 0x5a, (byte) 0x5b, (byte) 0x5c, (byte) 0x5d, + (byte) 0x5e, (byte) 0x5f, (byte) 0x60, (byte) 0x61, (byte) 0x62, + (byte) 0x63, (byte) 0x64, (byte) 0x65, (byte) 0x66, (byte) 0x67, + (byte) 0x68, (byte) 0x69, (byte) 0x6a, (byte) 0x6b, (byte) 0x6c, + (byte) 0x6d, (byte) 0x6e, (byte) 0x6f, (byte) 0x70, (byte) 0x71, + (byte) 0x72, (byte) 0x73, (byte) 0x74, (byte) 0x75, (byte) 0x76, + (byte) 0x77, (byte) 0x78, (byte) 0x79, (byte) 0x7a, (byte) 0x7b, + (byte) 0x7c, (byte) 0x7d, (byte) 0x7e, (byte) 0x7f, (byte) 0x80, + (byte) 0x81, (byte) 0x82, (byte) 0x83, (byte) 0x84, (byte) 0x85, + (byte) 0x86, (byte) 0x87, (byte) 0x88, (byte) 0x89, (byte) 0x8a, + (byte) 0x8b, (byte) 0x8c, (byte) 0x8d, (byte) 0x8e, (byte) 0x8f, + (byte) 0x90, (byte) 0x91, (byte) 0x92, (byte) 0x93, (byte) 0x94, + (byte) 0x95, (byte) 0x96, (byte) 0x97, (byte) 0x98, (byte) 0x99, + (byte) 0x9a, (byte) 0x9b, (byte) 0x9c, (byte) 0x9d, (byte) 0x9e, + (byte) 0x9f, (byte) 0xa0, (byte) 0xa1, (byte) 0xa2, (byte) 0xa3, + (byte) 0xa4, (byte) 0xa5, (byte) 0xa6, (byte) 0xa7, (byte) 0xa8, + (byte) 0xa9, (byte) 0xaa, (byte) 0xab, (byte) 0xac, (byte) 0xad, + (byte) 0xae, (byte) 0xaf, (byte) 0xb0, (byte) 0xb1, (byte) 0xb2, + (byte) 0xb3, (byte) 0xb4, (byte) 0xb5, (byte) 0xb6, (byte) 0xb7, + (byte) 0xb8, (byte) 0xb9, (byte) 0xba, (byte) 0xbb, (byte) 0xbc, + (byte) 0xbd, (byte) 0xbe, (byte) 0xbf, (byte) 0xc0, (byte) 0xc1, + (byte) 0xc2, (byte) 0xc3, (byte) 0xc4, (byte) 0xc5, (byte) 0xc6, + (byte) 0xc7, (byte) 0xc8, (byte) 0xc9, (byte) 0xca, (byte) 0xcb, + (byte) 0xcc, (byte) 0xcd, (byte) 0xce, (byte) 0xcf, (byte) 0xd0, + (byte) 0xd1, (byte) 0xd2, (byte) 0xd3, (byte) 0xd4, (byte) 0xd5, + (byte) 0xd6, (byte) 0xd7, (byte) 0xd8, (byte) 0xd9, (byte) 0xda, + (byte) 0xdb, (byte) 0xdc, (byte) 0xdd, (byte) 0xde, (byte) 0xdf, + (byte) 0xe0, (byte) 0xe1, (byte) 0xe2, (byte) 0xe3, (byte) 0xe4, + (byte) 0xe5, (byte) 0xe6, (byte) 0xe7, (byte) 0xe8, (byte) 0xe9, + (byte) 0xea, (byte) 0xeb, (byte) 0xec, (byte) 0xed, (byte) 0xee, + (byte) 0xef, (byte) 0xf0, (byte) 0xf1, (byte) 0xf2, (byte) 0xf3, + (byte) 0xf4, (byte) 0xf5, (byte) 0xf6, (byte) 0xf7, (byte) 0xf8, + (byte) 0xf9, (byte) 0xfa, (byte) 0xfb, (byte) 0xfc, (byte) 0xfd, + (byte) 0xfe, (byte) 0xff, (byte) 0x00, (byte) 0x01, (byte) 0x02, + (byte) 0x03, (byte) 0x04, (byte) 0x05, (byte) 0x06, (byte) 0x07, + (byte) 0x08, (byte) 0x09, (byte) 0x0a, (byte) 0x0b, (byte) 0x0c, + (byte) 0x0d, (byte) 0x0e, (byte) 0x0f, (byte) 0x10, (byte) 0x11, + (byte) 0x12, (byte) 0x13, (byte) 0x14, (byte) 0x15, (byte) 0x16, + (byte) 0x17, (byte) 0x18, (byte) 0x19, (byte) 0x1a, (byte) 0x1b, + (byte) 0x1c, (byte) 0x1d, (byte) 0x1e, (byte) 0x1f, (byte) 0x20, + (byte) 0x21, (byte) 0x22, (byte) 0x23, (byte) 0x24, (byte) 0x25, + (byte) 0x26, (byte) 0x27, (byte) 0x28, (byte) 0x29, (byte) 0x2a, + (byte) 0x2b, (byte) 0x2c, (byte) 0x2d, (byte) 0x2e, (byte) 0x2f, + (byte) 0x30, (byte) 0x31, (byte) 0x32, (byte) 0x33, (byte) 0x34, + (byte) 0x35, (byte) 0x36, (byte) 0x37, (byte) 0x38, (byte) 0x39, + (byte) 0x3a, (byte) 0x3b, (byte) 0x3c, (byte) 0x3d, (byte) 0x3e, + (byte) 0x3f, (byte) 0x40, (byte) 0x41, (byte) 0x42, (byte) 0x43, + (byte) 0x44, (byte) 0x45, (byte) 0x46, (byte) 0x47, (byte) 0x48, + (byte) 0x49, (byte) 0x4a, (byte) 0x4b, (byte) 0x4c, (byte) 0x4d, + (byte) 0x4e, (byte) 0x4f, (byte) 0x50, (byte) 0x51, (byte) 0x52, + (byte) 0x53, (byte) 0x54, (byte) 0x55, (byte) 0x56, (byte) 0x57, + (byte) 0x58, (byte) 0x59, (byte) 0x5a, (byte) 0x5b, (byte) 0x5c, + (byte) 0x5d, (byte) 0x5e, (byte) 0x5f, (byte) 0x60, (byte) 0x61, + (byte) 0x62, (byte) 0x63, (byte) 0x64, (byte) 0x65, (byte) 0x66, + (byte) 0x67, (byte) 0x68, (byte) 0x69, (byte) 0x6a, (byte) 0x6b, + (byte) 0x6c, (byte) 0x6d, (byte) 0x6e, (byte) 0x6f, (byte) 0x70, + (byte) 0x71, (byte) 0x72, (byte) 0x73, (byte) 0x74, (byte) 0x75, + (byte) 0x76, (byte) 0x77, (byte) 0x78, (byte) 0x79, (byte) 0x7a, + (byte) 0x7b, (byte) 0x7c, (byte) 0x7d, (byte) 0x7e, (byte) 0x7f, + (byte) 0x80, (byte) 0x81, (byte) 0x82, (byte) 0x83, (byte) 0x84, + (byte) 0x85, (byte) 0x86, (byte) 0x87, (byte) 0x88, (byte) 0x89, + (byte) 0x8a, (byte) 0x8b, (byte) 0x8c, (byte) 0x8d, (byte) 0x8e, + (byte) 0x8f, (byte) 0x90, (byte) 0x91, (byte) 0x92, (byte) 0x93, + (byte) 0x94, (byte) 0x95, (byte) 0x96, (byte) 0x97, (byte) 0x98, + (byte) 0x99, (byte) 0x9a, (byte) 0x9b, (byte) 0x9c, (byte) 0x9d, + (byte) 0x9e, (byte) 0x9f, (byte) 0xa0, (byte) 0xa1, (byte) 0xa2, + (byte) 0xa3, (byte) 0xa4, (byte) 0xa5, (byte) 0xa6, (byte) 0xa7, + (byte) 0xa8, (byte) 0xa9, (byte) 0xaa, (byte) 0xab, (byte) 0xac, + (byte) 0xad, (byte) 0xae, (byte) 0xaf, (byte) 0xb0, (byte) 0xb1, + (byte) 0xb2, (byte) 0xb3, (byte) 0xb4, (byte) 0xb5, (byte) 0xb6, + (byte) 0xb7, (byte) 0xb8, (byte) 0xb9, (byte) 0xba, (byte) 0xbb, + (byte) 0xbc, (byte) 0xbd, (byte) 0xbe, (byte) 0xbf, (byte) 0xc0, + (byte) 0xc1, (byte) 0xc2, (byte) 0xc3, (byte) 0xc4, (byte) 0xc5, + (byte) 0xc6, (byte) 0xc7, (byte) 0xc8, (byte) 0xc9, (byte) 0xca, + (byte) 0xcb, (byte) 0xcc, (byte) 0xcd, (byte) 0xce, (byte) 0xcf, + (byte) 0xd0, (byte) 0xd1, (byte) 0xd2, (byte) 0xd3, (byte) 0xd4, + (byte) 0xd5, (byte) 0xd6, (byte) 0xd7, (byte) 0xd8, (byte) 0xd9, + (byte) 0xda, (byte) 0xdb, (byte) 0xdc, (byte) 0xdd, (byte) 0xde, + (byte) 0xdf, (byte) 0xe0, (byte) 0xe1, (byte) 0xe2, (byte) 0xe3, + (byte) 0xe4, (byte) 0xe5, (byte) 0xe6, (byte) 0xe7, (byte) 0xe8, + (byte) 0xe9, (byte) 0xea, (byte) 0xeb, (byte) 0xec, (byte) 0xed, + (byte) 0xee, (byte) 0xef, (byte) 0xf0, (byte) 0xf1, (byte) 0xf2, + (byte) 0xf3, (byte) 0xf4, (byte) 0xf5, (byte) 0xf6, (byte) 0xf7, + (byte) 0xf8, (byte) 0xf9, (byte) 0xfa, (byte) 0xfb, (byte) 0xfc, + (byte) 0xfd, (byte) 0xfe, (byte) 0xff, (byte) 0x00, (byte) 0x01, + (byte) 0x02, (byte) 0x03, (byte) 0x04, (byte) 0x05, (byte) 0x06, + (byte) 0x07, (byte) 0x08, (byte) 0x09, (byte) 0x0a, (byte) 0x0b, + (byte) 0x0c, (byte) 0x0d, (byte) 0x0e, (byte) 0x0f, (byte) 0x10, + (byte) 0x11, (byte) 0x12, (byte) 0x13, (byte) 0x14, (byte) 0x15, + (byte) 0x16, (byte) 0x17, (byte) 0x18, (byte) 0x19, (byte) 0x1a, + (byte) 0x1b, (byte) 0x1c, (byte) 0x1d, (byte) 0x1e, (byte) 0x1f, + (byte) 0x20, (byte) 0x21, (byte) 0x22, (byte) 0x23, (byte) 0x24, + (byte) 0x25, (byte) 0x26, (byte) 0x27, (byte) 0x28, (byte) 0x29, + (byte) 0x2a, (byte) 0x2b, (byte) 0x2c, (byte) 0x2d, (byte) 0x2e, + (byte) 0x2f, (byte) 0x30, (byte) 0x31, (byte) 0x32, (byte) 0x33, + (byte) 0x34, (byte) 0x35, (byte) 0x36, (byte) 0x37, (byte) 0x38, + (byte) 0x39, (byte) 0x3a, (byte) 0x3b, (byte) 0x3c, (byte) 0x3d, + (byte) 0x3e, (byte) 0x3f, (byte) 0x40, (byte) 0x41, (byte) 0x42, + (byte) 0x43, (byte) 0x44, (byte) 0x45, (byte) 0x46, (byte) 0x47, + (byte) 0x48, (byte) 0x49, (byte) 0x4a, (byte) 0x4b, (byte) 0x4c, + (byte) 0x4d, (byte) 0x4e, (byte) 0x4f, (byte) 0x50, (byte) 0x51, + (byte) 0x52, (byte) 0x53, (byte) 0x54, (byte) 0x55, (byte) 0x56, + (byte) 0x57, (byte) 0x58, (byte) 0x59, (byte) 0x5a, (byte) 0x5b, + (byte) 0x5c, (byte) 0x5d, (byte) 0x5e, (byte) 0x5f, (byte) 0x60, + (byte) 0x61, (byte) 0x62, (byte) 0x63, (byte) 0x64, (byte) 0x65, + (byte) 0x66, (byte) 0x67, (byte) 0x68, (byte) 0x69, (byte) 0x6a, + (byte) 0x6b, (byte) 0x6c, (byte) 0x6d, (byte) 0x6e, (byte) 0x6f, + (byte) 0x70, (byte) 0x71, (byte) 0x72, (byte) 0x73, (byte) 0x74, + (byte) 0x75, (byte) 0x76, (byte) 0x77, (byte) 0x78, (byte) 0x79, + (byte) 0x7a, (byte) 0x7b, (byte) 0x7c, (byte) 0x7d, (byte) 0x7e, + (byte) 0x7f, (byte) 0x80, (byte) 0x81, (byte) 0x82, (byte) 0x83, + (byte) 0x84, (byte) 0x85, (byte) 0x86, (byte) 0x87, (byte) 0x88, + (byte) 0x89, (byte) 0x8a, (byte) 0x8b, (byte) 0x8c, (byte) 0x8d, + (byte) 0x8e, (byte) 0x8f, (byte) 0x90, (byte) 0x91, (byte) 0x92, + (byte) 0x93, (byte) 0x94, (byte) 0x95, (byte) 0x96, (byte) 0x97, + (byte) 0x98, (byte) 0x99, (byte) 0x9a, (byte) 0x9b, (byte) 0x9c, + (byte) 0x9d, (byte) 0x9e, (byte) 0x9f, (byte) 0xa0, (byte) 0xa1, + (byte) 0xa2, (byte) 0xa3, (byte) 0xa4, (byte) 0xa5, (byte) 0xa6, + (byte) 0xa7, (byte) 0xa8, (byte) 0xa9, (byte) 0xaa, (byte) 0xab, + (byte) 0xac, (byte) 0xad, (byte) 0xae, (byte) 0xaf, (byte) 0xb0, + (byte) 0xb1, (byte) 0xb2, (byte) 0xb3, (byte) 0xb4, (byte) 0xb5, + (byte) 0xb6, (byte) 0xb7, (byte) 0xb8, (byte) 0xb9, (byte) 0xba, + (byte) 0xbb, (byte) 0xbc, (byte) 0xbd, (byte) 0xbe, (byte) 0xbf, + (byte) 0xc0, (byte) 0xc1, (byte) 0xc2, (byte) 0xc3, (byte) 0xc4, + (byte) 0xc5, (byte) 0xc6, (byte) 0xc7, (byte) 0xc8, (byte) 0xc9, + (byte) 0xca, (byte) 0xcb, (byte) 0xcc, (byte) 0xcd, (byte) 0xce, + (byte) 0xcf, (byte) 0xd0, (byte) 0xd1, (byte) 0xd2, (byte) 0xd3, + (byte) 0xd4, (byte) 0xd5, (byte) 0xd6, (byte) 0xd7, (byte) 0xd8, + (byte) 0xd9, (byte) 0xda, (byte) 0xdb, (byte) 0xdc, (byte) 0xdd, + (byte) 0xde, (byte) 0xdf, (byte) 0xe0, (byte) 0xe1, (byte) 0xe2, + (byte) 0xe3, (byte) 0xe4, (byte) 0xe5, (byte) 0xe6, (byte) 0xe7, + (byte) 0xe8, (byte) 0xe9, (byte) 0xea, (byte) 0xeb, (byte) 0xec, + (byte) 0xed, (byte) 0xee, (byte) 0xef, (byte) 0xf0, (byte) 0xf1, + (byte) 0xf2, (byte) 0xf3, (byte) 0xf4, (byte) 0xf5, (byte) 0xf6, + (byte) 0xf7, (byte) 0xf8, (byte) 0xf9, (byte) 0xfa, (byte) 0xfb, + (byte) 0xfc, (byte) 0xfd, (byte) 0xfe, (byte) 0xff, (byte) 0x00, + (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x04, (byte) 0x05, + (byte) 0x06, (byte) 0x07, (byte) 0x08, (byte) 0x09, (byte) 0x0a, + (byte) 0x0b, (byte) 0x0c, (byte) 0x0d, (byte) 0x0e, (byte) 0x0f, + (byte) 0x10, (byte) 0x11, (byte) 0x12, (byte) 0x13, (byte) 0x14, + (byte) 0x15, (byte) 0x16, (byte) 0x17, (byte) 0x18, (byte) 0x19, + (byte) 0x1a, (byte) 0x1b, (byte) 0x1c, (byte) 0x1d, (byte) 0x1e, + (byte) 0x1f, (byte) 0x20, (byte) 0x21, (byte) 0x22, (byte) 0x23, + (byte) 0x24, (byte) 0x25, (byte) 0x26, (byte) 0x27, (byte) 0x28, + (byte) 0x29, (byte) 0x2a, (byte) 0x2b, (byte) 0x2c, (byte) 0x2d, + (byte) 0x2e, (byte) 0x2f, (byte) 0x30, (byte) 0x31, (byte) 0x32, + (byte) 0x33, (byte) 0x34, (byte) 0x35, (byte) 0x36, (byte) 0x37, + (byte) 0x38, (byte) 0x39, (byte) 0x3a, (byte) 0x3b, (byte) 0x3c, + (byte) 0x3d, (byte) 0x3e, (byte) 0x3f, (byte) 0x40, (byte) 0x41, + (byte) 0x42, (byte) 0x43, (byte) 0x44, (byte) 0x45, (byte) 0x46, + (byte) 0x47, (byte) 0x48, (byte) 0x49, (byte) 0x4a, (byte) 0x4b, + (byte) 0x4c, (byte) 0x4d, (byte) 0x4e, (byte) 0x4f, (byte) 0x50, + (byte) 0x51, (byte) 0x52, (byte) 0x53, (byte) 0x54, (byte) 0x55, + (byte) 0x56, (byte) 0x57, (byte) 0x58, (byte) 0x59, (byte) 0x5a, + (byte) 0x5b, (byte) 0x5c, (byte) 0x5d, (byte) 0x5e, (byte) 0x5f, + (byte) 0x60, (byte) 0x61, (byte) 0x62, (byte) 0x63, (byte) 0x64, + (byte) 0x65, (byte) 0x66, (byte) 0x67, (byte) 0x68, (byte) 0x69, + (byte) 0x6a, (byte) 0x6b, (byte) 0x6c, (byte) 0x6d, (byte) 0x6e, + (byte) 0x6f, (byte) 0x70, (byte) 0x71, (byte) 0x72, (byte) 0x73, + (byte) 0x74, (byte) 0x75, (byte) 0x76, (byte) 0x77, (byte) 0x78, + (byte) 0x79, (byte) 0x7a, (byte) 0x7b, (byte) 0x7c, (byte) 0x7d, + (byte) 0x7e, (byte) 0x7f, (byte) 0x80, (byte) 0x81, (byte) 0x82, + (byte) 0x83, (byte) 0x84, (byte) 0x85, (byte) 0x86, (byte) 0x87, + (byte) 0x88, (byte) 0x89, (byte) 0x8a, (byte) 0x8b, (byte) 0x8c, + (byte) 0x8d, (byte) 0x8e, (byte) 0x8f, (byte) 0x90, (byte) 0x91, + (byte) 0x92, (byte) 0x93, (byte) 0x94, (byte) 0x95, (byte) 0x96, + (byte) 0x97, (byte) 0x98, (byte) 0x99, (byte) 0x9a, (byte) 0x9b, + (byte) 0x9c, (byte) 0x9d, (byte) 0x9e, (byte) 0x9f, (byte) 0xa0, + (byte) 0xa1, (byte) 0xa2, (byte) 0xa3, (byte) 0xa4, (byte) 0xa5, + (byte) 0xa6, (byte) 0xa7, (byte) 0xa8, (byte) 0xa9, (byte) 0xaa, + (byte) 0xab, (byte) 0xac, (byte) 0xad, (byte) 0xae, (byte) 0xaf, + (byte) 0xb0, (byte) 0xb1, (byte) 0xb2, (byte) 0xb3, (byte) 0xb4, + (byte) 0xb5, (byte) 0xb6, (byte) 0xb7, (byte) 0xb8, (byte) 0xb9, + (byte) 0xba, (byte) 0xbb, (byte) 0xbc, (byte) 0xbd, (byte) 0xbe, + (byte) 0xbf, (byte) 0xc0, (byte) 0xc1, (byte) 0xc2, (byte) 0xc3, + (byte) 0xc4, (byte) 0xc5, (byte) 0xc6, (byte) 0xc7, (byte) 0xc8, + (byte) 0xc9, (byte) 0xca, (byte) 0xcb, (byte) 0xcc, (byte) 0xcd, + (byte) 0xce, (byte) 0xcf, (byte) 0xd0, (byte) 0xd1, (byte) 0xd2, + (byte) 0xd3, (byte) 0xd4, (byte) 0xd5, (byte) 0xd6, (byte) 0xd7, + (byte) 0xd8, (byte) 0xd9, (byte) 0xda, (byte) 0xdb, (byte) 0xdc, + (byte) 0xdd, (byte) 0xde, (byte) 0xdf, (byte) 0xe0, (byte) 0xe1, + (byte) 0xe2, (byte) 0xe3, (byte) 0xe4, (byte) 0xe5, (byte) 0xe6, + (byte) 0xe7, (byte) 0xe8, (byte) 0xe9, (byte) 0xea, (byte) 0xeb, + (byte) 0xec, (byte) 0xed, (byte) 0xee, (byte) 0xef, (byte) 0xf0, + (byte) 0xf1, (byte) 0xf2, (byte) 0xf3, (byte) 0xf4, (byte) 0xf5, + (byte) 0xf6, (byte) 0xf7, (byte) 0xf8, (byte) 0xf9, (byte) 0xfa, + (byte) 0xfb, (byte) 0xfc, (byte) 0xfd, (byte) 0xfe, (byte) 0xff, }; + + /** + * "valid" encoding for DH with alg params + */ + private static final byte[] dhEncryptedPrivateKeyInfo = new byte[] { + (byte) 0x30, (byte) 0x82, (byte) 0x05, (byte) 0x22, (byte) 0x30, + (byte) 0x82, (byte) 0x01, (byte) 0x1a, (byte) 0x06, (byte) 0x09, + (byte) 0x2a, (byte) 0x86, (byte) 0x48, (byte) 0x86, (byte) 0xf7, + (byte) 0x0d, (byte) 0x01, (byte) 0x03, (byte) 0x01, (byte) 0x30, + (byte) 0x82, (byte) 0x01, (byte) 0x0b, (byte) 0x02, (byte) 0x81, + (byte) 0x81, (byte) 0x00, (byte) 0xce, (byte) 0x2c, (byte) 0x4f, + (byte) 0xea, (byte) 0xf2, (byte) 0x83, (byte) 0xc5, (byte) 0x38, + (byte) 0xc9, (byte) 0xb6, (byte) 0xd4, (byte) 0xf8, (byte) 0xb8, + (byte) 0x17, (byte) 0xa1, (byte) 0x7d, (byte) 0x4c, (byte) 0xec, + (byte) 0x6b, (byte) 0xd7, (byte) 0xc2, (byte) 0x1a, (byte) 0x35, + (byte) 0x85, (byte) 0x54, (byte) 0x14, (byte) 0x6c, (byte) 0x52, + (byte) 0x24, (byte) 0xbf, (byte) 0xe6, (byte) 0x32, (byte) 0xd8, + (byte) 0x42, (byte) 0xac, (byte) 0xb3, (byte) 0x28, (byte) 0x4f, + (byte) 0x77, (byte) 0xf6, (byte) 0xfc, (byte) 0xea, (byte) 0xea, + (byte) 0x72, (byte) 0xcf, (byte) 0x1d, (byte) 0x7b, (byte) 0xe1, + (byte) 0x72, (byte) 0xfa, (byte) 0x77, (byte) 0x12, (byte) 0xa9, + (byte) 0x42, (byte) 0xba, (byte) 0xc4, (byte) 0xf4, (byte) 0xfb, + (byte) 0xbd, (byte) 0x9f, (byte) 0x63, (byte) 0x9a, (byte) 0x58, + (byte) 0x6b, (byte) 0xb6, (byte) 0xa2, (byte) 0x6e, (byte) 0x3a, + (byte) 0x71, (byte) 0xf3, (byte) 0x43, (byte) 0x5e, (byte) 0x6f, + (byte) 0x8a, (byte) 0xd0, (byte) 0xac, (byte) 0xe5, (byte) 0x60, + (byte) 0x76, (byte) 0x57, (byte) 0x1f, (byte) 0x83, (byte) 0x4d, + (byte) 0xbc, (byte) 0xaa, (byte) 0xb1, (byte) 0x18, (byte) 0x40, + (byte) 0x19, (byte) 0xac, (byte) 0x31, (byte) 0xd4, (byte) 0xfc, + (byte) 0x39, (byte) 0x01, (byte) 0x46, (byte) 0xab, (byte) 0xab, + (byte) 0x53, (byte) 0x19, (byte) 0x2d, (byte) 0xf8, (byte) 0x4c, + (byte) 0xd3, (byte) 0x9f, (byte) 0x4d, (byte) 0xa6, (byte) 0x71, + (byte) 0x92, (byte) 0x06, (byte) 0xc7, (byte) 0x89, (byte) 0x70, + (byte) 0xc4, (byte) 0xc6, (byte) 0xa2, (byte) 0x1f, (byte) 0x05, + (byte) 0x4a, (byte) 0x5b, (byte) 0x84, (byte) 0xf9, (byte) 0xfb, + (byte) 0x98, (byte) 0x63, (byte) 0xc9, (byte) 0x9c, (byte) 0x13, + (byte) 0x02, (byte) 0x81, (byte) 0x80, (byte) 0x36, (byte) 0x55, + (byte) 0x93, (byte) 0xb3, (byte) 0x22, (byte) 0x0c, (byte) 0xcd, + (byte) 0x7c, (byte) 0xc3, (byte) 0xe3, (byte) 0xa3, (byte) 0x8a, + (byte) 0xd7, (byte) 0xb4, (byte) 0xe9, (byte) 0xe0, (byte) 0xfa, + (byte) 0xa9, (byte) 0xa8, (byte) 0x69, (byte) 0xd6, (byte) 0xa6, + (byte) 0x20, (byte) 0xb8, (byte) 0xd4, (byte) 0xe7, (byte) 0x87, + (byte) 0x4e, (byte) 0xf3, (byte) 0x90, (byte) 0x10, (byte) 0xdd, + (byte) 0x75, (byte) 0x5d, (byte) 0xff, (byte) 0xee, (byte) 0xf0, + (byte) 0xef, (byte) 0x6a, (byte) 0x0a, (byte) 0xb0, (byte) 0xf1, + (byte) 0x8a, (byte) 0xb6, (byte) 0x7b, (byte) 0x39, (byte) 0x95, + (byte) 0xd5, (byte) 0x24, (byte) 0x83, (byte) 0x10, (byte) 0x95, + (byte) 0x34, (byte) 0x08, (byte) 0x77, (byte) 0x1d, (byte) 0xaf, + (byte) 0x69, (byte) 0xf0, (byte) 0xb5, (byte) 0xdb, (byte) 0x24, + (byte) 0x89, (byte) 0x72, (byte) 0xb2, (byte) 0x0d, (byte) 0x57, + (byte) 0x94, (byte) 0xb0, (byte) 0xe8, (byte) 0xc2, (byte) 0x37, + (byte) 0x45, (byte) 0x5a, (byte) 0xfc, (byte) 0xa1, (byte) 0xa0, + (byte) 0x41, (byte) 0xe4, (byte) 0x0c, (byte) 0xa3, (byte) 0x40, + (byte) 0x8b, (byte) 0x9c, (byte) 0x19, (byte) 0x63, (byte) 0x61, + (byte) 0xd9, (byte) 0x05, (byte) 0xbf, (byte) 0xc5, (byte) 0xe8, + (byte) 0xf7, (byte) 0xbd, (byte) 0x3a, (byte) 0xf5, (byte) 0x78, + (byte) 0xc2, (byte) 0x92, (byte) 0xe8, (byte) 0x60, (byte) 0x07, + (byte) 0x3e, (byte) 0x57, (byte) 0x12, (byte) 0xf6, (byte) 0x97, + (byte) 0x1f, (byte) 0xea, (byte) 0x02, (byte) 0xa3, (byte) 0x19, + (byte) 0xa7, (byte) 0x5a, (byte) 0x9b, (byte) 0xf6, (byte) 0xd2, + (byte) 0x0f, (byte) 0xe9, (byte) 0x6b, (byte) 0xeb, (byte) 0xd7, + (byte) 0x93, (byte) 0x9a, (byte) 0x7e, (byte) 0x4f, (byte) 0xd6, + (byte) 0x29, (byte) 0x02, (byte) 0x02, (byte) 0x03, (byte) 0xff, + (byte) 0x04, (byte) 0x82, (byte) 0x04, (byte) 0x00, (byte) 0x00, + (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x04, (byte) 0x05, + (byte) 0x06, (byte) 0x07, (byte) 0x08, (byte) 0x09, (byte) 0x0a, + (byte) 0x0b, (byte) 0x0c, (byte) 0x0d, (byte) 0x0e, (byte) 0x0f, + (byte) 0x10, (byte) 0x11, (byte) 0x12, (byte) 0x13, (byte) 0x14, + (byte) 0x15, (byte) 0x16, (byte) 0x17, (byte) 0x18, (byte) 0x19, + (byte) 0x1a, (byte) 0x1b, (byte) 0x1c, (byte) 0x1d, (byte) 0x1e, + (byte) 0x1f, (byte) 0x20, (byte) 0x21, (byte) 0x22, (byte) 0x23, + (byte) 0x24, (byte) 0x25, (byte) 0x26, (byte) 0x27, (byte) 0x28, + (byte) 0x29, (byte) 0x2a, (byte) 0x2b, (byte) 0x2c, (byte) 0x2d, + (byte) 0x2e, (byte) 0x2f, (byte) 0x30, (byte) 0x31, (byte) 0x32, + (byte) 0x33, (byte) 0x34, (byte) 0x35, (byte) 0x36, (byte) 0x37, + (byte) 0x38, (byte) 0x39, (byte) 0x3a, (byte) 0x3b, (byte) 0x3c, + (byte) 0x3d, (byte) 0x3e, (byte) 0x3f, (byte) 0x40, (byte) 0x41, + (byte) 0x42, (byte) 0x43, (byte) 0x44, (byte) 0x45, (byte) 0x46, + (byte) 0x47, (byte) 0x48, (byte) 0x49, (byte) 0x4a, (byte) 0x4b, + (byte) 0x4c, (byte) 0x4d, (byte) 0x4e, (byte) 0x4f, (byte) 0x50, + (byte) 0x51, (byte) 0x52, (byte) 0x53, (byte) 0x54, (byte) 0x55, + (byte) 0x56, (byte) 0x57, (byte) 0x58, (byte) 0x59, (byte) 0x5a, + (byte) 0x5b, (byte) 0x5c, (byte) 0x5d, (byte) 0x5e, (byte) 0x5f, + (byte) 0x60, (byte) 0x61, (byte) 0x62, (byte) 0x63, (byte) 0x64, + (byte) 0x65, (byte) 0x66, (byte) 0x67, (byte) 0x68, (byte) 0x69, + (byte) 0x6a, (byte) 0x6b, (byte) 0x6c, (byte) 0x6d, (byte) 0x6e, + (byte) 0x6f, (byte) 0x70, (byte) 0x71, (byte) 0x72, (byte) 0x73, + (byte) 0x74, (byte) 0x75, (byte) 0x76, (byte) 0x77, (byte) 0x78, + (byte) 0x79, (byte) 0x7a, (byte) 0x7b, (byte) 0x7c, (byte) 0x7d, + (byte) 0x7e, (byte) 0x7f, (byte) 0x80, (byte) 0x81, (byte) 0x82, + (byte) 0x83, (byte) 0x84, (byte) 0x85, (byte) 0x86, (byte) 0x87, + (byte) 0x88, (byte) 0x89, (byte) 0x8a, (byte) 0x8b, (byte) 0x8c, + (byte) 0x8d, (byte) 0x8e, (byte) 0x8f, (byte) 0x90, (byte) 0x91, + (byte) 0x92, (byte) 0x93, (byte) 0x94, (byte) 0x95, (byte) 0x96, + (byte) 0x97, (byte) 0x98, (byte) 0x99, (byte) 0x9a, (byte) 0x9b, + (byte) 0x9c, (byte) 0x9d, (byte) 0x9e, (byte) 0x9f, (byte) 0xa0, + (byte) 0xa1, (byte) 0xa2, (byte) 0xa3, (byte) 0xa4, (byte) 0xa5, + (byte) 0xa6, (byte) 0xa7, (byte) 0xa8, (byte) 0xa9, (byte) 0xaa, + (byte) 0xab, (byte) 0xac, (byte) 0xad, (byte) 0xae, (byte) 0xaf, + (byte) 0xb0, (byte) 0xb1, (byte) 0xb2, (byte) 0xb3, (byte) 0xb4, + (byte) 0xb5, (byte) 0xb6, (byte) 0xb7, (byte) 0xb8, (byte) 0xb9, + (byte) 0xba, (byte) 0xbb, (byte) 0xbc, (byte) 0xbd, (byte) 0xbe, + (byte) 0xbf, (byte) 0xc0, (byte) 0xc1, (byte) 0xc2, (byte) 0xc3, + (byte) 0xc4, (byte) 0xc5, (byte) 0xc6, (byte) 0xc7, (byte) 0xc8, + (byte) 0xc9, (byte) 0xca, (byte) 0xcb, (byte) 0xcc, (byte) 0xcd, + (byte) 0xce, (byte) 0xcf, (byte) 0xd0, (byte) 0xd1, (byte) 0xd2, + (byte) 0xd3, (byte) 0xd4, (byte) 0xd5, (byte) 0xd6, (byte) 0xd7, + (byte) 0xd8, (byte) 0xd9, (byte) 0xda, (byte) 0xdb, (byte) 0xdc, + (byte) 0xdd, (byte) 0xde, (byte) 0xdf, (byte) 0xe0, (byte) 0xe1, + (byte) 0xe2, (byte) 0xe3, (byte) 0xe4, (byte) 0xe5, (byte) 0xe6, + (byte) 0xe7, (byte) 0xe8, (byte) 0xe9, (byte) 0xea, (byte) 0xeb, + (byte) 0xec, (byte) 0xed, (byte) 0xee, (byte) 0xef, (byte) 0xf0, + (byte) 0xf1, (byte) 0xf2, (byte) 0xf3, (byte) 0xf4, (byte) 0xf5, + (byte) 0xf6, (byte) 0xf7, (byte) 0xf8, (byte) 0xf9, (byte) 0xfa, + (byte) 0xfb, (byte) 0xfc, (byte) 0xfd, (byte) 0xfe, (byte) 0xff, + (byte) 0x00, (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x04, + (byte) 0x05, (byte) 0x06, (byte) 0x07, (byte) 0x08, (byte) 0x09, + (byte) 0x0a, (byte) 0x0b, (byte) 0x0c, (byte) 0x0d, (byte) 0x0e, + (byte) 0x0f, (byte) 0x10, (byte) 0x11, (byte) 0x12, (byte) 0x13, + (byte) 0x14, (byte) 0x15, (byte) 0x16, (byte) 0x17, (byte) 0x18, + (byte) 0x19, (byte) 0x1a, (byte) 0x1b, (byte) 0x1c, (byte) 0x1d, + (byte) 0x1e, (byte) 0x1f, (byte) 0x20, (byte) 0x21, (byte) 0x22, + (byte) 0x23, (byte) 0x24, (byte) 0x25, (byte) 0x26, (byte) 0x27, + (byte) 0x28, (byte) 0x29, (byte) 0x2a, (byte) 0x2b, (byte) 0x2c, + (byte) 0x2d, (byte) 0x2e, (byte) 0x2f, (byte) 0x30, (byte) 0x31, + (byte) 0x32, (byte) 0x33, (byte) 0x34, (byte) 0x35, (byte) 0x36, + (byte) 0x37, (byte) 0x38, (byte) 0x39, (byte) 0x3a, (byte) 0x3b, + (byte) 0x3c, (byte) 0x3d, (byte) 0x3e, (byte) 0x3f, (byte) 0x40, + (byte) 0x41, (byte) 0x42, (byte) 0x43, (byte) 0x44, (byte) 0x45, + (byte) 0x46, (byte) 0x47, (byte) 0x48, (byte) 0x49, (byte) 0x4a, + (byte) 0x4b, (byte) 0x4c, (byte) 0x4d, (byte) 0x4e, (byte) 0x4f, + (byte) 0x50, (byte) 0x51, (byte) 0x52, (byte) 0x53, (byte) 0x54, + (byte) 0x55, (byte) 0x56, (byte) 0x57, (byte) 0x58, (byte) 0x59, + (byte) 0x5a, (byte) 0x5b, (byte) 0x5c, (byte) 0x5d, (byte) 0x5e, + (byte) 0x5f, (byte) 0x60, (byte) 0x61, (byte) 0x62, (byte) 0x63, + (byte) 0x64, (byte) 0x65, (byte) 0x66, (byte) 0x67, (byte) 0x68, + (byte) 0x69, (byte) 0x6a, (byte) 0x6b, (byte) 0x6c, (byte) 0x6d, + (byte) 0x6e, (byte) 0x6f, (byte) 0x70, (byte) 0x71, (byte) 0x72, + (byte) 0x73, (byte) 0x74, (byte) 0x75, (byte) 0x76, (byte) 0x77, + (byte) 0x78, (byte) 0x79, (byte) 0x7a, (byte) 0x7b, (byte) 0x7c, + (byte) 0x7d, (byte) 0x7e, (byte) 0x7f, (byte) 0x80, (byte) 0x81, + (byte) 0x82, (byte) 0x83, (byte) 0x84, (byte) 0x85, (byte) 0x86, + (byte) 0x87, (byte) 0x88, (byte) 0x89, (byte) 0x8a, (byte) 0x8b, + (byte) 0x8c, (byte) 0x8d, (byte) 0x8e, (byte) 0x8f, (byte) 0x90, + (byte) 0x91, (byte) 0x92, (byte) 0x93, (byte) 0x94, (byte) 0x95, + (byte) 0x96, (byte) 0x97, (byte) 0x98, (byte) 0x99, (byte) 0x9a, + (byte) 0x9b, (byte) 0x9c, (byte) 0x9d, (byte) 0x9e, (byte) 0x9f, + (byte) 0xa0, (byte) 0xa1, (byte) 0xa2, (byte) 0xa3, (byte) 0xa4, + (byte) 0xa5, (byte) 0xa6, (byte) 0xa7, (byte) 0xa8, (byte) 0xa9, + (byte) 0xaa, (byte) 0xab, (byte) 0xac, (byte) 0xad, (byte) 0xae, + (byte) 0xaf, (byte) 0xb0, (byte) 0xb1, (byte) 0xb2, (byte) 0xb3, + (byte) 0xb4, (byte) 0xb5, (byte) 0xb6, (byte) 0xb7, (byte) 0xb8, + (byte) 0xb9, (byte) 0xba, (byte) 0xbb, (byte) 0xbc, (byte) 0xbd, + (byte) 0xbe, (byte) 0xbf, (byte) 0xc0, (byte) 0xc1, (byte) 0xc2, + (byte) 0xc3, (byte) 0xc4, (byte) 0xc5, (byte) 0xc6, (byte) 0xc7, + (byte) 0xc8, (byte) 0xc9, (byte) 0xca, (byte) 0xcb, (byte) 0xcc, + (byte) 0xcd, (byte) 0xce, (byte) 0xcf, (byte) 0xd0, (byte) 0xd1, + (byte) 0xd2, (byte) 0xd3, (byte) 0xd4, (byte) 0xd5, (byte) 0xd6, + (byte) 0xd7, (byte) 0xd8, (byte) 0xd9, (byte) 0xda, (byte) 0xdb, + (byte) 0xdc, (byte) 0xdd, (byte) 0xde, (byte) 0xdf, (byte) 0xe0, + (byte) 0xe1, (byte) 0xe2, (byte) 0xe3, (byte) 0xe4, (byte) 0xe5, + (byte) 0xe6, (byte) 0xe7, (byte) 0xe8, (byte) 0xe9, (byte) 0xea, + (byte) 0xeb, (byte) 0xec, (byte) 0xed, (byte) 0xee, (byte) 0xef, + (byte) 0xf0, (byte) 0xf1, (byte) 0xf2, (byte) 0xf3, (byte) 0xf4, + (byte) 0xf5, (byte) 0xf6, (byte) 0xf7, (byte) 0xf8, (byte) 0xf9, + (byte) 0xfa, (byte) 0xfb, (byte) 0xfc, (byte) 0xfd, (byte) 0xfe, + (byte) 0xff, (byte) 0x00, (byte) 0x01, (byte) 0x02, (byte) 0x03, + (byte) 0x04, (byte) 0x05, (byte) 0x06, (byte) 0x07, (byte) 0x08, + (byte) 0x09, (byte) 0x0a, (byte) 0x0b, (byte) 0x0c, (byte) 0x0d, + (byte) 0x0e, (byte) 0x0f, (byte) 0x10, (byte) 0x11, (byte) 0x12, + (byte) 0x13, (byte) 0x14, (byte) 0x15, (byte) 0x16, (byte) 0x17, + (byte) 0x18, (byte) 0x19, (byte) 0x1a, (byte) 0x1b, (byte) 0x1c, + (byte) 0x1d, (byte) 0x1e, (byte) 0x1f, (byte) 0x20, (byte) 0x21, + (byte) 0x22, (byte) 0x23, (byte) 0x24, (byte) 0x25, (byte) 0x26, + (byte) 0x27, (byte) 0x28, (byte) 0x29, (byte) 0x2a, (byte) 0x2b, + (byte) 0x2c, (byte) 0x2d, (byte) 0x2e, (byte) 0x2f, (byte) 0x30, + (byte) 0x31, (byte) 0x32, (byte) 0x33, (byte) 0x34, (byte) 0x35, + (byte) 0x36, (byte) 0x37, (byte) 0x38, (byte) 0x39, (byte) 0x3a, + (byte) 0x3b, (byte) 0x3c, (byte) 0x3d, (byte) 0x3e, (byte) 0x3f, + (byte) 0x40, (byte) 0x41, (byte) 0x42, (byte) 0x43, (byte) 0x44, + (byte) 0x45, (byte) 0x46, (byte) 0x47, (byte) 0x48, (byte) 0x49, + (byte) 0x4a, (byte) 0x4b, (byte) 0x4c, (byte) 0x4d, (byte) 0x4e, + (byte) 0x4f, (byte) 0x50, (byte) 0x51, (byte) 0x52, (byte) 0x53, + (byte) 0x54, (byte) 0x55, (byte) 0x56, (byte) 0x57, (byte) 0x58, + (byte) 0x59, (byte) 0x5a, (byte) 0x5b, (byte) 0x5c, (byte) 0x5d, + (byte) 0x5e, (byte) 0x5f, (byte) 0x60, (byte) 0x61, (byte) 0x62, + (byte) 0x63, (byte) 0x64, (byte) 0x65, (byte) 0x66, (byte) 0x67, + (byte) 0x68, (byte) 0x69, (byte) 0x6a, (byte) 0x6b, (byte) 0x6c, + (byte) 0x6d, (byte) 0x6e, (byte) 0x6f, (byte) 0x70, (byte) 0x71, + (byte) 0x72, (byte) 0x73, (byte) 0x74, (byte) 0x75, (byte) 0x76, + (byte) 0x77, (byte) 0x78, (byte) 0x79, (byte) 0x7a, (byte) 0x7b, + (byte) 0x7c, (byte) 0x7d, (byte) 0x7e, (byte) 0x7f, (byte) 0x80, + (byte) 0x81, (byte) 0x82, (byte) 0x83, (byte) 0x84, (byte) 0x85, + (byte) 0x86, (byte) 0x87, (byte) 0x88, (byte) 0x89, (byte) 0x8a, + (byte) 0x8b, (byte) 0x8c, (byte) 0x8d, (byte) 0x8e, (byte) 0x8f, + (byte) 0x90, (byte) 0x91, (byte) 0x92, (byte) 0x93, (byte) 0x94, + (byte) 0x95, (byte) 0x96, (byte) 0x97, (byte) 0x98, (byte) 0x99, + (byte) 0x9a, (byte) 0x9b, (byte) 0x9c, (byte) 0x9d, (byte) 0x9e, + (byte) 0x9f, (byte) 0xa0, (byte) 0xa1, (byte) 0xa2, (byte) 0xa3, + (byte) 0xa4, (byte) 0xa5, (byte) 0xa6, (byte) 0xa7, (byte) 0xa8, + (byte) 0xa9, (byte) 0xaa, (byte) 0xab, (byte) 0xac, (byte) 0xad, + (byte) 0xae, (byte) 0xaf, (byte) 0xb0, (byte) 0xb1, (byte) 0xb2, + (byte) 0xb3, (byte) 0xb4, (byte) 0xb5, (byte) 0xb6, (byte) 0xb7, + (byte) 0xb8, (byte) 0xb9, (byte) 0xba, (byte) 0xbb, (byte) 0xbc, + (byte) 0xbd, (byte) 0xbe, (byte) 0xbf, (byte) 0xc0, (byte) 0xc1, + (byte) 0xc2, (byte) 0xc3, (byte) 0xc4, (byte) 0xc5, (byte) 0xc6, + (byte) 0xc7, (byte) 0xc8, (byte) 0xc9, (byte) 0xca, (byte) 0xcb, + (byte) 0xcc, (byte) 0xcd, (byte) 0xce, (byte) 0xcf, (byte) 0xd0, + (byte) 0xd1, (byte) 0xd2, (byte) 0xd3, (byte) 0xd4, (byte) 0xd5, + (byte) 0xd6, (byte) 0xd7, (byte) 0xd8, (byte) 0xd9, (byte) 0xda, + (byte) 0xdb, (byte) 0xdc, (byte) 0xdd, (byte) 0xde, (byte) 0xdf, + (byte) 0xe0, (byte) 0xe1, (byte) 0xe2, (byte) 0xe3, (byte) 0xe4, + (byte) 0xe5, (byte) 0xe6, (byte) 0xe7, (byte) 0xe8, (byte) 0xe9, + (byte) 0xea, (byte) 0xeb, (byte) 0xec, (byte) 0xed, (byte) 0xee, + (byte) 0xef, (byte) 0xf0, (byte) 0xf1, (byte) 0xf2, (byte) 0xf3, + (byte) 0xf4, (byte) 0xf5, (byte) 0xf6, (byte) 0xf7, (byte) 0xf8, + (byte) 0xf9, (byte) 0xfa, (byte) 0xfb, (byte) 0xfc, (byte) 0xfd, + (byte) 0xfe, (byte) 0xff, (byte) 0x00, (byte) 0x01, (byte) 0x02, + (byte) 0x03, (byte) 0x04, (byte) 0x05, (byte) 0x06, (byte) 0x07, + (byte) 0x08, (byte) 0x09, (byte) 0x0a, (byte) 0x0b, (byte) 0x0c, + (byte) 0x0d, (byte) 0x0e, (byte) 0x0f, (byte) 0x10, (byte) 0x11, + (byte) 0x12, (byte) 0x13, (byte) 0x14, (byte) 0x15, (byte) 0x16, + (byte) 0x17, (byte) 0x18, (byte) 0x19, (byte) 0x1a, (byte) 0x1b, + (byte) 0x1c, (byte) 0x1d, (byte) 0x1e, (byte) 0x1f, (byte) 0x20, + (byte) 0x21, (byte) 0x22, (byte) 0x23, (byte) 0x24, (byte) 0x25, + (byte) 0x26, (byte) 0x27, (byte) 0x28, (byte) 0x29, (byte) 0x2a, + (byte) 0x2b, (byte) 0x2c, (byte) 0x2d, (byte) 0x2e, (byte) 0x2f, + (byte) 0x30, (byte) 0x31, (byte) 0x32, (byte) 0x33, (byte) 0x34, + (byte) 0x35, (byte) 0x36, (byte) 0x37, (byte) 0x38, (byte) 0x39, + (byte) 0x3a, (byte) 0x3b, (byte) 0x3c, (byte) 0x3d, (byte) 0x3e, + (byte) 0x3f, (byte) 0x40, (byte) 0x41, (byte) 0x42, (byte) 0x43, + (byte) 0x44, (byte) 0x45, (byte) 0x46, (byte) 0x47, (byte) 0x48, + (byte) 0x49, (byte) 0x4a, (byte) 0x4b, (byte) 0x4c, (byte) 0x4d, + (byte) 0x4e, (byte) 0x4f, (byte) 0x50, (byte) 0x51, (byte) 0x52, + (byte) 0x53, (byte) 0x54, (byte) 0x55, (byte) 0x56, (byte) 0x57, + (byte) 0x58, (byte) 0x59, (byte) 0x5a, (byte) 0x5b, (byte) 0x5c, + (byte) 0x5d, (byte) 0x5e, (byte) 0x5f, (byte) 0x60, (byte) 0x61, + (byte) 0x62, (byte) 0x63, (byte) 0x64, (byte) 0x65, (byte) 0x66, + (byte) 0x67, (byte) 0x68, (byte) 0x69, (byte) 0x6a, (byte) 0x6b, + (byte) 0x6c, (byte) 0x6d, (byte) 0x6e, (byte) 0x6f, (byte) 0x70, + (byte) 0x71, (byte) 0x72, (byte) 0x73, (byte) 0x74, (byte) 0x75, + (byte) 0x76, (byte) 0x77, (byte) 0x78, (byte) 0x79, (byte) 0x7a, + (byte) 0x7b, (byte) 0x7c, (byte) 0x7d, (byte) 0x7e, (byte) 0x7f, + (byte) 0x80, (byte) 0x81, (byte) 0x82, (byte) 0x83, (byte) 0x84, + (byte) 0x85, (byte) 0x86, (byte) 0x87, (byte) 0x88, (byte) 0x89, + (byte) 0x8a, (byte) 0x8b, (byte) 0x8c, (byte) 0x8d, (byte) 0x8e, + (byte) 0x8f, (byte) 0x90, (byte) 0x91, (byte) 0x92, (byte) 0x93, + (byte) 0x94, (byte) 0x95, (byte) 0x96, (byte) 0x97, (byte) 0x98, + (byte) 0x99, (byte) 0x9a, (byte) 0x9b, (byte) 0x9c, (byte) 0x9d, + (byte) 0x9e, (byte) 0x9f, (byte) 0xa0, (byte) 0xa1, (byte) 0xa2, + (byte) 0xa3, (byte) 0xa4, (byte) 0xa5, (byte) 0xa6, (byte) 0xa7, + (byte) 0xa8, (byte) 0xa9, (byte) 0xaa, (byte) 0xab, (byte) 0xac, + (byte) 0xad, (byte) 0xae, (byte) 0xaf, (byte) 0xb0, (byte) 0xb1, + (byte) 0xb2, (byte) 0xb3, (byte) 0xb4, (byte) 0xb5, (byte) 0xb6, + (byte) 0xb7, (byte) 0xb8, (byte) 0xb9, (byte) 0xba, (byte) 0xbb, + (byte) 0xbc, (byte) 0xbd, (byte) 0xbe, (byte) 0xbf, (byte) 0xc0, + (byte) 0xc1, (byte) 0xc2, (byte) 0xc3, (byte) 0xc4, (byte) 0xc5, + (byte) 0xc6, (byte) 0xc7, (byte) 0xc8, (byte) 0xc9, (byte) 0xca, + (byte) 0xcb, (byte) 0xcc, (byte) 0xcd, (byte) 0xce, (byte) 0xcf, + (byte) 0xd0, (byte) 0xd1, (byte) 0xd2, (byte) 0xd3, (byte) 0xd4, + (byte) 0xd5, (byte) 0xd6, (byte) 0xd7, (byte) 0xd8, (byte) 0xd9, + (byte) 0xda, (byte) 0xdb, (byte) 0xdc, (byte) 0xdd, (byte) 0xde, + (byte) 0xdf, (byte) 0xe0, (byte) 0xe1, (byte) 0xe2, (byte) 0xe3, + (byte) 0xe4, (byte) 0xe5, (byte) 0xe6, (byte) 0xe7, (byte) 0xe8, + (byte) 0xe9, (byte) 0xea, (byte) 0xeb, (byte) 0xec, (byte) 0xed, + (byte) 0xee, (byte) 0xef, (byte) 0xf0, (byte) 0xf1, (byte) 0xf2, + (byte) 0xf3, (byte) 0xf4, (byte) 0xf5, (byte) 0xf6, (byte) 0xf7, + (byte) 0xf8, (byte) 0xf9, (byte) 0xfa, (byte) 0xfb, (byte) 0xfc, + (byte) 0xfd, (byte) 0xfe, (byte) 0xff }; + + /** + * "valid" encoding for DH - no alg params + */ + private static final byte[] dhEncryptedPrivateKeyInfoNP = new byte[] { + (byte) 0x30, (byte) 0x82, (byte) 0x04, (byte) 0x13, (byte) 0x30, + (byte) 0x0d, (byte) 0x06, (byte) 0x09, (byte) 0x2a, (byte) 0x86, + (byte) 0x48, (byte) 0x86, (byte) 0xf7, (byte) 0x0d, (byte) 0x01, + (byte) 0x03, (byte) 0x01, (byte) 0x05, (byte) 0x00, (byte) 0x04, + (byte) 0x82, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x01, + (byte) 0x02, (byte) 0x03, (byte) 0x04, (byte) 0x05, (byte) 0x06, + (byte) 0x07, (byte) 0x08, (byte) 0x09, (byte) 0x0a, (byte) 0x0b, + (byte) 0x0c, (byte) 0x0d, (byte) 0x0e, (byte) 0x0f, (byte) 0x10, + (byte) 0x11, (byte) 0x12, (byte) 0x13, (byte) 0x14, (byte) 0x15, + (byte) 0x16, (byte) 0x17, (byte) 0x18, (byte) 0x19, (byte) 0x1a, + (byte) 0x1b, (byte) 0x1c, (byte) 0x1d, (byte) 0x1e, (byte) 0x1f, + (byte) 0x20, (byte) 0x21, (byte) 0x22, (byte) 0x23, (byte) 0x24, + (byte) 0x25, (byte) 0x26, (byte) 0x27, (byte) 0x28, (byte) 0x29, + (byte) 0x2a, (byte) 0x2b, (byte) 0x2c, (byte) 0x2d, (byte) 0x2e, + (byte) 0x2f, (byte) 0x30, (byte) 0x31, (byte) 0x32, (byte) 0x33, + (byte) 0x34, (byte) 0x35, (byte) 0x36, (byte) 0x37, (byte) 0x38, + (byte) 0x39, (byte) 0x3a, (byte) 0x3b, (byte) 0x3c, (byte) 0x3d, + (byte) 0x3e, (byte) 0x3f, (byte) 0x40, (byte) 0x41, (byte) 0x42, + (byte) 0x43, (byte) 0x44, (byte) 0x45, (byte) 0x46, (byte) 0x47, + (byte) 0x48, (byte) 0x49, (byte) 0x4a, (byte) 0x4b, (byte) 0x4c, + (byte) 0x4d, (byte) 0x4e, (byte) 0x4f, (byte) 0x50, (byte) 0x51, + (byte) 0x52, (byte) 0x53, (byte) 0x54, (byte) 0x55, (byte) 0x56, + (byte) 0x57, (byte) 0x58, (byte) 0x59, (byte) 0x5a, (byte) 0x5b, + (byte) 0x5c, (byte) 0x5d, (byte) 0x5e, (byte) 0x5f, (byte) 0x60, + (byte) 0x61, (byte) 0x62, (byte) 0x63, (byte) 0x64, (byte) 0x65, + (byte) 0x66, (byte) 0x67, (byte) 0x68, (byte) 0x69, (byte) 0x6a, + (byte) 0x6b, (byte) 0x6c, (byte) 0x6d, (byte) 0x6e, (byte) 0x6f, + (byte) 0x70, (byte) 0x71, (byte) 0x72, (byte) 0x73, (byte) 0x74, + (byte) 0x75, (byte) 0x76, (byte) 0x77, (byte) 0x78, (byte) 0x79, + (byte) 0x7a, (byte) 0x7b, (byte) 0x7c, (byte) 0x7d, (byte) 0x7e, + (byte) 0x7f, (byte) 0x80, (byte) 0x81, (byte) 0x82, (byte) 0x83, + (byte) 0x84, (byte) 0x85, (byte) 0x86, (byte) 0x87, (byte) 0x88, + (byte) 0x89, (byte) 0x8a, (byte) 0x8b, (byte) 0x8c, (byte) 0x8d, + (byte) 0x8e, (byte) 0x8f, (byte) 0x90, (byte) 0x91, (byte) 0x92, + (byte) 0x93, (byte) 0x94, (byte) 0x95, (byte) 0x96, (byte) 0x97, + (byte) 0x98, (byte) 0x99, (byte) 0x9a, (byte) 0x9b, (byte) 0x9c, + (byte) 0x9d, (byte) 0x9e, (byte) 0x9f, (byte) 0xa0, (byte) 0xa1, + (byte) 0xa2, (byte) 0xa3, (byte) 0xa4, (byte) 0xa5, (byte) 0xa6, + (byte) 0xa7, (byte) 0xa8, (byte) 0xa9, (byte) 0xaa, (byte) 0xab, + (byte) 0xac, (byte) 0xad, (byte) 0xae, (byte) 0xaf, (byte) 0xb0, + (byte) 0xb1, (byte) 0xb2, (byte) 0xb3, (byte) 0xb4, (byte) 0xb5, + (byte) 0xb6, (byte) 0xb7, (byte) 0xb8, (byte) 0xb9, (byte) 0xba, + (byte) 0xbb, (byte) 0xbc, (byte) 0xbd, (byte) 0xbe, (byte) 0xbf, + (byte) 0xc0, (byte) 0xc1, (byte) 0xc2, (byte) 0xc3, (byte) 0xc4, + (byte) 0xc5, (byte) 0xc6, (byte) 0xc7, (byte) 0xc8, (byte) 0xc9, + (byte) 0xca, (byte) 0xcb, (byte) 0xcc, (byte) 0xcd, (byte) 0xce, + (byte) 0xcf, (byte) 0xd0, (byte) 0xd1, (byte) 0xd2, (byte) 0xd3, + (byte) 0xd4, (byte) 0xd5, (byte) 0xd6, (byte) 0xd7, (byte) 0xd8, + (byte) 0xd9, (byte) 0xda, (byte) 0xdb, (byte) 0xdc, (byte) 0xdd, + (byte) 0xde, (byte) 0xdf, (byte) 0xe0, (byte) 0xe1, (byte) 0xe2, + (byte) 0xe3, (byte) 0xe4, (byte) 0xe5, (byte) 0xe6, (byte) 0xe7, + (byte) 0xe8, (byte) 0xe9, (byte) 0xea, (byte) 0xeb, (byte) 0xec, + (byte) 0xed, (byte) 0xee, (byte) 0xef, (byte) 0xf0, (byte) 0xf1, + (byte) 0xf2, (byte) 0xf3, (byte) 0xf4, (byte) 0xf5, (byte) 0xf6, + (byte) 0xf7, (byte) 0xf8, (byte) 0xf9, (byte) 0xfa, (byte) 0xfb, + (byte) 0xfc, (byte) 0xfd, (byte) 0xfe, (byte) 0xff, (byte) 0x00, + (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x04, (byte) 0x05, + (byte) 0x06, (byte) 0x07, (byte) 0x08, (byte) 0x09, (byte) 0x0a, + (byte) 0x0b, (byte) 0x0c, (byte) 0x0d, (byte) 0x0e, (byte) 0x0f, + (byte) 0x10, (byte) 0x11, (byte) 0x12, (byte) 0x13, (byte) 0x14, + (byte) 0x15, (byte) 0x16, (byte) 0x17, (byte) 0x18, (byte) 0x19, + (byte) 0x1a, (byte) 0x1b, (byte) 0x1c, (byte) 0x1d, (byte) 0x1e, + (byte) 0x1f, (byte) 0x20, (byte) 0x21, (byte) 0x22, (byte) 0x23, + (byte) 0x24, (byte) 0x25, (byte) 0x26, (byte) 0x27, (byte) 0x28, + (byte) 0x29, (byte) 0x2a, (byte) 0x2b, (byte) 0x2c, (byte) 0x2d, + (byte) 0x2e, (byte) 0x2f, (byte) 0x30, (byte) 0x31, (byte) 0x32, + (byte) 0x33, (byte) 0x34, (byte) 0x35, (byte) 0x36, (byte) 0x37, + (byte) 0x38, (byte) 0x39, (byte) 0x3a, (byte) 0x3b, (byte) 0x3c, + (byte) 0x3d, (byte) 0x3e, (byte) 0x3f, (byte) 0x40, (byte) 0x41, + (byte) 0x42, (byte) 0x43, (byte) 0x44, (byte) 0x45, (byte) 0x46, + (byte) 0x47, (byte) 0x48, (byte) 0x49, (byte) 0x4a, (byte) 0x4b, + (byte) 0x4c, (byte) 0x4d, (byte) 0x4e, (byte) 0x4f, (byte) 0x50, + (byte) 0x51, (byte) 0x52, (byte) 0x53, (byte) 0x54, (byte) 0x55, + (byte) 0x56, (byte) 0x57, (byte) 0x58, (byte) 0x59, (byte) 0x5a, + (byte) 0x5b, (byte) 0x5c, (byte) 0x5d, (byte) 0x5e, (byte) 0x5f, + (byte) 0x60, (byte) 0x61, (byte) 0x62, (byte) 0x63, (byte) 0x64, + (byte) 0x65, (byte) 0x66, (byte) 0x67, (byte) 0x68, (byte) 0x69, + (byte) 0x6a, (byte) 0x6b, (byte) 0x6c, (byte) 0x6d, (byte) 0x6e, + (byte) 0x6f, (byte) 0x70, (byte) 0x71, (byte) 0x72, (byte) 0x73, + (byte) 0x74, (byte) 0x75, (byte) 0x76, (byte) 0x77, (byte) 0x78, + (byte) 0x79, (byte) 0x7a, (byte) 0x7b, (byte) 0x7c, (byte) 0x7d, + (byte) 0x7e, (byte) 0x7f, (byte) 0x80, (byte) 0x81, (byte) 0x82, + (byte) 0x83, (byte) 0x84, (byte) 0x85, (byte) 0x86, (byte) 0x87, + (byte) 0x88, (byte) 0x89, (byte) 0x8a, (byte) 0x8b, (byte) 0x8c, + (byte) 0x8d, (byte) 0x8e, (byte) 0x8f, (byte) 0x90, (byte) 0x91, + (byte) 0x92, (byte) 0x93, (byte) 0x94, (byte) 0x95, (byte) 0x96, + (byte) 0x97, (byte) 0x98, (byte) 0x99, (byte) 0x9a, (byte) 0x9b, + (byte) 0x9c, (byte) 0x9d, (byte) 0x9e, (byte) 0x9f, (byte) 0xa0, + (byte) 0xa1, (byte) 0xa2, (byte) 0xa3, (byte) 0xa4, (byte) 0xa5, + (byte) 0xa6, (byte) 0xa7, (byte) 0xa8, (byte) 0xa9, (byte) 0xaa, + (byte) 0xab, (byte) 0xac, (byte) 0xad, (byte) 0xae, (byte) 0xaf, + (byte) 0xb0, (byte) 0xb1, (byte) 0xb2, (byte) 0xb3, (byte) 0xb4, + (byte) 0xb5, (byte) 0xb6, (byte) 0xb7, (byte) 0xb8, (byte) 0xb9, + (byte) 0xba, (byte) 0xbb, (byte) 0xbc, (byte) 0xbd, (byte) 0xbe, + (byte) 0xbf, (byte) 0xc0, (byte) 0xc1, (byte) 0xc2, (byte) 0xc3, + (byte) 0xc4, (byte) 0xc5, (byte) 0xc6, (byte) 0xc7, (byte) 0xc8, + (byte) 0xc9, (byte) 0xca, (byte) 0xcb, (byte) 0xcc, (byte) 0xcd, + (byte) 0xce, (byte) 0xcf, (byte) 0xd0, (byte) 0xd1, (byte) 0xd2, + (byte) 0xd3, (byte) 0xd4, (byte) 0xd5, (byte) 0xd6, (byte) 0xd7, + (byte) 0xd8, (byte) 0xd9, (byte) 0xda, (byte) 0xdb, (byte) 0xdc, + (byte) 0xdd, (byte) 0xde, (byte) 0xdf, (byte) 0xe0, (byte) 0xe1, + (byte) 0xe2, (byte) 0xe3, (byte) 0xe4, (byte) 0xe5, (byte) 0xe6, + (byte) 0xe7, (byte) 0xe8, (byte) 0xe9, (byte) 0xea, (byte) 0xeb, + (byte) 0xec, (byte) 0xed, (byte) 0xee, (byte) 0xef, (byte) 0xf0, + (byte) 0xf1, (byte) 0xf2, (byte) 0xf3, (byte) 0xf4, (byte) 0xf5, + (byte) 0xf6, (byte) 0xf7, (byte) 0xf8, (byte) 0xf9, (byte) 0xfa, + (byte) 0xfb, (byte) 0xfc, (byte) 0xfd, (byte) 0xfe, (byte) 0xff, + (byte) 0x00, (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x04, + (byte) 0x05, (byte) 0x06, (byte) 0x07, (byte) 0x08, (byte) 0x09, + (byte) 0x0a, (byte) 0x0b, (byte) 0x0c, (byte) 0x0d, (byte) 0x0e, + (byte) 0x0f, (byte) 0x10, (byte) 0x11, (byte) 0x12, (byte) 0x13, + (byte) 0x14, (byte) 0x15, (byte) 0x16, (byte) 0x17, (byte) 0x18, + (byte) 0x19, (byte) 0x1a, (byte) 0x1b, (byte) 0x1c, (byte) 0x1d, + (byte) 0x1e, (byte) 0x1f, (byte) 0x20, (byte) 0x21, (byte) 0x22, + (byte) 0x23, (byte) 0x24, (byte) 0x25, (byte) 0x26, (byte) 0x27, + (byte) 0x28, (byte) 0x29, (byte) 0x2a, (byte) 0x2b, (byte) 0x2c, + (byte) 0x2d, (byte) 0x2e, (byte) 0x2f, (byte) 0x30, (byte) 0x31, + (byte) 0x32, (byte) 0x33, (byte) 0x34, (byte) 0x35, (byte) 0x36, + (byte) 0x37, (byte) 0x38, (byte) 0x39, (byte) 0x3a, (byte) 0x3b, + (byte) 0x3c, (byte) 0x3d, (byte) 0x3e, (byte) 0x3f, (byte) 0x40, + (byte) 0x41, (byte) 0x42, (byte) 0x43, (byte) 0x44, (byte) 0x45, + (byte) 0x46, (byte) 0x47, (byte) 0x48, (byte) 0x49, (byte) 0x4a, + (byte) 0x4b, (byte) 0x4c, (byte) 0x4d, (byte) 0x4e, (byte) 0x4f, + (byte) 0x50, (byte) 0x51, (byte) 0x52, (byte) 0x53, (byte) 0x54, + (byte) 0x55, (byte) 0x56, (byte) 0x57, (byte) 0x58, (byte) 0x59, + (byte) 0x5a, (byte) 0x5b, (byte) 0x5c, (byte) 0x5d, (byte) 0x5e, + (byte) 0x5f, (byte) 0x60, (byte) 0x61, (byte) 0x62, (byte) 0x63, + (byte) 0x64, (byte) 0x65, (byte) 0x66, (byte) 0x67, (byte) 0x68, + (byte) 0x69, (byte) 0x6a, (byte) 0x6b, (byte) 0x6c, (byte) 0x6d, + (byte) 0x6e, (byte) 0x6f, (byte) 0x70, (byte) 0x71, (byte) 0x72, + (byte) 0x73, (byte) 0x74, (byte) 0x75, (byte) 0x76, (byte) 0x77, + (byte) 0x78, (byte) 0x79, (byte) 0x7a, (byte) 0x7b, (byte) 0x7c, + (byte) 0x7d, (byte) 0x7e, (byte) 0x7f, (byte) 0x80, (byte) 0x81, + (byte) 0x82, (byte) 0x83, (byte) 0x84, (byte) 0x85, (byte) 0x86, + (byte) 0x87, (byte) 0x88, (byte) 0x89, (byte) 0x8a, (byte) 0x8b, + (byte) 0x8c, (byte) 0x8d, (byte) 0x8e, (byte) 0x8f, (byte) 0x90, + (byte) 0x91, (byte) 0x92, (byte) 0x93, (byte) 0x94, (byte) 0x95, + (byte) 0x96, (byte) 0x97, (byte) 0x98, (byte) 0x99, (byte) 0x9a, + (byte) 0x9b, (byte) 0x9c, (byte) 0x9d, (byte) 0x9e, (byte) 0x9f, + (byte) 0xa0, (byte) 0xa1, (byte) 0xa2, (byte) 0xa3, (byte) 0xa4, + (byte) 0xa5, (byte) 0xa6, (byte) 0xa7, (byte) 0xa8, (byte) 0xa9, + (byte) 0xaa, (byte) 0xab, (byte) 0xac, (byte) 0xad, (byte) 0xae, + (byte) 0xaf, (byte) 0xb0, (byte) 0xb1, (byte) 0xb2, (byte) 0xb3, + (byte) 0xb4, (byte) 0xb5, (byte) 0xb6, (byte) 0xb7, (byte) 0xb8, + (byte) 0xb9, (byte) 0xba, (byte) 0xbb, (byte) 0xbc, (byte) 0xbd, + (byte) 0xbe, (byte) 0xbf, (byte) 0xc0, (byte) 0xc1, (byte) 0xc2, + (byte) 0xc3, (byte) 0xc4, (byte) 0xc5, (byte) 0xc6, (byte) 0xc7, + (byte) 0xc8, (byte) 0xc9, (byte) 0xca, (byte) 0xcb, (byte) 0xcc, + (byte) 0xcd, (byte) 0xce, (byte) 0xcf, (byte) 0xd0, (byte) 0xd1, + (byte) 0xd2, (byte) 0xd3, (byte) 0xd4, (byte) 0xd5, (byte) 0xd6, + (byte) 0xd7, (byte) 0xd8, (byte) 0xd9, (byte) 0xda, (byte) 0xdb, + (byte) 0xdc, (byte) 0xdd, (byte) 0xde, (byte) 0xdf, (byte) 0xe0, + (byte) 0xe1, (byte) 0xe2, (byte) 0xe3, (byte) 0xe4, (byte) 0xe5, + (byte) 0xe6, (byte) 0xe7, (byte) 0xe8, (byte) 0xe9, (byte) 0xea, + (byte) 0xeb, (byte) 0xec, (byte) 0xed, (byte) 0xee, (byte) 0xef, + (byte) 0xf0, (byte) 0xf1, (byte) 0xf2, (byte) 0xf3, (byte) 0xf4, + (byte) 0xf5, (byte) 0xf6, (byte) 0xf7, (byte) 0xf8, (byte) 0xf9, + (byte) 0xfa, (byte) 0xfb, (byte) 0xfc, (byte) 0xfd, (byte) 0xfe, + (byte) 0xff, (byte) 0x00, (byte) 0x01, (byte) 0x02, (byte) 0x03, + (byte) 0x04, (byte) 0x05, (byte) 0x06, (byte) 0x07, (byte) 0x08, + (byte) 0x09, (byte) 0x0a, (byte) 0x0b, (byte) 0x0c, (byte) 0x0d, + (byte) 0x0e, (byte) 0x0f, (byte) 0x10, (byte) 0x11, (byte) 0x12, + (byte) 0x13, (byte) 0x14, (byte) 0x15, (byte) 0x16, (byte) 0x17, + (byte) 0x18, (byte) 0x19, (byte) 0x1a, (byte) 0x1b, (byte) 0x1c, + (byte) 0x1d, (byte) 0x1e, (byte) 0x1f, (byte) 0x20, (byte) 0x21, + (byte) 0x22, (byte) 0x23, (byte) 0x24, (byte) 0x25, (byte) 0x26, + (byte) 0x27, (byte) 0x28, (byte) 0x29, (byte) 0x2a, (byte) 0x2b, + (byte) 0x2c, (byte) 0x2d, (byte) 0x2e, (byte) 0x2f, (byte) 0x30, + (byte) 0x31, (byte) 0x32, (byte) 0x33, (byte) 0x34, (byte) 0x35, + (byte) 0x36, (byte) 0x37, (byte) 0x38, (byte) 0x39, (byte) 0x3a, + (byte) 0x3b, (byte) 0x3c, (byte) 0x3d, (byte) 0x3e, (byte) 0x3f, + (byte) 0x40, (byte) 0x41, (byte) 0x42, (byte) 0x43, (byte) 0x44, + (byte) 0x45, (byte) 0x46, (byte) 0x47, (byte) 0x48, (byte) 0x49, + (byte) 0x4a, (byte) 0x4b, (byte) 0x4c, (byte) 0x4d, (byte) 0x4e, + (byte) 0x4f, (byte) 0x50, (byte) 0x51, (byte) 0x52, (byte) 0x53, + (byte) 0x54, (byte) 0x55, (byte) 0x56, (byte) 0x57, (byte) 0x58, + (byte) 0x59, (byte) 0x5a, (byte) 0x5b, (byte) 0x5c, (byte) 0x5d, + (byte) 0x5e, (byte) 0x5f, (byte) 0x60, (byte) 0x61, (byte) 0x62, + (byte) 0x63, (byte) 0x64, (byte) 0x65, (byte) 0x66, (byte) 0x67, + (byte) 0x68, (byte) 0x69, (byte) 0x6a, (byte) 0x6b, (byte) 0x6c, + (byte) 0x6d, (byte) 0x6e, (byte) 0x6f, (byte) 0x70, (byte) 0x71, + (byte) 0x72, (byte) 0x73, (byte) 0x74, (byte) 0x75, (byte) 0x76, + (byte) 0x77, (byte) 0x78, (byte) 0x79, (byte) 0x7a, (byte) 0x7b, + (byte) 0x7c, (byte) 0x7d, (byte) 0x7e, (byte) 0x7f, (byte) 0x80, + (byte) 0x81, (byte) 0x82, (byte) 0x83, (byte) 0x84, (byte) 0x85, + (byte) 0x86, (byte) 0x87, (byte) 0x88, (byte) 0x89, (byte) 0x8a, + (byte) 0x8b, (byte) 0x8c, (byte) 0x8d, (byte) 0x8e, (byte) 0x8f, + (byte) 0x90, (byte) 0x91, (byte) 0x92, (byte) 0x93, (byte) 0x94, + (byte) 0x95, (byte) 0x96, (byte) 0x97, (byte) 0x98, (byte) 0x99, + (byte) 0x9a, (byte) 0x9b, (byte) 0x9c, (byte) 0x9d, (byte) 0x9e, + (byte) 0x9f, (byte) 0xa0, (byte) 0xa1, (byte) 0xa2, (byte) 0xa3, + (byte) 0xa4, (byte) 0xa5, (byte) 0xa6, (byte) 0xa7, (byte) 0xa8, + (byte) 0xa9, (byte) 0xaa, (byte) 0xab, (byte) 0xac, (byte) 0xad, + (byte) 0xae, (byte) 0xaf, (byte) 0xb0, (byte) 0xb1, (byte) 0xb2, + (byte) 0xb3, (byte) 0xb4, (byte) 0xb5, (byte) 0xb6, (byte) 0xb7, + (byte) 0xb8, (byte) 0xb9, (byte) 0xba, (byte) 0xbb, (byte) 0xbc, + (byte) 0xbd, (byte) 0xbe, (byte) 0xbf, (byte) 0xc0, (byte) 0xc1, + (byte) 0xc2, (byte) 0xc3, (byte) 0xc4, (byte) 0xc5, (byte) 0xc6, + (byte) 0xc7, (byte) 0xc8, (byte) 0xc9, (byte) 0xca, (byte) 0xcb, + (byte) 0xcc, (byte) 0xcd, (byte) 0xce, (byte) 0xcf, (byte) 0xd0, + (byte) 0xd1, (byte) 0xd2, (byte) 0xd3, (byte) 0xd4, (byte) 0xd5, + (byte) 0xd6, (byte) 0xd7, (byte) 0xd8, (byte) 0xd9, (byte) 0xda, + (byte) 0xdb, (byte) 0xdc, (byte) 0xdd, (byte) 0xde, (byte) 0xdf, + (byte) 0xe0, (byte) 0xe1, (byte) 0xe2, (byte) 0xe3, (byte) 0xe4, + (byte) 0xe5, (byte) 0xe6, (byte) 0xe7, (byte) 0xe8, (byte) 0xe9, + (byte) 0xea, (byte) 0xeb, (byte) 0xec, (byte) 0xed, (byte) 0xee, + (byte) 0xef, (byte) 0xf0, (byte) 0xf1, (byte) 0xf2, (byte) 0xf3, + (byte) 0xf4, (byte) 0xf5, (byte) 0xf6, (byte) 0xf7, (byte) 0xf8, + (byte) 0xf9, (byte) 0xfa, (byte) 0xfb, (byte) 0xfc, (byte) 0xfd, + (byte) 0xfe, (byte) 0xff, }; + + /** + * Valid DSA parameters encoding + */ + private static final byte[] dsaParamsEncoded = { (byte) 0x30, (byte) 0x82, + (byte) 0x01, (byte) 0x1e, (byte) 0x02, (byte) 0x81, (byte) 0x81, + (byte) 0x00, (byte) 0x9f, (byte) 0x5e, (byte) 0x76, (byte) 0x19, + (byte) 0x59, (byte) 0xd8, (byte) 0xf7, (byte) 0x6b, (byte) 0x91, + (byte) 0x6d, (byte) 0x15, (byte) 0x7e, (byte) 0x14, (byte) 0x27, + (byte) 0x25, (byte) 0x6e, (byte) 0x59, (byte) 0x2c, (byte) 0xec, + (byte) 0x21, (byte) 0x7a, (byte) 0xb7, (byte) 0xd4, (byte) 0xf4, + (byte) 0xa0, (byte) 0x26, (byte) 0x4e, (byte) 0x72, (byte) 0x29, + (byte) 0x18, (byte) 0x4a, (byte) 0x1c, (byte) 0x9a, (byte) 0xc9, + (byte) 0xcd, (byte) 0x85, (byte) 0x1b, (byte) 0x39, (byte) 0x41, + (byte) 0x9e, (byte) 0x58, (byte) 0x16, (byte) 0xeb, (byte) 0x20, + (byte) 0x84, (byte) 0x28, (byte) 0x2a, (byte) 0xb9, (byte) 0xce, + (byte) 0xc7, (byte) 0x6d, (byte) 0x74, (byte) 0x99, (byte) 0xfe, + (byte) 0xa5, (byte) 0xe8, (byte) 0x66, (byte) 0xe1, (byte) 0x48, + (byte) 0xdd, (byte) 0x2e, (byte) 0xcf, (byte) 0xfe, (byte) 0xb9, + (byte) 0x6a, (byte) 0x8e, (byte) 0x12, (byte) 0x4b, (byte) 0xa4, + (byte) 0xa8, (byte) 0x87, (byte) 0xd7, (byte) 0xab, (byte) 0x26, + (byte) 0xd6, (byte) 0xc3, (byte) 0xd1, (byte) 0x3b, (byte) 0x95, + (byte) 0xc4, (byte) 0x97, (byte) 0x2c, (byte) 0xdc, (byte) 0xab, + (byte) 0x5d, (byte) 0xf5, (byte) 0x55, (byte) 0xae, (byte) 0x58, + (byte) 0x68, (byte) 0x84, (byte) 0x41, (byte) 0x99, (byte) 0x1b, + (byte) 0xd3, (byte) 0xd0, (byte) 0xd9, (byte) 0xd3, (byte) 0xdd, + (byte) 0xf5, (byte) 0x48, (byte) 0x04, (byte) 0xa2, (byte) 0x92, + (byte) 0x61, (byte) 0xf8, (byte) 0xb1, (byte) 0xe6, (byte) 0x24, + (byte) 0x65, (byte) 0x8f, (byte) 0xa4, (byte) 0x97, (byte) 0x40, + (byte) 0x1d, (byte) 0x3f, (byte) 0x2b, (byte) 0x85, (byte) 0x00, + (byte) 0xd5, (byte) 0xcb, (byte) 0x8d, (byte) 0x66, (byte) 0x9a, + (byte) 0xac, (byte) 0x7b, (byte) 0x5f, (byte) 0xc7, (byte) 0x02, + (byte) 0x15, (byte) 0x00, (byte) 0x9a, (byte) 0xfb, (byte) 0x6f, + (byte) 0x72, (byte) 0x15, (byte) 0x01, (byte) 0x03, (byte) 0x16, + (byte) 0x2a, (byte) 0xd6, (byte) 0xca, (byte) 0x60, (byte) 0x10, + (byte) 0x47, (byte) 0xde, (byte) 0x4b, (byte) 0x0f, (byte) 0xd6, + (byte) 0x73, (byte) 0x37, (byte) 0x02, (byte) 0x81, (byte) 0x80, + (byte) 0x5d, (byte) 0x51, (byte) 0x28, (byte) 0x64, (byte) 0xb2, + (byte) 0x2b, (byte) 0xeb, (byte) 0x85, (byte) 0xb4, (byte) 0x14, + (byte) 0x0d, (byte) 0xad, (byte) 0xec, (byte) 0xc8, (byte) 0x1f, + (byte) 0x96, (byte) 0x1e, (byte) 0x6a, (byte) 0x52, (byte) 0xd4, + (byte) 0x0b, (byte) 0x69, (byte) 0xb0, (byte) 0x33, (byte) 0xa1, + (byte) 0xd1, (byte) 0xbc, (byte) 0x64, (byte) 0xd6, (byte) 0x64, + (byte) 0xef, (byte) 0x2c, (byte) 0x89, (byte) 0xc7, (byte) 0x39, + (byte) 0x75, (byte) 0x87, (byte) 0x82, (byte) 0x61, (byte) 0xbe, + (byte) 0xd1, (byte) 0xcd, (byte) 0x70, (byte) 0x41, (byte) 0x85, + (byte) 0x99, (byte) 0x55, (byte) 0x75, (byte) 0x6f, (byte) 0x16, + (byte) 0xc0, (byte) 0x40, (byte) 0xf1, (byte) 0x0c, (byte) 0x78, + (byte) 0x1f, (byte) 0xe8, (byte) 0x63, (byte) 0x5d, (byte) 0xfa, + (byte) 0x37, (byte) 0xc1, (byte) 0xce, (byte) 0x97, (byte) 0x76, + (byte) 0xa5, (byte) 0x48, (byte) 0x5b, (byte) 0x88, (byte) 0xe4, + (byte) 0xd5, (byte) 0xb8, (byte) 0x06, (byte) 0xf5, (byte) 0x7f, + (byte) 0x92, (byte) 0xda, (byte) 0x99, (byte) 0xa5, (byte) 0x5a, + (byte) 0x64, (byte) 0xc9, (byte) 0x30, (byte) 0x2c, (byte) 0x77, + (byte) 0x58, (byte) 0x60, (byte) 0xa6, (byte) 0x35, (byte) 0x1d, + (byte) 0x71, (byte) 0xfb, (byte) 0x49, (byte) 0x24, (byte) 0x6c, + (byte) 0x34, (byte) 0x29, (byte) 0xa0, (byte) 0x47, (byte) 0xf1, + (byte) 0x14, (byte) 0xad, (byte) 0xc2, (byte) 0x85, (byte) 0x41, + (byte) 0xdd, (byte) 0x2c, (byte) 0x78, (byte) 0x2a, (byte) 0x5a, + (byte) 0x24, (byte) 0x7f, (byte) 0x19, (byte) 0xf4, (byte) 0x0a, + (byte) 0x2e, (byte) 0x1d, (byte) 0x92, (byte) 0x80, (byte) 0xe5, + (byte) 0xe4, (byte) 0x05, (byte) 0x28, (byte) 0x48, (byte) 0x5c, + (byte) 0x34, (byte) 0xc8, (byte) 0x22 }; + + /** + * Valid DH parameters encoding + */ + private static final byte[] dhParamsEncoded = { (byte) 0x30, (byte) 0x82, + (byte) 0x01, (byte) 0x0b, (byte) 0x02, (byte) 0x81, (byte) 0x81, + (byte) 0x00, (byte) 0xce, (byte) 0x2c, (byte) 0x4f, (byte) 0xea, + (byte) 0xf2, (byte) 0x83, (byte) 0xc5, (byte) 0x38, (byte) 0xc9, + (byte) 0xb6, (byte) 0xd4, (byte) 0xf8, (byte) 0xb8, (byte) 0x17, + (byte) 0xa1, (byte) 0x7d, (byte) 0x4c, (byte) 0xec, (byte) 0x6b, + (byte) 0xd7, (byte) 0xc2, (byte) 0x1a, (byte) 0x35, (byte) 0x85, + (byte) 0x54, (byte) 0x14, (byte) 0x6c, (byte) 0x52, (byte) 0x24, + (byte) 0xbf, (byte) 0xe6, (byte) 0x32, (byte) 0xd8, (byte) 0x42, + (byte) 0xac, (byte) 0xb3, (byte) 0x28, (byte) 0x4f, (byte) 0x77, + (byte) 0xf6, (byte) 0xfc, (byte) 0xea, (byte) 0xea, (byte) 0x72, + (byte) 0xcf, (byte) 0x1d, (byte) 0x7b, (byte) 0xe1, (byte) 0x72, + (byte) 0xfa, (byte) 0x77, (byte) 0x12, (byte) 0xa9, (byte) 0x42, + (byte) 0xba, (byte) 0xc4, (byte) 0xf4, (byte) 0xfb, (byte) 0xbd, + (byte) 0x9f, (byte) 0x63, (byte) 0x9a, (byte) 0x58, (byte) 0x6b, + (byte) 0xb6, (byte) 0xa2, (byte) 0x6e, (byte) 0x3a, (byte) 0x71, + (byte) 0xf3, (byte) 0x43, (byte) 0x5e, (byte) 0x6f, (byte) 0x8a, + (byte) 0xd0, (byte) 0xac, (byte) 0xe5, (byte) 0x60, (byte) 0x76, + (byte) 0x57, (byte) 0x1f, (byte) 0x83, (byte) 0x4d, (byte) 0xbc, + (byte) 0xaa, (byte) 0xb1, (byte) 0x18, (byte) 0x40, (byte) 0x19, + (byte) 0xac, (byte) 0x31, (byte) 0xd4, (byte) 0xfc, (byte) 0x39, + (byte) 0x01, (byte) 0x46, (byte) 0xab, (byte) 0xab, (byte) 0x53, + (byte) 0x19, (byte) 0x2d, (byte) 0xf8, (byte) 0x4c, (byte) 0xd3, + (byte) 0x9f, (byte) 0x4d, (byte) 0xa6, (byte) 0x71, (byte) 0x92, + (byte) 0x06, (byte) 0xc7, (byte) 0x89, (byte) 0x70, (byte) 0xc4, + (byte) 0xc6, (byte) 0xa2, (byte) 0x1f, (byte) 0x05, (byte) 0x4a, + (byte) 0x5b, (byte) 0x84, (byte) 0xf9, (byte) 0xfb, (byte) 0x98, + (byte) 0x63, (byte) 0xc9, (byte) 0x9c, (byte) 0x13, (byte) 0x02, + (byte) 0x81, (byte) 0x80, (byte) 0x36, (byte) 0x55, (byte) 0x93, + (byte) 0xb3, (byte) 0x22, (byte) 0x0c, (byte) 0xcd, (byte) 0x7c, + (byte) 0xc3, (byte) 0xe3, (byte) 0xa3, (byte) 0x8a, (byte) 0xd7, + (byte) 0xb4, (byte) 0xe9, (byte) 0xe0, (byte) 0xfa, (byte) 0xa9, + (byte) 0xa8, (byte) 0x69, (byte) 0xd6, (byte) 0xa6, (byte) 0x20, + (byte) 0xb8, (byte) 0xd4, (byte) 0xe7, (byte) 0x87, (byte) 0x4e, + (byte) 0xf3, (byte) 0x90, (byte) 0x10, (byte) 0xdd, (byte) 0x75, + (byte) 0x5d, (byte) 0xff, (byte) 0xee, (byte) 0xf0, (byte) 0xef, + (byte) 0x6a, (byte) 0x0a, (byte) 0xb0, (byte) 0xf1, (byte) 0x8a, + (byte) 0xb6, (byte) 0x7b, (byte) 0x39, (byte) 0x95, (byte) 0xd5, + (byte) 0x24, (byte) 0x83, (byte) 0x10, (byte) 0x95, (byte) 0x34, + (byte) 0x08, (byte) 0x77, (byte) 0x1d, (byte) 0xaf, (byte) 0x69, + (byte) 0xf0, (byte) 0xb5, (byte) 0xdb, (byte) 0x24, (byte) 0x89, + (byte) 0x72, (byte) 0xb2, (byte) 0x0d, (byte) 0x57, (byte) 0x94, + (byte) 0xb0, (byte) 0xe8, (byte) 0xc2, (byte) 0x37, (byte) 0x45, + (byte) 0x5a, (byte) 0xfc, (byte) 0xa1, (byte) 0xa0, (byte) 0x41, + (byte) 0xe4, (byte) 0x0c, (byte) 0xa3, (byte) 0x40, (byte) 0x8b, + (byte) 0x9c, (byte) 0x19, (byte) 0x63, (byte) 0x61, (byte) 0xd9, + (byte) 0x05, (byte) 0xbf, (byte) 0xc5, (byte) 0xe8, (byte) 0xf7, + (byte) 0xbd, (byte) 0x3a, (byte) 0xf5, (byte) 0x78, (byte) 0xc2, + (byte) 0x92, (byte) 0xe8, (byte) 0x60, (byte) 0x07, (byte) 0x3e, + (byte) 0x57, (byte) 0x12, (byte) 0xf6, (byte) 0x97, (byte) 0x1f, + (byte) 0xea, (byte) 0x02, (byte) 0xa3, (byte) 0x19, (byte) 0xa7, + (byte) 0x5a, (byte) 0x9b, (byte) 0xf6, (byte) 0xd2, (byte) 0x0f, + (byte) 0xe9, (byte) 0x6b, (byte) 0xeb, (byte) 0xd7, (byte) 0x93, + (byte) 0x9a, (byte) 0x7e, (byte) 0x4f, (byte) 0xd6, (byte) 0x29, + (byte) 0x02, (byte) 0x02, (byte) 0x03, (byte) 0xff }; + + /** + * pretends to be encrypted private key + */ + public static final byte[] encryptedData; + + private static final HashMap<String, byte[]> validEPKIEncodings = new HashMap<String, byte[]>(); + + private static final HashMap<String, byte[]> validEPKIEncodingsNP = new HashMap<String, byte[]>(); + + private static final HashMap<String, byte[]> validAPEncodings = new HashMap<String, byte[]>(); + + static { + validEPKIEncodings.put("DH", dhEncryptedPrivateKeyInfo); + validEPKIEncodings.put("DIFFIEHELLMAN", dhEncryptedPrivateKeyInfo); + validEPKIEncodings.put("DIFFIE-HELLMAN", dhEncryptedPrivateKeyInfo); + validEPKIEncodings.put("1.2.840.113549.1.3.1", + dhEncryptedPrivateKeyInfo); + validEPKIEncodingsNP.put("DH", dhEncryptedPrivateKeyInfoNP); + validEPKIEncodingsNP.put("DIFFIEHELLMAN", dhEncryptedPrivateKeyInfoNP); + validEPKIEncodingsNP.put("DIFFIE-HELLMAN", dhEncryptedPrivateKeyInfoNP); + validEPKIEncodings.put("DSA", dsaEncryptedPrivateKeyInfo); + validEPKIEncodings.put("1.2.840.10040.4.1", dsaEncryptedPrivateKeyInfo); + validEPKIEncodingsNP.put("DIFFIE-HELLMAN", dhEncryptedPrivateKeyInfoNP); + validEPKIEncodingsNP.put("DSA", dsaEncryptedPrivateKeyInfoNP); + validAPEncodings.put("DH", dhParamsEncoded); + validAPEncodings.put("DIFFIEHELLMAN", dhParamsEncoded); + validAPEncodings.put("DIFFIE-HELLMAN", dhParamsEncoded); + validAPEncodings.put("1.2.840.113549.1.3.1", dhParamsEncoded); + validAPEncodings.put("DSA", dsaParamsEncoded); + validAPEncodings.put("1.2.840.10040.4.1", dsaParamsEncoded); + + encryptedData = new byte[1024]; + for (int i = 0; i < encryptedData.length; i++) { + encryptedData[i] = (byte) i; + } + } + + /** + * Algorithm_names/standard_names to be used in tests "DSA" and "DH" must be + * always presented + */ + public final static String[][] algName0 = new String[][] { + { "DSA", "DSA" }, + { "DH", "DiffieHellman", "Diffie-Hellman" }, + { "1.2.840.10040.4.1", "DSA" }, + { "1.2.840.113549.1.1.1", "RSA" }, + { "1.2.840.113549.1.3.1", "DiffieHellman" }, + { "1.2.840.113549.1.5.3", "pbeWithMD5AndDES-CBC" }, + { "1.2.840.113549.1.12.1.3", "pbeWithSHAAnd3-KeyTripleDES-CBC" }, + // {"1.2.840.113549.1.12.1.6", "pbeWithSHAAnd40BitRC2-CBC"}, + { "1.2.840.113549.3.2", "RC2-CBC" }, + { "1.2.840.113549.3.3", "RC2-EBC" }, + { "1.2.840.113549.3.4", "RC4" }, + { "1.2.840.113549.3.5", "RC4WithMAC" }, + { "1.2.840.113549.3.6", "DESx-CBC" }, + { "1.2.840.113549.3.7", "TripleDES-CBC" }, + { "1.2.840.113549.3.8", "rc5CBC" }, + { "1.2.840.113549.3.9", "RC5-CBC" }, + { "1.2.840.113549.3.10", "DESCDMF" }, }; + + /** + * Returns valid encoding of EncryptedPrivateKeyInfo However encoded private + * key field (encryptedData) does not contain valid encrypted data. + * + * @throws NoSuchAlgorithmException + */ + public static byte[] getValidEncryptedPrivateKeyInfoEncoding( + String algName, boolean includingAlgParameters) + throws NoSuchAlgorithmException { + String algNameUC = algName.toUpperCase(); + byte[] ret = includingAlgParameters ? validEPKIEncodings + .get(algNameUC) : validEPKIEncodingsNP.get(algNameUC); + if (ret != null) { + return ret.clone(); + } + throw new NoSuchAlgorithmException("No encoding available for " + + algName); + } + + public static byte[] getValidEncryptedPrivateKeyInfoEncoding(String algName) + throws NoSuchAlgorithmException { + return getValidEncryptedPrivateKeyInfoEncoding(algName, true); + } + + /** + * Returns valid encoding of EncryptedPrivateKeyInfo However encoded private + * key field (encryptedData) does not contain valid encrypted data. + * + * @throws NoSuchAlgorithmException + */ + public static byte[] getParametersEncoding(String algName) + throws NoSuchAlgorithmException { + String algNameUC = algName.toUpperCase(); + byte[] ret = validAPEncodings.get(algNameUC); + if (ret != null) { + return ret; + } + throw new NoSuchAlgorithmException("No AP encoding available for " + + algName); + } + +} diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/support/MyCipher.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/support/MyCipher.java new file mode 100644 index 0000000..c9eb26e --- /dev/null +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/support/MyCipher.java @@ -0,0 +1,122 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** +* @author Boris V. Kuznetsov +* @version $Revision$ +*/ + +package org.apache.harmony.crypto.tests.support; + +import java.security.AlgorithmParameters; +import java.security.InvalidAlgorithmParameterException; +import java.security.InvalidKeyException; +import java.security.Key; +import java.security.NoSuchAlgorithmException; +import java.security.SecureRandom; +import java.security.spec.AlgorithmParameterSpec; + +import javax.crypto.BadPaddingException; +import javax.crypto.CipherSpi; +import javax.crypto.IllegalBlockSizeException; +import javax.crypto.NoSuchPaddingException; +import javax.crypto.ShortBufferException; + +/** + * + * Cipher implementation for testing + */ +public class MyCipher extends CipherSpi { + + public MyCipher() { + super(); + } + + @Override + protected void engineSetMode(String mode) throws NoSuchAlgorithmException { + } + + @Override + protected void engineSetPadding(String padding) + throws NoSuchPaddingException { + if (!"PKCS5Padding".equals(padding)) { + throw new NoSuchPaddingException(padding); + } + } + + @Override + protected int engineGetBlockSize() { + return 111; + } + + @Override + protected int engineGetOutputSize(int inputLen) { + return inputLen + 10; + } + + @Override + protected byte[] engineGetIV() { + byte[] b = {1,2,3}; + return b; + } + + @Override + protected AlgorithmParameters engineGetParameters() { + return null; + } + + @Override + protected void engineInit(int opmode, Key key, SecureRandom random) + throws InvalidKeyException { + } + + @Override + protected void engineInit(int opmode, Key key, + AlgorithmParameterSpec params, SecureRandom random) + throws InvalidKeyException, InvalidAlgorithmParameterException { + } + + @Override + protected void engineInit(int opmode, Key key, AlgorithmParameters params, + SecureRandom random) throws InvalidKeyException, + InvalidAlgorithmParameterException { + } + + @Override + protected byte[] engineUpdate(byte[] input, int inputOffset, int inputLen) { + return null; + } + + @Override + protected int engineUpdate(byte[] input, int inputOffset, int inputLen, + byte[] output, int outputOffset) throws ShortBufferException { + return 0; + } + + @Override + protected byte[] engineDoFinal(byte[] input, int inputOffset, int inputLen) + throws IllegalBlockSizeException, BadPaddingException { + return null; + } + + @Override + protected int engineDoFinal(byte[] input, int inputOffset, int inputLen, + byte[] output, int outputOffset) throws ShortBufferException, + IllegalBlockSizeException, BadPaddingException { + return 0; + } + +} diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/support/MyExemptionMechanismSpi.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/support/MyExemptionMechanismSpi.java new file mode 100644 index 0000000..750765e --- /dev/null +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/support/MyExemptionMechanismSpi.java @@ -0,0 +1,134 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Vera Y. Petrashkova +* @version $Revision$ +*/ + +package org.apache.harmony.crypto.tests.support; + +import java.security.AlgorithmParameters; +import java.security.InvalidAlgorithmParameterException; +import java.security.InvalidKeyException; +import java.security.Key; +import java.security.spec.AlgorithmParameterSpec; + +import javax.crypto.ExemptionMechanismException; +import javax.crypto.ExemptionMechanismSpi; +import javax.crypto.ShortBufferException; + +/** + * Additional class for verification ExemptionMechanismSpi + * and ExemptionMechanism classes + * + */ + +public class MyExemptionMechanismSpi extends ExemptionMechanismSpi { + + private static final int byteArrayLength = 5; + + public static final int getLength() { + return byteArrayLength; + } + @Override + protected byte[] engineGenExemptionBlob() + throws ExemptionMechanismException { + return new byte[byteArrayLength]; + } + + @Override + protected int engineGenExemptionBlob(byte[] output, int outputOffset) + throws ShortBufferException, ExemptionMechanismException { + return byteArrayLength; + } + + @Override + protected int engineGetOutputSize(int inputLen) { + return 10; + } + + @Override + protected void engineInit(Key key) throws InvalidKeyException, + ExemptionMechanismException { + if (key == null) { + throw new InvalidKeyException("key is null"); + } + if (!(key instanceof tmpKey)) { + throw new ExemptionMechanismException("Incorrect key"); + } + } + + @Override + protected void engineInit(Key key, AlgorithmParameters params) + throws InvalidKeyException, InvalidAlgorithmParameterException, + ExemptionMechanismException { + if (key == null) { + throw new InvalidKeyException("key is null"); + } + if (!(key instanceof tmpKey)) { + throw new ExemptionMechanismException("Incorrect key"); + } + } + + @Override + protected void engineInit(Key key, AlgorithmParameterSpec params) + throws InvalidKeyException, InvalidAlgorithmParameterException, + ExemptionMechanismException { + if (key == null) { + throw new InvalidKeyException("key is null"); + } + if (!(key instanceof tmpKey)) { + throw new ExemptionMechanismException("Incorrect key"); + } + } + + @SuppressWarnings("serial") + public class tmpKey implements Key { + private String alg; + private byte[] enc; + public tmpKey(String alg, byte[] enc) { + this.alg = alg; + this.enc = enc; + } + public String getFormat() { + return "tmpKey"; + } + public String getAlgorithm() { + return alg; + } + public byte[] getEncoded() { + return enc; + } + } + @SuppressWarnings("serial") + public class tmp1Key implements Key { + private byte[] enc; + public tmp1Key(String alg, byte[] enc) { + this.enc = enc; + } + public String getAlgorithm() { + return "tmp1Key"; + } + public String getFormat() { + return "tmp1Key"; + } + public byte[] getEncoded() { + return enc; + } + } +} diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/support/MyKeyAgreementSpi.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/support/MyKeyAgreementSpi.java new file mode 100644 index 0000000..51e541a --- /dev/null +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/support/MyKeyAgreementSpi.java @@ -0,0 +1,86 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Vera Y. Petrashkova +* @version $Revision$ +*/ + +package org.apache.harmony.crypto.tests.support; + +import java.security.InvalidAlgorithmParameterException; +import java.security.InvalidKeyException; +import java.security.Key; +import java.security.NoSuchAlgorithmException; +import java.security.SecureRandom; +import java.security.spec.AlgorithmParameterSpec; + +import javax.crypto.KeyAgreementSpi; +import javax.crypto.SecretKey; +import javax.crypto.ShortBufferException; + +/** + * Additional class for verification of KeyAgreementSpi + * and KeyAgreement functionality + * + */ + +public class MyKeyAgreementSpi extends KeyAgreementSpi { + + @Override + protected Key engineDoPhase(Key key, boolean lastPhase) + throws InvalidKeyException, IllegalStateException { + if (!lastPhase) { + throw new IllegalStateException("last Phase is false"); + } + return null; + } + + @Override + protected byte[] engineGenerateSecret() throws IllegalStateException { + return new byte[0]; + } + + @Override + protected int engineGenerateSecret(byte[] sharedSecret, int offset) + throws IllegalStateException, ShortBufferException { + return -1; + } + + @Override + protected SecretKey engineGenerateSecret(String algorithm) + throws IllegalStateException, NoSuchAlgorithmException, + InvalidKeyException { + if (algorithm.length() == 0) { + throw new NoSuchAlgorithmException("Algorithm is empty"); + } + return null; + } + + @Override + protected void engineInit(Key key, SecureRandom random) + throws InvalidKeyException { + throw new IllegalArgumentException("Invalid parameter"); + } + + @Override + protected void engineInit(Key key, AlgorithmParameterSpec params, + SecureRandom random) throws InvalidKeyException, + InvalidAlgorithmParameterException { + throw new IllegalArgumentException("Invalid parameter"); + } +} diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/support/MyKeyGeneratorSpi.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/support/MyKeyGeneratorSpi.java new file mode 100644 index 0000000..86b21c2 --- /dev/null +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/support/MyKeyGeneratorSpi.java @@ -0,0 +1,64 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Vera Y. Petrashkova +* @version $Revision$ +*/ + +package org.apache.harmony.crypto.tests.support; + +import java.security.InvalidAlgorithmParameterException; +import java.security.SecureRandom; +import java.security.spec.AlgorithmParameterSpec; + +import javax.crypto.KeyGeneratorSpi; +import javax.crypto.SecretKey; + +/** + * Additional class for verification of + * KeyGeneratorSpi and KeyGenerator functionality + * + */ + +public class MyKeyGeneratorSpi extends KeyGeneratorSpi { + + @Override + protected SecretKey engineGenerateKey() { + return null; + } + + @Override + protected void engineInit(AlgorithmParameterSpec params, SecureRandom random) + throws InvalidAlgorithmParameterException { + if (params == null) { + throw new InvalidAlgorithmParameterException("params is null"); + } + } + + @Override + protected void engineInit(int keysize, SecureRandom random) { + if (keysize <= 77) { + throw new IllegalArgumentException("Invalid keysize"); + } + } + + @Override + protected void engineInit(SecureRandom random) { + throw new IllegalArgumentException("Invalid random"); + } +} diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/support/MyMacSpi.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/support/MyMacSpi.java new file mode 100644 index 0000000..8913c2e --- /dev/null +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/support/MyMacSpi.java @@ -0,0 +1,76 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Vera Y. Petrashkova +* @version $Revision$ +*/ + +package org.apache.harmony.crypto.tests.support; + +import java.security.InvalidAlgorithmParameterException; +import java.security.InvalidKeyException; +import java.security.Key; +import java.security.spec.AlgorithmParameterSpec; + +import javax.crypto.MacSpi; +import javax.crypto.spec.SecretKeySpec; + +/** + * Additional class for verification of MacGeneratorSpi and MacSpi + * + */ + +public class MyMacSpi extends MacSpi { + + private int length = 0; + @Override + protected int engineGetMacLength() { + return length; + } + + @Override + protected void engineInit(Key key, AlgorithmParameterSpec params) + throws InvalidKeyException, InvalidAlgorithmParameterException { + if (params == null) { + if (!(key instanceof SecretKeySpec)) { + throw new IllegalArgumentException("params is null and key is SecretKeySpec"); + } + } + } + + @Override + protected void engineUpdate(byte input) { + } + + @Override + protected void engineUpdate(byte[] input, int offset, int len) { + if (offset >= 0 && len >= 0) { + length = len; + } + } + + @Override + protected byte[] engineDoFinal() { + return new byte[length]; + } + + @Override + protected void engineReset() { + length++; + } +} diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/support/MySecretKeyFactorySpi.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/support/MySecretKeyFactorySpi.java new file mode 100644 index 0000000..0dbff5d --- /dev/null +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/support/MySecretKeyFactorySpi.java @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Vera Y. Petrashkova +* @version $Revision$ +*/ + +package org.apache.harmony.crypto.tests.support; + +import java.security.InvalidKeyException; +import java.security.spec.InvalidKeySpecException; +import java.security.spec.KeySpec; + +import javax.crypto.SecretKey; +import javax.crypto.SecretKeyFactorySpi; + +/** + * Additional class for verification of SecretKeyFactorySpi + * and SecretKeyFactory functionality + * + */ + +public class MySecretKeyFactorySpi extends SecretKeyFactorySpi { + @Override + protected SecretKey engineGenerateSecret(KeySpec keySpec) + throws InvalidKeySpecException { + return null; + } + + @SuppressWarnings("unchecked") + @Override + protected KeySpec engineGetKeySpec(SecretKey key, Class keySpec) + throws InvalidKeySpecException { + return null; + } + + @Override + protected SecretKey engineTranslateKey(SecretKey key) + throws InvalidKeyException { + return null; + } +} diff --git a/crypto/src/test/java/resources/hyts_des-ede3-cbc.test1.ciphertext b/crypto/src/test/java/resources/hyts_des-ede3-cbc.test1.ciphertext new file mode 100644 index 0000000..2d7b94b --- /dev/null +++ b/crypto/src/test/java/resources/hyts_des-ede3-cbc.test1.ciphertext @@ -0,0 +1 @@ +!#oN{@
\ No newline at end of file diff --git a/crypto/src/test/java/resources/hyts_des-ede3-cbc.test1.iv b/crypto/src/test/java/resources/hyts_des-ede3-cbc.test1.iv new file mode 100644 index 0000000..401f335 --- /dev/null +++ b/crypto/src/test/java/resources/hyts_des-ede3-cbc.test1.iv @@ -0,0 +1 @@ +Q2#P\
\ No newline at end of file diff --git a/crypto/src/test/java/resources/hyts_des-ede3-cbc.test1.key b/crypto/src/test/java/resources/hyts_des-ede3-cbc.test1.key new file mode 100644 index 0000000..2ffb5ea --- /dev/null +++ b/crypto/src/test/java/resources/hyts_des-ede3-cbc.test1.key @@ -0,0 +1 @@ +igkXܴtyA#{ $
\ No newline at end of file diff --git a/crypto/src/test/java/resources/hyts_des-ede3-cbc.test1.plaintext b/crypto/src/test/java/resources/hyts_des-ede3-cbc.test1.plaintext new file mode 100644 index 0000000..9787ee2 --- /dev/null +++ b/crypto/src/test/java/resources/hyts_des-ede3-cbc.test1.plaintext @@ -0,0 +1 @@ +
C
\ No newline at end of file diff --git a/crypto/src/test/java/resources/hyts_des-ede3-cbc.test2.ciphertext b/crypto/src/test/java/resources/hyts_des-ede3-cbc.test2.ciphertext Binary files differnew file mode 100644 index 0000000..1ae3f96 --- /dev/null +++ b/crypto/src/test/java/resources/hyts_des-ede3-cbc.test2.ciphertext diff --git a/crypto/src/test/java/resources/hyts_des-ede3-cbc.test2.iv b/crypto/src/test/java/resources/hyts_des-ede3-cbc.test2.iv new file mode 100644 index 0000000..72660fc --- /dev/null +++ b/crypto/src/test/java/resources/hyts_des-ede3-cbc.test2.iv @@ -0,0 +1 @@ +@"З<
\ No newline at end of file diff --git a/crypto/src/test/java/resources/hyts_des-ede3-cbc.test2.key b/crypto/src/test/java/resources/hyts_des-ede3-cbc.test2.key new file mode 100644 index 0000000..9876f3f --- /dev/null +++ b/crypto/src/test/java/resources/hyts_des-ede3-cbc.test2.key @@ -0,0 +1 @@ +q<(GΡԑI:'
\ No newline at end of file diff --git a/crypto/src/test/java/resources/hyts_des-ede3-cbc.test2.plaintext b/crypto/src/test/java/resources/hyts_des-ede3-cbc.test2.plaintext Binary files differnew file mode 100644 index 0000000..1b5ef4a --- /dev/null +++ b/crypto/src/test/java/resources/hyts_des-ede3-cbc.test2.plaintext diff --git a/crypto/src/test/java/resources/hyts_des-ede3-cbc.test3.ciphertext b/crypto/src/test/java/resources/hyts_des-ede3-cbc.test3.ciphertext Binary files differnew file mode 100644 index 0000000..b9dd600 --- /dev/null +++ b/crypto/src/test/java/resources/hyts_des-ede3-cbc.test3.ciphertext diff --git a/crypto/src/test/java/resources/hyts_des-ede3-cbc.test3.iv b/crypto/src/test/java/resources/hyts_des-ede3-cbc.test3.iv new file mode 100644 index 0000000..7a6ded5 --- /dev/null +++ b/crypto/src/test/java/resources/hyts_des-ede3-cbc.test3.iv @@ -0,0 +1 @@ +~Sr[
\ No newline at end of file diff --git a/crypto/src/test/java/resources/hyts_des-ede3-cbc.test3.key b/crypto/src/test/java/resources/hyts_des-ede3-cbc.test3.key new file mode 100644 index 0000000..e18fd89 --- /dev/null +++ b/crypto/src/test/java/resources/hyts_des-ede3-cbc.test3.key @@ -0,0 +1 @@ +/]oDεPe0?6
\ No newline at end of file diff --git a/crypto/src/test/java/resources/hyts_des-ede3-cbc.test3.plaintext b/crypto/src/test/java/resources/hyts_des-ede3-cbc.test3.plaintext Binary files differnew file mode 100644 index 0000000..f45bd88 --- /dev/null +++ b/crypto/src/test/java/resources/hyts_des-ede3-cbc.test3.plaintext diff --git a/crypto/src/test/java/serialization/org/apache/harmony/crypto/tests/javax/crypto/serialization/BadPaddingExceptionTest.golden.0.ser b/crypto/src/test/java/serialization/org/apache/harmony/crypto/tests/javax/crypto/serialization/BadPaddingExceptionTest.golden.0.ser Binary files differnew file mode 100644 index 0000000..a7d6333 --- /dev/null +++ b/crypto/src/test/java/serialization/org/apache/harmony/crypto/tests/javax/crypto/serialization/BadPaddingExceptionTest.golden.0.ser diff --git a/crypto/src/test/java/serialization/org/apache/harmony/crypto/tests/javax/crypto/serialization/BadPaddingExceptionTest.golden.1.ser b/crypto/src/test/java/serialization/org/apache/harmony/crypto/tests/javax/crypto/serialization/BadPaddingExceptionTest.golden.1.ser Binary files differnew file mode 100644 index 0000000..447c1f4 --- /dev/null +++ b/crypto/src/test/java/serialization/org/apache/harmony/crypto/tests/javax/crypto/serialization/BadPaddingExceptionTest.golden.1.ser diff --git a/crypto/src/test/java/serialization/org/apache/harmony/crypto/tests/javax/crypto/serialization/BadPaddingExceptionTest.golden.2.ser b/crypto/src/test/java/serialization/org/apache/harmony/crypto/tests/javax/crypto/serialization/BadPaddingExceptionTest.golden.2.ser Binary files differnew file mode 100644 index 0000000..ae028bd --- /dev/null +++ b/crypto/src/test/java/serialization/org/apache/harmony/crypto/tests/javax/crypto/serialization/BadPaddingExceptionTest.golden.2.ser diff --git a/crypto/src/test/java/serialization/org/apache/harmony/crypto/tests/javax/crypto/serialization/ExemptionMechanismExceptionTest.golden.0.ser b/crypto/src/test/java/serialization/org/apache/harmony/crypto/tests/javax/crypto/serialization/ExemptionMechanismExceptionTest.golden.0.ser Binary files differnew file mode 100644 index 0000000..60c67c0 --- /dev/null +++ b/crypto/src/test/java/serialization/org/apache/harmony/crypto/tests/javax/crypto/serialization/ExemptionMechanismExceptionTest.golden.0.ser diff --git a/crypto/src/test/java/serialization/org/apache/harmony/crypto/tests/javax/crypto/serialization/ExemptionMechanismExceptionTest.golden.1.ser b/crypto/src/test/java/serialization/org/apache/harmony/crypto/tests/javax/crypto/serialization/ExemptionMechanismExceptionTest.golden.1.ser Binary files differnew file mode 100644 index 0000000..58b303f --- /dev/null +++ b/crypto/src/test/java/serialization/org/apache/harmony/crypto/tests/javax/crypto/serialization/ExemptionMechanismExceptionTest.golden.1.ser diff --git a/crypto/src/test/java/serialization/org/apache/harmony/crypto/tests/javax/crypto/serialization/ExemptionMechanismExceptionTest.golden.2.ser b/crypto/src/test/java/serialization/org/apache/harmony/crypto/tests/javax/crypto/serialization/ExemptionMechanismExceptionTest.golden.2.ser Binary files differnew file mode 100644 index 0000000..ee41ad6 --- /dev/null +++ b/crypto/src/test/java/serialization/org/apache/harmony/crypto/tests/javax/crypto/serialization/ExemptionMechanismExceptionTest.golden.2.ser diff --git a/crypto/src/test/java/serialization/org/apache/harmony/crypto/tests/javax/crypto/serialization/IllegalBlockSizeExceptionTest.golden.0.ser b/crypto/src/test/java/serialization/org/apache/harmony/crypto/tests/javax/crypto/serialization/IllegalBlockSizeExceptionTest.golden.0.ser Binary files differnew file mode 100644 index 0000000..98823fc --- /dev/null +++ b/crypto/src/test/java/serialization/org/apache/harmony/crypto/tests/javax/crypto/serialization/IllegalBlockSizeExceptionTest.golden.0.ser diff --git a/crypto/src/test/java/serialization/org/apache/harmony/crypto/tests/javax/crypto/serialization/IllegalBlockSizeExceptionTest.golden.1.ser b/crypto/src/test/java/serialization/org/apache/harmony/crypto/tests/javax/crypto/serialization/IllegalBlockSizeExceptionTest.golden.1.ser Binary files differnew file mode 100644 index 0000000..a69ae56 --- /dev/null +++ b/crypto/src/test/java/serialization/org/apache/harmony/crypto/tests/javax/crypto/serialization/IllegalBlockSizeExceptionTest.golden.1.ser diff --git a/crypto/src/test/java/serialization/org/apache/harmony/crypto/tests/javax/crypto/serialization/IllegalBlockSizeExceptionTest.golden.2.ser b/crypto/src/test/java/serialization/org/apache/harmony/crypto/tests/javax/crypto/serialization/IllegalBlockSizeExceptionTest.golden.2.ser Binary files differnew file mode 100644 index 0000000..f23826c --- /dev/null +++ b/crypto/src/test/java/serialization/org/apache/harmony/crypto/tests/javax/crypto/serialization/IllegalBlockSizeExceptionTest.golden.2.ser diff --git a/crypto/src/test/java/serialization/org/apache/harmony/crypto/tests/javax/crypto/serialization/NoSuchPaddingExceptionTest.golden.0.ser b/crypto/src/test/java/serialization/org/apache/harmony/crypto/tests/javax/crypto/serialization/NoSuchPaddingExceptionTest.golden.0.ser Binary files differnew file mode 100644 index 0000000..0cdc09d --- /dev/null +++ b/crypto/src/test/java/serialization/org/apache/harmony/crypto/tests/javax/crypto/serialization/NoSuchPaddingExceptionTest.golden.0.ser diff --git a/crypto/src/test/java/serialization/org/apache/harmony/crypto/tests/javax/crypto/serialization/NoSuchPaddingExceptionTest.golden.1.ser b/crypto/src/test/java/serialization/org/apache/harmony/crypto/tests/javax/crypto/serialization/NoSuchPaddingExceptionTest.golden.1.ser Binary files differnew file mode 100644 index 0000000..3a12187 --- /dev/null +++ b/crypto/src/test/java/serialization/org/apache/harmony/crypto/tests/javax/crypto/serialization/NoSuchPaddingExceptionTest.golden.1.ser diff --git a/crypto/src/test/java/serialization/org/apache/harmony/crypto/tests/javax/crypto/serialization/NoSuchPaddingExceptionTest.golden.2.ser b/crypto/src/test/java/serialization/org/apache/harmony/crypto/tests/javax/crypto/serialization/NoSuchPaddingExceptionTest.golden.2.ser Binary files differnew file mode 100644 index 0000000..5818cd4 --- /dev/null +++ b/crypto/src/test/java/serialization/org/apache/harmony/crypto/tests/javax/crypto/serialization/NoSuchPaddingExceptionTest.golden.2.ser diff --git a/crypto/src/test/java/serialization/org/apache/harmony/crypto/tests/javax/crypto/serialization/ShortBufferExceptionTest.golden.0.ser b/crypto/src/test/java/serialization/org/apache/harmony/crypto/tests/javax/crypto/serialization/ShortBufferExceptionTest.golden.0.ser Binary files differnew file mode 100644 index 0000000..1f8e55f --- /dev/null +++ b/crypto/src/test/java/serialization/org/apache/harmony/crypto/tests/javax/crypto/serialization/ShortBufferExceptionTest.golden.0.ser diff --git a/crypto/src/test/java/serialization/org/apache/harmony/crypto/tests/javax/crypto/serialization/ShortBufferExceptionTest.golden.1.ser b/crypto/src/test/java/serialization/org/apache/harmony/crypto/tests/javax/crypto/serialization/ShortBufferExceptionTest.golden.1.ser Binary files differnew file mode 100644 index 0000000..b0fadb2 --- /dev/null +++ b/crypto/src/test/java/serialization/org/apache/harmony/crypto/tests/javax/crypto/serialization/ShortBufferExceptionTest.golden.1.ser diff --git a/crypto/src/test/java/serialization/org/apache/harmony/crypto/tests/javax/crypto/serialization/ShortBufferExceptionTest.golden.2.ser b/crypto/src/test/java/serialization/org/apache/harmony/crypto/tests/javax/crypto/serialization/ShortBufferExceptionTest.golden.2.ser Binary files differnew file mode 100644 index 0000000..9edf260 --- /dev/null +++ b/crypto/src/test/java/serialization/org/apache/harmony/crypto/tests/javax/crypto/serialization/ShortBufferExceptionTest.golden.2.ser diff --git a/crypto/src/test/java/tests/crypto/AllTests.java b/crypto/src/test/java/tests/crypto/AllTests.java new file mode 100644 index 0000000..8079d3e --- /dev/null +++ b/crypto/src/test/java/tests/crypto/AllTests.java @@ -0,0 +1,42 @@ +/* Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package tests.crypto; + +import junit.framework.Test; +import junit.framework.TestSuite; + +/** + * Test suite that includes all tests for the regex project. + */ +public class AllTests { + + public static void main(String[] args) { + junit.textui.TestRunner.run(AllTests.suite()); +//AllTests.java + } + + public static Test suite() { + TestSuite suite = new TestSuite("All crypto test suites"); + // $JUnit-BEGIN$ + suite.addTest(org.apache.harmony.crypto.tests.javax.crypto.interfaces.AllTests.suite()); + suite.addTest(org.apache.harmony.crypto.tests.javax.crypto.serialization.AllTests.suite()); + suite.addTest(org.apache.harmony.crypto.tests.javax.crypto.spec.AllTests.suite()); + suite.addTest(org.apache.harmony.crypto.tests.javax.crypto.AllTests.suite()); + // $JUnit-END$ + return suite; + } +} |