Examples of ASN1Choice


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

    /**
     * TODO Put method description here
     */
    public void testChoiceOfChoice() throws Exception {

        ASN1Choice choice1 = new ASN1Choice(new ASN1Type[] {
                ASN1Oid.getInstance(), // first
                ASN1Boolean.getInstance(),// second: decoded component
                ASN1Integer.getInstance() // third
                }) {

            public Object getDecodedObject(BerInputStream in)
                    throws IOException {

                assertEquals("choice1", 1, in.choiceIndex);

                return in.content;
            }

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

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

        ASN1Choice choice2 = new ASN1Choice(new ASN1Type[] { choice1, // first: decoded component
                ASN1BitString.getInstance() // second
                }) {

            public Object getDecodedObject(BerInputStream in)
                    throws IOException {

                assertEquals("choice2", 0, in.choiceIndex);

                return in.content;
            }

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

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

        Boolean b = (Boolean) choice2.decode(new byte[] { 0x01, 0x01, 0x00 });

        assertTrue(b == Boolean.FALSE);
    }
View Full Code Here

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

    /**
     * TODO Put method description here
     */
    public void testDistinctTags() throws Exception {

        ASN1Choice choice1 = new ASN1Choice(new ASN1Type[] {
                ASN1Boolean.getInstance(),// component to be checked
                ASN1Oid.getInstance(), ASN1Integer.getInstance() }) {

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

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

        // two ASN.1 booleans
        try {
            new ASN1Choice(new ASN1Type[] { choice1, //
                    ASN1Boolean.getInstance() // component to be checked
                    }) {

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

                public int getIndex(Object obj) {
                    return 0;
                }
            };
            fail("No expected IllegalArgumentException");
        } catch (IllegalArgumentException e) {
        }

        // ASN.1 ANY
        try {
            new ASN1Choice(new ASN1Type[] { choice1,//
                    ASN1Any.getInstance() // component to be checked
                    }) {

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

                public int getIndex(Object obj) {
                    return 0;
                }
            };
            fail("No expected IllegalArgumentException");
        } catch (IllegalArgumentException e) {
        }

        // two choices
        ASN1Choice choice2 = new ASN1Choice(new ASN1Type[] {
                ASN1BitString.getInstance(), //
                ASN1Boolean.getInstance() //component to be checked
                }) {

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

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

        try {
            new ASN1Choice(new ASN1Type[] { choice1, choice2 }) {

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

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.