Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/security/x509/X500Name/NullX500Name.java
38854 views
/*1* Copyright (c) 1998, 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*/2728import java.util.Arrays;29import sun.security.util.DerOutputStream;30import sun.security.x509.*;31import sun.misc.HexDumpEncoder;3233public class NullX500Name {3435public static void main(String[] argv) throws Exception {36X500Name subject;37String name = "";3839subject = new X500Name(name);40System.out.println("subject:" + subject.toString());4142System.out.println("getCN:" + subject.getCommonName());4344System.out.println("getC:" + subject.getCountry());4546System.out.println("getL:" + subject.getLocality());4748System.out.println("getST:" + subject.getState());4950System.out.println("getName:" + subject.getName());5152System.out.println("getO:" + subject.getOrganization());5354System.out.println("getOU:" + subject.getOrganizationalUnit());5556System.out.println("getType:" + subject.getType());5758// encode, getEncoded()59DerOutputStream dos = new DerOutputStream();60subject.encode(dos);61byte[] out = dos.toByteArray();62byte[] enc = subject.getEncoded();63HexDumpEncoder e = new HexDumpEncoder();64if (Arrays.equals(out, enc))65System.out.println("Sucess: out:" + e.encodeBuffer(out));66else {67System.out.println("Failed: encode:" + e.encodeBuffer(out));68System.out.println("getEncoded:" + e.encodeBuffer(enc));69}70X500Name x = new X500Name(enc);71if (x.equals(subject))72System.out.println("Sucess: X500Name(byte[]):" + x.toString());73else74System.out.println("Failed: X500Name(byte[]):" + x.toString());75}76}777879