test/sun/security/util/DerValue/BadValue.java

Print this page




   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 6864911
  27  * @summary ASN.1/DER input stream parser needs more work
  28  * @modules java.base/sun.misc
  29  *          java.base/sun.security.util
  30  */
  31 
  32 import java.io.*;
  33 import sun.security.util.*;
  34 import sun.misc.IOUtils;
  35 
  36 public class BadValue {
  37 
  38     public static void main(String[] args) throws Exception {
  39 
  40         // Test IOUtils.readFully
  41 
  42         // We have 4 bytes
  43         InputStream in = new ByteArrayInputStream(new byte[10]);
  44         byte[] bs = IOUtils.readFully(in, 4, true);
  45         if (bs.length != 4 || in.available() != 6) {
  46             throw new Exception("First read error");
  47         }
  48         // But only 6 left
  49         bs = IOUtils.readFully(in, 10, false);
  50         if (bs.length != 6 || in.available() != 0) {
  51             throw new Exception("Second read error");
  52         }
  53         // MAX read as much as it can
  54         in = new ByteArrayInputStream(new byte[10]);




   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 6864911
  27  * @summary ASN.1/DER input stream parser needs more work
  28  * @modules java.base/sun.security.util

  29  */
  30 
  31 import java.io.*;
  32 import sun.security.util.*;

  33 
  34 public class BadValue {
  35 
  36     public static void main(String[] args) throws Exception {
  37 
  38         // Test IOUtils.readFully
  39 
  40         // We have 4 bytes
  41         InputStream in = new ByteArrayInputStream(new byte[10]);
  42         byte[] bs = IOUtils.readFully(in, 4, true);
  43         if (bs.length != 4 || in.available() != 6) {
  44             throw new Exception("First read error");
  45         }
  46         // But only 6 left
  47         bs = IOUtils.readFully(in, 10, false);
  48         if (bs.length != 6 || in.available() != 0) {
  49             throw new Exception("Second read error");
  50         }
  51         // MAX read as much as it can
  52         in = new ByteArrayInputStream(new byte[10]);