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/PaddedBitString.java
38854 views
1
/*
2
* Copyright (c) 2002, 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 4511556
27
* @summary Verify BitString value containing padding bits is accepted.
28
*/
29
30
import java.io.*;
31
import java.util.Arrays;
32
import java.math.BigInteger;
33
34
import sun.security.util.DerInputStream;
35
36
public class PaddedBitString {
37
38
// Relaxed the BitString parsing routine to accept bit strings
39
// with padding bits, ex. treat DER_BITSTRING_PAD6 as the same
40
// bit string as DER_BITSTRING_NOPAD.
41
// Note:
42
// 1. the number of padding bits has to be in [0...7]
43
// 2. value of the padding bits is ignored
44
45
// bit string (01011101 11000000)
46
// With 6 padding bits (01011101 11001011)
47
private final static byte[] DER_BITSTRING_PAD6 = { 3, 3, 6,
48
(byte)0x5d, (byte)0xcb };
49
50
// With no padding bits
51
private final static byte[] DER_BITSTRING_NOPAD = { 3, 3, 0,
52
(byte)0x5d, (byte)0xc0 };
53
54
public static void main(String args[]) throws Exception {
55
byte[] ba0, ba1;
56
try {
57
DerInputStream derin = new DerInputStream(DER_BITSTRING_PAD6);
58
ba1 = derin.getBitString();
59
} catch( IOException e ) {
60
e.printStackTrace();
61
throw new Exception("Unable to parse BitString with 6 padding bits");
62
}
63
64
try {
65
DerInputStream derin = new DerInputStream(DER_BITSTRING_NOPAD);
66
ba0 = derin.getBitString();
67
} catch( IOException e ) {
68
e.printStackTrace();
69
throw new Exception("Unable to parse BitString with no padding");
70
}
71
72
if (Arrays.equals(ba1, ba0) == false ) {
73
throw new Exception("BitString comparison check failed");
74
}
75
}
76
}
77
78