1/*
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
8 *
9 *     http://www.apache.org/licenses/LICENSE-2.0
10 *
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.
16 */
17
18/**
19* @author Vera Y. Petrashkova
20* @version $Revision$
21*/
22
23package org.apache.harmony.crypto.tests.javax.crypto.interfaces;
24
25import dalvik.annotation.BrokenTest;
26
27import junit.framework.TestCase;
28
29import java.math.BigInteger;
30import java.security.KeyPair;
31import java.security.KeyPairGenerator;
32
33import javax.crypto.interfaces.DHKey;
34import javax.crypto.interfaces.DHPublicKey;
35import javax.crypto.spec.DHParameterSpec;
36
37
38/**
39 * Tests for <code>DHPublicKey</code> class field
40 *
41 */
42public class DHPublicKeyTest extends TestCase {
43
44    /**
45     * Test for <code>serialVersionUID</code> field
46     */
47    public void testField() {
48        checkDHPublicKey key = new checkDHPublicKey();
49        assertEquals("Incorrect serialVersionUID",
50                key.getSerVerUID(), //DHPublicKey.serialVersionUID
51                -6628103563352519193L);
52    }
53
54    @BrokenTest("Too slow - disabling for now")
55    public void test_getParams() throws Exception {
56        KeyPairGenerator kg = KeyPairGenerator.getInstance("DH");
57        kg.initialize(1024);
58        KeyPair kp1 = kg.genKeyPair();
59        KeyPair kp2 = kg.genKeyPair();
60        DHPublicKey pk1 = (DHPublicKey) kp1.getPublic();
61        DHPublicKey pk2 = (DHPublicKey) kp2.getPublic();
62
63        assertTrue(pk1.getY().getClass().getCanonicalName().equals("java.math.BigInteger"));
64        assertTrue(pk2.getParams().getClass().getCanonicalName().equals("javax.crypto.spec.DHParameterSpec"));
65        assertFalse(pk1.equals(pk2));
66        assertTrue(pk1.getY().equals(pk1.getY()));
67    }
68
69    public class checkDHPublicKey implements DHPublicKey {
70        public String getAlgorithm() {
71            return "SecretKey";
72        }
73        public String getFormat() {
74            return "Format";
75        }
76        public byte[] getEncoded() {
77            return new byte[0];
78        }
79        public long getSerVerUID() {
80            return serialVersionUID;
81        }
82        public BigInteger getY() {
83            return null;
84        }
85        public DHParameterSpec getParams() {
86            return null;
87        }
88    }
89}
90