You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by ml...@apache.org on 2006/05/30 13:35:46 UTC
svn commit: r410243 [2/7] - in
/incubator/harmony/enhanced/classlib/trunk/modules/crypto: make/common/
src/main/java/javax/crypto/ src/main/java/javax/crypto/spec/
src/main/java/org/apache/harmony/crypto/internal/
src/test/api/java.injected/javax/crypt...
Modified: incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/main/java/javax/crypto/KeyAgreement.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/main/java/javax/crypto/KeyAgreement.java?rev=410243&r1=410242&r2=410243&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/main/java/javax/crypto/KeyAgreement.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/main/java/javax/crypto/KeyAgreement.java Tue May 30 04:35:44 2006
@@ -1,213 +1,213 @@
-/*
- * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
- *
- * 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.
- */
-
-/**
-* @author Vera Y. Petrashkova
-* @version $Revision$
-*/
-
-package javax.crypto;
-
-import java.security.InvalidAlgorithmParameterException;
-import java.security.InvalidKeyException;
-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 org.apache.harmony.security.fortress.Engine;
-
-
-/**
- * @com.intel.drl.spec_ref
- *
- */
-
-public class KeyAgreement {
-
- // Store spi implementation service name
- private static final String SERVICE = "KeyAgreement";
-
- // Used to access common engine functionality
- private static Engine engine = new Engine(SERVICE);
-
- // Store SecureRandom
- private static SecureRandom rndm = new SecureRandom();
-
- // Store used provider
- private final Provider provider;
-
- // Store used spi implementation
- private final KeyAgreementSpi spiImpl;
-
- // Store used algorithm name
- private final String algorithm;
-
- /**
- * @com.intel.drl.spec_ref
- *
- */
- protected KeyAgreement(KeyAgreementSpi keyAgreeSpi, Provider provider,
- String algorithm) {
- this.provider = provider;
- this.algorithm = algorithm;
- this.spiImpl = keyAgreeSpi;
- }
-
- /**
- * @com.intel.drl.spec_ref
- *
- */
- public final String getAlgorithm() {
- return algorithm;
- }
-
- /**
- * @com.intel.drl.spec_ref
- *
- */
- public final Provider getProvider() {
- return provider;
- }
-
- /**
- * @com.intel.drl.spec_ref
- *
- */
- public static final KeyAgreement getInstance(String algorithm)
- throws NoSuchAlgorithmException {
- if (algorithm == null) {
- throw new NullPointerException("Algorithm is null");
- }
- synchronized (engine) {
- engine.getInstance(algorithm, null);
- return new KeyAgreement((KeyAgreementSpi) engine.spi, engine.provider,
- algorithm);
- }
- }
-
- /**
- * @com.intel.drl.spec_ref
- *
- */
- public static final KeyAgreement getInstance(String algorithm,
- String provider) throws NoSuchAlgorithmException,
- NoSuchProviderException {
- if ((provider == null) || (provider.length() == 0)) {
- throw new IllegalArgumentException("Provider is null or empty");
- }
- Provider impProvider = Security.getProvider(provider);
- if (impProvider == null) {
- throw new NoSuchProviderException(provider);
- }
- return getInstance(algorithm, impProvider);
- }
-
- /**
- * @com.intel.drl.spec_ref
- *
- */
- public static final KeyAgreement getInstance(String algorithm,
- Provider provider) throws NoSuchAlgorithmException {
- if (provider == null) {
- throw new IllegalArgumentException("Provider is null");
- }
- if (algorithm == null) {
- throw new NullPointerException("Algorithm is null");
- }
- synchronized (engine) {
- engine.getInstance(algorithm, provider, null);
- return new KeyAgreement((KeyAgreementSpi) engine.spi, provider,
- algorithm);
- }
- }
-
- /**
- * @com.intel.drl.spec_ref
- *
- */
- public final void init(Key key) throws InvalidKeyException {
- spiImpl.engineInit(key, rndm);//new SecureRandom());
- }
-
- /**
- * @com.intel.drl.spec_ref
- *
- */
- public final void init(Key key, SecureRandom random)
- throws InvalidKeyException {
- spiImpl.engineInit(key, random);
- }
-
- /**
- * @com.intel.drl.spec_ref
- *
- */
- public final void init(Key key, AlgorithmParameterSpec params)
- throws InvalidKeyException, InvalidAlgorithmParameterException {
- spiImpl.engineInit(key, params, rndm);//new SecureRandom());
- }
-
- /**
- * @com.intel.drl.spec_ref
- *
- */
- public final void init(Key key, AlgorithmParameterSpec params,
- SecureRandom random) throws InvalidKeyException,
- InvalidAlgorithmParameterException {
- spiImpl.engineInit(key, params, random);
- }
-
- /**
- * @com.intel.drl.spec_ref
- *
- */
- public final Key doPhase(Key key, boolean lastPhase)
- throws InvalidKeyException, IllegalStateException {
- return spiImpl.engineDoPhase(key, lastPhase);
- }
-
- /**
- * @com.intel.drl.spec_ref
- *
- */
- public final byte[] generateSecret() throws IllegalStateException {
- return spiImpl.engineGenerateSecret();
- }
-
- /**
- * @com.intel.drl.spec_ref
- *
- */
- public final int generateSecret(byte[] sharedSecret, int offset)
- throws IllegalStateException, ShortBufferException {
- return spiImpl.engineGenerateSecret(sharedSecret, offset);
- }
-
- /**
- * @com.intel.drl.spec_ref
- *
- */
- public final SecretKey generateSecret(String algorithm)
- throws IllegalStateException, NoSuchAlgorithmException,
- InvalidKeyException {
- return spiImpl.engineGenerateSecret(algorithm);
- }
-
+/*
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * 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.
+ */
+
+/**
+* @author Vera Y. Petrashkova
+* @version $Revision$
+*/
+
+package javax.crypto;
+
+import java.security.InvalidAlgorithmParameterException;
+import java.security.InvalidKeyException;
+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 org.apache.harmony.security.fortress.Engine;
+
+
+/**
+ * @com.intel.drl.spec_ref
+ *
+ */
+
+public class KeyAgreement {
+
+ // Store spi implementation service name
+ private static final String SERVICE = "KeyAgreement";
+
+ // Used to access common engine functionality
+ private static Engine engine = new Engine(SERVICE);
+
+ // Store SecureRandom
+ private static SecureRandom rndm = new SecureRandom();
+
+ // Store used provider
+ private final Provider provider;
+
+ // Store used spi implementation
+ private final KeyAgreementSpi spiImpl;
+
+ // Store used algorithm name
+ private final String algorithm;
+
+ /**
+ * @com.intel.drl.spec_ref
+ *
+ */
+ protected KeyAgreement(KeyAgreementSpi keyAgreeSpi, Provider provider,
+ String algorithm) {
+ this.provider = provider;
+ this.algorithm = algorithm;
+ this.spiImpl = keyAgreeSpi;
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ *
+ */
+ public final String getAlgorithm() {
+ return algorithm;
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ *
+ */
+ public final Provider getProvider() {
+ return provider;
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ *
+ */
+ public static final KeyAgreement getInstance(String algorithm)
+ throws NoSuchAlgorithmException {
+ if (algorithm == null) {
+ throw new NullPointerException("Algorithm is null");
+ }
+ synchronized (engine) {
+ engine.getInstance(algorithm, null);
+ return new KeyAgreement((KeyAgreementSpi) engine.spi, engine.provider,
+ algorithm);
+ }
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ *
+ */
+ public static final KeyAgreement getInstance(String algorithm,
+ String provider) throws NoSuchAlgorithmException,
+ NoSuchProviderException {
+ if ((provider == null) || (provider.length() == 0)) {
+ throw new IllegalArgumentException("Provider is null or empty");
+ }
+ Provider impProvider = Security.getProvider(provider);
+ if (impProvider == null) {
+ throw new NoSuchProviderException(provider);
+ }
+ return getInstance(algorithm, impProvider);
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ *
+ */
+ public static final KeyAgreement getInstance(String algorithm,
+ Provider provider) throws NoSuchAlgorithmException {
+ if (provider == null) {
+ throw new IllegalArgumentException("Provider is null");
+ }
+ if (algorithm == null) {
+ throw new NullPointerException("Algorithm is null");
+ }
+ synchronized (engine) {
+ engine.getInstance(algorithm, provider, null);
+ return new KeyAgreement((KeyAgreementSpi) engine.spi, provider,
+ algorithm);
+ }
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ *
+ */
+ public final void init(Key key) throws InvalidKeyException {
+ spiImpl.engineInit(key, rndm);//new SecureRandom());
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ *
+ */
+ public final void init(Key key, SecureRandom random)
+ throws InvalidKeyException {
+ spiImpl.engineInit(key, random);
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ *
+ */
+ public final void init(Key key, AlgorithmParameterSpec params)
+ throws InvalidKeyException, InvalidAlgorithmParameterException {
+ spiImpl.engineInit(key, params, rndm);//new SecureRandom());
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ *
+ */
+ public final void init(Key key, AlgorithmParameterSpec params,
+ SecureRandom random) throws InvalidKeyException,
+ InvalidAlgorithmParameterException {
+ spiImpl.engineInit(key, params, random);
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ *
+ */
+ public final Key doPhase(Key key, boolean lastPhase)
+ throws InvalidKeyException, IllegalStateException {
+ return spiImpl.engineDoPhase(key, lastPhase);
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ *
+ */
+ public final byte[] generateSecret() throws IllegalStateException {
+ return spiImpl.engineGenerateSecret();
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ *
+ */
+ public final int generateSecret(byte[] sharedSecret, int offset)
+ throws IllegalStateException, ShortBufferException {
+ return spiImpl.engineGenerateSecret(sharedSecret, offset);
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ *
+ */
+ public final SecretKey generateSecret(String algorithm)
+ throws IllegalStateException, NoSuchAlgorithmException,
+ InvalidKeyException {
+ return spiImpl.engineGenerateSecret(algorithm);
+ }
+
}
Modified: incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/main/java/javax/crypto/KeyGenerator.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/main/java/javax/crypto/KeyGenerator.java?rev=410243&r1=410242&r2=410243&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/main/java/javax/crypto/KeyGenerator.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/main/java/javax/crypto/KeyGenerator.java Tue May 30 04:35:44 2006
@@ -1,188 +1,188 @@
-/*
- * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
- *
- * 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.
- */
-
-/**
-* @author Vera Y. Petrashkova
-* @version $Revision$
-*/
-
-package javax.crypto;
-
-import java.security.InvalidAlgorithmParameterException;
-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 org.apache.harmony.security.fortress.Engine;
-
-
-/**
- * @com.intel.drl.spec_ref
- *
- */
-
-public class KeyGenerator {
-
- // Store spi implementation service name
- private static final String SERVICE = "KeyGenerator";
-
- // Used to access common engine functionality
- private static Engine engine = new Engine(SERVICE);
-
- // Store SecureRandom
- private static SecureRandom rndm = new SecureRandom();
-
- // Store used provider
- private final Provider provider;
-
- // Store used spi implementation
- private final KeyGeneratorSpi spiImpl;
-
- // Store used algorithm name
- private final String algorithm;
-
- /**
- * @com.intel.drl.spec_ref
- *
- */
- protected KeyGenerator(KeyGeneratorSpi keyGenSpi, Provider provider,
- String algorithm) {
- this.provider = provider;
- this.algorithm = algorithm;
- this.spiImpl = keyGenSpi;
- }
-
- /**
- * @com.intel.drl.spec_ref
- *
- */
- public final String getAlgorithm() {
- return algorithm;
- }
-
- /**
- * @com.intel.drl.spec_ref
- *
- */
- public final Provider getProvider() {
- return provider;
- }
-
- /**
- * @com.intel.drl.spec_ref
- *
- */
- public static final KeyGenerator getInstance(String algorithm)
- throws NoSuchAlgorithmException {
- if (algorithm == null) {
- throw new NullPointerException("Algorithm is null");
- }
- synchronized (engine) {
- engine.getInstance(algorithm, null);
- return new KeyGenerator((KeyGeneratorSpi) engine.spi, engine.provider,
- algorithm);
- }
- }
-
- /**
- * @com.intel.drl.spec_ref
- *
- */
- public static final KeyGenerator getInstance(String algorithm,
- String provider) throws NoSuchAlgorithmException,
- NoSuchProviderException {
- if ((provider == null) || (provider.length() == 0)) {
- throw new IllegalArgumentException("Provider is null or empty");
- }
- Provider impProvider = Security.getProvider(provider);
- if (impProvider == null) {
- throw new NoSuchProviderException(provider);
- }
- return getInstance(algorithm, impProvider);
- }
-
- /**
- * @com.intel.drl.spec_ref
- *
- */
- public static final KeyGenerator getInstance(String algorithm,
- Provider provider) throws NoSuchAlgorithmException {
- if (provider == null) {
- throw new IllegalArgumentException("Provider is null");
- }
- if (algorithm == null) {
- throw new NullPointerException("Algorithm is null");
- }
- synchronized (engine) {
- engine.getInstance(algorithm, provider, null);
- return new KeyGenerator((KeyGeneratorSpi) engine.spi, provider,
- algorithm);
- }
- }
-
- /**
- * @com.intel.drl.spec_ref
- *
- */
- public final SecretKey generateKey() {
- return spiImpl.engineGenerateKey();
- }
-
- /**
- * @com.intel.drl.spec_ref
- *
- */
- public final void init(AlgorithmParameterSpec params)
- throws InvalidAlgorithmParameterException {
- spiImpl.engineInit(params, rndm);//new SecureRandom());
- }
-
- /**
- * @com.intel.drl.spec_ref
- *
- */
- public final void init(AlgorithmParameterSpec params, SecureRandom random)
- throws InvalidAlgorithmParameterException {
- spiImpl.engineInit(params, random);
- }
-
- /**
- * @com.intel.drl.spec_ref
- *
- */
- public final void init(int keysize) {
- spiImpl.engineInit(keysize, rndm);//new SecureRandom());
- }
-
- /**
- * @com.intel.drl.spec_ref
- *
- */
- public final void init(int keysize, SecureRandom random) {
- spiImpl.engineInit(keysize, random);
- }
-
- /**
- * @com.intel.drl.spec_ref
- *
- */
- public final void init(SecureRandom random) {
- spiImpl.engineInit(random);
- }
+/*
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * 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.
+ */
+
+/**
+* @author Vera Y. Petrashkova
+* @version $Revision$
+*/
+
+package javax.crypto;
+
+import java.security.InvalidAlgorithmParameterException;
+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 org.apache.harmony.security.fortress.Engine;
+
+
+/**
+ * @com.intel.drl.spec_ref
+ *
+ */
+
+public class KeyGenerator {
+
+ // Store spi implementation service name
+ private static final String SERVICE = "KeyGenerator";
+
+ // Used to access common engine functionality
+ private static Engine engine = new Engine(SERVICE);
+
+ // Store SecureRandom
+ private static SecureRandom rndm = new SecureRandom();
+
+ // Store used provider
+ private final Provider provider;
+
+ // Store used spi implementation
+ private final KeyGeneratorSpi spiImpl;
+
+ // Store used algorithm name
+ private final String algorithm;
+
+ /**
+ * @com.intel.drl.spec_ref
+ *
+ */
+ protected KeyGenerator(KeyGeneratorSpi keyGenSpi, Provider provider,
+ String algorithm) {
+ this.provider = provider;
+ this.algorithm = algorithm;
+ this.spiImpl = keyGenSpi;
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ *
+ */
+ public final String getAlgorithm() {
+ return algorithm;
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ *
+ */
+ public final Provider getProvider() {
+ return provider;
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ *
+ */
+ public static final KeyGenerator getInstance(String algorithm)
+ throws NoSuchAlgorithmException {
+ if (algorithm == null) {
+ throw new NullPointerException("Algorithm is null");
+ }
+ synchronized (engine) {
+ engine.getInstance(algorithm, null);
+ return new KeyGenerator((KeyGeneratorSpi) engine.spi, engine.provider,
+ algorithm);
+ }
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ *
+ */
+ public static final KeyGenerator getInstance(String algorithm,
+ String provider) throws NoSuchAlgorithmException,
+ NoSuchProviderException {
+ if ((provider == null) || (provider.length() == 0)) {
+ throw new IllegalArgumentException("Provider is null or empty");
+ }
+ Provider impProvider = Security.getProvider(provider);
+ if (impProvider == null) {
+ throw new NoSuchProviderException(provider);
+ }
+ return getInstance(algorithm, impProvider);
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ *
+ */
+ public static final KeyGenerator getInstance(String algorithm,
+ Provider provider) throws NoSuchAlgorithmException {
+ if (provider == null) {
+ throw new IllegalArgumentException("Provider is null");
+ }
+ if (algorithm == null) {
+ throw new NullPointerException("Algorithm is null");
+ }
+ synchronized (engine) {
+ engine.getInstance(algorithm, provider, null);
+ return new KeyGenerator((KeyGeneratorSpi) engine.spi, provider,
+ algorithm);
+ }
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ *
+ */
+ public final SecretKey generateKey() {
+ return spiImpl.engineGenerateKey();
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ *
+ */
+ public final void init(AlgorithmParameterSpec params)
+ throws InvalidAlgorithmParameterException {
+ spiImpl.engineInit(params, rndm);//new SecureRandom());
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ *
+ */
+ public final void init(AlgorithmParameterSpec params, SecureRandom random)
+ throws InvalidAlgorithmParameterException {
+ spiImpl.engineInit(params, random);
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ *
+ */
+ public final void init(int keysize) {
+ spiImpl.engineInit(keysize, rndm);//new SecureRandom());
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ *
+ */
+ public final void init(int keysize, SecureRandom random) {
+ spiImpl.engineInit(keysize, random);
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ *
+ */
+ public final void init(SecureRandom random) {
+ spiImpl.engineInit(random);
+ }
}
Modified: incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/main/java/javax/crypto/Mac.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/main/java/javax/crypto/Mac.java?rev=410243&r1=410242&r2=410243&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/main/java/javax/crypto/Mac.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/main/java/javax/crypto/Mac.java Tue May 30 04:35:44 2006
@@ -1,311 +1,311 @@
-/*
- * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
- *
- * 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.
- */
-
-/**
-* @author Vera Y. Petrashkova
-* @version $Revision$
-*/
-
-package javax.crypto;
-
-import java.nio.ByteBuffer;
-import java.security.InvalidAlgorithmParameterException;
-import java.security.InvalidKeyException;
-import java.security.Key;
-import java.security.NoSuchAlgorithmException;
-import java.security.NoSuchProviderException;
-import java.security.Provider;
-import java.security.Security;
-import java.security.spec.AlgorithmParameterSpec;
-
-import org.apache.harmony.security.fortress.Engine;
-
-
-/**
- * @com.intel.drl.spec_ref
- *
- */
-
-public class Mac implements Cloneable {
-
- // Store spi implementation service name
- private static final String SERVICE = "Mac";
-
- //Used to access common engine functionality
- private static Engine engine = new Engine(SERVICE);
-
- // Warning for reporting about not initialized Mac
- private static final String NOTINITMAC = "MAC was not initialized";
-
- // Store used provider
- private final Provider provider;
-
- // Store used spi implementation
- private final MacSpi spiImpl;
-
- // Store used algorithm name
- private final String algorithm;
-
- // Store Mac state (initialized or not initialized)
- private boolean isInitMac;
-
- /**
- * @com.intel.drl.spec_ref
- *
- */
- protected Mac(MacSpi macSpi, Provider provider, String algorithm) {
- this.provider = provider;
- this.algorithm = algorithm;
- this.spiImpl = macSpi;
- this.isInitMac = false;
- }
-
- /**
- * @com.intel.drl.spec_ref
- *
- */
- public final String getAlgorithm() {
- return algorithm;
- }
-
- /**
- * @com.intel.drl.spec_ref
- *
- */
- public final Provider getProvider() {
- return provider;
- }
-
- /**
- * @com.intel.drl.spec_ref
- *
- * throws NullPointerException if algorithm is null (instead of
- * NoSuchAlgorithmException as in 1.4 release)
- */
- public static final Mac getInstance(String algorithm)
- throws NoSuchAlgorithmException {
- if (algorithm == null) {
- throw new NullPointerException("algorithm is null");
- }
- synchronized (engine) {
- engine.getInstance(algorithm, null);
- return new Mac((MacSpi) engine.spi, engine.provider, algorithm);
- }
- }
-
- /**
- * @com.intel.drl.spec_ref
- *
- * throws NullPointerException if algorithm is null (instead of
- * NoSuchAlgorithmException as in 1.4 release)
- */
- public static final Mac getInstance(String algorithm, String provider)
- throws NoSuchAlgorithmException, NoSuchProviderException {
- if ((provider == null) || (provider.length() == 0)) {
- throw new IllegalArgumentException("Provider is null or empty");
- }
- Provider impProvider = Security.getProvider(provider);
- if (impProvider == null) {
- throw new NoSuchProviderException(provider);
- }
- return getInstance(algorithm, impProvider);
- }
-
- /**
- * @com.intel.drl.spec_ref
- *
- * throws NullPointerException if algorithm is null (instead of
- * NoSuchAlgorithmException as in 1.4 release)
- */
- public static final Mac getInstance(String algorithm, Provider provider)
- throws NoSuchAlgorithmException {
- if (provider == null) {
- throw new IllegalArgumentException("Provider is null");
- }
- if (algorithm == null) {
- throw new NullPointerException("algorithm is null");
- }
- synchronized (engine) {
- engine.getInstance(algorithm, provider, null);
- return new Mac((MacSpi) engine.spi, provider, algorithm);
- }
- }
-
- /**
- * @com.intel.drl.spec_ref
- *
- */
- public final int getMacLength() {
- return spiImpl.engineGetMacLength();
- }
-
- /**
- * @com.intel.drl.spec_ref
- *
- */
- public final void init(Key key, AlgorithmParameterSpec params)
- throws InvalidKeyException, InvalidAlgorithmParameterException {
- if (key == null) {
- throw new InvalidKeyException("key is null");
- }
- spiImpl.engineInit(key, params);
- isInitMac = true;
- }
-
- /**
- * @com.intel.drl.spec_ref
- *
- */
- public final void init(Key key) throws InvalidKeyException {
- if (key == null) {
- throw new InvalidKeyException("key is null");
- }
- try {
- spiImpl.engineInit(key, null);
- isInitMac = true;
- } catch (InvalidAlgorithmParameterException e) {
- throw new RuntimeException(e);
- }
- }
-
- /**
- * @com.intel.drl.spec_ref
- *
- */
- public final void update(byte input) throws IllegalStateException {
- if (!isInitMac) {
- throw new IllegalStateException(NOTINITMAC);
- }
- spiImpl.engineUpdate(input);
- }
-
- /**
- * @com.intel.drl.spec_ref
- *
- */
- public final void update(byte[] input, int offset, int len)
- throws IllegalStateException {
- if (!isInitMac) {
- throw new IllegalStateException(NOTINITMAC);
- }
- if (input == null) {
- return;
- }
- if ((offset < 0) || (len < 0) || ((offset + len) > input.length)) {
- throw new IllegalArgumentException("Incorrect arguments");
- }
- spiImpl.engineUpdate(input, offset, len);
- }
-
- /**
- * @com.intel.drl.spec_ref
- *
- */
- public final void update(byte[] input) throws IllegalStateException {
- if (!isInitMac) {
- throw new IllegalStateException(NOTINITMAC);
- }
- if (input != null) {
- spiImpl.engineUpdate(input, 0, input.length);
- }
- }
-
- /**
- * @com.intel.drl.spec_ref
- *
- */
- public final void update(ByteBuffer input) {
- if (!isInitMac) {
- throw new IllegalStateException(NOTINITMAC);
- }
- if (input != null) {
- spiImpl.engineUpdate(input);
- } else {
- throw new IllegalArgumentException("input is null");
- }
- }
-
- /**
- * @com.intel.drl.spec_ref
- *
- */
- public final byte[] doFinal() throws IllegalStateException {
- if (!isInitMac) {
- throw new IllegalStateException(NOTINITMAC);
- }
- return spiImpl.engineDoFinal();
- }
-
- /**
- * @com.intel.drl.spec_ref
- *
- */
- public final void doFinal(byte[] output, int outOffset)
- throws ShortBufferException, IllegalStateException {
- if (!isInitMac) {
- throw new IllegalStateException(NOTINITMAC);
- }
- if (output == null) {
- throw new ShortBufferException("Output buffer is null");
- }
- if ((outOffset < 0) || (outOffset >= output.length)) {
- throw new ShortBufferException("Incorrect outOffset parameter: "
- + Integer.toString(outOffset));
- }
- int t = spiImpl.engineGetMacLength();
- if (t > (output.length - outOffset)) {
- throw new ShortBufferException(
- "Output buffer is short. It is needed "
- + Integer.toString(t) + " bytes");
- }
- byte[] result = spiImpl.engineDoFinal();
- System.arraycopy(result, 0, output, outOffset, result.length);
-
- }
-
- /**
- * @com.intel.drl.spec_ref
- *
- */
- public final byte[] doFinal(byte[] input) throws IllegalStateException {
- if (!isInitMac) {
- throw new IllegalStateException("Not initialized Mac");
- }
- if (input != null) {
- spiImpl.engineUpdate(input, 0, input.length);
- }
- return spiImpl.engineDoFinal();
- }
-
- /**
- * @com.intel.drl.spec_ref
- *
- */
- public final void reset() {
- spiImpl.engineReset();
- }
-
- /**
- * @com.intel.drl.spec_ref
- *
- */
- public final Object clone() throws CloneNotSupportedException {
- MacSpi newSpiImpl = (MacSpi)spiImpl.clone();
- Mac mac = new Mac(newSpiImpl, this.provider, this.algorithm);
- mac.isInitMac = this.isInitMac;
- return mac;
- }
+/*
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * 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.
+ */
+
+/**
+* @author Vera Y. Petrashkova
+* @version $Revision$
+*/
+
+package javax.crypto;
+
+import java.nio.ByteBuffer;
+import java.security.InvalidAlgorithmParameterException;
+import java.security.InvalidKeyException;
+import java.security.Key;
+import java.security.NoSuchAlgorithmException;
+import java.security.NoSuchProviderException;
+import java.security.Provider;
+import java.security.Security;
+import java.security.spec.AlgorithmParameterSpec;
+
+import org.apache.harmony.security.fortress.Engine;
+
+
+/**
+ * @com.intel.drl.spec_ref
+ *
+ */
+
+public class Mac implements Cloneable {
+
+ // Store spi implementation service name
+ private static final String SERVICE = "Mac";
+
+ //Used to access common engine functionality
+ private static Engine engine = new Engine(SERVICE);
+
+ // Warning for reporting about not initialized Mac
+ private static final String NOTINITMAC = "MAC was not initialized";
+
+ // Store used provider
+ private final Provider provider;
+
+ // Store used spi implementation
+ private final MacSpi spiImpl;
+
+ // Store used algorithm name
+ private final String algorithm;
+
+ // Store Mac state (initialized or not initialized)
+ private boolean isInitMac;
+
+ /**
+ * @com.intel.drl.spec_ref
+ *
+ */
+ protected Mac(MacSpi macSpi, Provider provider, String algorithm) {
+ this.provider = provider;
+ this.algorithm = algorithm;
+ this.spiImpl = macSpi;
+ this.isInitMac = false;
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ *
+ */
+ public final String getAlgorithm() {
+ return algorithm;
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ *
+ */
+ public final Provider getProvider() {
+ return provider;
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ *
+ * throws NullPointerException if algorithm is null (instead of
+ * NoSuchAlgorithmException as in 1.4 release)
+ */
+ public static final Mac getInstance(String algorithm)
+ throws NoSuchAlgorithmException {
+ if (algorithm == null) {
+ throw new NullPointerException("algorithm is null");
+ }
+ synchronized (engine) {
+ engine.getInstance(algorithm, null);
+ return new Mac((MacSpi) engine.spi, engine.provider, algorithm);
+ }
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ *
+ * throws NullPointerException if algorithm is null (instead of
+ * NoSuchAlgorithmException as in 1.4 release)
+ */
+ public static final Mac getInstance(String algorithm, String provider)
+ throws NoSuchAlgorithmException, NoSuchProviderException {
+ if ((provider == null) || (provider.length() == 0)) {
+ throw new IllegalArgumentException("Provider is null or empty");
+ }
+ Provider impProvider = Security.getProvider(provider);
+ if (impProvider == null) {
+ throw new NoSuchProviderException(provider);
+ }
+ return getInstance(algorithm, impProvider);
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ *
+ * throws NullPointerException if algorithm is null (instead of
+ * NoSuchAlgorithmException as in 1.4 release)
+ */
+ public static final Mac getInstance(String algorithm, Provider provider)
+ throws NoSuchAlgorithmException {
+ if (provider == null) {
+ throw new IllegalArgumentException("Provider is null");
+ }
+ if (algorithm == null) {
+ throw new NullPointerException("algorithm is null");
+ }
+ synchronized (engine) {
+ engine.getInstance(algorithm, provider, null);
+ return new Mac((MacSpi) engine.spi, provider, algorithm);
+ }
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ *
+ */
+ public final int getMacLength() {
+ return spiImpl.engineGetMacLength();
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ *
+ */
+ public final void init(Key key, AlgorithmParameterSpec params)
+ throws InvalidKeyException, InvalidAlgorithmParameterException {
+ if (key == null) {
+ throw new InvalidKeyException("key is null");
+ }
+ spiImpl.engineInit(key, params);
+ isInitMac = true;
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ *
+ */
+ public final void init(Key key) throws InvalidKeyException {
+ if (key == null) {
+ throw new InvalidKeyException("key is null");
+ }
+ try {
+ spiImpl.engineInit(key, null);
+ isInitMac = true;
+ } catch (InvalidAlgorithmParameterException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ *
+ */
+ public final void update(byte input) throws IllegalStateException {
+ if (!isInitMac) {
+ throw new IllegalStateException(NOTINITMAC);
+ }
+ spiImpl.engineUpdate(input);
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ *
+ */
+ public final void update(byte[] input, int offset, int len)
+ throws IllegalStateException {
+ if (!isInitMac) {
+ throw new IllegalStateException(NOTINITMAC);
+ }
+ if (input == null) {
+ return;
+ }
+ if ((offset < 0) || (len < 0) || ((offset + len) > input.length)) {
+ throw new IllegalArgumentException("Incorrect arguments");
+ }
+ spiImpl.engineUpdate(input, offset, len);
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ *
+ */
+ public final void update(byte[] input) throws IllegalStateException {
+ if (!isInitMac) {
+ throw new IllegalStateException(NOTINITMAC);
+ }
+ if (input != null) {
+ spiImpl.engineUpdate(input, 0, input.length);
+ }
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ *
+ */
+ public final void update(ByteBuffer input) {
+ if (!isInitMac) {
+ throw new IllegalStateException(NOTINITMAC);
+ }
+ if (input != null) {
+ spiImpl.engineUpdate(input);
+ } else {
+ throw new IllegalArgumentException("input is null");
+ }
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ *
+ */
+ public final byte[] doFinal() throws IllegalStateException {
+ if (!isInitMac) {
+ throw new IllegalStateException(NOTINITMAC);
+ }
+ return spiImpl.engineDoFinal();
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ *
+ */
+ public final void doFinal(byte[] output, int outOffset)
+ throws ShortBufferException, IllegalStateException {
+ if (!isInitMac) {
+ throw new IllegalStateException(NOTINITMAC);
+ }
+ if (output == null) {
+ throw new ShortBufferException("Output buffer is null");
+ }
+ if ((outOffset < 0) || (outOffset >= output.length)) {
+ throw new ShortBufferException("Incorrect outOffset parameter: "
+ + Integer.toString(outOffset));
+ }
+ int t = spiImpl.engineGetMacLength();
+ if (t > (output.length - outOffset)) {
+ throw new ShortBufferException(
+ "Output buffer is short. It is needed "
+ + Integer.toString(t) + " bytes");
+ }
+ byte[] result = spiImpl.engineDoFinal();
+ System.arraycopy(result, 0, output, outOffset, result.length);
+
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ *
+ */
+ public final byte[] doFinal(byte[] input) throws IllegalStateException {
+ if (!isInitMac) {
+ throw new IllegalStateException("Not initialized Mac");
+ }
+ if (input != null) {
+ spiImpl.engineUpdate(input, 0, input.length);
+ }
+ return spiImpl.engineDoFinal();
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ *
+ */
+ public final void reset() {
+ spiImpl.engineReset();
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ *
+ */
+ public final Object clone() throws CloneNotSupportedException {
+ MacSpi newSpiImpl = (MacSpi)spiImpl.clone();
+ Mac mac = new Mac(newSpiImpl, this.provider, this.algorithm);
+ mac.isInitMac = this.isInitMac;
+ return mac;
+ }
}
Modified: incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/main/java/javax/crypto/SecretKeyFactory.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/main/java/javax/crypto/SecretKeyFactory.java?rev=410243&r1=410242&r2=410243&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/main/java/javax/crypto/SecretKeyFactory.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/main/java/javax/crypto/SecretKeyFactory.java Tue May 30 04:35:44 2006
@@ -1,162 +1,162 @@
-/*
- * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
- *
- * 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.
- */
-
-/**
-* @author Vera Y. Petrashkova
-* @version $Revision$
-*/
-
-package javax.crypto;
-
-import java.security.InvalidKeyException;
-import java.security.NoSuchAlgorithmException;
-import java.security.NoSuchProviderException;
-import java.security.Provider;
-import java.security.Security;
-import java.security.spec.InvalidKeySpecException;
-import java.security.spec.KeySpec;
-
-import org.apache.harmony.security.fortress.Engine;
-
-
-/**
- * @com.intel.drl.spec_ref
- *
- */
-public class SecretKeyFactory {
-
- // Store spi implementation service name
- private static final String SERVICE = "SecretKeyFactory";
-
- // Used to access common engine functionality
- private static Engine engine = new Engine(SERVICE);
-
- // Store used provider
- private final Provider provider;
-
- // Store used spi implementation
- private final SecretKeyFactorySpi spiImpl;
-
- // Store used algorithm name
- private final String algorithm;
-
- /**
- * @com.intel.drl.spec_ref
- *
- */
- protected SecretKeyFactory(SecretKeyFactorySpi keyFacSpi,
- Provider provider, String algorithm) {
- this.provider = provider;
- this.algorithm = algorithm;
- this.spiImpl = keyFacSpi;
- }
-
- /**
- * @com.intel.drl.spec_ref
- *
- */
- public final String getAlgorithm() {
- return algorithm;
- }
-
- /**
- * @com.intel.drl.spec_ref
- *
- */
- public final Provider getProvider() {
- return provider;
- }
-
- /**
- * @com.intel.drl.spec_ref
- *
- */
- public static final SecretKeyFactory getInstance(String algorithm)
- throws NoSuchAlgorithmException {
- if (algorithm == null) {
- throw new NullPointerException("Algorithm is null");
- }
- synchronized (engine) {
- engine.getInstance(algorithm, null);
- return new SecretKeyFactory((SecretKeyFactorySpi) engine.spi,
- engine.provider, algorithm);
- }
- }
-
- /**
- * @com.intel.drl.spec_ref
- *
- */
- public static final SecretKeyFactory getInstance(String algorithm,
- String provider) throws NoSuchAlgorithmException,
- NoSuchProviderException {
- if ((provider == null) || (provider.length() == 0)) {
- throw new IllegalArgumentException("Provider is null or empty");
- }
- Provider impProvider = Security.getProvider(provider);
- if (impProvider == null) {
- throw new NoSuchProviderException(provider);
- }
- return getInstance(algorithm, impProvider);
- }
-
- /**
- * @com.intel.drl.spec_ref
- *
- */
- public static final SecretKeyFactory getInstance(String algorithm,
- Provider provider) throws NoSuchAlgorithmException {
- if (provider == null) {
- throw new IllegalArgumentException("Provider is null");
- }
- if (algorithm == null) {
- throw new NullPointerException("Algorithm is null");
- }
- synchronized (engine) {
- engine.getInstance(algorithm, provider, null);
- return new SecretKeyFactory((SecretKeyFactorySpi) engine.spi, provider,
- algorithm);
- }
- }
-
- /**
- * @com.intel.drl.spec_ref
- *
- */
- public final SecretKey generateSecret(KeySpec keySpec)
- throws InvalidKeySpecException {
- return spiImpl.engineGenerateSecret(keySpec);
- }
-
- /**
- * @com.intel.drl.spec_ref
- *
- */
- public final KeySpec getKeySpec(SecretKey key, Class keySpec)
- throws InvalidKeySpecException {
- return spiImpl.engineGetKeySpec(key, keySpec);
- }
-
- /**
- * @com.intel.drl.spec_ref
- *
- */
- public final SecretKey translateKey(SecretKey key)
- throws InvalidKeyException {
- return spiImpl.engineTranslateKey(key);
-
- }
+/*
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * 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.
+ */
+
+/**
+* @author Vera Y. Petrashkova
+* @version $Revision$
+*/
+
+package javax.crypto;
+
+import java.security.InvalidKeyException;
+import java.security.NoSuchAlgorithmException;
+import java.security.NoSuchProviderException;
+import java.security.Provider;
+import java.security.Security;
+import java.security.spec.InvalidKeySpecException;
+import java.security.spec.KeySpec;
+
+import org.apache.harmony.security.fortress.Engine;
+
+
+/**
+ * @com.intel.drl.spec_ref
+ *
+ */
+public class SecretKeyFactory {
+
+ // Store spi implementation service name
+ private static final String SERVICE = "SecretKeyFactory";
+
+ // Used to access common engine functionality
+ private static Engine engine = new Engine(SERVICE);
+
+ // Store used provider
+ private final Provider provider;
+
+ // Store used spi implementation
+ private final SecretKeyFactorySpi spiImpl;
+
+ // Store used algorithm name
+ private final String algorithm;
+
+ /**
+ * @com.intel.drl.spec_ref
+ *
+ */
+ protected SecretKeyFactory(SecretKeyFactorySpi keyFacSpi,
+ Provider provider, String algorithm) {
+ this.provider = provider;
+ this.algorithm = algorithm;
+ this.spiImpl = keyFacSpi;
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ *
+ */
+ public final String getAlgorithm() {
+ return algorithm;
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ *
+ */
+ public final Provider getProvider() {
+ return provider;
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ *
+ */
+ public static final SecretKeyFactory getInstance(String algorithm)
+ throws NoSuchAlgorithmException {
+ if (algorithm == null) {
+ throw new NullPointerException("Algorithm is null");
+ }
+ synchronized (engine) {
+ engine.getInstance(algorithm, null);
+ return new SecretKeyFactory((SecretKeyFactorySpi) engine.spi,
+ engine.provider, algorithm);
+ }
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ *
+ */
+ public static final SecretKeyFactory getInstance(String algorithm,
+ String provider) throws NoSuchAlgorithmException,
+ NoSuchProviderException {
+ if ((provider == null) || (provider.length() == 0)) {
+ throw new IllegalArgumentException("Provider is null or empty");
+ }
+ Provider impProvider = Security.getProvider(provider);
+ if (impProvider == null) {
+ throw new NoSuchProviderException(provider);
+ }
+ return getInstance(algorithm, impProvider);
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ *
+ */
+ public static final SecretKeyFactory getInstance(String algorithm,
+ Provider provider) throws NoSuchAlgorithmException {
+ if (provider == null) {
+ throw new IllegalArgumentException("Provider is null");
+ }
+ if (algorithm == null) {
+ throw new NullPointerException("Algorithm is null");
+ }
+ synchronized (engine) {
+ engine.getInstance(algorithm, provider, null);
+ return new SecretKeyFactory((SecretKeyFactorySpi) engine.spi, provider,
+ algorithm);
+ }
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ *
+ */
+ public final SecretKey generateSecret(KeySpec keySpec)
+ throws InvalidKeySpecException {
+ return spiImpl.engineGenerateSecret(keySpec);
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ *
+ */
+ public final KeySpec getKeySpec(SecretKey key, Class keySpec)
+ throws InvalidKeySpecException {
+ return spiImpl.engineGetKeySpec(key, keySpec);
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ *
+ */
+ public final SecretKey translateKey(SecretKey key)
+ throws InvalidKeyException {
+ return spiImpl.engineTranslateKey(key);
+
+ }
}
Modified: incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/main/java/javax/crypto/spec/SecretKeySpec.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/main/java/javax/crypto/spec/SecretKeySpec.java?rev=410243&r1=410242&r2=410243&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/main/java/javax/crypto/spec/SecretKeySpec.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/main/java/javax/crypto/spec/SecretKeySpec.java Tue May 30 04:35:44 2006
@@ -1,132 +1,132 @@
-/*
- * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
- *
- * 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.
- */
-
-/**
-* @author Alexander Y. Kleymenov
-* @version $Revision$
-*/
-
-package javax.crypto.spec;
-
-import java.io.Serializable;
-import java.security.spec.KeySpec;
-import java.util.Arrays;
-import javax.crypto.SecretKey;
-
-/**
- * @com.intel.drl.spec_ref
- */
-public class SecretKeySpec implements SecretKey, KeySpec, Serializable {
-
- // The 5.0 spec. doesn't declare this serialVersionUID field
- // In order to be compatible it is explicitly declared here
- // for details see HARMONY-233
- private static final long serialVersionUID = 6577238317307289933L;
-
- private final byte[] key;
- private final String algorithm;
- private final String format = "RAW";
-
- /**
- * @com.intel.drl.spec_ref
- */
- public SecretKeySpec(byte[] key, String algorithm) {
- if (key == null) {
- throw new IllegalArgumentException("key is null");
- }
- if (key.length == 0) {
- throw new IllegalArgumentException("key is empty");
- }
- if (algorithm == null) {
- throw new IllegalArgumentException("algorithm is null");
- }
-
- this.algorithm = algorithm;
- this.key = new byte[key.length];
- System.arraycopy(key, 0, this.key, 0, key.length);
- }
-
- /**
- * @com.intel.drl.spec_ref
- */
- public SecretKeySpec(byte[] key, int offset, int len, String algorithm) {
- if (key == null) {
- throw new IllegalArgumentException("key is null");
- }
- if (key.length == 0) {
- throw new IllegalArgumentException("key is empty");
- }
- if ((key.length - offset < len)) {
- throw new IllegalArgumentException("key is too short");
- }
- if (algorithm == null) {
- throw new IllegalArgumentException("algorithm is null");
- }
- this.algorithm = algorithm;
- this.key = new byte[len];
- System.arraycopy(key, offset, this.key, 0, len);
- }
-
- /**
- * @com.intel.drl.spec_ref
- */
- public String getAlgorithm() {
- return algorithm;
- }
-
- /**
- * @com.intel.drl.spec_ref
- */
- public String getFormat() {
- return format;
- }
-
- /**
- * @com.intel.drl.spec_ref
- */
- public byte[] getEncoded() {
- byte[] result = new byte[key.length];
- System.arraycopy(key, 0, result, 0, key.length);
- return result;
- }
-
- /**
- * @com.intel.drl.spec_ref
- */
- public int hashCode() {
- int result = algorithm.length();
- for (int i=0; i<key.length; i++) {
- result += key[i];
- }
- return result;
- }
-
- /**
- * @com.intel.drl.spec_ref
- */
- public boolean equals(Object obj) {
- if (obj == this) {
- return true;
- }
- if (!(obj instanceof SecretKeySpec)) {
- return false;
- }
- SecretKeySpec ks = (SecretKeySpec) obj;
- return (algorithm.equalsIgnoreCase(ks.algorithm))
- && (Arrays.equals(key, ks.key));
- }
-}
-
+/*
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * 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.
+ */
+
+/**
+* @author Alexander Y. Kleymenov
+* @version $Revision$
+*/
+
+package javax.crypto.spec;
+
+import java.io.Serializable;
+import java.security.spec.KeySpec;
+import java.util.Arrays;
+import javax.crypto.SecretKey;
+
+/**
+ * @com.intel.drl.spec_ref
+ */
+public class SecretKeySpec implements SecretKey, KeySpec, Serializable {
+
+ // The 5.0 spec. doesn't declare this serialVersionUID field
+ // In order to be compatible it is explicitly declared here
+ // for details see HARMONY-233
+ private static final long serialVersionUID = 6577238317307289933L;
+
+ private final byte[] key;
+ private final String algorithm;
+ private final String format = "RAW";
+
+ /**
+ * @com.intel.drl.spec_ref
+ */
+ public SecretKeySpec(byte[] key, String algorithm) {
+ if (key == null) {
+ throw new IllegalArgumentException("key is null");
+ }
+ if (key.length == 0) {
+ throw new IllegalArgumentException("key is empty");
+ }
+ if (algorithm == null) {
+ throw new IllegalArgumentException("algorithm is null");
+ }
+
+ this.algorithm = algorithm;
+ this.key = new byte[key.length];
+ System.arraycopy(key, 0, this.key, 0, key.length);
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ */
+ public SecretKeySpec(byte[] key, int offset, int len, String algorithm) {
+ if (key == null) {
+ throw new IllegalArgumentException("key is null");
+ }
+ if (key.length == 0) {
+ throw new IllegalArgumentException("key is empty");
+ }
+ if ((key.length - offset < len)) {
+ throw new IllegalArgumentException("key is too short");
+ }
+ if (algorithm == null) {
+ throw new IllegalArgumentException("algorithm is null");
+ }
+ this.algorithm = algorithm;
+ this.key = new byte[len];
+ System.arraycopy(key, offset, this.key, 0, len);
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ */
+ public String getAlgorithm() {
+ return algorithm;
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ */
+ public String getFormat() {
+ return format;
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ */
+ public byte[] getEncoded() {
+ byte[] result = new byte[key.length];
+ System.arraycopy(key, 0, result, 0, key.length);
+ return result;
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ */
+ public int hashCode() {
+ int result = algorithm.length();
+ for (int i=0; i<key.length; i++) {
+ result += key[i];
+ }
+ return result;
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ */
+ public boolean equals(Object obj) {
+ if (obj == this) {
+ return true;
+ }
+ if (!(obj instanceof SecretKeySpec)) {
+ return false;
+ }
+ SecretKeySpec ks = (SecretKeySpec) obj;
+ return (algorithm.equalsIgnoreCase(ks.algorithm))
+ && (Arrays.equals(key, ks.key));
+ }
+}
+
Modified: incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/main/java/org/apache/harmony/crypto/internal/NullCipherSpi.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/main/java/org/apache/harmony/crypto/internal/NullCipherSpi.java?rev=410243&r1=410242&r2=410243&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/main/java/org/apache/harmony/crypto/internal/NullCipherSpi.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/main/java/org/apache/harmony/crypto/internal/NullCipherSpi.java Tue May 30 04:35:44 2006
@@ -74,7 +74,7 @@
* See javax.crypto.CipherSpi#engineGetIV()
*/
public byte[] engineGetIV() {
- return null;
+ return new byte[8]; // compatible with RI
}
/**
Modified: incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/api/java.injected/javax/crypto/CipherInputStreamTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/api/java.injected/javax/crypto/CipherInputStreamTest.java?rev=410243&r1=410242&r2=410243&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/api/java.injected/javax/crypto/CipherInputStreamTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/api/java.injected/javax/crypto/CipherInputStreamTest.java Tue May 30 04:35:44 2006
@@ -55,50 +55,39 @@
* CipherInputStream uses NullCipher if Cipher is not specified
* in the constructor.
*/
- public void testCipherInputStream() {
- byte[] data = new byte[] {-127, -100, -50, -10, -1, 0, 1, 10, 50, 127};
+ 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);
- try {
- 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.");
+ for (int i = 0; i < data.length; i++) {
+ if ((byte) cis.read() != data[i]) {
+ fail("NullCipher should be used "
+ + "if Cipher is not specified.");
}
- } catch (IOException e) {
- e.printStackTrace();
- fail("Unexpected IOException was thrown.");
+ }
+ 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.
+ * (related to the InputStream) and that it returns -1 at the end of stream.
*/
- public void testRead1() {
- byte[] data = new byte[] {-127, -100, -50, -10, -1, 0, 1, 10, 50, 127};
+ 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;
- try {
- 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 + ".");
- }
+ 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.");
- }
- } catch (IOException e) {
- e.printStackTrace();
- fail("Unexpected IOException was thrown.");
+ }
+ if (cis.read() != -1) {
+ fail("read() should return -1 at the end of the stream.");
}
}
@@ -107,168 +96,139 @@
* value (related to the InputStream) and that it returns -1 at the end of
* stream.
*/
- public void testRead2() {
- byte[] data = new byte[] {-127, -100, -50, -10, -1, 0, 1, 10, 50, 127};
+ 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());
- try {
- 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);
+
+ 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 (cis.read(result) != -1) {
- fail("read(byte[] b) should return -1 "
- + "at the end of the stream.");
- }
- } catch (IOException e) {
- e.printStackTrace();
- fail("Unexpected IOException was thrown.");
+ 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
- * dicards bytes in the case of null buffer, and that it returns -1 at
- * the end of stream.
+ * returns the correct value (related to the InputStream), that it dicards
+ * bytes in the case of null buffer, and that it returns -1 at the end of
+ * stream.
*/
- public void testRead3() {
- byte[] data = new byte[] {-127, -100, -50, -10, -1, 0, 1, 10, 50, 127};
+ 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());
- try {
- 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);
- }
+
+ 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 (cis.read(result, 0, 1) != -1) {
- fail("read() should return -1 at the end of the stream.");
+ 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);
}
- } catch (NullPointerException e) {
- e.printStackTrace();
- fail("Unexpected NullPointerException was thrown.");
- } catch (IOException e) {
- e.printStackTrace();
- fail("Unexpected IOException was thrown.");
+ }
+ 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.
+ * skip(long n) method testing. Tests that the method correctly skips the
+ * bytes.
*/
- public void testSkip() {
- byte[] data = new byte[] {-127, -100, -50, -10, -1, 0, 1, 10, 50, 127};
+ 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());
- try {
- 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);
+ 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 = cis.read(result, 0, 1)) != -1) {
- fail("read() should return -1 at the end of the stream. "
- + "Output is: " + got + ".");
- }
- } catch (NullPointerException e) {
- e.printStackTrace();
- fail("Unexpected NullPointerException was thrown.");
- } catch (IOException e) {
- e.printStackTrace();
- fail("Unexpected IOException was thrown.");
+ 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.
*/
- public void testAvailable() {
- byte[] data = new byte[] {-127, -100, -50, -10, -1, 0, 1, 10, 50, 127};
+ 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());
- try {
- assertEquals("The returned by available() method value "
- + "should be 0.", cis.available(), 0);
- } catch (IOException e) {
- e.printStackTrace();
- fail("Unexpected IOException was thrown.");
- }
+ 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.
*/
- public void testClose() {
- byte[] data = new byte[] {-127, -100, -50, -10, -1, 0, 1, 10, 50, 127};
+ 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());
- try {
- cis.close();
- assertTrue("The close() method should call the close() method "
- + "of its underlying input stream.", tis.wasClosed());
- } catch (IOException e) {
- e.printStackTrace();
- fail("Unexpected IOException was thrown.");
- }
+ cis.close();
+ assertTrue("The close() method should call the close() method "
+ + "of its underlying input stream.", tis.wasClosed());
}
/**
@@ -282,12 +242,5 @@
+ "should be false.", cis.markSupported());
}
- public static Test suite() {
- return new TestSuite(CipherInputStreamTest.class);
- }
-
- public static void main(String[] args) {
- junit.textui.TestRunner.run(suite());
- }
}
Modified: incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/api/java.injected/javax/crypto/CipherOutputStreamTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/api/java.injected/javax/crypto/CipherOutputStreamTest.java?rev=410243&r1=410242&r2=410243&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/api/java.injected/javax/crypto/CipherOutputStreamTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/api/java.injected/javax/crypto/CipherOutputStreamTest.java Tue May 30 04:35:44 2006
@@ -52,46 +52,33 @@
* CipherOutputStream uses NullCipher if Cipher is not specified
* in the constructor.
*/
- public void testCipherOutputStream() {
- byte[] data = new byte[] {-127, -100, -50, -10, -1, 0, 1, 10, 50, 127};
+ 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);
-
- try {
- cos.write(data);
- cos.flush();
- byte[] result = tos.toByteArray();
- if (!Arrays.equals(result, data)) {
- fail("NullCipher should be used "
- + "if Cipher is not specified.");
- }
- } catch (IOException e) {
- e.printStackTrace();
- fail("Unexpected IOException was thrown.");
+ 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.
+ * write(int b) method testing. Tests that method writes correct values to
+ * the underlying output stream.
*/
- public void testWrite1() {
- byte[] data = new byte[] {-127, -100, -50, -10, -1, 0, 1, 10, 50, 127};
+ 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());
-
- try {
- 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.");
- }
- } catch (IOException e) {
- e.printStackTrace();
- fail("Unexpected IOException was thrown.");
+ 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.");
}
}
@@ -99,44 +86,32 @@
* write(byte[] b) method testing. Tests that method writes correct values
* to the underlying output stream.
*/
- public void testWrite2() {
- byte[] data = new byte[] {-127, -100, -50, -10, -1, 0, 1, 10, 50, 127};
+ 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());
-
- try {
- cos.write(data);
- cos.flush();
- byte[] result = tos.toByteArray();
- if (!Arrays.equals(result, data)) {
- fail("CipherOutputStream wrote incorrect data.");
- }
- } catch (IOException e) {
- e.printStackTrace();
- fail("Unexpected IOException was thrown.");
+ 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.
*/
- public void testWrite3() {
- byte[] data = new byte[] {-127, -100, -50, -10, -1, 0, 1, 10, 50, 127};
+ 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());
-
- try {
- 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.");
- }
- } catch (IOException e) {
- e.printStackTrace();
- fail("Unexpected IOException was thrown.");
+ 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.");
}
}
@@ -144,54 +119,34 @@
* flush() method testing. Tests that method flushes the data to the
* underlying output stream.
*/
- public void testFlush() {
- byte[] data = new byte[] {-127, -100, -50, -10, -1, 0, 1, 10, 50, 127};
+ 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);
-
- try {
- cos.write(data);
- cos.flush();
- byte[] result = tos.toByteArray();
- if (!Arrays.equals(result, data)) {
- fail("CipherOutputStream did not flush the data.");
- }
- } catch (IOException e) {
- e.printStackTrace();
- fail("Unexpected IOException was thrown.");
+ 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.
+ * close() method testing. Tests that the method calls the close() method of
+ * the underlying input stream.
*/
- public void testClose() {
- byte[] data = new byte[] {-127, -100, -50, -10, -1, 0, 1, 10, 50, 127};
+ 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);
-
- try {
- 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());
- } catch (IOException e) {
- e.printStackTrace();
- fail("Unexpected IOException was thrown.");
+ cos.write(data);
+ cos.close();
+ byte[] result = tos.toByteArray();
+ if (!Arrays.equals(result, data)) {
+ fail("CipherOutputStream did not flush the data.");
}
- }
-
- public static Test suite() {
- return new TestSuite(CipherOutputStreamTest.class);
- }
-
- public static void main(String[] args) {
- junit.textui.TestRunner.run(suite());
+ assertTrue("The close() method should call the close() method "
+ + "of its underlying output stream.", tos.wasClosed());
}
}
Modified: incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/api/java.injected/javax/crypto/CipherSpiTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/api/java.injected/javax/crypto/CipherSpiTest.java?rev=410243&r1=410242&r2=410243&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/api/java.injected/javax/crypto/CipherSpiTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/api/java.injected/javax/crypto/CipherSpiTest.java Tue May 30 04:35:44 2006
@@ -82,16 +82,12 @@
* Test for <code>engineGetKeySize(Key)</code> method
* Assertion: It throws UnsupportedOperationException if it is not overriden
*/
- public void testCipherSpi02() {
+ public void testCipherSpi02() throws Exception {
CipherSpi cSpi = new myCipherSpi();
try {
cSpi.engineGetKeySize(null);
assertTrue("UnsupportedOperationException must be thrown", false);
} catch (UnsupportedOperationException e) {
- } catch (Exception e) {
- assertTrue(
- "Unexpected ".concat(e.toString()).concat(" was thrown"),
- false);
}
}
@@ -99,16 +95,12 @@
* Test for <code>engineWrap(Key)</code> method
* Assertion: It throws UnsupportedOperationException if it is not overriden
*/
- public void testCipherSpi03() {
+ public void testCipherSpi03() throws Exception {
CipherSpi cSpi = new myCipherSpi();
try {
cSpi.engineWrap(null);
assertTrue("UnsupportedOperationException must be thrown", false);
} catch (UnsupportedOperationException e) {
- } catch (Exception e) {
- assertTrue(
- "Unexpected ".concat(e.toString()).concat(" was thrown"),
- false);
}
}
@@ -116,16 +108,12 @@
* Test for <code>engineUnwrap(byte[], String, int)</code> method
* Assertion: It throws UnsupportedOperationException if it is not overriden
*/
- public void testCipherSpi04() {
+ public void testCipherSpi04() throws Exception {
CipherSpi cSpi = new myCipherSpi();
try {
cSpi.engineUnwrap(new byte[0], "", 0);
assertTrue("UnsupportedOperationException must be thrown", false);
} catch (UnsupportedOperationException e) {
- } catch (Exception e) {
- assertTrue(
- "Unexpected ".concat(e.toString()).concat(" was thrown"),
- false);
}
}
@@ -223,10 +211,6 @@
bb1.position(pos);
bb2.position(0);
assertTrue("Incorrect result", cSpi.engineDoFinal(bb1, bb2) > 0);
- }
-
- public static void main(String args[]) {
- junit.textui.TestRunner.run(CipherSpiTest.class);
}
}
/**