directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r159168 - in directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/primitives: ./ IntegerDecoder.java LdapDNDecoder.java LdapStringDecoder.java
Date Sun, 27 Mar 2005 18:41:51 GMT
Author: elecharny
Date: Sun Mar 27 10:41:50 2005
New Revision: 159168

URL: http://svn.apache.org/viewcvs?view=rev&rev=159168
Log:
A first working version of the new ASN.1 LDAP decoder.

Added:
    directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/primitives/
    directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/primitives/IntegerDecoder.java
    directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/primitives/LdapDNDecoder.java
    directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/primitives/LdapStringDecoder.java

Added: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/primitives/IntegerDecoder.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/primitives/IntegerDecoder.java?view=auto&rev=159168
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/primitives/IntegerDecoder.java
(added)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/primitives/IntegerDecoder.java
Sun Mar 27 10:41:50 2005
@@ -0,0 +1,85 @@
+/*
+ *   Copyright 2005 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.asn1.ldap.codec.primitives;
+
+import org.apache.asn1.ber.tlv.Value;
+import org.apache.asn1.ldap.codec.DecoderException;
+
+
+/**
+ * Parse and decode an Integer value.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class IntegerDecoder
+{
+    //~ Methods ------------------------------------------------------------------------------------
+
+    /**
+     * Parse a byte buffer and send back an integer 
+     *
+     * @param value The byte buffer to parse
+     * @param min Lowest value allowed, included
+     * @param max Highest value allowed, included
+     *
+     * @return An integer
+     *
+     * @throws DecoderException Thrown if the byte stream does not contains an integer
+     */
+    public static int parse( Value value, int min, int max ) throws DecoderException
+    {
+
+        int    result = 0;
+
+        byte[] bytes  = value.getData();
+
+        if ( bytes.length > 4 )
+        {
+            throw new DecoderException(
+                "The value is more than 4 bytes long. This is not allowed for an integer"
);
+        }
+
+        for ( int i = 0; ( i < bytes.length ) && ( i < 5 ); i++ )
+        {
+            result = ( result << 8 ) | ( bytes[i] & 0x00FF );
+        }
+
+        if ( ( result >= min ) && ( result <= max ) )
+        {
+
+            return result;
+        }
+        else
+        {
+            throw new DecoderException( "The value is not in the range [" + min + ", " +
max + "]" );
+        }
+    }
+    
+    /**
+     * Parse a byte buffer and send back an integer 
+     *
+     * @param value The byte buffer to parse
+     *
+     * @return An integer
+     *
+     * @throws DecoderException Thrown if the byte stream does not contains an integer
+     */
+    public static int parse( Value value ) throws DecoderException
+    {
+    	return parse( value, Integer.MIN_VALUE, Integer.MAX_VALUE ); 
+    }
+}

Added: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/primitives/LdapDNDecoder.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/primitives/LdapDNDecoder.java?view=auto&rev=159168
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/primitives/LdapDNDecoder.java
(added)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/primitives/LdapDNDecoder.java
Sun Mar 27 10:41:50 2005
@@ -0,0 +1,59 @@
+/*
+ *   Copyright 2005 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.asn1.ldap.codec.primitives;
+
+import java.io.UnsupportedEncodingException;
+
+import org.apache.asn1.ber.tlv.Value;
+import org.apache.asn1.ldap.codec.DecoderException;
+import org.apache.asn1.ldap.codec.utils.LdapDN;
+
+
+/**
+ * Decode and check a LdapDN. 
+ * 
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ */
+public class LdapDNDecoder
+{
+    //~ Methods ------------------------------------------------------------------------------------
+
+    /**
+     * Transform the byte array to a String. A check is done to insure that
+     * it complies with RFC 2044.
+     * 
+     * @param value The byte array to transform
+     * @return A String that represent the LDAPString
+     * @throws DecoderException If the byte array does not comply with RFC 2044
+     */
+    public static String parse( Value value ) throws DecoderException
+    {
+    	try
+		{
+	        byte[] data = value.getData();
+	        String text = new String(data, "UTF-8");
+	        char[] chars = new char[text.length()];
+	        text.getChars(0, data.length, chars, 0);
+	
+	        return LdapDN.parseDN( chars );
+		}
+    	catch (UnsupportedEncodingException uee)
+		{
+    		throw new DecoderException("Error while decoding the string");
+		}
+    }
+}

Added: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/primitives/LdapStringDecoder.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/primitives/LdapStringDecoder.java?view=auto&rev=159168
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/primitives/LdapStringDecoder.java
(added)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/primitives/LdapStringDecoder.java
Sun Mar 27 10:41:50 2005
@@ -0,0 +1,57 @@
+/*
+ *   Copyright 2005 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.asn1.ldap.codec.primitives;
+
+import org.apache.asn1.ber.tlv.Value;
+import org.apache.asn1.ldap.codec.DecoderException;
+
+import java.io.UnsupportedEncodingException;
+
+
+/**
+ * Decodes a LdapString, and checks that the character set used comply
+ * the ISO 10646 encoded following the UTF-8 algorithm (RFC 2044, RFC 2279)
+ * .
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class LdapStringDecoder
+{
+    //~ Methods ------------------------------------------------------------------------------------
+
+    /**
+     * Transform the byte array to a String. A check is done to insure that
+     * it complies with RFC 2279.
+     * 
+     * @param value The byte array to transform
+     * @return A String that represent the LDAPSTRING
+     * 
+     * @throws DecoderException If the byte array does not comply with RFC 2279
+     */
+    public static String parse( Value value ) throws DecoderException
+    {
+
+        try
+        {
+            return new String( value.getData(), "UTF-8" );
+        }
+        catch ( UnsupportedEncodingException uee )
+        {
+            throw new DecoderException( "Error while decoding the string" );
+        }
+    }
+}



Mime
View raw message