Source Code Cross Referenced for CertificateVersion.java in  » 6.0-JDK-Modules » j2me » sun » security » x509 » 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 » 6.0 JDK Modules » j2me » sun.security.x509 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * @(#)CertificateVersion.java	1.19 06/10/10
003:         *
004:         * Copyright  1990-2006 Sun Microsystems, Inc. All Rights Reserved.  
005:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER  
006:         *   
007:         * This program is free software; you can redistribute it and/or  
008:         * modify it under the terms of the GNU General Public License version  
009:         * 2 only, as published by the Free Software Foundation.   
010:         *   
011:         * This program is distributed in the hope that it will be useful, but  
012:         * WITHOUT ANY WARRANTY; without even the implied warranty of  
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU  
014:         * General Public License version 2 for more details (a copy is  
015:         * included at /legal/license.txt).   
016:         *   
017:         * You should have received a copy of the GNU General Public License  
018:         * version 2 along with this work; if not, write to the Free Software  
019:         * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  
020:         * 02110-1301 USA   
021:         *   
022:         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa  
023:         * Clara, CA 95054 or visit www.sun.com if you need additional  
024:         * information or have any questions. 
025:         *
026:         */
027:
028:        package sun.security.x509;
029:
030:        import java.io.IOException;
031:        import java.io.InputStream;
032:        import java.io.OutputStream;
033:        import java.util.Date;
034:        import java.util.Enumeration;
035:
036:        import sun.security.util.*;
037:
038:        /**
039:         * This class defines the version of the X509 Certificate.
040:         *
041:         * @author Amit Kapoor
042:         * @author Hemma Prafullchandra
043:         * @version 1.12
044:         * @see CertAttrSet
045:         */
046:        public class CertificateVersion implements  CertAttrSet {
047:            /**
048:             * X509Certificate Version 1
049:             */
050:            public static final int V1 = 0;
051:            /**
052:             * X509Certificate Version 2
053:             */
054:            public static final int V2 = 1;
055:            /**
056:             * X509Certificate Version 3
057:             */
058:            public static final int V3 = 2;
059:            /**
060:             * Identifier for this attribute, to be used with the
061:             * get, set, delete methods of Certificate, x509 type.
062:             */
063:            public static final String IDENT = "x509.info.version";
064:            /**
065:             * Sub attributes name for this CertAttrSet.
066:             */
067:            public static final String NAME = "version";
068:            public static final String VERSION = "number";
069:
070:            // Private data members
071:            int version = V1;
072:
073:            // Returns the version number.
074:            private int getVersion() {
075:                return (version);
076:            }
077:
078:            // Construct the class from the passed DerValue
079:            private void construct(DerValue derVal) throws IOException {
080:                if (derVal.isConstructed() && derVal.isContextSpecific()) {
081:                    derVal = derVal.data.getDerValue();
082:                    version = derVal.getInteger();
083:                    if (derVal.data.available() != 0) {
084:                        throw new IOException("X.509 version, bad format");
085:                    }
086:                }
087:            }
088:
089:            /**
090:             * The default constructor for this class,
091:             *  sets the version to 0 (i.e. X.509 version 1).
092:             */
093:            public CertificateVersion() {
094:                version = V1;
095:            }
096:
097:            /**
098:             * The constructor for this class for the required version.
099:             *
100:             * @param version the version for the certificate.
101:             * @exception IOException if the version is not valid.
102:             */
103:            public CertificateVersion(int version) throws IOException {
104:
105:                // check that it is a valid version
106:                if (version == V1 || version == V2 || version == V3)
107:                    this .version = version;
108:                else {
109:                    throw new IOException("X.509 Certificate version "
110:                            + version + " not supported.\n");
111:                }
112:            }
113:
114:            /**
115:             * Create the object, decoding the values from the passed DER stream.
116:             *
117:             * @param in the DerInputStream to read the CertificateVersion from.
118:             * @exception IOException on decoding errors.
119:             */
120:            public CertificateVersion(DerInputStream in) throws IOException {
121:                version = V1;
122:                DerValue derVal = in.getDerValue();
123:
124:                construct(derVal);
125:            }
126:
127:            /**
128:             * Create the object, decoding the values from the passed stream.
129:             *
130:             * @param in the InputStream to read the CertificateVersion from.
131:             * @exception IOException on decoding errors.
132:             */
133:            public CertificateVersion(InputStream in) throws IOException {
134:                version = V1;
135:                DerValue derVal = new DerValue(in);
136:
137:                construct(derVal);
138:            }
139:
140:            /**
141:             * Create the object, decoding the values from the passed DerValue.
142:             *
143:             * @param val the Der encoded value.
144:             * @exception IOException on decoding errors.
145:             */
146:            public CertificateVersion(DerValue val) throws IOException {
147:                version = V1;
148:
149:                construct(val);
150:            }
151:
152:            /**
153:             * Return the version number of the certificate.
154:             */
155:            public String toString() {
156:                return ("Version: V" + (version + 1));
157:            }
158:
159:            /**
160:             * Encode the CertificateVersion period in DER form to the stream.
161:             *
162:             * @param out the OutputStream to marshal the contents to.
163:             * @exception IOException on errors.
164:             */
165:            public void encode(OutputStream out) throws IOException {
166:                // Nothing for default
167:                if (version == V1) {
168:                    return;
169:                }
170:                DerOutputStream tmp = new DerOutputStream();
171:                tmp.putInteger(version);
172:
173:                DerOutputStream seq = new DerOutputStream();
174:                seq.write(DerValue.createTag(DerValue.TAG_CONTEXT, true,
175:                        (byte) 0), tmp);
176:
177:                out.write(seq.toByteArray());
178:            }
179:
180:            /**
181:             * Decode the CertificateVersion period in DER form from the stream.
182:             *
183:             * @param in the InputStream to unmarshal the contents from.
184:             * @exception IOException on errors.
185:             */
186:            public void decode(InputStream in) throws IOException {
187:                DerValue derVal = new DerValue(in);
188:                construct(derVal);
189:            }
190:
191:            /**
192:             * Set the attribute value.
193:             */
194:            public void set(String name, Object obj) throws IOException {
195:                if (!(obj instanceof  Integer)) {
196:                    throw new IOException("Attribute must be of type Integer.");
197:                }
198:                if (name.equalsIgnoreCase(VERSION)) {
199:                    version = ((Integer) obj).intValue();
200:                } else {
201:                    throw new IOException("Attribute name not recognized by "
202:                            + "CertAttrSet: CertificateVersion.");
203:                }
204:            }
205:
206:            /**
207:             * Get the attribute value.
208:             */
209:            public Object get(String name) throws IOException {
210:                if (name.equalsIgnoreCase(VERSION)) {
211:                    return (new Integer(getVersion()));
212:                } else {
213:                    throw new IOException("Attribute name not recognized by "
214:                            + "CertAttrSet: CertificateVersion.");
215:                }
216:            }
217:
218:            /**
219:             * Delete the attribute value.
220:             */
221:            public void delete(String name) throws IOException {
222:                if (name.equalsIgnoreCase(VERSION)) {
223:                    version = V1;
224:                } else {
225:                    throw new IOException("Attribute name not recognized by "
226:                            + "CertAttrSet: CertificateVersion.");
227:                }
228:            }
229:
230:            /**
231:             * Return an enumeration of names of attributes existing within this
232:             * attribute.
233:             */
234:            public Enumeration getElements() {
235:                AttributeNameEnumeration elements = new AttributeNameEnumeration();
236:                elements.addElement(VERSION);
237:
238:                return (elements.elements());
239:            }
240:
241:            /**
242:             * Return the name of this attribute.
243:             */
244:            public String getName() {
245:                return (NAME);
246:            }
247:
248:            /**
249:             * Compare versions.
250:             */
251:            public int compare(int vers) {
252:                return (version - vers);
253:            }
254:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.