Examples of BerInputStream


Examples of com.chaosinmotion.asn1.BerInputStream

    public static void main(String[] args) throws IOException {
        byte[] data=BytesUtil.fromHexString(s3);
//        String reverse=BytesUtils.bytesToHexString(data);
//        System.out.println(reverse);
        ByteArrayInputStream inStream = new ByteArrayInputStream(data);
        BerInputStream in = new BerInputStream(inStream);
       
        TestParser parser = new TestParser();
        BerNode node;
        while (null != (node = parser.readPacket(in))) {
            System.out.println(node.toString());
View Full Code Here

Examples of org.apache.harmony.security.asn1.BerInputStream

                        BigInteger.valueOf(0xFFFFFF) }, };

        // positive testcases
        for (int i = 0; i < testcase.length; i++) {
            try {
                BerInputStream in = new BerInputStream(
                        new ByteArrayInputStream((byte[]) testcase[i][0]));

                int expected = ((BigInteger) testcase[i][1]).intValue();

                assertEquals(expected, in.getLength());
            } catch (IOException e) {
                e.printStackTrace();
                fail("Testcase: " + i + "\nUnexpected exception." + e);
            }
        }

        // negative testcase
        try {
            new BerInputStream(new ByteArrayInputStream(new byte[] { 0x30,
                    (byte) 0x84, 0x01, 0x01, 0x01, 0x01 }));
            fail("No expected ASN1Exception");
        } catch (ASN1Exception e) {
            assertTrue(e.getMessage().startsWith("Too long"));
        }
View Full Code Here

Examples of org.apache.harmony.security.asn1.BerInputStream

                0x06, 0x02, 0x01, 0x03, // oid bytes
                0x01, 0x00 // just random bytes
        };

        // pass boolean encoding
        BerInputStream in = new BerInputStream(encoded, 0, 3);
        assertEquals("boolean", 1, in.getLength());

        // pass oid encoding
        in = new BerInputStream(encoded, 3, 4);
        assertEquals("boolean", 2, in.getLength());

        // pass random encoding (equals to ANY)
        in = new BerInputStream(encoded, 7, 2);
        assertEquals("any", 0, in.getLength());

        // extra bytes for oid
        try {
            new BerInputStream(encoded, 3, 5);
            fail("No expected ASN1Exception");
        } catch (ASN1Exception e) {
            assertEquals("Wrong content length", e.getMessage());
        }

        // less bytes for oid
        try {
            new BerInputStream(encoded, 3, 3);
            fail("No expected ASN1Exception");
        } catch (ASN1Exception e) {
            assertEquals("Wrong content length", e.getMessage());
        }
    }
View Full Code Here

Examples of org.apache.harmony.security.asn1.BerInputStream

                        inStream.reset();
                        return result;
                    }
                }
                // Check the data format
                BerInputStream in = (encoding == null)
                                        ? new BerInputStream(inStream)
                                        : new BerInputStream(encoding);
                // read the next ASN.1 tag
                second_asn1_tag = in.next(); // inStream position changed
                if (encoding == null) {
                    // keep whole structure in the stream
                    inStream.reset();
                }
                // check if it is a TBSCertificate structure
View Full Code Here

Examples of org.apache.harmony.security.asn1.BerInputStream

                        inStream.reset();
                        return result;
                    }
                }
                // Check the data format
                BerInputStream in = (encoding == null)
                                        ? new BerInputStream(inStream)
                                        : new BerInputStream(encoding);
                // read the next ASN.1 tag
                second_asn1_tag = in.next();
                if (encoding == null) {
                    // keep whole structure in the stream
                    inStream.reset();
                }
                // check if it is a TBSCertList structure
View Full Code Here

Examples of org.apache.harmony.security.asn1.BerInputStream

                }

            }
        };

        BerInputStream berIn = new BerInputStream(in);
        berIn.readContent();

        assertTrue(Arrays.equals(encoding, berIn.getEncoded()));

        //
        // negative test case: the stream returns only 4 bytes of content
        //
        in = new ByteArrayInputStream(encoding) {

            int i = 0;

            public int read(byte[] b, int off, int len) {
                if (i == 0) {
                    i++;
                    return super.read(b, off, 4);
                } else {
                    return 0;
                }

            }
        };
        berIn = new BerInputStream(in);
        try {
            berIn.readContent();
            fail("No expected ASN1Exception");
        } catch (ASN1Exception e) {
        }
    }
View Full Code Here

Examples of org.apache.harmony.security.asn1.BerInputStream

                        BigInteger.valueOf(0xFFFFFF) }, };

        // positive testcases
        for (int i = 0; i < testcase.length; i++) {
            try {
                BerInputStream in = new BerInputStream(
                        new ByteArrayInputStream((byte[]) testcase[i][0]));

                int expected = ((BigInteger) testcase[i][1]).intValue();

                assertEquals(expected, in.getLength());
            } catch (IOException e) {
                e.printStackTrace();
                fail("Testcase: " + i + "\nUnexpected exception." + e);
            }
        }

        // negative testcase
        try {
            new BerInputStream(new ByteArrayInputStream(new byte[] { 0x30,
                    (byte) 0x84, 0x01, 0x01, 0x01, 0x01 }));
            fail("No expected ASN1Exception");
        } catch (ASN1Exception e) {
            assertTrue(e.getMessage().startsWith("Too long"));
        }

        //
        // Test for correct internal array reallocation
        // Regression for HARMONY-5054
        //

        // must be greater then buffer initial size (16K)
        int arrayLength = 17000;

        // 1 byte for tag and 3 for length
        byte[] encoding = new byte[arrayLength + 4];

        // fill tag and length bytes
        encoding[0] = ASN1Constants.TAG_OCTETSTRING;
        encoding[1] = (byte) 0x82; // length is encoded in two bytes
        encoding[2] = (byte) (arrayLength >> 8);
        encoding[3] = (byte) (arrayLength & 0xFF);

        BerInputStream in = new BerInputStream(new ByteArrayInputStream(
                encoding));
        assertEquals(encoding.length, in.getBuffer().length);
    }
View Full Code Here

Examples of org.apache.harmony.security.asn1.BerInputStream

                0x06, 0x02, 0x01, 0x03, // oid bytes
                0x01, 0x00 // just random bytes
        };

        // pass boolean encoding
        BerInputStream in = new BerInputStream(encoded, 0, 3);
        assertEquals("boolean", 1, in.getLength());

        // pass oid encoding
        in = new BerInputStream(encoded, 3, 4);
        assertEquals("boolean", 2, in.getLength());

        // pass random encoding (equals to ANY)
        in = new BerInputStream(encoded, 7, 2);
        assertEquals("any", 0, in.getLength());

        // extra bytes for oid
        try {
            new BerInputStream(encoded, 3, 5);
            fail("No expected ASN1Exception");
        } catch (ASN1Exception e) {
            assertEquals("Wrong content length", e.getMessage());
        }

        // less bytes for oid
        try {
            new BerInputStream(encoded, 3, 3);
            fail("No expected ASN1Exception");
        } catch (ASN1Exception e) {
            assertEquals("Wrong content length", e.getMessage());
        }
    }
View Full Code Here

Examples of org.apache.harmony.security.asn1.BerInputStream

                        inStream.reset();
                        return result;
                    }
                }
                // Check the data format
                BerInputStream in = (encoding == null)
                                        ? new BerInputStream(inStream)
                                        : new BerInputStream(encoding);
                // read the next ASN.1 tag
                second_asn1_tag = in.next(); // inStream position changed
                if (encoding == null) {
                    // keep whole structure in the stream
                    inStream.reset();
                }
                // check if it is a TBSCertificate structure
View Full Code Here

Examples of org.apache.harmony.security.asn1.BerInputStream

                        inStream.reset();
                        return result;
                    }
                }
                // Check the data format
                BerInputStream in = (encoding == null)
                                        ? new BerInputStream(inStream)
                                        : new BerInputStream(encoding);
                // read the next ASN.1 tag
                second_asn1_tag = in.next();
                if (encoding == null) {
                    // keep whole structure in the stream
                    inStream.reset();
                }
                // check if it is a TBSCertList structure
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.