directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r574996 - in /directory/shared/trunk/asn1/src: main/java/org/apache/directory/shared/asn1/ber/tlv/UniversalTag.java main/java/org/apache/directory/shared/asn1/ber/tlv/Value.java test/java/org/apache/directory/shared/asn1/ber/tlv/ValueTest.java
Date Wed, 12 Sep 2007 15:40:40 GMT
Author: elecharny
Date: Wed Sep 12 08:40:35 2007
New Revision: 574996

URL: http://svn.apache.org/viewvc?rev=574996&view=rev
Log:
Added a Tag for BitString and Generalized Time (they are used in Kerberos code)
Added a decode method in Value
Added a test case

Modified:
    directory/shared/trunk/asn1/src/main/java/org/apache/directory/shared/asn1/ber/tlv/UniversalTag.java
    directory/shared/trunk/asn1/src/main/java/org/apache/directory/shared/asn1/ber/tlv/Value.java
    directory/shared/trunk/asn1/src/test/java/org/apache/directory/shared/asn1/ber/tlv/ValueTest.java

Modified: directory/shared/trunk/asn1/src/main/java/org/apache/directory/shared/asn1/ber/tlv/UniversalTag.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/asn1/src/main/java/org/apache/directory/shared/asn1/ber/tlv/UniversalTag.java?rev=574996&r1=574995&r2=574996&view=diff
==============================================================================
--- directory/shared/trunk/asn1/src/main/java/org/apache/directory/shared/asn1/ber/tlv/UniversalTag.java
(original)
+++ directory/shared/trunk/asn1/src/main/java/org/apache/directory/shared/asn1/ber/tlv/UniversalTag.java
Wed Sep 12 08:40:35 2007
@@ -310,6 +310,8 @@
 
     public static final byte INTEGER_TAG = 0x02;
 
+    public static final byte BIT_STRING_TAG = 0x03;
+
     public static final byte OCTET_STRING_TAG = 0x04;
 
     public static final byte ENUMERATED_TAG = 0x0A;
@@ -317,6 +319,8 @@
     public static final byte UTF8_STRING_TAG = 0x0C;
 
     public static final byte GENERALIZED_TIME_TAG = 0x18;
+
+    public static final byte GENERALIZED_STRING_TAG = 0x1B;
 
     public static final byte SEQUENCE_TAG = 0x30;
 

Modified: directory/shared/trunk/asn1/src/main/java/org/apache/directory/shared/asn1/ber/tlv/Value.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/asn1/src/main/java/org/apache/directory/shared/asn1/ber/tlv/Value.java?rev=574996&r1=574995&r2=574996&view=diff
==============================================================================
--- directory/shared/trunk/asn1/src/main/java/org/apache/directory/shared/asn1/ber/tlv/Value.java
(original)
+++ directory/shared/trunk/asn1/src/main/java/org/apache/directory/shared/asn1/ber/tlv/Value.java
Wed Sep 12 08:40:35 2007
@@ -22,6 +22,7 @@
 
 import org.apache.directory.shared.asn1.ber.tlv.UniversalTag;
 import org.apache.directory.shared.asn1.codec.EncoderException;
+import org.apache.directory.shared.asn1.primitives.BitString;
 import org.apache.directory.shared.asn1.primitives.OID;
 import org.apache.directory.shared.asn1.util.Asn1StringUtils;
 
@@ -358,6 +359,39 @@
             {
                 buffer.put( value );
             }
+        }
+        catch ( BufferOverflowException boe )
+        {
+            throw new EncoderException( "The PDU buffer size is too small !" );
+        }
+
+        return;
+    }
+
+    /**
+     * Encode a BIT STRING value
+     * 
+     * @param buffer The PDU in which the value will be put
+     * @param bitString The BitString to be encoded.
+     */
+    public static void encode( ByteBuffer buffer, BitString bitString ) throws EncoderException
+    {
+        if ( buffer == null )
+        {
+            throw new EncoderException( "Cannot put a PDU in a null buffer !" );
+        }
+
+        try
+        {
+            buffer.put( UniversalTag.BIT_STRING_TAG );
+            
+            // The BitString length. We add one byte for the unused number 
+            // of bits
+            int length = bitString.size() + 1;
+            
+            buffer.put( TLV.getBytes( length ) );
+            buffer.put( bitString.getUnusedBits() );
+            buffer.put( bitString.getData() );
         }
         catch ( BufferOverflowException boe )
         {

Modified: directory/shared/trunk/asn1/src/test/java/org/apache/directory/shared/asn1/ber/tlv/ValueTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/asn1/src/test/java/org/apache/directory/shared/asn1/ber/tlv/ValueTest.java?rev=574996&r1=574995&r2=574996&view=diff
==============================================================================
--- directory/shared/trunk/asn1/src/test/java/org/apache/directory/shared/asn1/ber/tlv/ValueTest.java
(original)
+++ directory/shared/trunk/asn1/src/test/java/org/apache/directory/shared/asn1/ber/tlv/ValueTest.java
Wed Sep 12 08:40:35 2007
@@ -21,8 +21,12 @@
 
 
 import java.math.BigInteger;
+import java.nio.ByteBuffer;
 
 import org.apache.directory.shared.asn1.ber.tlv.Value;
+import org.apache.directory.shared.asn1.codec.EncoderException;
+import org.apache.directory.shared.asn1.primitives.BitString;
+import org.apache.directory.shared.asn1.util.Asn1StringUtils;
 import org.apache.directory.shared.asn1.util.IntegerDecoder;
 
 import junit.framework.Assert;
@@ -282,4 +286,25 @@
         bb[0] = 0x00;
         assertEquals( 0x01, vv[0] );
     }
+
+    
+    public void testEncodeBitString()
+    {
+        BitString bs = new BitString( 10 );
+        bs.setBit( 9 );
+        
+        ByteBuffer buffer = ByteBuffer.allocate( 5 );
+        
+        try
+        {
+            Value.encode( buffer, bs );
+        }
+        catch ( EncoderException ee )
+        {
+            
+        }
+        
+        assertEquals( "0x03 0x03 0x06 0x00 0x40 ", Asn1StringUtils.dumpBytes( buffer.array()
)  );
+    }
 }
+



Mime
View raw message