Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/security/util/DerInputBuffer/PaddedBitString.java
38854 views
/*1* Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 451155626* @summary Verify BitString value containing padding bits is accepted.27*/2829import java.io.*;30import java.util.Arrays;31import java.math.BigInteger;3233import sun.security.util.DerInputStream;3435public class PaddedBitString {3637// Relaxed the BitString parsing routine to accept bit strings38// with padding bits, ex. treat DER_BITSTRING_PAD6 as the same39// bit string as DER_BITSTRING_NOPAD.40// Note:41// 1. the number of padding bits has to be in [0...7]42// 2. value of the padding bits is ignored4344// bit string (01011101 11000000)45// With 6 padding bits (01011101 11001011)46private final static byte[] DER_BITSTRING_PAD6 = { 3, 3, 6,47(byte)0x5d, (byte)0xcb };4849// With no padding bits50private final static byte[] DER_BITSTRING_NOPAD = { 3, 3, 0,51(byte)0x5d, (byte)0xc0 };5253public static void main(String args[]) throws Exception {54byte[] ba0, ba1;55try {56DerInputStream derin = new DerInputStream(DER_BITSTRING_PAD6);57ba1 = derin.getBitString();58} catch( IOException e ) {59e.printStackTrace();60throw new Exception("Unable to parse BitString with 6 padding bits");61}6263try {64DerInputStream derin = new DerInputStream(DER_BITSTRING_NOPAD);65ba0 = derin.getBitString();66} catch( IOException e ) {67e.printStackTrace();68throw new Exception("Unable to parse BitString with no padding");69}7071if (Arrays.equals(ba1, ba0) == false ) {72throw new Exception("BitString comparison check failed");73}74}75}767778