Path: blob/master/test/jdk/sun/security/x509/X500Name/DerValueConstructor.java
41153 views
/*1* Copyright (c) 1999, 2021, 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 422883325* @library /test/lib26* @summary Make sure constructor that takes DerValue argument works27* @modules java.base/sun.security.util28* java.base/sun.security.x50929*/3031import jdk.test.lib.hexdump.ASN1Formatter;32import jdk.test.lib.hexdump.HexPrinter;33import sun.security.util.*;34import sun.security.x509.*;3536import java.util.HexFormat;3738public class DerValueConstructor {39// Hex formatter to upper case with ":" delimiter40private static final HexFormat HEX = HexFormat.ofDelimiter(":").withUpperCase();414243public static void main(String[] args) throws Exception {44String name = "CN=anne test";4546DerOutputStream debugDER;47byte[] ba;4849/*50* X500Name51*/5253// encode54X500Name dn = new X500Name(name);55System.err.println("DEBUG: dn: " + dn.toString());56debugDER = new DerOutputStream();57dn.encode(debugDER);58ba = debugDER.toByteArray();59System.err.print("DEBUG: encoded X500Name bytes: ");60System.out.println(HEX.formatHex(ba));61System.out.println(HexPrinter.simple()62.formatter(ASN1Formatter.formatter())63.toString(ba));64System.err.println();6566// decode67System.out.println("DEBUG: decoding into X500Name ...");68X500Name dn1 = new X500Name(new DerValue(ba));69System.err.println("DEBUG: dn1: " + dn1.toString());70System.err.println();71dn1 = new X500Name(ba);72System.err.println("DEBUG: dn1: " + dn1.toString());73System.err.println();74dn1 = new X500Name(new DerInputStream(ba));75System.err.println("DEBUG: dn1: " + dn1.toString());76System.err.println();7778/*79* GeneralName80*/8182// encode83GeneralName gn = new GeneralName(dn);84System.err.println("DEBUG: gn: " + gn.toString());85debugDER = new DerOutputStream();86gn.encode(debugDER);87ba = debugDER.toByteArray();88System.err.print("DEBUG: encoded GeneralName bytes: ");89System.out.println(HEX.formatHex(ba));90System.out.println(HexPrinter.simple()91.formatter(ASN1Formatter.formatter())92.toString(ba));93System.err.println();9495// decode96System.out.println("DEBUG: decoding into GeneralName ...");97GeneralName gn1 = new GeneralName(new DerValue(ba));98System.err.println("DEBUG: gn1: " + gn1.toString());99System.err.println();100101/*102* GeneralSubtree103*/104105// encode106GeneralSubtree subTree = new GeneralSubtree(gn, 0, -1);107System.err.println("DEBUG: subTree: " + subTree.toString());108debugDER = new DerOutputStream();109subTree.encode(debugDER);110ba = debugDER.toByteArray();111System.err.print("DEBUG: encoded GeneralSubtree bytes: ");112System.out.println(HEX.formatHex(ba));113System.out.println(HexPrinter.simple()114.formatter(ASN1Formatter.formatter())115.toString(ba));116System.err.println();117118// decode119GeneralSubtree debugSubtree = new GeneralSubtree(new DerValue(ba));120}121}122123124