Package org.apache.harmony.security.asn1

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


        }
    }

    public void testVerify() throws IOException {

        ASN1SequenceOf seqVerify = new ASN1SequenceOf(ASN1Boolean.getInstance()) {

            public Object getDecodedObject(BerInputStream in)
                    throws IOException {
                throw new IOException(
                        "Method getDecodedObject MUST not be invoked");
            }
        };

        for (int i = 0; i < testcases.length; i++) {
            DerInputStream in = new DerInputStream((byte[]) testcases[i][1]);
            in.setVerify();
            seqVerify.decode(in);
        }
    }
View Full Code Here


            public Object getObjectToEncode(Object object) {
                return object;
            }
        };

        ASN1SequenceOf sequenceOf = new ASN1SequenceOf(choice);

        ArrayList list = new ArrayList();
        list.add(Boolean.FALSE);
        list.add(new byte[] { 0x09 });

        byte[] encoded = new byte[] {
        // Sequence Of
                0x30, 0x06,
                // Boolean
                0x01, 0x01, 0x00,
                // Integer
                0x02, 0x01, 0x09 };

        assertTrue("Encoded: ", Arrays.equals(encoded, sequenceOf.encode(list)));

        List values = (List) sequenceOf.decode(encoded);

        assertEquals("Size: ", 2, values.size());
        assertEquals("First: ", Boolean.FALSE, values.get(0));
        assertTrue("Second: ", Arrays.equals(new byte[] { 0x09 },
                (byte[]) values.get(1)));
View Full Code Here

                        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

                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

                        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

                        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

                }

            }
        };

        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

                        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

                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

                        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

TOP

Related Classes of org.apache.harmony.security.asn1.ASN1Sequence

Copyright © 2018 www.massapicom. 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.