Source Code Cross Referenced for OidTest.java in  » Apache-Harmony-Java-SE » org-package » org » apache » harmony » security » tests » asn1 » der » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Apache Harmony Java SE » org package » org.apache.harmony.security.tests.asn1.der 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         */
017:
018:        /**
019:         * @author Stepan M. Mishura
020:         * @version $Revision$
021:         */package org.apache.harmony.security.tests.asn1.der;
022:
023:        import java.io.IOException;
024:        import java.util.Arrays;
025:
026:        import org.apache.harmony.security.asn1.ASN1Exception;
027:        import org.apache.harmony.security.asn1.ASN1Oid;
028:        import org.apache.harmony.security.asn1.DerInputStream;
029:        import org.apache.harmony.security.asn1.DerOutputStream;
030:
031:        import junit.framework.TestCase;
032:
033:        /**
034:         * ASN.1 DER test for OID type
035:         * 
036:         * @see http://asn1.elibel.tm.fr/en/standards/index.htm
037:         */
038:
039:        public class OidTest extends TestCase {
040:
041:            public static void main(String[] args) {
042:                junit.textui.TestRunner.run(OidTest.class);
043:            }
044:
045:            private static Object[][] oid = {
046:            //oid array format: string / int array / DER encoding
047:                    { "0.0", // as string
048:                            new int[] { 0, 0 }, // as int array
049:                            new byte[] { 0x06, 0x01, 0x00 } },
050:                    //
051:                    { "0.0.3", // as string
052:                            new int[] { 0, 0, 3 }, // as int array
053:                            new byte[] { 0x06, 0x02, 0x00, 0x03 } },
054:                    //
055:                    { "0.1.3", // as string
056:                            new int[] { 0, 1, 3 }, // as int array
057:                            new byte[] { 0x06, 0x02, 0x01, 0x03 } },
058:                    //
059:                    { "0.5", // as string
060:                            new int[] { 0, 5 }, // as int array
061:                            new byte[] { 0x06, 0x01, 0x05 } },
062:                    //
063:                    { "0.39.3", // as string
064:                            new int[] { 0, 39, 3 }, // as int array
065:                            new byte[] { 0x06, 0x02, 0x27, 0x03 } },
066:                    //
067:                    { "1.0.3", // as string
068:                            new int[] { 1, 0, 3 }, // as int array
069:                            new byte[] { 0x06, 0x02, 0x28, 0x03 } },
070:                    //
071:                    { "1.1", // as string
072:                            new int[] { 1, 1 }, // as int array
073:                            new byte[] { 0x06, 0x01, 0x29 } },
074:                    //
075:                    { "1.2.1.2.1",// as string
076:                            new int[] { 1, 2, 1, 2, 1 }, // as int array
077:                            new byte[] { 0x06, 0x04, 0x2A, 0x01, 0x02, 0x01 } },
078:                    //
079:                    {
080:                            "1.2.840.113554.1.2.2",// as string
081:                            new int[] { 1, 2, 840, 113554, 1, 2, 2 }, // as int array
082:                            new byte[] { 0x06, 0x09, 0x2A, (byte) 0x86, 0x48,
083:                                    (byte) 0x86, (byte) 0xF7, 0x12, 0x01, 0x02,
084:                                    0x02 } },
085:                    //
086:                    { "1.39.3",// as string
087:                            new int[] { 1, 39, 3 }, // as int array
088:                            new byte[] { 0x06, 0x02, 0x4F, 0x03 } },
089:                    //
090:                    { "2.0.3",// as string
091:                            new int[] { 2, 0, 3 }, // as int array
092:                            new byte[] { 0x06, 0x02, 0x50, 0x03 } },
093:                    //
094:                    { "2.5.4.3",// as string
095:                            new int[] { 2, 5, 4, 3 }, // as int array
096:                            new byte[] { 0x06, 0x03, 0x55, 0x04, 0x03 } },
097:                    // 
098:                    { "2.39.3", // as string
099:                            new int[] { 2, 39, 3 }, // as int array
100:                            new byte[] { 0x06, 0x02, 0x77, 0x03 } },
101:                    //
102:                    { "2.40.3", // as string
103:                            new int[] { 2, 40, 3 }, // as int array
104:                            new byte[] { 0x06, 0x02, 0x78, 0x03 } },
105:                    //
106:                    { "2.47", // as string
107:                            new int[] { 2, 47 }, // as int array
108:                            new byte[] { 0x06, 0x01, 0x7F } },
109:                    //
110:                    { "2.48", // as string
111:                            new int[] { 2, 48 }, // as int array
112:                            new byte[] { 0x06, 0x02, (byte) 0x81, 0x00 } },
113:                    //
114:                    { "2.48.5", // as string
115:                            new int[] { 2, 48, 5 }, // as int array
116:                            new byte[] { 0x06, 0x03, (byte) 0x81, 0x00, 0x05 } },
117:                    //
118:                    { "2.100.3", // as string
119:                            new int[] { 2, 100, 3 }, // as int array
120:                            new byte[] { 0x06, 0x03, (byte) 0x81, 0x34, 0x03 } } };
121:
122:            public void test_MappingToIntArray() throws IOException {
123:
124:                // oid decoder/encoder for testing
125:                ASN1Oid asn1 = ASN1Oid.getInstance();
126:
127:                // testing decoding
128:                for (int i = 0; i < oid.length; i++) {
129:
130:                    int[] decoded = (int[]) asn1.decode(new DerInputStream(
131:                            (byte[]) oid[i][2]));
132:
133:                    assertTrue("Failed to decode oid: " + oid[i][0], // error message
134:                            Arrays.equals((int[]) oid[i][1], // expected array
135:                                    decoded));
136:                }
137:
138:                // testing encoding
139:                for (int i = 0; i < oid.length; i++) {
140:
141:                    byte[] encoded = new DerOutputStream(ASN1Oid.getInstance(),
142:                            oid[i][1]).encoded;
143:
144:                    assertTrue("Failed to encode oid: " + oid[i][0], // error message
145:                            Arrays.equals((byte[]) oid[i][2], // expected encoding
146:                                    encoded));
147:                }
148:            }
149:
150:            public void testDecode_Invalid() throws IOException {
151:                byte[][] invalid = new byte[][] {
152:                // wrong tag: tag is not 0x06
153:                        new byte[] { 0x02, 0x01, 0x00 },
154:                        // wrong length: length is 0
155:                        new byte[] { 0x06, 0x00 },
156:                        // wrong content: bit 8 of the last byte is not 0 
157:                        new byte[] { 0x06, 0x02, (byte) 0x81, (byte) 0x80 },
158:                // wrong content: is not encoded in fewest number of bytes 
159:                //FIXME new byte[] { 0x06, 0x02, (byte) 0x80, (byte) 0x01 }
160:                };
161:
162:                for (int i = 0; i < invalid.length; i++) {
163:                    try {
164:                        DerInputStream in = new DerInputStream(invalid[i]);
165:                        ASN1Oid.getInstance().decode(in);
166:                        fail("No expected ASN1Exception for:" + i);
167:                    } catch (ASN1Exception e) {
168:                    }
169:                }
170:            }
171:
172:            public void test_MappingToString() throws IOException {
173:
174:                // oid decoder/encoder for testing
175:                ASN1Oid asn1 = ASN1Oid.getInstanceForString();
176:
177:                // testing decoding
178:                for (int i = 0; i < oid.length; i++) {
179:                    assertEquals("Failed to decode oid: " + oid[i][0], // error message
180:                            oid[i][0], // expected string
181:                            asn1.decode(new DerInputStream((byte[]) oid[i][2])));
182:                }
183:
184:                // testing encoding
185:                for (int i = 0; i < oid.length; i++) {
186:                    assertTrue(
187:                            "Failed to encode oid: " + oid[i][0], // error message
188:                            Arrays
189:                                    .equals(
190:                                            (byte[]) oid[i][2], // expected encoding
191:                                            new DerOutputStream(asn1, oid[i][0]).encoded));
192:                }
193:            }
194:        }
www___.__ja___v__a_2_s_.__c_o_m___ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.