Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/security/util/DerInputBuffer/TimeParsing.java
38853 views
1
/*
2
* Copyright (c) 2002, 2017, 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 4558835 4915146 8181841
27
* @summary Verify timezone offset and fractional seconds are correctly parsed
28
*/
29
30
import java.io.*;
31
import java.util.Date;
32
33
import sun.security.util.DerInputStream;
34
35
public class TimeParsing {
36
37
// 10 Aug 2001 17:43:51 GMT
38
private final static long TIME = 997465431000l;
39
private final static long TIME_FRACT1 = 997465431700l;
40
private final static long TIME_FRACT2 = 997465431760l;
41
private final static long TIME_FRACT3 = 997465431765l;
42
43
// 010810174351Z
44
private final static byte[] UTC_ZULU =
45
{0x17, 0x0d, 0x30, 0x31, 0x30, 0x38, 0x31, 0x30, 0x31, 0x37, 0x34, 0x33, 0x35, 0x31, 0x5a};
46
47
// 010810184351+0100
48
private final static byte[] UTC_PLUS1 =
49
{0x17, 0x11, 0x30, 0x31, 0x30, 0x38, 0x31, 0x30, 0x31, 0x38, 0x34, 0x33, 0x35, 0x31, 0x2b, 0x30, 0x31, 0x30, 0x30};
50
51
// 010810164351-0100
52
private final static byte[] UTC_MINUS1 =
53
{0x17, 0x11, 0x30, 0x31, 0x30, 0x38, 0x31, 0x30, 0x31, 0x36, 0x34, 0x33, 0x35, 0x31, 0x2d, 0x30, 0x31, 0x30, 0x30};
54
55
// 20010810174351Z
56
private final static byte[] GEN_ZULU =
57
{0x18, 0x0f, 0x32, 0x30, 0x30, 0x31, 0x30, 0x38, 0x31, 0x30, 0x31, 0x37, 0x34, 0x33, 0x35, 0x31, 0x5a};
58
59
// 20010810184351+0100
60
private final static byte[] GEN_PLUS1 =
61
{0x18, 0x13, 0x32, 0x30, 0x30, 0x31, 0x30, 0x38, 0x31, 0x30, 0x31, 0x38, 0x34, 0x33, 0x35, 0x31, 0x2b, 0x30, 0x31, 0x30, 0x30};
62
63
// 20010810164351-0100
64
private final static byte[] GEN_MINUS1 =
65
{0x18, 0x13, 0x32, 0x30, 0x30, 0x31, 0x30, 0x38, 0x31, 0x30, 0x31, 0x36, 0x34, 0x33, 0x35, 0x31, 0x2d, 0x30, 0x31, 0x30, 0x30};
66
67
// 20010810174351.7Z
68
private final static byte[] GEN_FRACT1_ZULU =
69
{0x18, 0x11, 0x32, 0x30, 0x30, 0x31, 0x30, 0x38, 0x31, 0x30, 0x31, 0x37, 0x34, 0x33, 0x35, 0x31, 0x2e, 0x37, 0x5a};
70
71
// 20010810174351.76Z
72
private final static byte[] GEN_FRACT2_ZULU =
73
{0x18, 0x12, 0x32, 0x30, 0x30, 0x31, 0x30, 0x38, 0x31, 0x30, 0x31, 0x37, 0x34, 0x33, 0x35, 0x31, 0x2e, 0x37, 0x36, 0x5a};
74
75
// 20010810174351.765Z
76
private final static byte[] GEN_FRACT3_ZULU =
77
{0x18, 0x13, 0x32, 0x30, 0x30, 0x31, 0x30, 0x38, 0x31, 0x30, 0x31, 0x37, 0x34, 0x33, 0x35, 0x31, 0x2e, 0x37, 0x36, 0x35, 0x5a};
78
79
// 20010810174351.7654Z
80
private final static byte[] GEN_FRACT4_ZULU =
81
{0x18, 0x14, 0x32, 0x30, 0x30, 0x31, 0x30, 0x38, 0x31, 0x30, 0x31, 0x37, 0x34, 0x33, 0x35, 0x31, 0x2e, 0x37, 0x36, 0x35, 0x34, 0x5a};
82
83
// 20010810184351.7+0100
84
private final static byte[] GEN_FRACT1_PLUS1 =
85
{0x18, 0x15, 0x32, 0x30, 0x30, 0x31, 0x30, 0x38, 0x31, 0x30, 0x31, 0x38, 0x34, 0x33, 0x35, 0x31, 0x2e, 0x37, 0x2b, 0x30, 0x31, 0x30, 0x30};
86
87
// 20010810184351.76+0100
88
private final static byte[] GEN_FRACT2_PLUS1 =
89
{0x18, 0x16, 0x32, 0x30, 0x30, 0x31, 0x30, 0x38, 0x31, 0x30, 0x31, 0x38, 0x34, 0x33, 0x35, 0x31, 0x2e, 0x37, 0x36, 0x2b, 0x30, 0x31, 0x30, 0x30};
90
91
// 20010810184351.765+0100
92
private final static byte[] GEN_FRACT3_PLUS1 =
93
{0x18, 0x17, 0x32, 0x30, 0x30, 0x31, 0x30, 0x38, 0x31, 0x30, 0x31, 0x38, 0x34, 0x33, 0x35, 0x31, 0x2e, 0x37, 0x36, 0x35, 0x2b, 0x30, 0x31, 0x30, 0x30};
94
95
// 20010810184351.7654+0100
96
private final static byte[] GEN_FRACT4_PLUS1 =
97
{0x18, 0x18, 0x32, 0x30, 0x30, 0x31, 0x30, 0x38, 0x31, 0x30, 0x31, 0x38, 0x34, 0x33, 0x35, 0x31, 0x2e, 0x37, 0x36, 0x35, 0x34, 0x2b, 0x30, 0x31, 0x30, 0x30};
98
99
// 20010810184351,765+0100
100
private final static byte[] GEN_FRACT3_COMMA_PLUS1 =
101
{0x18, 0x17, 0x32, 0x30, 0x30, 0x31, 0x30, 0x38, 0x31, 0x30, 0x31, 0x38, 0x34, 0x33, 0x35, 0x31, 0x2c, 0x37, 0x36, 0x35, 0x2b, 0x30, 0x31, 0x30, 0x30};
102
103
// 20010810184351,7654+0100
104
private final static byte[] GEN_FRACT4_COMMA_PLUS1 =
105
{0x18, 0x18, 0x32, 0x30, 0x30, 0x31, 0x30, 0x38, 0x31, 0x30, 0x31, 0x38, 0x34, 0x33, 0x35, 0x31, 0x2c, 0x37, 0x36, 0x35, 0x34, 0x2b, 0x30, 0x31, 0x30, 0x30};
106
107
private static Date decodeUTC(byte[] b) throws IOException {
108
DerInputStream derin = new DerInputStream(b);
109
return derin.getUTCTime();
110
}
111
112
private static Date decodeGeneralized(byte[] b) throws IOException {
113
DerInputStream derin = new DerInputStream(b);
114
return derin.getGeneralizedTime();
115
}
116
117
private static void checkUTC(Date d0, byte[] b, String text) throws Exception {
118
Date d1 = decodeUTC(b);
119
if( !d0.equals(d1) ) {
120
throw new Exception("UTCTime " + text + " failed: " + d1.toGMTString());
121
} else {
122
System.out.println("UTCTime " + text + " ok");
123
}
124
}
125
126
private static void checkGeneralized(Date d0, byte[] b, String text) throws Exception {
127
Date d1 = decodeGeneralized(b);
128
if( !d0.equals(d1) ) {
129
throw new Exception("GeneralizedTime " + text + " failed: " + d1.toGMTString());
130
} else {
131
System.out.println("GeneralizedTime " + text + " ok");
132
}
133
}
134
135
public static void main(String args[]) throws Exception {
136
Date d0 = new Date(TIME);
137
System.out.println(d0.toGMTString());
138
139
checkUTC(d0, UTC_ZULU, "Zulu");
140
checkUTC(d0, UTC_PLUS1, "+0100");
141
checkUTC(d0, UTC_MINUS1, "-0100");
142
143
checkGeneralized(d0, GEN_ZULU, "Zulu");
144
checkGeneralized(d0, GEN_PLUS1, "+0100");
145
checkGeneralized(d0, GEN_MINUS1, "-0100");
146
147
Date d1 = new Date(TIME_FRACT1);
148
checkGeneralized(d1, GEN_FRACT1_ZULU, "fractional seconds (Zulu)");
149
checkGeneralized(d1, GEN_FRACT1_PLUS1, "fractional seconds (+0100)");
150
151
Date d2 = new Date(TIME_FRACT2);
152
checkGeneralized(d2, GEN_FRACT2_ZULU, "fractional seconds (Zulu)");
153
checkGeneralized(d2, GEN_FRACT2_PLUS1, "fractional seconds (+0100)");
154
155
Date d3 = new Date(TIME_FRACT3);
156
checkGeneralized(d3, GEN_FRACT3_ZULU, "fractional seconds (Zulu)");
157
checkGeneralized(d3, GEN_FRACT3_PLUS1, "fractional seconds (+0100)");
158
checkGeneralized(d3, GEN_FRACT3_COMMA_PLUS1, "fractional seconds (+0100)");
159
checkGeneralized(d3, GEN_FRACT4_ZULU, "fractional seconds (Zulu)");
160
checkGeneralized(d3, GEN_FRACT4_PLUS1, "fractional seconds (+0100)");
161
checkGeneralized(d3, GEN_FRACT4_COMMA_PLUS1, "fractional seconds (+0100)");
162
}
163
}
164
165