Path: blob/master/test/jdk/sun/security/x509/X500Name/NullX500Name.java
41153 views
/*1* Copyright (c) 1998, 2020, 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/* @test24* @bug 411881825* @summary allow null X.500 Names26* @library /test/lib27* @modules java.base/sun.security.util28* java.base/sun.security.x50929*/3031import java.util.Arrays;32import sun.security.util.DerOutputStream;33import sun.security.x509.*;34import jdk.test.lib.hexdump.HexPrinter;3536public class NullX500Name {3738public static void main(String[] argv) throws Exception {39X500Name subject;40String name = "";4142subject = new X500Name(name);43System.out.println("subject:" + subject.toString());4445System.out.println("getCN:" + subject.getCommonName());4647System.out.println("getC:" + subject.getCountry());4849System.out.println("getL:" + subject.getLocality());5051System.out.println("getST:" + subject.getState());5253System.out.println("getName:" + subject.getName());5455System.out.println("getO:" + subject.getOrganization());5657System.out.println("getOU:" + subject.getOrganizationalUnit());5859System.out.println("getType:" + subject.getType());6061// encode, getEncoded()62DerOutputStream dos = new DerOutputStream();63subject.encode(dos);64byte[] out = dos.toByteArray();65byte[] enc = subject.getEncoded();66HexPrinter e = HexPrinter.simple();67if (Arrays.equals(out, enc))68System.out.println("Success: out:" + e.toString(out));69else {70System.out.println("Failed: encode:" + e.toString(out));71System.out.println("getEncoded:" + e.toString(enc));72}73X500Name x = new X500Name(enc);74if (x.equals(subject))75System.out.println("Success: X500Name(byte[]):" + x.toString());76else77System.out.println("Failed: X500Name(byte[]):" + x.toString());78}79}808182