From commits-return-27300-apmail-directory-commits-archive=directory.apache.org@directory.apache.org Sun Sep 05 15:47:35 2010 Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 78376 invoked from network); 5 Sep 2010 15:47:35 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 5 Sep 2010 15:47:35 -0000 Received: (qmail 18514 invoked by uid 500); 5 Sep 2010 15:47:34 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 18455 invoked by uid 500); 5 Sep 2010 15:47:34 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 18446 invoked by uid 99); 5 Sep 2010 15:47:34 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 05 Sep 2010 15:47:34 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 05 Sep 2010 15:47:33 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 07F6C23889E9; Sun, 5 Sep 2010 15:47:13 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r992807 - in /directory/shared/trunk: asn1/src/main/java/org/apache/directory/shared/asn1/ber/tlv/ asn1/src/main/java/org/apache/directory/shared/asn1/primitives/ i18n/src/main/java/org/apache/directory/shared/i18n/ i18n/src/main/resources/... Date: Sun, 05 Sep 2010 15:47:12 -0000 To: commits@directory.apache.org From: elecharny@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100905154713.07F6C23889E9@eris.apache.org> Author: elecharny Date: Sun Sep 5 15:47:12 2010 New Revision: 992807 URL: http://svn.apache.org/viewvc?rev=992807&view=rev Log: o Reviewed some asn1 files o Fixed some error messages Modified: directory/shared/trunk/asn1/src/main/java/org/apache/directory/shared/asn1/ber/tlv/Value.java directory/shared/trunk/asn1/src/main/java/org/apache/directory/shared/asn1/primitives/BitString.java directory/shared/trunk/asn1/src/main/java/org/apache/directory/shared/asn1/primitives/OID.java directory/shared/trunk/i18n/src/main/java/org/apache/directory/shared/i18n/I18n.java directory/shared/trunk/i18n/src/main/resources/org/apache/directory/shared/i18n/errors.properties 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=992807&r1=992806&r2=992807&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 Sun Sep 5 15:47:12 2010 @@ -686,7 +686,7 @@ public class Value implements Serializab buffer.put( TLV.getBytes( length ) ); buffer.put( bitString.getUnusedBits() ); - buffer.put( bitString.getData() ); + buffer.put( bitString.getDataRef() ); } catch ( BufferOverflowException boe ) { Modified: directory/shared/trunk/asn1/src/main/java/org/apache/directory/shared/asn1/primitives/BitString.java URL: http://svn.apache.org/viewvc/directory/shared/trunk/asn1/src/main/java/org/apache/directory/shared/asn1/primitives/BitString.java?rev=992807&r1=992806&r2=992807&view=diff ============================================================================== --- directory/shared/trunk/asn1/src/main/java/org/apache/directory/shared/asn1/primitives/BitString.java (original) +++ directory/shared/trunk/asn1/src/main/java/org/apache/directory/shared/asn1/primitives/BitString.java Sun Sep 5 15:47:12 2010 @@ -36,9 +36,6 @@ public class BitString implements Serial /** The serialVersion UID constant */ private static final long serialVersionUID = 1L; - // ~ Static fields/initializers - // ----------------------------------------------------------------- - /** A null MutableString */ public static final BitString EMPTY_STRING = new BitString( 1 ); @@ -78,20 +75,23 @@ public class BitString implements Serial if ( length <= 0 ) { // This is not allowed - throw new IndexOutOfBoundsException( I18n.err( I18n.ERR_00029 ) ); + throw new IndexOutOfBoundsException( I18n.err( I18n.ERR_NULL_OR_NEG_LENGTH_NOT_ALLOWED_00029 ) ); } nbBits = length; // As we store values in bytes, we must divide the length by 8 - nbBytes = ( length / 8 ) + ( ( ( length % 8 ) != 0 ) ? 1 : 0 ); + nbBytes = ( length / 8 ); + + if ( ( length % 8 ) != 0 ) + { + nbBytes += 1; + } nbUnusedBits = ( 8 - length % 8 ) % 8; if ( nbBytes > DEFAULT_LENGTH ) { - - // TODO : implement the streaming isStreamed = true; bytes = new byte[nbBytes]; } @@ -105,37 +105,31 @@ public class BitString implements Serial /** * Creates a streamed BitString with a specific length. Actually, it's just - * a simple BitString. TODO Implement streaming. + * a simple BitString. * - * @param length - * The BitString length, in number of bits - * @param isStreamed - * Tells if the BitString must be streamed or not + * @param length The BitString length, in number of bits + * @param isStreamed Tells if the BitString must be streamed or not */ public BitString( int length, boolean isStreamed ) { if ( length <= 0 ) { // This is not allowed - throw new IndexOutOfBoundsException( I18n.err( I18n.ERR_00029 ) ); + throw new IndexOutOfBoundsException( I18n.err( I18n.ERR_NULL_OR_NEG_LENGTH_NOT_ALLOWED_00029 ) ); } nbBits = length; this.isStreamed = isStreamed; - nbBytes = ( length / 8 ) + ( ( ( length % 8 ) != 0 ) ? 1 : 0 ); - - nbUnusedBits = length % 8; + nbBytes = ( length / 8 ); - if ( isStreamed ) + if ( ( length % 8 ) != 0 ) { - - // TODO : implement the streaming - bytes = new byte[nbBytes]; - } - else - { - bytes = new byte[nbBytes]; + nbBytes += 1; } + + nbUnusedBits = length % 8; + + bytes = new byte[nbBytes]; } @@ -154,7 +148,6 @@ public class BitString implements Serial isStreamed = true; // It will be a streamed OctetString. - // TODO : implement the streaming this.bytes = new byte[nbBytes]; } else @@ -168,9 +161,6 @@ public class BitString implements Serial } - // ~ Methods - // ------------------------------------------------------------------------------------ - /** * Set the value into the bytes. * @@ -179,7 +169,6 @@ public class BitString implements Serial */ private void setBytes( byte[] bytes, int nbBytes ) { - // The first byte contains the number of unused ints nbUnusedBits = bytes[0] & 0x07; nbBits = ( nbBytes * 8 ) - nbUnusedBits; @@ -200,7 +189,6 @@ public class BitString implements Serial */ public void setData( byte[] bytes ) { - if ( ( bytes == null ) || ( bytes.length == 0 ) ) { nbBits = -1; @@ -211,10 +199,8 @@ public class BitString implements Serial if ( ( nbb > DEFAULT_LENGTH ) && ( bytes.length < nbb ) ) { - // The current size is too small. // We have to allocate more space - // TODO : implement the streaming bytes = new byte[nbb]; } @@ -229,6 +215,21 @@ public class BitString implements Serial */ public byte[] getData() { + byte[] copy = new byte[bytes.length]; + + System.arraycopy( bytes, 0, copy, 0, bytes.length ); + + return copy; + } + + + /** + * Get the representation of a BitString + * + * @return A byte array which represent the BitString (this is a reference to the internal bytes) + */ + public byte[] getDataRef() + { return bytes; } @@ -255,7 +256,7 @@ public class BitString implements Serial { if ( ( pos < 0 ) || ( pos > nbBits ) ) { - throw new IndexOutOfBoundsException( I18n.err( I18n.ERR_00030 ) ); + throw new IndexOutOfBoundsException( I18n.err( I18n.ERR_BIT_NUMBER_OUT_OF_BOUND_00030 ) ); } int posInt = nbBytes - 1 - ( ( pos + nbUnusedBits ) >> 3 ); @@ -277,7 +278,7 @@ public class BitString implements Serial { if ( ( pos < 0 ) || ( pos > nbBits ) ) { - throw new IndexOutOfBoundsException( I18n.err( I18n.ERR_00030 ) ); + throw new IndexOutOfBoundsException( I18n.err( I18n.ERR_BIT_NUMBER_OUT_OF_BOUND_00030 ) ); } int posInt = nbBytes - 1 - ( ( pos + nbUnusedBits ) >> 3 ); @@ -309,10 +310,9 @@ public class BitString implements Serial */ public boolean getBit( int pos ) { - if ( pos > nbBits ) { - throw new IndexOutOfBoundsException( I18n.err( I18n.ERR_00031, pos, nbBits ) ); + throw new IndexOutOfBoundsException( I18n.err( I18n.ERR_CANNOT_FIND_BIT_00031, pos, nbBits ) ); } int posInt = nbBytes - 1 - ( ( pos + nbUnusedBits ) >> 3 ); @@ -333,18 +333,27 @@ public class BitString implements Serial /** + * Tells if the OctetString is streamed or not + * + * @return true if the OctetString is streamed. + */ + public boolean isStreamed() + { + return isStreamed; + } + + + /** * Return a native String representation of the BitString. * * @return A String representing the BitString */ public String toString() { - - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); for ( int i = nbBits; i > 0; i-- ) { - if ( getBit( i ) ) { sb.append( '1' ); @@ -357,15 +366,4 @@ public class BitString implements Serial return sb.toString(); } - - - /** - * Tells if the OctetString is streamed or not - * - * @return true if the OctetString is streamed. - */ - public boolean isStreamed() - { - return isStreamed; - } } Modified: directory/shared/trunk/asn1/src/main/java/org/apache/directory/shared/asn1/primitives/OID.java URL: http://svn.apache.org/viewvc/directory/shared/trunk/asn1/src/main/java/org/apache/directory/shared/asn1/primitives/OID.java?rev=992807&r1=992806&r2=992807&view=diff ============================================================================== --- directory/shared/trunk/asn1/src/main/java/org/apache/directory/shared/asn1/primitives/OID.java (original) +++ directory/shared/trunk/asn1/src/main/java/org/apache/directory/shared/asn1/primitives/OID.java Sun Sep 5 15:47:12 2010 @@ -111,8 +111,6 @@ public class OID implements Serializable } - // ~ Methods - // ------------------------------------------------------------------------------------ /** * Set the OID. It will be translated from a byte array to an internal * representation. @@ -124,12 +122,12 @@ public class OID implements Serializable { if ( oid == null ) { - throw new DecoderException( I18n.err( I18n.ERR_00032 ) ); + throw new DecoderException( I18n.err( I18n.ERR_NULL_OID_00032 ) ); } if ( oid.length < 1 ) { - throw new DecoderException( I18n.err( I18n.ERR_00033, Asn1StringUtils.dumpBytes( oid ) ) ); + throw new DecoderException( I18n.err( I18n.ERR_INVALID_OID_00033, Asn1StringUtils.dumpBytes( oid ) ) ); } // First, we have to calculate the number of int to allocate @@ -221,7 +219,7 @@ public class OID implements Serializable { if ( ( oid == null ) || ( oid.length() == 0 ) ) { - throw new DecoderException( I18n.err( I18n.ERR_00032 ) ); + throw new DecoderException( I18n.err( I18n.ERR_NULL_OID_00032 ) ); } int nbValues = 1; @@ -236,7 +234,7 @@ public class OID implements Serializable if ( dotSeen ) { // Two dots, that's an error ! - throw new DecoderException( I18n.err( I18n.ERR_00033, oid ) ); + throw new DecoderException( I18n.err( I18n.ERR_INVALID_OID_00033, oid ) ); } nbValues++; @@ -251,7 +249,7 @@ public class OID implements Serializable // We must have at least 2 ints if ( nbValues < 2 ) { - throw new DecoderException( I18n.err( I18n.ERR_00033, oid ) ); + throw new DecoderException( I18n.err( I18n.ERR_INVALID_OID_00033, oid ) ); } oidValues = new long[nbValues]; @@ -274,13 +272,13 @@ public class OID implements Serializable break; default: // error, this value is not allowed - throw new DecoderException( I18n.err( I18n.ERR_00033, oid ) ); + throw new DecoderException( I18n.err( I18n.ERR_INVALID_OID_00033, oid ) ); } // We must have a dot if ( chars[pos++] != '.' ) { - throw new DecoderException( I18n.err( I18n.ERR_00033, oid ) ); + throw new DecoderException( I18n.err( I18n.ERR_INVALID_OID_00033, oid ) ); } dotSeen = true; @@ -294,12 +292,12 @@ public class OID implements Serializable if ( dotSeen ) { // Two dots, that's an error ! - throw new DecoderException( I18n.err( I18n.ERR_00033, oid ) ); + throw new DecoderException( I18n.err( I18n.ERR_INVALID_OID_00033, oid ) ); } if ( ituOrIso && value > 39 ) { - throw new DecoderException( I18n.err( I18n.ERR_00033, oid ) ); + throw new DecoderException( I18n.err( I18n.ERR_INVALID_OID_00033, oid ) ); } else { @@ -319,7 +317,7 @@ public class OID implements Serializable else { // We don't have a number, this is an error - throw new DecoderException( I18n.err( I18n.ERR_00033, oid ) ); + throw new DecoderException( I18n.err( I18n.ERR_INVALID_OID_00033, oid ) ); } } @@ -335,7 +333,11 @@ public class OID implements Serializable */ public long[] getOIDValues() { - return oidValues; + long[] copy = new long[oidValues.length]; + + System.arraycopy( oidValues, 0, copy, 0, oidValues.length ); + + return copy; } Modified: directory/shared/trunk/i18n/src/main/java/org/apache/directory/shared/i18n/I18n.java URL: http://svn.apache.org/viewvc/directory/shared/trunk/i18n/src/main/java/org/apache/directory/shared/i18n/I18n.java?rev=992807&r1=992806&r2=992807&view=diff ============================================================================== --- directory/shared/trunk/i18n/src/main/java/org/apache/directory/shared/i18n/I18n.java (original) +++ directory/shared/trunk/i18n/src/main/java/org/apache/directory/shared/i18n/I18n.java Sun Sep 5 15:47:12 2010 @@ -63,11 +63,11 @@ public enum I18n ERR_00026( "ERR_00026" ), ERR_00027( "ERR_00027" ), ERR_00028( "ERR_00028" ), - ERR_00029( "ERR_00029" ), - ERR_00030( "ERR_00030" ), - ERR_00031( "ERR_00031" ), - ERR_00032( "ERR_00032" ), - ERR_00033( "ERR_00033" ), + ERR_NULL_OR_NEG_LENGTH_NOT_ALLOWED_00029( "ERR_NULL_OR_NEG_LENGTH_NOT_ALLOWED_00029" ), + ERR_BIT_NUMBER_OUT_OF_BOUND_00030( "ERR_BIT_NUMBER_OUT_OF_BOUND_00030" ), + ERR_CANNOT_FIND_BIT_00031( "ERR_CANNOT_FIND_BIT_00031" ), + ERR_NULL_OID_00032( "ERR_NULL_OID_00032" ), + ERR_INVALID_OID_00033( "ERR_INVALID_OID_00033" ), ERR_00034( "ERR_00034" ), ERR_00035( "ERR_00035" ), ERR_00036( "ERR_00036" ), Modified: directory/shared/trunk/i18n/src/main/resources/org/apache/directory/shared/i18n/errors.properties URL: http://svn.apache.org/viewvc/directory/shared/trunk/i18n/src/main/resources/org/apache/directory/shared/i18n/errors.properties?rev=992807&r1=992806&r2=992807&view=diff ============================================================================== --- directory/shared/trunk/i18n/src/main/resources/org/apache/directory/shared/i18n/errors.properties (original) +++ directory/shared/trunk/i18n/src/main/resources/org/apache/directory/shared/i18n/errors.properties Sun Sep 5 15:47:12 2010 @@ -47,11 +47,11 @@ ERR_00025={0} found in input should only ERR_00026=Exception converting octets {0} ERR_00027=Not implemented: {0} ERR_00028=Internal error encoding BitString. -ERR_00029=Null or negative length are not allowed -ERR_00030=Bad bit number : out of bound -ERR_00031=Cannot get a bit at position {0} when the BitString contains only {1} ints -ERR_00032=Null OID -ERR_00033=Invalid OID : {0} +ERR_NULL_OR_NEG_LENGTH_NOT_ALLOWED_00029=Null or negative length are not allowed +ERR_BIT_NUMBER_OUT_OF_BOUND_00030=Bad bit number : out of bound +ERR_CANNOT_FIND_BIT_00031=Cannot get a bit at position {0} when the BitString contains only {1} ints +ERR_NULL_OID_00032=Null OID +ERR_INVALID_OID_00033=Invalid OID : {0} ERR_00034=The value is 0 byte long. This is not allowed for a boolean ERR_00035=The value is not 1 byte long. This is not allowed for a boolean ERR_00036=The value is 0 byte long. This is not allowed for an integer