Package org.apache.harmony.security.asn1

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


        }
    }

    public void testVerify() throws IOException {

        ASN1Sequence seqVerify = new ASN1Sequence(new ASN1Type[] {
                ASN1Boolean.getInstance(), sequenceOf }) {
            {
                setDefault(Boolean.TRUE, 0);
                setDefault(defaultList, 1);
            }

            protected 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 void testEncodeDefault() throws IOException {

        //
        // Boolean as default
        //
        ASN1Sequence s = new ASN1Sequence(new ASN1Type[] { ASN1Boolean
                .getInstance() }) {
            {
                setDefault(Boolean.TRUE, 0);
            }

            protected void getValues(Object object, Object[] values) {
                values = (Object[]) object;
            }
        };

        byte[] expectedArray = new byte[] { 0x30, 0x00 };

        byte[] encoded = s.encode(new Object[] { Boolean.TRUE });
        assertTrue("Encoded boolean:", Arrays.equals(expectedArray, encoded));

        //
        // Integer as default
        //
        s = new ASN1Sequence(new ASN1Type[] { ASN1Integer.getInstance() }) {
            {
                setDefault(new byte[] { 0x01 }, 0);
            }

            protected void getValues(Object object, Object[] values) {
                values = (Object[]) object;
            }
        };

        encoded = s.encode(new Object[] { new byte[] { 0x01 } });
        assertTrue("Encoded integer:", Arrays.equals(expectedArray, encoded));
    }
View Full Code Here

    public void testEncodeOptional() throws IOException {

        //
        // Test not optional
        //
        ASN1Sequence s = new ASN1Sequence(new ASN1Type[] { ASN1Boolean
                .getInstance() }) {

            protected void getValues(Object object, Object[] values) {
                values[0] = ((Object[]) object)[0];
            }
        };

        try {
            s.encode(new Object[] { null });
            fail("No expected RuntimeException");
        } catch (RuntimeException e) {
        }

        //
        // Test optional
        //
        s = new ASN1Sequence(new ASN1Type[] { ASN1Boolean.getInstance() }) {
            {
                setOptional(0);
            }

            protected void getValues(Object object, Object[] values) {
                values[0] = ((Object[]) object)[0];
            }
        };

        byte[] expectedArray = new byte[] { 0x30, 0x00 };

        byte[] encoded = s.encode(new Object[] { null });
        assertTrue("Encoded boolean:", Arrays.equals(expectedArray, encoded));
    }
View Full Code Here

                while (it.hasNext()) {
                    oa[id] = ASN1Oid.getInstanceForString();
                    val[id++] = (String) it.next();
                }
                return ASN1OctetString.getInstance().encode(
                    new ASN1Sequence(oa).encode(val));
            }
            if ("2.5.29.19".equals(oid)) {
                return ASN1OctetString.getInstance().encode(
                            new ASN1Sequence(
                                    new ASN1Type[] {
                                            ASN1Boolean.getInstance(),
                                            ASN1Integer.getInstance()
                                    }).encode(
                                           new Object[] {
View Full Code Here

        }
    }

    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

TOP

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

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.