2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
19 * @author Alexander Y. Kleymenov
23 package org.apache.harmony.crypto.tests.javax.crypto.spec;
25 import dalvik.annotation.TestTargetClass;
26 import dalvik.annotation.TestTargets;
27 import dalvik.annotation.TestLevel;
28 import dalvik.annotation.TestTargetNew;
30 import java.security.spec.MGF1ParameterSpec;
31 import java.security.spec.AlgorithmParameterSpec;
33 import javax.crypto.spec.OAEPParameterSpec;
34 import javax.crypto.spec.PSource;
36 import junit.framework.Test;
37 import junit.framework.TestCase;
38 import junit.framework.TestSuite;
40 @TestTargetClass(OAEPParameterSpec.class)
44 public class OAEPParameterSpecTest extends TestCase {
47 * OAEPParameterSpec(String mdName, String mgfName, AlgorithmParameterSpec
48 * mgfSpec, PSource pSrc) method testing. Tests that NullPointerException
49 * is thrown in the case of inappropriate constructor parameters and checks
50 * the value of DEFAULT field.
53 level = TestLevel.COMPLETE,
55 method = "OAEPParameterSpec",
56 args = {java.lang.String.class, java.lang.String.class, java.security.spec.AlgorithmParameterSpec.class, javax.crypto.spec.PSource.class}
58 public void testOAEPParameterSpec() {
59 // using init values for OAEPParameterSpec.DEFAULT
60 String mdName = "SHA-1";
61 String mgfName = "MGF1";
62 AlgorithmParameterSpec mgfSpec = MGF1ParameterSpec.SHA1;
63 PSource pSrc = PSource.PSpecified.DEFAULT;
66 new OAEPParameterSpec(null, mgfName, mgfSpec, pSrc);
67 fail("NullPointerException should be thrown in the case of "
69 } catch (NullPointerException e) {
73 new OAEPParameterSpec(mdName, null, mgfSpec, pSrc);
74 fail("NullPointerException should be thrown in the case of "
76 } catch (NullPointerException e) {
80 new OAEPParameterSpec(mdName, mgfName, mgfSpec, null);
81 fail("NullPointerException should be thrown in the case of "
83 } catch (NullPointerException e) {
86 assertTrue("The message digest algorithm name of "
87 + "OAEPParameterSpec.DEFAULT field should be " + mdName,
88 OAEPParameterSpec.DEFAULT.getDigestAlgorithm().equals(mdName));
90 assertTrue("The mask generation function algorithm name of "
91 + "OAEPParameterSpec.DEFAULT field should be " + mgfName,
92 OAEPParameterSpec.DEFAULT.getMGFAlgorithm().equals(mgfName));
94 assertTrue("The mask generation function parameters of "
95 + "OAEPParameterSpec.DEFAULT field should be the same object "
96 + "as MGF1ParameterSpec.SHA1",
97 OAEPParameterSpec.DEFAULT.getMGFParameters()
98 == MGF1ParameterSpec.SHA1);
99 assertTrue("The source of the encoding input P of "
100 + "OAEPParameterSpec.DEFAULT field should be the same object "
101 + "PSource.PSpecified.DEFAULT",
102 OAEPParameterSpec.DEFAULT.getPSource()
103 == PSource.PSpecified.DEFAULT);
107 * getDigestAlgorithm() method testing.
110 level = TestLevel.COMPLETE,
112 method = "getDigestAlgorithm",
115 public void testGetDigestAlgorithm() {
116 String mdName = "SHA-1";
117 String mgfName = "MGF1";
118 AlgorithmParameterSpec mgfSpec = MGF1ParameterSpec.SHA1;
119 PSource pSrc = PSource.PSpecified.DEFAULT;
121 OAEPParameterSpec ps = new OAEPParameterSpec(mdName, mgfName,
123 assertTrue("The returned value does not equal to the "
124 + "value specified in the constructor.",
125 ps.getDigestAlgorithm().equals(mdName));
129 * getMGFAlgorithm() method testing.
132 level = TestLevel.COMPLETE,
134 method = "getMGFAlgorithm",
137 public void testGetMGFAlgorithm() {
138 String mdName = "SHA-1";
139 String mgfName = "MGF1";
140 AlgorithmParameterSpec mgfSpec = MGF1ParameterSpec.SHA1;
141 PSource pSrc = PSource.PSpecified.DEFAULT;
143 OAEPParameterSpec ps = new OAEPParameterSpec(mdName, mgfName,
145 assertTrue("The returned value does not equal to the "
146 + "value specified in the constructor.",
147 ps.getMGFAlgorithm().equals(mgfName));
151 * getMGFParameters() method testing.
154 level = TestLevel.COMPLETE,
156 method = "getMGFParameters",
159 public void testGetMGFParameters() {
160 String mdName = "SHA-1";
161 String mgfName = "MGF1";
162 AlgorithmParameterSpec mgfSpec = MGF1ParameterSpec.SHA1;
163 PSource pSrc = PSource.PSpecified.DEFAULT;
165 OAEPParameterSpec ps = new OAEPParameterSpec(mdName, mgfName,
167 assertTrue("The returned value does not equal to the "
168 + "value specified in the constructor.",
169 ps.getMGFParameters() == mgfSpec);
173 * getPSource() method testing.
176 level = TestLevel.COMPLETE,
178 method = "getPSource",
181 public void testGetPSource() {
182 String mdName = "SHA-1";
183 String mgfName = "MGF1";
184 AlgorithmParameterSpec mgfSpec = MGF1ParameterSpec.SHA1;
185 PSource pSrc = PSource.PSpecified.DEFAULT;
187 OAEPParameterSpec ps = new OAEPParameterSpec(mdName, mgfName,
189 assertTrue("The returned value does not equal to the "
190 + "value specified in the constructor.",
191 ps.getPSource() == pSrc);
194 public static Test suite() {
195 return new TestSuite(OAEPParameterSpecTest.class);