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


001:        package org.bouncycastle.asn1;
002:
003:        import java.io.IOException;
004:        import java.util.Enumeration;
005:        import java.util.Vector;
006:
007:        public abstract class ASN1Sequence extends ASN1Object {
008:            private Vector seq = new Vector();
009:
010:            /**
011:             * return an ASN1Sequence from the given object.
012:             *
013:             * @param obj the object we want converted.
014:             * @exception IllegalArgumentException if the object cannot be converted.
015:             */
016:            public static ASN1Sequence getInstance(Object obj) {
017:                if (obj == null || obj instanceof  ASN1Sequence) {
018:                    return (ASN1Sequence) obj;
019:                }
020:
021:                throw new IllegalArgumentException(
022:                        "unknown object in getInstance");
023:            }
024:
025:            /**
026:             * Return an ASN1 sequence from a tagged object. There is a special
027:             * case here, if an object appears to have been explicitly tagged on 
028:             * reading but we were expecting it to be implictly tagged in the 
029:             * normal course of events it indicates that we lost the surrounding
030:             * sequence - so we need to add it back (this will happen if the tagged
031:             * object is a sequence that contains other sequences). If you are
032:             * dealing with implicitly tagged sequences you really <b>should</b>
033:             * be using this method.
034:             *
035:             * @param obj the tagged object.
036:             * @param explicit true if the object is meant to be explicitly tagged,
037:             *          false otherwise.
038:             * @exception IllegalArgumentException if the tagged object cannot
039:             *          be converted.
040:             */
041:            public static ASN1Sequence getInstance(ASN1TaggedObject obj,
042:                    boolean explicit) {
043:                if (explicit) {
044:                    if (!obj.isExplicit()) {
045:                        throw new IllegalArgumentException(
046:                                "object implicit - explicit expected.");
047:                    }
048:
049:                    return (ASN1Sequence) obj.getObject();
050:                } else {
051:                    //
052:                    // constructed object which appears to be explicitly tagged
053:                    // when it should be implicit means we have to add the
054:                    // surrounding sequence.
055:                    //
056:                    if (obj.isExplicit()) {
057:                        if (obj instanceof  BERTaggedObject) {
058:                            return new BERSequence(obj.getObject());
059:                        } else {
060:                            return new DERSequence(obj.getObject());
061:                        }
062:                    } else {
063:                        if (obj.getObject() instanceof  ASN1Sequence) {
064:                            return (ASN1Sequence) obj.getObject();
065:                        }
066:                    }
067:                }
068:
069:                throw new IllegalArgumentException(
070:                        "unknown object in getInstanceFromTagged");
071:            }
072:
073:            public Enumeration getObjects() {
074:                return seq.elements();
075:            }
076:
077:            public ASN1SequenceParser parser() {
078:                final ASN1Sequence outer = this ;
079:
080:                return new ASN1SequenceParser() {
081:                    private final int max = size();
082:
083:                    private int index;
084:
085:                    public DEREncodable readObject() throws IOException {
086:                        if (index == max) {
087:                            return null;
088:                        }
089:
090:                        DEREncodable obj = getObjectAt(index++);
091:                        if (obj instanceof  ASN1Sequence) {
092:                            return ((ASN1Sequence) obj).parser();
093:                        }
094:                        if (obj instanceof  ASN1Set) {
095:                            return ((ASN1Set) obj).parser();
096:                        }
097:
098:                        return obj;
099:                    }
100:
101:                    public DERObject getDERObject() {
102:                        return outer;
103:                    }
104:                };
105:            }
106:
107:            /**
108:             * return the object at the sequence postion indicated by index.
109:             *
110:             * @param index the sequence number (starting at zero) of the object
111:             * @return the object at the sequence postion indicated by index.
112:             */
113:            public DEREncodable getObjectAt(int index) {
114:                return (DEREncodable) seq.elementAt(index);
115:            }
116:
117:            /**
118:             * return the number of objects in this sequence.
119:             *
120:             * @return the number of objects in this sequence.
121:             */
122:            public int size() {
123:                return seq.size();
124:            }
125:
126:            public int hashCode() {
127:                Enumeration e = this .getObjects();
128:                int hashCode = 0;
129:
130:                while (e.hasMoreElements()) {
131:                    Object o = e.nextElement();
132:
133:                    if (o != null) {
134:                        hashCode ^= o.hashCode();
135:                    }
136:                }
137:
138:                return hashCode;
139:            }
140:
141:            boolean asn1Equals(DERObject o) {
142:                if (!(o instanceof  ASN1Sequence)) {
143:                    return false;
144:                }
145:
146:                ASN1Sequence other = (ASN1Sequence) o;
147:
148:                if (this .size() != other.size()) {
149:                    return false;
150:                }
151:
152:                Enumeration s1 = this .getObjects();
153:                Enumeration s2 = other.getObjects();
154:
155:                while (s1.hasMoreElements()) {
156:                    DERObject o1 = ((DEREncodable) s1.nextElement())
157:                            .getDERObject();
158:                    DERObject o2 = ((DEREncodable) s2.nextElement())
159:                            .getDERObject();
160:
161:                    if (o1 == o2 || (o1 != null && o1.equals(o2))) {
162:                        continue;
163:                    }
164:
165:                    return false;
166:                }
167:
168:                return true;
169:            }
170:
171:            protected void addObject(DEREncodable obj) {
172:                seq.addElement(obj);
173:            }
174:
175:            abstract void encode(DEROutputStream out) throws IOException;
176:
177:            public String toString() {
178:                return seq.toString();
179:            }
180:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.