Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sun/security/x509/X500Name/DerValueConstructor.java
41153 views
1
/*
2
* Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
/* @test
25
* @bug 4228833
26
* @library /test/lib
27
* @summary Make sure constructor that takes DerValue argument works
28
* @modules java.base/sun.security.util
29
* java.base/sun.security.x509
30
*/
31
32
import jdk.test.lib.hexdump.ASN1Formatter;
33
import jdk.test.lib.hexdump.HexPrinter;
34
import sun.security.util.*;
35
import sun.security.x509.*;
36
37
import java.util.HexFormat;
38
39
public class DerValueConstructor {
40
// Hex formatter to upper case with ":" delimiter
41
private static final HexFormat HEX = HexFormat.ofDelimiter(":").withUpperCase();
42
43
44
public static void main(String[] args) throws Exception {
45
String name = "CN=anne test";
46
47
DerOutputStream debugDER;
48
byte[] ba;
49
50
/*
51
* X500Name
52
*/
53
54
// encode
55
X500Name dn = new X500Name(name);
56
System.err.println("DEBUG: dn: " + dn.toString());
57
debugDER = new DerOutputStream();
58
dn.encode(debugDER);
59
ba = debugDER.toByteArray();
60
System.err.print("DEBUG: encoded X500Name bytes: ");
61
System.out.println(HEX.formatHex(ba));
62
System.out.println(HexPrinter.simple()
63
.formatter(ASN1Formatter.formatter())
64
.toString(ba));
65
System.err.println();
66
67
// decode
68
System.out.println("DEBUG: decoding into X500Name ...");
69
X500Name dn1 = new X500Name(new DerValue(ba));
70
System.err.println("DEBUG: dn1: " + dn1.toString());
71
System.err.println();
72
dn1 = new X500Name(ba);
73
System.err.println("DEBUG: dn1: " + dn1.toString());
74
System.err.println();
75
dn1 = new X500Name(new DerInputStream(ba));
76
System.err.println("DEBUG: dn1: " + dn1.toString());
77
System.err.println();
78
79
/*
80
* GeneralName
81
*/
82
83
// encode
84
GeneralName gn = new GeneralName(dn);
85
System.err.println("DEBUG: gn: " + gn.toString());
86
debugDER = new DerOutputStream();
87
gn.encode(debugDER);
88
ba = debugDER.toByteArray();
89
System.err.print("DEBUG: encoded GeneralName bytes: ");
90
System.out.println(HEX.formatHex(ba));
91
System.out.println(HexPrinter.simple()
92
.formatter(ASN1Formatter.formatter())
93
.toString(ba));
94
System.err.println();
95
96
// decode
97
System.out.println("DEBUG: decoding into GeneralName ...");
98
GeneralName gn1 = new GeneralName(new DerValue(ba));
99
System.err.println("DEBUG: gn1: " + gn1.toString());
100
System.err.println();
101
102
/*
103
* GeneralSubtree
104
*/
105
106
// encode
107
GeneralSubtree subTree = new GeneralSubtree(gn, 0, -1);
108
System.err.println("DEBUG: subTree: " + subTree.toString());
109
debugDER = new DerOutputStream();
110
subTree.encode(debugDER);
111
ba = debugDER.toByteArray();
112
System.err.print("DEBUG: encoded GeneralSubtree bytes: ");
113
System.out.println(HEX.formatHex(ba));
114
System.out.println(HexPrinter.simple()
115
.formatter(ASN1Formatter.formatter())
116
.toString(ba));
117
System.err.println();
118
119
// decode
120
GeneralSubtree debugSubtree = new GeneralSubtree(new DerValue(ba));
121
}
122
}
123
124