Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/xml/crypto/dsig/GetInstanceTests.java
41152 views
1
/*
2
* Copyright (c) 2016, 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
/**
25
* @test
26
* @bug 8159488
27
* @summary Basic tests for the various getInstance() methods of
28
* XMLSignatureFactory, TransformService, and KeyInfoFactory classes
29
* @run main GetInstanceTests
30
*/
31
import java.security.*;
32
import javax.xml.crypto.dsig.*;
33
import javax.xml.crypto.dsig.keyinfo.KeyInfoFactory;
34
35
36
public class GetInstanceTests {
37
38
public static void main(String[] argv) throws Exception {
39
TestTransformService(CanonicalizationMethod.INCLUSIVE, "DOM");
40
TestTransformService(CanonicalizationMethod.EXCLUSIVE_WITH_COMMENTS, "DOM");
41
TestTransformService(Transform.BASE64, "DOM");
42
TestTransformService(Transform.XPATH2, "DOM");
43
TestXMLSignatureFactory();
44
TestKeyInfoFactory();
45
}
46
47
private static void TestTransformService(String algo,
48
String mechType) throws Exception {
49
TransformService ts = TransformService.getInstance(algo, mechType);
50
Provider p = ts.getProvider();
51
try {
52
ts = TransformService.getInstance(algo, mechType, p);
53
ts = TransformService.getInstance(algo, mechType, p.getName());
54
} catch (Exception ex) {
55
throw new RuntimeException("Error: Unexpected exception", ex);
56
}
57
}
58
59
private static void TestXMLSignatureFactory() throws Exception {
60
XMLSignatureFactory fac = XMLSignatureFactory.getInstance();
61
Provider p = fac.getProvider();
62
String mechType = fac.getMechanismType();
63
Provider p2;
64
try {
65
fac = XMLSignatureFactory.getInstance(mechType);
66
p2 = fac.getProvider();
67
fac = XMLSignatureFactory.getInstance(mechType, p);
68
fac = XMLSignatureFactory.getInstance(mechType, p.getName());
69
} catch (Exception ex) {
70
throw new RuntimeException("Error: Unexpected exception", ex);
71
}
72
if (p2.getName() != p.getName()) {
73
throw new RuntimeException("Error: Provider equality check failed");
74
}
75
if (p2.getName() != p.getName()) {
76
throw new RuntimeException("Error: Provider equality check failed");
77
}
78
}
79
80
private static void TestKeyInfoFactory() throws Exception {
81
KeyInfoFactory fac = KeyInfoFactory.getInstance();
82
Provider p = fac.getProvider();
83
String mechType = fac.getMechanismType();
84
Provider p2;
85
try {
86
fac = KeyInfoFactory.getInstance(mechType);
87
p2 = fac.getProvider();
88
fac = KeyInfoFactory.getInstance(mechType, p);
89
fac = KeyInfoFactory.getInstance(mechType, p.getName());
90
} catch (Exception ex) {
91
throw new RuntimeException("Error: Unexpected exception", ex);
92
}
93
if (p2.getName() != p.getName()) {
94
throw new RuntimeException("Error: Provider equality check failed");
95
}
96
}
97
}
98
99