Package org.apache.harmony.security.asn1

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


            public int getIndex(Object obj) {
                return 0;
            }
        };

        ASN1Explicit explicit = new ASN1Explicit(0, choice);

        byte[] encoded = new byte[] { (byte) 0xA0, 0x03, 0x01, 0x01, 0x00 };

        assertEquals("False: ", Boolean.FALSE, explicit.decode(encoded));

        encoded[4] = (byte) 0xFF;

        assertEquals("True: ", Boolean.TRUE, explicit.decode(encoded));
    }
View Full Code Here


            public int getIndex(Object obj) {
                return 0;
            }
        };

        ASN1Explicit explicit = new ASN1Explicit(0, choice);

        byte[] encoded = new byte[] { (byte) 0xA0, 0x03, 0x01, 0x01, 0x00 };

        assertEquals("False: ", Boolean.FALSE, explicit.decode(encoded));

        encoded[4] = (byte) 0xFF;

        assertEquals("True: ", Boolean.TRUE, explicit.decode(encoded));
    }
View Full Code Here

                // [UNIVERSAL 5] Boolean
                new Object[] {
                        Boolean.FALSE,
                        new byte[] { 0x25, 0x03, 0x01, 0x01, 0x00 },
                        new ASN1Explicit(ASN1Constants.CLASS_UNIVERSAL, 5,
                                ASN1Boolean.getInstance()) },

                // [APPLICATION 5] Boolean
                new Object[] {
                        Boolean.FALSE,
                        new byte[] { 0x65, 0x03, 0x01, 0x01, 0x00 },
                        new ASN1Explicit(ASN1Constants.CLASS_APPLICATION, 5,
                                ASN1Boolean.getInstance()) },

                // [CONTEXT-SPECIFIC 5] Boolean
                new Object[] {
                        Boolean.FALSE,
                        new byte[] { (byte) 0xA5, 0x03, 0x01, 0x01, 0x00 },
                        new ASN1Explicit(ASN1Constants.CLASS_CONTEXTSPECIFIC,
                                5, ASN1Boolean.getInstance()) },

                // [5] Boolean (default = CONTEXT-SPECIFIC)
                new Object[] { Boolean.FALSE,
                        new byte[] { (byte) 0xA5, 0x03, 0x01, 0x01, 0x00 },
                        new ASN1Explicit(5, ASN1Boolean.getInstance()) },

                // [PRIVATE 5] Boolean
                new Object[] {
                        Boolean.FALSE,
                        new byte[] { (byte) 0xE5, 0x03, 0x01, 0x01, 0x00 },
                        new ASN1Explicit(ASN1Constants.CLASS_PRIVATE, 5,
                                ASN1Boolean.getInstance()) },

                //
                // Boolean = true
                //

                // [UNIVERSAL 5] Boolean
                new Object[] {
                        Boolean.TRUE,
                        new byte[] { 0x25, 0x03, 0x01, 0x01, (byte) 0xFF },
                        new ASN1Explicit(ASN1Constants.CLASS_UNIVERSAL, 5,
                                ASN1Boolean.getInstance()) },

                // [APPLICATION 5] Boolean
                new Object[] {
                        Boolean.TRUE,
                        new byte[] { 0x65, 0x03, 0x01, 0x01, (byte) 0xFF },
                        new ASN1Explicit(ASN1Constants.CLASS_APPLICATION, 5,
                                ASN1Boolean.getInstance()) },

                // [CONTEXT-SPECIFIC 5] Boolean
                new Object[] {
                        Boolean.TRUE,
                        new byte[] { (byte) 0xA5, 0x03, 0x01, 0x01, (byte) 0xFF },
                        new ASN1Explicit(ASN1Constants.CLASS_CONTEXTSPECIFIC,
                                5, ASN1Boolean.getInstance()) },

                // [5] Boolean (default = CONTEXT-SPECIFIC)
                new Object[] {
                        Boolean.TRUE,
                        new byte[] { (byte) 0xA5, 0x03, 0x01, 0x01, (byte) 0xFF },
                        new ASN1Explicit(ASN1Constants.CLASS_CONTEXTSPECIFIC,
                                5, ASN1Boolean.getInstance()) },

                // [PRIVATE 5] Boolean
                new Object[] {
                        Boolean.TRUE,
                        new byte[] { (byte) 0xE5, 0x03, 0x01, 0x01, (byte) 0xFF },
                        new ASN1Explicit(ASN1Constants.CLASS_PRIVATE, 5,
                                ASN1Boolean.getInstance()) },
                //
                // SequenceOf - testing constructed ASN.1 type
                //

                // [UNIVERSAL 5] SequenceOf
                new Object[] {
                        new ArrayList(),
                        new byte[] { 0x25, 0x02, 0x30, 0x00 },
                        new ASN1Explicit(ASN1Constants.CLASS_UNIVERSAL, 5,
                                sequence) },

                // [APPLICATION 5] SequenceOf
                new Object[] {
                        new ArrayList(),
                        new byte[] { 0x65, 0x02, 0x30, 0x00 },
                        new ASN1Explicit(ASN1Constants.CLASS_APPLICATION, 5,
                                sequence) },

                // [CONTEXT-SPECIFIC 5] SequenceOf
                new Object[] {
                        new ArrayList(),
                        new byte[] { (byte) 0xA5, 0x02, 0x30, 0x00 },
                        new ASN1Explicit(ASN1Constants.CLASS_CONTEXTSPECIFIC,
                                5, sequence) },

                // [5] SequenceOf (default = CONTEXT-SPECIFIC)
                new Object[] {
                        new ArrayList(),
                        new byte[] { (byte) 0xA5, 0x02, 0x30, 0x00 },
                        new ASN1Explicit(ASN1Constants.CLASS_CONTEXTSPECIFIC,
                                5, sequence) },

                // [PRIVATE 5] SequenceOf
                new Object[] {
                        new ArrayList(),
                        new byte[] { (byte) 0xE5, 0x02, 0x30, 0x00 },
                        new ASN1Explicit(ASN1Constants.CLASS_PRIVATE, 5,
                                sequence) } };
    }
View Full Code Here

     *
     * TYPE1 = [1] IMPLICIT OCTET STRING
     * TYPE2 = [2] IMPLICIT TYPE1
     */
    public void testConsecutiveStringTagging() throws Exception {
        ASN1Implicit type1 = new ASN1Implicit(1, ASN1OctetString.getInstance());

        ASN1Implicit type2 = new ASN1Implicit(2, type1);

        byte[] primitiveEncoding = new byte[] {
        // tag: class(CONTEXT SPECIFIC) + number (2)
                (byte) 0x82,
                // length
                0x03,
                // value
                0x00, 0x01, 0x02 };

        byte[] constructedEncoding = new byte[] {
        // tag: class(CONTEXT SPECIFIC) + constructed +number (2)
                (byte) 0xA2,
                // length
                0x00 };

        byte[] array = new byte[] { 0x00, 0x01, 0x02 };

        // decode primitive
        assertTrue(Arrays.equals(array, (byte[]) type2
                .decode(primitiveEncoding)));

        // encode primitive
        assertTrue(Arrays.equals(primitiveEncoding, type2.encode(array)));

        // decode constructed
        try {
            type2.decode(constructedEncoding);
            fail("No expected ASN1Exception");
        } catch (ASN1Exception e) {
            // FIXME any other check instead of comparing the message???
            assertEquals(
                    "ASN.1 octetstring: constructed identifier at [0]. Not valid for DER.",
View Full Code Here

     * Tests decoding/encoding integers to/from byte array
     */
    public void testDecode_Encode() throws IOException {

        // oid decoder/encoder for testing
        ASN1Integer asn1 = ASN1Integer.getInstance();

        // decode from byte array
        for (int i = 0; i < validTestcase.length; i++) {
            DerInputStream in = new DerInputStream((byte[]) validTestcase[i][2]);
            assertTrue((validTestcase[i][0]).toString(), // message
                    Arrays.equals((byte[]) validTestcase[i][1], // expected
                            (byte[]) asn1.decode(in))); // returned
        }
       
        // decode from input stream
        for (int i = 0; i < validTestcase.length; i++) {
            DerInputStream in = new DerInputStream(new ByteArrayInputStream(
                    (byte[]) validTestcase[i][2]));
            assertTrue((validTestcase[i][0]).toString(), //message
                    Arrays.equals((byte[]) validTestcase[i][1], //expected
                            (byte[]) asn1.decode(in))); //returned
        }

        // encoding
        for (int i = 0; i < validTestcase.length; i++) {
            DerOutputStream out = new DerOutputStream(asn1, validTestcase[i][1]);
View Full Code Here

                    new byte[] { 0x06, 0x03, (byte) 0x81, 0x34, 0x03 } } };

    public void test_MappingToIntArray() throws IOException {

        // oid decoder/encoder for testing
        ASN1Oid asn1 = ASN1Oid.getInstance();

        // testing decoding
        for (int i = 0; i < oid.length; i++) {

            int[] decoded = (int[]) asn1.decode(new DerInputStream(
                    (byte[]) oid[i][2]));

            assertTrue("Failed to decode oid: " + oid[i][0], // error message
                    Arrays.equals((int[]) oid[i][1], // expected array
                            decoded));
View Full Code Here

    }

    public void test_MappingToString() throws IOException {

        // oid decoder/encoder for testing
        ASN1Oid asn1 = ASN1Oid.getInstanceForString();
       
        // testing decoding
        for (int i = 0; i < oid.length; i++) {
            assertEquals("Failed to decode oid: " + oid[i][0], // error message
                    oid[i][0], // expected string
                    asn1.decode(new DerInputStream((byte[]) oid[i][2])));
        }

        // testing encoding
        for (int i = 0; i < oid.length; i++) {
            assertTrue("Failed to encode oid: " + oid[i][0], // error message
View Full Code Here

     * AttributeValue ::= ANY DEFINED BY AttributeType
     *
     */
    public static ASN1Sequence getASN1(InformationObjectSet set) {
        ASN1OpenType.Id id = new ASN1OpenType.Id();
        ASN1OpenType any = new ASN1OpenType(id, set);

        return new ASN1Sequence(new ASN1Type[] { id, new ASN1SetOf(any) });
    }
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

        //

        defaultList = new ArrayList();
        defaultList.add(Boolean.FALSE);

        sequence = new ASN1Sequence(new ASN1Type[] { ASN1Boolean.getInstance(),
                sequenceOf }) {
            {
                setDefault(Boolean.TRUE, 0);
                setDefault(defaultList, 1);
            }
View Full Code Here

TOP

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

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.