< prev index next >

src/java.base/share/classes/sun/security/util/DerInputBuffer.java

Print this page

        

*** 1,7 **** /* ! * Copyright (c) 1996, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this --- 1,7 ---- /* ! * Copyright (c) 1996, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this
*** 42,61 **** * * @author David Brownell */ class DerInputBuffer extends ByteArrayInputStream implements Cloneable { ! DerInputBuffer(byte[] buf) { super(buf); } ! DerInputBuffer(byte[] buf, int offset, int len) { super(buf, offset, len); } DerInputBuffer dup() { try { DerInputBuffer retval = (DerInputBuffer)clone(); - retval.mark(Integer.MAX_VALUE); return retval; } catch (CloneNotSupportedException e) { throw new IllegalArgumentException(e.toString()); } --- 42,71 ---- * * @author David Brownell */ class DerInputBuffer extends ByteArrayInputStream implements Cloneable { ! boolean allowBER = true; ! // used by sun/security/util/DerInputBuffer/DerInputBufferEqualsHashCode.java ! DerInputBuffer(byte[] buf) { ! this(buf, true); ! } ! ! DerInputBuffer(byte[] buf, boolean allowBER) { ! super(buf); ! this.allowBER = allowBER; ! } ! ! DerInputBuffer(byte[] buf, int offset, int len, boolean allowBER) { super(buf, offset, len); + this.allowBER = allowBER; } DerInputBuffer dup() { try { DerInputBuffer retval = (DerInputBuffer)clone(); retval.mark(Integer.MAX_VALUE); return retval; } catch (CloneNotSupportedException e) { throw new IllegalArgumentException(e.toString()); }
*** 145,156 **** byte[] bytes = new byte[len]; System.arraycopy(buf, pos, bytes, 0, len); skip(len); ! // check to make sure no extra leading 0s for DER ! if (len >= 2 && (bytes[0] == 0) && (bytes[1] >= 0)) { throw new IOException("Invalid encoding: redundant leading 0s"); } if (makePositive) { return new BigInteger(1, bytes); --- 155,166 ---- byte[] bytes = new byte[len]; System.arraycopy(buf, pos, bytes, 0, len); skip(len); ! // BER allows leading 0s but DER does not ! if (!allowBER && (len >= 2 && (bytes[0] == 0) && (bytes[1] >= 0))) { throw new IOException("Invalid encoding: redundant leading 0s"); } if (makePositive) { return new BigInteger(1, bytes);
< prev index next >