directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r227090 - /directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/tlv/Value.java
Date Tue, 02 Aug 2005 22:22:26 GMT
Author: elecharny
Date: Tue Aug  2 15:22:21 2005
New Revision: 227090

URL: http://svn.apache.org/viewcvs?rev=227090&view=rev
Log:
Added a method to encode an OID

Modified:
    directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/tlv/Value.java

Modified: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/tlv/Value.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/tlv/Value.java?rev=227090&r1=227089&r2=227090&view=diff
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/tlv/Value.java (original)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/tlv/Value.java Tue
Aug  2 15:22:21 2005
@@ -17,6 +17,7 @@
 package org.apache.asn1.ber.tlv;
 
 import org.apache.asn1.EncoderException;
+import org.apache.asn1.primitives.OID;
 import org.apache.asn1.primitives.OctetString;
 import org.apache.asn1.util.MutableString;
 import org.apache.asn1.util.StringUtils;
@@ -286,6 +287,37 @@
             if ( string.getLength() != 0 )
             {
                 buffer.put( string.getValue() );
+            }
+        }
+        catch ( BufferOverflowException boe )
+        {
+            throw new EncoderException("The PDU buffer size is too small !"); 
+        }
+
+        return;
+    }
+
+    /**
+     * Encode an OID value 
+     * 
+     * @param buffer The PDU in which the value will be put
+     * @param string The OID to be encoded
+     */
+    public static void encode( ByteBuffer buffer, OID oid ) throws EncoderException
+    {
+        if ( buffer == null )
+        {
+            throw new EncoderException( "Cannot put a PDU in a null buffer !" );
+        }
+
+        try 
+        {
+            buffer.put( UniversalTag.OCTET_STRING_TAG );
+            buffer.put( Length.getBytes( oid.getOIDLength() ) );
+    
+            if ( oid.getOIDLength() != 0 )
+            {
+                buffer.put( oid.getOID() );
             }
         }
         catch ( BufferOverflowException boe )



Mime
View raw message