Path: blob/master/test/jdk/sun/security/pkcs/EncryptedPrivateKeyInfo/EncryptedPKInfoEqualsHashCode.java
41153 views
/*1* Copyright (c) 1999, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @author Gary Ellison26* @bug 417063527* @summary Verify equals()/hashCode() contract honored28* @modules java.base/sun.security.pkcs29* java.base/sun.security.x50930*/3132import java.io.*;3334import sun.security.x509.*;35import sun.security.pkcs.*;363738public class EncryptedPKInfoEqualsHashCode {3940public static void main(String[] args) throws Exception {4142EncryptedPrivateKeyInfo ev1;43EncryptedPrivateKeyInfo ev2;4445AlgorithmId dh = AlgorithmId.get("DH");4647byte key1[] = {48(byte)0xD4,(byte)0xA0,(byte)0xBA,(byte)0x02,49(byte)0x50,(byte)0xB6,(byte)0xFD,(byte)0x2E,50(byte)0xC6,(byte)0x26,(byte)0xE7,(byte)0xEF,51(byte)0xD6,(byte)0x37,(byte)0xDF,(byte)0x76,52(byte)0xC7,(byte)0x16,(byte)0xE2,(byte)0x2D,53(byte)0x09,(byte)0x44,(byte)0xB8,(byte)0x8B,54};5556ev1 = new EncryptedPrivateKeyInfo(dh, key1);57ev2 = new EncryptedPrivateKeyInfo(dh, key1);5859// the test60if ( (ev1.equals(ev2)) == (ev1.hashCode()==ev2.hashCode()) )61System.out.println("PASSED");62else63throw new Exception("Failed equals()/hashCode() contract");6465}66}676869