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