Source Code Cross Referenced for DERNumericString.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:
005:        /**
006:         * DER NumericString object - this is an ascii string of characters {0,1,2,3,4,5,6,7,8,9, }.
007:         */
008:        public class DERNumericString extends ASN1Object implements  DERString {
009:            String string;
010:
011:            /**
012:             * return a Numeric string from the passed in object
013:             *
014:             * @exception IllegalArgumentException if the object cannot be converted.
015:             */
016:            public static DERNumericString getInstance(Object obj) {
017:                if (obj == null || obj instanceof  DERNumericString) {
018:                    return (DERNumericString) obj;
019:                }
020:
021:                if (obj instanceof  ASN1OctetString) {
022:                    return new DERNumericString(((ASN1OctetString) obj)
023:                            .getOctets());
024:                }
025:
026:                if (obj instanceof  ASN1TaggedObject) {
027:                    return getInstance(((ASN1TaggedObject) obj).getObject());
028:                }
029:
030:                throw new IllegalArgumentException(
031:                        "illegal object in getInstance: "
032:                                + obj.getClass().getName());
033:            }
034:
035:            /**
036:             * return an Numeric String from a tagged object.
037:             *
038:             * @param obj the tagged object holding the object we want
039:             * @param explicit true if the object is meant to be explicitly
040:             *              tagged false otherwise.
041:             * @exception IllegalArgumentException if the tagged object cannot
042:             *               be converted.
043:             */
044:            public static DERNumericString getInstance(ASN1TaggedObject obj,
045:                    boolean explicit) {
046:                return getInstance(obj.getObject());
047:            }
048:
049:            /**
050:             * basic constructor - with bytes.
051:             */
052:            public DERNumericString(byte[] string) {
053:                char[] cs = new char[string.length];
054:
055:                for (int i = 0; i != cs.length; i++) {
056:                    cs[i] = (char) (string[i] & 0xff);
057:                }
058:
059:                this .string = new String(cs);
060:            }
061:
062:            /**
063:             * basic constructor -  without validation..
064:             */
065:            public DERNumericString(String string) {
066:                this (string, false);
067:            }
068:
069:            /**
070:             * Constructor with optional validation.
071:             *
072:             * @param string the base string to wrap.
073:             * @param validate whether or not to check the string.
074:             * @throws IllegalArgumentException if validate is true and the string
075:             * contains characters that should not be in a NumericString.
076:             */
077:            public DERNumericString(String string, boolean validate) {
078:                if (validate && !isNumericString(string)) {
079:                    throw new IllegalArgumentException(
080:                            "string contains illegal characters");
081:                }
082:
083:                this .string = string;
084:            }
085:
086:            public String getString() {
087:                return string;
088:            }
089:
090:            public String toString() {
091:                return string;
092:            }
093:
094:            public byte[] getOctets() {
095:                char[] cs = string.toCharArray();
096:                byte[] bs = new byte[cs.length];
097:
098:                for (int i = 0; i != cs.length; i++) {
099:                    bs[i] = (byte) cs[i];
100:                }
101:
102:                return bs;
103:            }
104:
105:            void encode(DEROutputStream out) throws IOException {
106:                out.writeEncoded(NUMERIC_STRING, this .getOctets());
107:            }
108:
109:            public int hashCode() {
110:                return this .getString().hashCode();
111:            }
112:
113:            boolean asn1Equals(DERObject o) {
114:                if (!(o instanceof  DERNumericString)) {
115:                    return false;
116:                }
117:
118:                DERNumericString s = (DERNumericString) o;
119:
120:                return this .getString().equals(s.getString());
121:            }
122:
123:            /**
124:             * Return true if the string can be represented as a NumericString ('0'..'9', ' ')
125:             *
126:             * @param str string to validate.
127:             * @return true if numeric, fale otherwise.
128:             */
129:            public static boolean isNumericString(String str) {
130:                for (int i = str.length() - 1; i >= 0; i--) {
131:                    char ch = str.charAt(i);
132:
133:                    if (ch > 0x007f) {
134:                        return false;
135:                    }
136:
137:                    if (('0' <= ch && ch <= '9') || ch == ' ') {
138:                        continue;
139:                    }
140:
141:                    return false;
142:                }
143:
144:                return true;
145:            }
146:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.