Source Code Cross Referenced for OIDTest.java in  » Security » Bouncy-Castle » org » bouncycastle » asn1 » test » 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 » Security » Bouncy Castle » org.bouncycastle.asn1.test 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.bouncycastle.asn1.test;
002:
003:        import java.io.ByteArrayInputStream;
004:        import java.io.ByteArrayOutputStream;
005:        import java.io.IOException;
006:
007:        import org.bouncycastle.asn1.ASN1InputStream;
008:        import org.bouncycastle.asn1.ASN1OutputStream;
009:        import org.bouncycastle.asn1.DERObjectIdentifier;
010:        import org.bouncycastle.asn1.DEROutputStream;
011:        import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers;
012:        import org.bouncycastle.util.encoders.Hex;
013:        import org.bouncycastle.util.test.SimpleTest;
014:
015:        /**
016:         * X.690 test example
017:         */
018:        public class OIDTest extends SimpleTest {
019:            byte[] req1 = Hex.decode("0603813403");
020:            byte[] req2 = Hex.decode("06082A36FFFFFFDD6311");
021:
022:            public String getName() {
023:                return "OID";
024:            }
025:
026:            private void recodeCheck(String oid, byte[] enc) throws IOException {
027:                ByteArrayInputStream bIn = new ByteArrayInputStream(enc);
028:                ASN1InputStream aIn = new ASN1InputStream(bIn);
029:
030:                DERObjectIdentifier o = new DERObjectIdentifier(oid);
031:                DERObjectIdentifier encO = (DERObjectIdentifier) aIn
032:                        .readObject();
033:
034:                if (!o.equals(encO)) {
035:                    fail("oid ID didn't match", o, encO);
036:                }
037:
038:                ByteArrayOutputStream bOut = new ByteArrayOutputStream();
039:                DEROutputStream dOut = new DEROutputStream(bOut);
040:
041:                dOut.writeObject(o);
042:
043:                byte[] bytes = bOut.toByteArray();
044:
045:                if (bytes.length != enc.length) {
046:                    fail("failed length test");
047:                }
048:
049:                for (int i = 0; i != enc.length; i++) {
050:                    if (bytes[i] != enc[i]) {
051:                        fail("failed comparison test", new String(Hex
052:                                .encode(enc)), new String(Hex.encode(bytes)));
053:                    }
054:                }
055:            }
056:
057:            private void validOidCheck(String oid) throws IOException {
058:                DERObjectIdentifier o = new DERObjectIdentifier(oid);
059:                ByteArrayOutputStream bOut = new ByteArrayOutputStream();
060:                ASN1OutputStream aOut = new ASN1OutputStream(bOut);
061:
062:                aOut.writeObject(o);
063:
064:                ByteArrayInputStream bIn = new ByteArrayInputStream(bOut
065:                        .toByteArray());
066:                ASN1InputStream aIn = new ASN1InputStream(bIn);
067:
068:                o = (DERObjectIdentifier) aIn.readObject();
069:
070:                if (!o.getId().equals(oid)) {
071:                    fail("failed oid check for " + oid);
072:                }
073:            }
074:
075:            private void invalidOidCheck(String oid) {
076:                try {
077:                    new DERObjectIdentifier(oid);
078:                    fail("failed to catch bad oid: " + oid);
079:                } catch (IllegalArgumentException e) {
080:                    // expected
081:                }
082:            }
083:
084:            public void performTest() throws IOException {
085:                recodeCheck("2.100.3", req1);
086:                recodeCheck("1.2.54.34359733987.17", req2);
087:
088:                validOidCheck(PKCSObjectIdentifiers.pkcs_9_at_contentType
089:                        .getId());
090:                validOidCheck("0.1");
091:                validOidCheck("1.1.127.32512.8323072.2130706432.545460846592.139637976727552.35747322042253312.9151314442816847872");
092:                validOidCheck("1.2.123.12345678901.1.1.1");
093:                validOidCheck("2.25.196556539987194312349856245628873852187.1");
094:
095:                invalidOidCheck("0");
096:                invalidOidCheck("1");
097:                invalidOidCheck("2");
098:                invalidOidCheck("3.1");
099:                invalidOidCheck("..1");
100:                invalidOidCheck("192.168.1.1");
101:                invalidOidCheck(".123452");
102:                invalidOidCheck("1.");
103:                invalidOidCheck("1.345.23.34..234");
104:                invalidOidCheck("1.345.23.34.234.");
105:                invalidOidCheck(".12.345.77.234");
106:                invalidOidCheck(".12.345.77.234.");
107:                invalidOidCheck("1.2.3.4.A.5");
108:                invalidOidCheck("1,2");
109:            }
110:
111:            public static void main(String[] args) {
112:                runTest(new OIDTest());
113:            }
114:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.