Source Code Cross Referenced for DIRF.java in  » 6.0-JDK-Modules » j2me » com » sun » satsa » util » pkcs15 » 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 » com.sun.satsa.util.pkcs15 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *   
003:         *
004:         * Copyright  1990-2007 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:        package com.sun.satsa.util.pkcs15;
027:
028:        import com.sun.satsa.util.*;
029:        import java.util.Vector;
030:        import java.io.IOException;
031:        import javax.microedition.io.ConnectionNotFoundException;
032:
033:        /**
034:         * This class represents the PKCS15 DIR file abstraction.
035:         *<pre>
036:         * It is assumed that the DIR file contains information about
037:         * files in the following format:
038:         *   APP_CONSTRUCTED_1 {          [APPLICATION 1]
039:         *       APP_PRIMITIVE_15           Aid (Octet_string)
040:         *       APP_PRIMITIVE_16           label (UTF8String / opt)
041:         *       APP_PRIMITIVE_17           path (octet_string)
042:         *       APP_PRIMITIVE_19 {          DDO (ddo / opt)
043:         *         SEQUENCE {
044:         *           oid OBJECT IDENTIFIER,
045:         *           odfPath Path OPTIONAL,
046:         *           tokenInfoPath [0] Path OPTIONAL,
047:         *           unusedPath [1] Path OPTIONAL,
048:         *         }
049:         *       }
050:         *   }
051:         * </pre>
052:         */
053:
054:        public class DIRF extends PKCS15File {
055:            /** Wrong DIR file status code */
056:            public static final int WRONG_DIR_FILE = -1;
057:            /** Success status code */
058:            public static final int SUCCESS = 0;
059:            /** AID is not found status code */
060:            public static final int AID_NOT_FOUND = 1;
061:            /** Root is not selected status code */
062:            public static final int ROOT_NOT_SELECTED = 2;
063:
064:            /** The PKCS15 application AID (according to pkcs15 spec. */
065:            byte[] PKCS_AID = { (byte) 0xa0, 0x0, 0x0, 0x0, 0x63, 0x50, 0x4b,
066:                    0x43, 0x53, 0x2d, 0x31, 0x35 };
067:            /** The PKCS15 DIR file name */
068:            short[] DIR_FILE = { 0x2F00 };
069:            /** ASN application specific flag used in types (0x40). */
070:            public static final int APPLICATION = 0x40;
071:            /** ASN application specific constructed flag used in types (0x60). */
072:            public static final int APP_CONSTRUCTED_0 = APPLICATION
073:                    + TLV.CONSTRUCTED;
074:            /** ASN application specific primitive flag */
075:            public static final int APP_PRIMITIVE_0 = APPLICATION;
076:            /** ASN application specific constructed flag used in types (0x60). */
077:            public static final int APP_CONSTRUCTED_1 = APP_CONSTRUCTED_0 + 1;
078:            /** ASN application specific flag for [APPLICATION 15] (aid) */
079:            public static final int APP_PRIMITIVE_15 = APP_PRIMITIVE_0 + 0xf;
080:            /** ASN application specific flag for [APPLICATION 16] (label) */
081:            public static final int APP_PRIMITIVE_16 = APP_PRIMITIVE_0 + 0x10;
082:            /** ASN application specific flag for [APPLICATION 17] (path) */
083:            public static final int APP_PRIMITIVE_17 = APP_PRIMITIVE_0 + 0x11;
084:            /** ASN application specific flag for [APPLICATION 19] (ddo) */
085:            public static final int APP_CONSTRUCTED_19 = APP_CONSTRUCTED_0 + 0x13;
086:
087:            /** This vector contains parsed objects from DIR */
088:            private Vector DIR;
089:
090:            /**
091:             * Creates the DIRF object
092:             * @param fs FileSystemAbstract file system that is used
093:             * to reading from file.
094:             */
095:            public DIRF(FileSystemAbstract fs) {
096:                super (fs);
097:            }
098:
099:            /**
100:             * Reads DIR .
101:             * @throws IOException if I/O error occurs
102:             * @throws TLVException if TLV error occurs
103:             */
104:            public void load() throws IOException, TLVException {
105:                DIR = new Vector();
106:                resetLoader(DIR, null, null);
107:                parseDF(DIR_FILE);
108:            }
109:
110:            /**
111:             * Seeks record in the DIR file according to the pointed AID
112:             * @param aid byte[] required AID
113:             * @return TLV containing the required record
114:             * @throws TLVException  if TLV error occurs
115:             */
116:            private TLV getApp(byte[] aid) throws TLVException {
117:                TLV root = (TLV) DIR.firstElement();
118:                if (root.type != APP_CONSTRUCTED_1) {
119:                    throw new TLVException(
120:                            "The first tag shall be APPLICATION 1");
121:                }
122:                while (root != null) {
123:                    TLV t = root.child; /* APP_PRIMITIVE_15 */
124:                    if (t.type != APP_PRIMITIVE_15) {
125:                        throw new TLVException(
126:                                "The first tag shall be APPLICATION 15 (AID)");
127:                    }
128:                    if (Utils.byteMatch(aid, t.getValue())) {
129:                        return root;
130:                    }
131:                    root = root.next;
132:                }
133:                return null;
134:            }
135:
136:            /**
137:             * Sets a root for the PKCS15 application
138:             * @return int Status code.
139:             */
140:            public int setPKCSRoot() {
141:                return setRoot(PKCS_AID);
142:            }
143:
144:            /**
145:             * Sets a root for the application with the pointed AID
146:             * @param aid byte[] required AID
147:             * @return int Status code.
148:             */
149:            public int setRoot(byte[] aid) {
150:                TLV root;
151:                try {
152:                    root = getApp(aid);
153:                } catch (TLVException e) {
154:                    return WRONG_DIR_FILE;
155:                }
156:                if (root == null) {
157:                    return AID_NOT_FOUND;
158:                }
159:                TLV t = root.child; /* AID */
160:                /* Find the path item */
161:                while ((t != null) && (t.type != APP_PRIMITIVE_17)) {
162:                    t = t.next;
163:                }
164:                if (t == null) {
165:                    return WRONG_DIR_FILE;
166:                }
167:                byte[] pth = t.getValue();
168:                short[] path = new short[pth.length / 2];
169:                for (int i = 0; i < pth.length; i = i + 2) {
170:                    path[i / 2] = Utils.getShort(pth, i);
171:                }
172:                try {
173:                    files.selectRoot(path);
174:                } catch (IOException ie) {
175:                    return ROOT_NOT_SELECTED;
176:                }
177:                return SUCCESS;
178:            }
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.