Package org.apache.harmony.security.asn1

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


     * @param encoding - ASN.1 DER encoding
     * @throws IOException - if encoding is wrong
     */
    public Name(byte[] encoding) throws IOException {

        DerInputStream in = new DerInputStream(encoding);

        if (in.getEndOffset() != encoding.length) {
            throw new IOException(Messages.getString("security.111")); //$NON-NLS-1$
        }

        ASN1.decode(in);

View Full Code Here


        this.hexString = hexString;
        this.encoded = encoded;

        try {
            DerInputStream in = new DerInputStream(encoded);

            tag = in.tag;

            if (DirectoryString.ASN1.checkTag(tag)) {
                // has string representation
View Full Code Here

     */
    public final void testGeneralizedEncoder() throws Exception {
        // full fractional seconds
        Date myDate = getGmtDate(1101980374187L);
        byte[] encoded =
            new DerOutputStream(gTime, myDate).encoded;
        String rep = new String(encoded, 2, encoded[1] & 0xff, "UTF-8");
        assertEquals("full", "20041202093934.187Z", rep);

        // 2 digit fractional seconds (last 0 must be trimmed out)
        myDate = getGmtDate(1101980374180L);
        encoded =
            new DerOutputStream(gTime, myDate).encoded;
        rep = new String(encoded, 2, encoded[1] & 0xff, "UTF-8");
        assertEquals("2 fraction", "20041202093934.18Z", rep);

        // 1 digit fractional seconds (last 2 0s must be trimmed out)
        myDate = getGmtDate(1101980374100L);
        encoded =
            new DerOutputStream(gTime, myDate).encoded;
        rep = new String(encoded, 2, encoded[1] & 0xff, "UTF-8");
        assertEquals("1 fraction", "20041202093934.1Z", rep);

        // no fractional seconds (last 3 0s and "." must be trimmed out)
        myDate = getGmtDate(1101980374000L);
        encoded =
            new DerOutputStream(gTime, myDate).encoded;
        rep = new String(encoded, 2, encoded[1] & 0xff, "UTF-8");
        assertEquals("no fraction", "20041202093934Z", rep);

        // midnight
        SimpleDateFormat sdf =
            new SimpleDateFormat("dd.MM.yyyy HH:mm");
        sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
        myDate = sdf.parse("06.06.2004 00:00");
        encoded =
            new DerOutputStream(gTime, myDate).encoded;
        rep = new String(encoded, 2, encoded[1] & 0xff, "UTF-8");
        assertEquals("midnight", "20040606000000Z", rep);
    }
View Full Code Here

    private final void runTest(boolean useInputStream)
        throws IOException, ParseException {
        // full fractional seconds
        Date myDate = new Date(1101980374187L);
        byte[] encoded =
            new DerOutputStream(gTime, myDate).encoded;
        DerInputStream dis = useInputStream
        ? new DerInputStream(new ByteArrayInputStream(encoded))
        : new DerInputStream(encoded);
        assertEquals("full", myDate, gTime.decode(dis));

        // 2 digit fractional seconds (last 0 must be trimmed out)
        myDate = new Date(1101980374180L);
        encoded =
            new DerOutputStream(gTime, myDate).encoded;
        dis = useInputStream
        ? new DerInputStream(new ByteArrayInputStream(encoded))
        : new DerInputStream(encoded);
        assertEquals("2 fraction", myDate, gTime.decode(dis));

        // 1 digit fractional seconds (last 2 0s must be trimmed out)
        myDate = new Date(1101980374100L);
        encoded =
            new DerOutputStream(gTime, myDate).encoded;
        dis = useInputStream
        ? new DerInputStream(new ByteArrayInputStream(encoded))
        : new DerInputStream(encoded);
        assertEquals("1 fraction", myDate, gTime.decode(dis));

        // no fractional seconds (last 3 0s and "." must be trimmed out)
        myDate = new Date(1101980374000L);
        encoded =
            new DerOutputStream(gTime, myDate).encoded;
        dis = useInputStream
        ? new DerInputStream(new ByteArrayInputStream(encoded))
        : new DerInputStream(encoded);
        assertEquals("no fraction", myDate, gTime.decode(dis));

        // midnight
        myDate = new SimpleDateFormat("MM.dd.yyyy HH:mm").
            parse("06.06.2004 00:00");
        encoded =
            new DerOutputStream(gTime, myDate).encoded;
        dis = useInputStream
        ? new DerInputStream(new ByteArrayInputStream(encoded))
        : new DerInputStream(encoded);
        assertEquals("midnight", myDate, gTime.decode(dis));

        // date 100 ms
        myDate = new Date(100L);
        encoded =
            new DerOutputStream(gTime, myDate).encoded;
        dis = useInputStream
        ? new DerInputStream(new ByteArrayInputStream(encoded))
        : new DerInputStream(encoded);
        assertEquals("100ms", myDate, gTime.decode(dis));
    }
View Full Code Here

     */
    public final void testUTCEncoder() throws Exception {
        // no fractional seconds (last 3 0s and "." must be trimmed out)
        Date myDate = getGmtDate(1101980374187L);
        byte[] encoded =
            new DerOutputStream(uTime, myDate).encoded;
        String rep = new String(encoded, 2, encoded[1] & 0xff, "UTF-8");
        assertEquals("no fraction", "041202093934Z", rep);

        // midnight
        SimpleDateFormat sdf =
            new SimpleDateFormat("dd.MM.yyyy HH:mm");
        sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
        myDate = sdf.parse("06.06.2004 00:00");
        encoded =
            new DerOutputStream(uTime, myDate).encoded;
        rep = new String(encoded, 2, encoded[1] & 0xff, "UTF-8");
        assertEquals("midnight", "040606000000Z", rep);
    }
View Full Code Here

    private final void runTest(boolean useInputStream)
        throws IOException, ParseException {
        Date myDate = new Date(1101980374187L);
        byte[] encoded =
            new DerOutputStream(uTime, myDate).encoded;
        DerInputStream dis = useInputStream
        ? new DerInputStream(new ByteArrayInputStream(encoded))
        : new DerInputStream(encoded);
        // the difference only fractional-seconds
        assertEquals(187, (myDate.getTime()-((Date)uTime.decode(dis)).getTime()));

        // midnight
        myDate = new SimpleDateFormat("MM.dd.yyyy HH:mm").
            parse("06.06.2004 00:00");
        encoded =
            new DerOutputStream(uTime, myDate).encoded;
        dis = useInputStream
        ? new DerInputStream(new ByteArrayInputStream(encoded))
        : new DerInputStream(encoded);
        assertEquals(myDate, uTime.decode(dis));
    }
View Full Code Here

     */
    public final void testGeneralizedEncoder() throws Exception {
        // full fractional seconds
        Date myDate = getGmtDate(1101980374187L);
        byte[] encoded =
            new DerOutputStream(gTime, myDate).encoded;
        String rep = new String(encoded, 2, encoded[1] & 0xff, "UTF-8");
        assertEquals("full", "20041202093934.187Z", rep);

        // 2 digit fractional seconds (last 0 must be trimmed out)
        myDate = getGmtDate(1101980374180L);
        encoded =
            new DerOutputStream(gTime, myDate).encoded;
        rep = new String(encoded, 2, encoded[1] & 0xff, "UTF-8");
        assertEquals("2 fraction", "20041202093934.18Z", rep);

        // 1 digit fractional seconds (last 2 0s must be trimmed out)
        myDate = getGmtDate(1101980374100L);
        encoded =
            new DerOutputStream(gTime, myDate).encoded;
        rep = new String(encoded, 2, encoded[1] & 0xff, "UTF-8");
        assertEquals("1 fraction", "20041202093934.1Z", rep);

        // no fractional seconds (last 3 0s and "." must be trimmed out)
        myDate = getGmtDate(1101980374000L);
        encoded =
            new DerOutputStream(gTime, myDate).encoded;
        rep = new String(encoded, 2, encoded[1] & 0xff, "UTF-8");
        assertEquals("no fraction", "20041202093934Z", rep);

        // midnight
        SimpleDateFormat sdf =
            new SimpleDateFormat("dd.MM.yyyy HH:mm");
        sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
        myDate = sdf.parse("06.06.2004 00:00");
        encoded =
            new DerOutputStream(gTime, myDate).encoded;
        rep = new String(encoded, 2, encoded[1] & 0xff, "UTF-8");
        assertEquals("midnight", "20040606000000Z", rep);
    }
View Full Code Here

    private final void runTest(boolean useInputStream)
        throws IOException, ParseException {
        // full fractional seconds
        Date myDate = new Date(1101980374187L);
        byte[] encoded =
            new DerOutputStream(gTime, myDate).encoded;
        DerInputStream dis = useInputStream
        ? new DerInputStream(new ByteArrayInputStream(encoded))
        : new DerInputStream(encoded);
        assertEquals("full", myDate, gTime.decode(dis));

        // 2 digit fractional seconds (last 0 must be trimmed out)
        myDate = new Date(1101980374180L);
        encoded =
            new DerOutputStream(gTime, myDate).encoded;
        dis = useInputStream
        ? new DerInputStream(new ByteArrayInputStream(encoded))
        : new DerInputStream(encoded);
        assertEquals("2 fraction", myDate, gTime.decode(dis));

        // 1 digit fractional seconds (last 2 0s must be trimmed out)
        myDate = new Date(1101980374100L);
        encoded =
            new DerOutputStream(gTime, myDate).encoded;
        dis = useInputStream
        ? new DerInputStream(new ByteArrayInputStream(encoded))
        : new DerInputStream(encoded);
        assertEquals("1 fraction", myDate, gTime.decode(dis));

        // no fractional seconds (last 3 0s and "." must be trimmed out)
        myDate = new Date(1101980374000L);
        encoded =
            new DerOutputStream(gTime, myDate).encoded;
        dis = useInputStream
        ? new DerInputStream(new ByteArrayInputStream(encoded))
        : new DerInputStream(encoded);
        assertEquals("no fraction", myDate, gTime.decode(dis));

        // midnight
        myDate = new SimpleDateFormat("MM.dd.yyyy HH:mm").
            parse("06.06.2004 00:00");
        encoded =
            new DerOutputStream(gTime, myDate).encoded;
        dis = useInputStream
        ? new DerInputStream(new ByteArrayInputStream(encoded))
        : new DerInputStream(encoded);
        assertEquals("midnight", myDate, gTime.decode(dis));

        // date 100 ms
        myDate = new Date(100L);
        encoded =
            new DerOutputStream(gTime, myDate).encoded;
        dis = useInputStream
        ? new DerInputStream(new ByteArrayInputStream(encoded))
        : new DerInputStream(encoded);
        assertEquals("100ms", myDate, gTime.decode(dis));
    }
View Full Code Here

    // FIXME need testcase for decoding invalid encodings

    public void testEncode() throws IOException {

        for (int i = 0; i < taggedType.length; i++) {
            DerOutputStream out = new DerOutputStream(
                    (ASN1Type) taggedType[i][2], taggedType[i][0]);
            assertTrue("Test case: " + i, Arrays.equals(
                    (byte[]) taggedType[i][1], out.encoded));
        }
    }
View Full Code Here

    //FIXME need testcase for decoding invalid encodings

    public void testEncode() throws IOException {

        for (int i = 0; i < testcases.length; i++) {
            DerOutputStream out = new DerOutputStream(sequence, testcases[i][0]);
            assertTrue("Test case: " + i, Arrays.equals(
                    (byte[]) testcases[i][1], out.encoded));
        }
    }
View Full Code Here

TOP

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

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.