You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2007/10/22 22:42:41 UTC
svn commit: r587242 - in
/directory/apacheds/branches/bigbang/kerberos-shared/src:
main/java/org/apache/directory/server/kerberos/shared/io/decoder/
main/java/org/apache/directory/server/kerberos/shared/io/encoder/
main/java/org/apache/directory/server...
Author: elecharny
Date: Mon Oct 22 13:42:40 2007
New Revision: 587242
URL: http://svn.apache.org/viewvc?rev=587242&view=rev
Log:
Replaced the HostAddress class with the new one.
Replaced the HostAddressType class by a HostAddrType Enum
Added:
directory/apacheds/branches/bigbang/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/messages/value/types/HostAddrType.java
directory/apacheds/branches/bigbang/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/value/HostAddressTest.java
Removed:
directory/apacheds/branches/bigbang/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/messages/value/HostAddressType.java
Modified:
directory/apacheds/branches/bigbang/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/io/decoder/HostAddressDecoder.java
directory/apacheds/branches/bigbang/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/io/encoder/HostAddressesEncoder.java
directory/apacheds/branches/bigbang/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/messages/value/HostAddress.java
Modified: directory/apacheds/branches/bigbang/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/io/decoder/HostAddressDecoder.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/io/decoder/HostAddressDecoder.java?rev=587242&r1=587241&r2=587242&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/io/decoder/HostAddressDecoder.java (original)
+++ directory/apacheds/branches/bigbang/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/io/decoder/HostAddressDecoder.java Mon Oct 22 13:42:40 2007
@@ -23,7 +23,7 @@
import java.util.Enumeration;
import org.apache.directory.server.kerberos.shared.messages.value.HostAddress;
-import org.apache.directory.server.kerberos.shared.messages.value.HostAddressType;
+import org.apache.directory.server.kerberos.shared.messages.value.types.HostAddrType;
import org.apache.directory.server.kerberos.shared.messages.value.HostAddresses;
import org.apache.directory.shared.asn1.der.DEREncodable;
import org.apache.directory.shared.asn1.der.DERInteger;
@@ -46,10 +46,10 @@
*/
protected static HostAddress decode( DERSequence sequence )
{
- HostAddressType type = HostAddressType.ADDRTYPE_IPV4;
+ HostAddrType type = HostAddrType.ADDRTYPE_INET;
byte[] value = null;
- for ( Enumeration e = sequence.getObjects(); e.hasMoreElements(); )
+ for ( Enumeration<DEREncodable> e = sequence.getObjects(); e.hasMoreElements(); )
{
DERTaggedObject object = ( DERTaggedObject ) e.nextElement();
int tag = object.getTagNo();
@@ -59,8 +59,9 @@
{
case 0:
DERInteger addressType = ( DERInteger ) derObject;
- type = HostAddressType.getTypeByOrdinal( addressType.intValue() );
+ type = HostAddrType.getTypeByOrdinal( addressType.intValue() );
break;
+
case 1:
DEROctetString address = ( DEROctetString ) derObject;
value = address.getOctets();
@@ -83,7 +84,8 @@
HostAddress[] addresses = new HostAddress[sequence.size()];
int ii = 0;
- for ( Enumeration e = sequence.getObjects(); e.hasMoreElements(); )
+
+ for ( Enumeration<DEREncodable> e = sequence.getObjects(); e.hasMoreElements(); )
{
DERSequence object = ( DERSequence ) e.nextElement();
HostAddress address = decode( object );
Modified: directory/apacheds/branches/bigbang/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/io/encoder/HostAddressesEncoder.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/io/encoder/HostAddressesEncoder.java?rev=587242&r1=587241&r2=587242&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/io/encoder/HostAddressesEncoder.java (original)
+++ directory/apacheds/branches/bigbang/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/io/encoder/HostAddressesEncoder.java Mon Oct 22 13:42:40 2007
@@ -64,7 +64,7 @@
{
DERSequence sequence = new DERSequence();
- sequence.add( new DERTaggedObject( 0, DERInteger.valueOf( host.getAddressType().getOrdinal() ) ) );
+ sequence.add( new DERTaggedObject( 0, DERInteger.valueOf( host.getAddrType().getOrdinal() ) ) );
sequence.add( new DERTaggedObject( 1, new DEROctetString( host.getAddress() ) ) );
return sequence;
Modified: directory/apacheds/branches/bigbang/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/messages/value/HostAddress.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/messages/value/HostAddress.java?rev=587242&r1=587241&r2=587242&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/messages/value/HostAddress.java (original)
+++ directory/apacheds/branches/bigbang/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/messages/value/HostAddress.java Mon Oct 22 13:42:40 2007
@@ -22,30 +22,76 @@
import java.net.InetAddress;
import java.net.UnknownHostException;
+import java.nio.BufferOverflowException;
+import java.nio.ByteBuffer;
+
+import org.apache.directory.server.kerberos.shared.messages.value.types.HostAddrType;
+import org.apache.directory.shared.asn1.AbstractAsn1Object;
+import org.apache.directory.shared.asn1.ber.tlv.TLV;
+import org.apache.directory.shared.asn1.ber.tlv.UniversalTag;
+import org.apache.directory.shared.asn1.ber.tlv.Value;
+import org.apache.directory.shared.asn1.codec.EncoderException;
+import org.apache.directory.shared.ldap.util.StringTools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* Provides host address information.
*
+ * The ASN.1 grammaor for this structure is :
+ *
+ * HostAddress ::= SEQUENCE {
+ * addr-type [0] Int32,
+ * address [1] OCTET STRING
+ * }
+ *
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
* @version $Rev$, $Date$
*/
-public class HostAddress
+public class HostAddress extends AbstractAsn1Object
{
- private HostAddressType addressType;
- private byte[] address;
+ /** The logger */
+ private static final Logger log = LoggerFactory.getLogger( HostAddress.class );
+
+ /** Speedup for logs */
+ private static final boolean IS_DEBUG = log.isDebugEnabled();
+
+ /** The host address type. One of :
+ * Address Type Value
+ *
+ * IPv4 2
+ * Directional 3
+ * ChaosNet 5
+ * XNS 6
+ * ISO 7
+ * DECNET Phase IV 12
+ * AppleTalk DDP 16
+ * NetBios 20
+ * IPv6 24
+ */
+ private HostAddrType addrType;
+
+ /** The address */
+ private byte[] addresse;
+
+ // Storage for computed lengths
+ private transient int addrTypeLength;
+ private transient int addressLength;
+ private transient int hostAddressLength;
+ private transient int hostAddressSeqLength;
/**
* Creates a new instance of HostAddress.
*
- * @param addressType
- * @param address
+ * @param addrType
+ * @param addr
*/
- public HostAddress( HostAddressType addressType, byte[] address )
+ public HostAddress( HostAddrType addrType, byte[] addresse )
{
- this.addressType = addressType;
- this.address = address;
+ this.addrType = addrType;
+ this.addresse = addresse;
}
@@ -56,37 +102,37 @@
*/
public HostAddress( InetAddress internetAddress )
{
- addressType = HostAddressType.ADDRTYPE_IPV4;
+ addrType = HostAddrType.ADDRTYPE_INET;
byte[] newAddress = internetAddress.getAddress();
- address = new byte[newAddress.length];
- System.arraycopy( newAddress, 0, address, 0, newAddress.length );
+ addresse = new byte[newAddress.length];
+ System.arraycopy( newAddress, 0, addresse, 0, newAddress.length );
}
/**
* Returns whether one {@link HostAddress} is equal to another.
*
- * @param that
+ * @param that The {@link HostAddress} to compare with
* @return true if the {@link HostAddress}'s are equal.
*/
public boolean equals( HostAddress that )
{
- if ( this.addressType != that.addressType || ( this.address != null && that.address == null )
- || ( this.address == null && that.address != null ) )
+ if ( this.addrType != that.addrType || ( this.addresse != null && that.addresse == null )
+ || ( this.addresse == null && that.addresse != null ) )
{
return false;
}
- if ( this.address != null && that.address != null )
+ if ( this.addresse != null && that.addresse != null )
{
- if ( this.address.length != that.address.length )
+ if ( this.addresse.length != that.addresse.length )
{
return false;
}
- for ( int ii = 0; ii < this.address.length; ii++ )
+ for ( int ii = 0; ii < this.addresse.length; ii++ )
{
- if ( this.address[ii] != that.address[ii] )
+ if ( this.addresse[ii] != that.addresse[ii] )
{
return false;
}
@@ -104,28 +150,133 @@
*/
public byte[] getAddress()
{
- return address;
+ return addresse;
}
/**
- * Returns the {@link HostAddressType} of this {@link HostAddress}.
+ * Compute the host address length
+ *
+ * HostAddress :
+ *
+ * 0x30 L1 hostAddress sequence
+ * |
+ * +--> 0xA0 L2 addrType tag
+ * | |
+ * | +--> 0x02 L2-1 addrType (int)
+ * |
+ * +--> 0xA1 L3 address tag
+ * |
+ * +--> 0x04 L3-1 address (OCTET STRING)
+ *
+ * where L1 = L2 + length(0xA0) + length(L2) +
+ * L3 + length(0xA1) + length(L3)
+ * and
+ * L2 = L2-1 + length(0x02) + length( L2-1)
+ * L3 = L3-1 + length(0x04) + length( L3-1)
+ */
+ public int computeLength()
+ {
+ // Compute the keyType. The Length will always be contained in 1 byte
+ addrTypeLength = 1 + 1 + Value.getNbBytes( addrType.getOrdinal() );
+ hostAddressLength = 1 + TLV.getNbBytes( addrTypeLength ) + addrTypeLength;
+
+ // Compute the keyValue
+ if ( addresse == null )
+ {
+ addressLength = 1 + 1;
+ }
+ else
+ {
+ addressLength = 1 + TLV.getNbBytes( addresse.length ) + addresse.length;
+ }
+
+ hostAddressLength += 1 + TLV.getNbBytes( addressLength ) + addressLength;
+
+ // Compute the whole sequence length
+ hostAddressSeqLength = 1 + Value.getNbBytes( hostAddressLength ) + hostAddressLength;
+
+ return hostAddressSeqLength;
+ }
+
+
+ /**
+ * Encode the HostAddress message to a PDU.
+ *
+ * HostAddress :
+ *
+ * 0x30 LL
+ * 0xA0 LL
+ * 0x02 0x01 addr-type
+ * 0xA1 LL
+ * 0x04 LL address
+ *
+ * @param buffer The buffer where to put the PDU. It should have been allocated
+ * before, with the right size.
+ * @return The constructed PDU.
+ */
+ public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException
+ {
+ if ( buffer == null )
+ {
+ throw new EncoderException( "Cannot put a PDU in a null buffer !" );
+ }
+
+ try
+ {
+ // The HostAddress SEQ Tag
+ buffer.put( UniversalTag.SEQUENCE_TAG );
+ buffer.put( TLV.getBytes( hostAddressLength ) );
+
+ // The addr-type, first the tag, then the value
+ buffer.put( ( byte ) 0xA0 );
+ buffer.put( TLV.getBytes( addrTypeLength ) );
+ Value.encode( buffer, addrType.getOrdinal() );
+
+ // The address, first the tag, then the value
+ buffer.put( ( byte ) 0xA1 );
+ buffer.put( TLV.getBytes( addressLength ) );
+ Value.encode( buffer, addresse );
+ }
+ catch ( BufferOverflowException boe )
+ {
+ log.error(
+ "Cannot encode the HostAddress object, the PDU size is {} when only {} bytes has been allocated", 1
+ + TLV.getNbBytes( hostAddressLength ) + hostAddressLength, buffer.capacity() );
+ throw new EncoderException( "The PDU buffer size is too small !" );
+ }
+
+ if ( IS_DEBUG )
+ {
+ log.debug( "Checksum encoding : {}", StringTools.dumpBytes( buffer.array() ) );
+ log.debug( "Checksum initial value : {}", toString() );
+ }
+
+ return buffer;
+ }
+
+
+ /**
+ * Returns the {@link HostaddrType} of this {@link HostAddress}.
*
- * @return The {@link HostAddressType}.
+ * @return The {@link HostaddrType}.
*/
- public HostAddressType getAddressType()
+ public HostAddrType getAddrType()
{
- return addressType;
+ return addrType;
}
+ /**
+ * @see Object#toString()
+ */
public String toString()
{
String result = "";
try
{
- result = InetAddress.getByAddress( address ).getHostAddress();
+ result = InetAddress.getByAddress( addresse ).getHostAddress();
}
catch ( UnknownHostException uhe )
{
Added: directory/apacheds/branches/bigbang/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/messages/value/types/HostAddrType.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/messages/value/types/HostAddrType.java?rev=587242&view=auto
==============================================================================
--- directory/apacheds/branches/bigbang/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/messages/value/types/HostAddrType.java (added)
+++ directory/apacheds/branches/bigbang/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/messages/value/types/HostAddrType.java Mon Oct 22 13:42:40 2007
@@ -0,0 +1,271 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.directory.server.kerberos.shared.messages.value.types;
+
+
+/**
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: 540371 $, $Date: 2007-05-22 02:00:43 +0200 (Tue, 22 May 2007) $
+ */
+public enum HostAddrType
+{
+ /**
+ * Constant for the "null" host address type.
+ */
+ NULL( 0 ),
+
+ /**
+ * Constant for the "Unix" host address type.
+ *
+ * Not in RFC
+ */
+ // ADDRTYPE_UNIX( 1 ),
+
+ /**
+ * Constant for the "Internet" host address type.
+ */
+ ADDRTYPE_INET( 2 ),
+
+ /**
+ * Constant for the "Arpanet" host address type.
+ */
+ ADDRTYPE_IMPLINK( 3 ),
+
+ /**
+ * Constant for the "PUP" host address type.
+ *
+ * Not in RFC
+ */
+ //ADDRTYPE_PUP( 4 ),
+
+ /**
+ * Constant for the "CHAOS" host address type.
+ */
+ ADDRTYPE_CHAOS( 5 ),
+
+ /**
+ * Constant for the "XEROX Network Services" host address type.
+ */
+ ADDRTYPE_XNS( 6 ),
+
+ /**
+ * Constant for the "IPX" host address type.
+ *
+ * Not in RFC
+ */
+ // ADDRTYPE_IPX( 6 ),
+
+ /**
+ * Constant for the "OSI" host address type.
+ */
+ ADDRTYPE_OSI( 7 ),
+
+ /**
+ * Constant for the "European Computer Manufacturers" host address type.
+ *
+ * Not in RFC
+ */
+ //ADDRTYPE_ECMA( 8 ),
+
+ /**
+ * Constant for the "Datakit" host address type.
+ *
+ * Not in RFC
+ */
+ //ADDRTYPE_DATAKIT( 9 ),
+
+ /**
+ * Constant for the "CCITT" host address type.
+ *
+ * Not in RFC
+ */
+ //pADDRTYPE_CCITT( 10 ),
+
+ /**
+ * Constant for the "SNA" host address type.
+ *
+ * Not in RFC
+ */
+ //ADDRTYPE_SNA( 11 ),
+
+ /**
+ * Constant for the "DECnet" host address type.
+ */
+ ADDRTYPE_DECNET( 12 ),
+
+ /**
+ * Constant for the "Direct Data Link Interface" host address type.
+ *
+ * Not in RFC
+ */
+ //ADDRTYPE_DLI( 13 ),
+
+ /**
+ * Constant for the "LAT" host address type.
+ *
+ * Not in RFC
+ */
+ //ADDRTYPE_LAT( 14 ),
+
+ /**
+ * Constant for the "NSC Hyperchannel" host address type.
+ *
+ * Not in RFC
+ */
+ //ADDRTYPE_HYLINK( 15 ),
+
+ /**
+ * Constant for the "AppleTalk" host address type.
+ */
+ ADDRTYPE_APPLETALK( 16 ),
+
+ /**
+ * Constant for the "VoiceView" host address type.
+ *
+ * Not in RFC
+ */
+ //ADDRTYPE_VOICEVIEW( 18 ),
+
+ /**
+ * Constant for the "Firefox" host address type.
+ *
+ * Not in RFC
+ */
+ //ADDRTYPE_FIREFOX( 19 ),
+
+ /**
+ * Constant for the "NetBios" host address type.
+ *
+ * Not in RFC
+ */
+ ADDRTYPE_NETBIOS( 20 ),
+
+ /**
+ * Constant for the "Banyan" host address type.
+ *
+ * Not in RFC
+ */
+ //ADDRTYPE_BAN( 21 ),
+
+ /**
+ * Constant for the "ATM" host address type.
+ *
+ * Not in RFC
+ */
+ //ADDRTYPE_ATM( 22 ),
+
+ /**
+ * Constant for the "Internet Protocol V6" host address type.
+ */
+ ADDRTYPE_INET6( 24 );
+
+ /**
+ * The value/code for the host address type.
+ */
+ private final int ordinal;
+
+
+ /**
+ * Private constructor prevents construction outside of this class.
+ */
+ private HostAddrType( int ordinal )
+ {
+ this.ordinal = ordinal;
+ }
+
+
+ /**
+ * Returns the host address type when specified by its ordinal.
+ *
+ * @param type
+ * @return The host address type.
+ */
+ public static HostAddrType getTypeByOrdinal( int type )
+ {
+ switch ( type )
+ {
+ case 0 : return NULL;
+ //case 1 : return ADDRTYPE_UNIX;
+ case 2 : return ADDRTYPE_INET;
+ case 3 : return ADDRTYPE_IMPLINK;
+ //case 4 : return ADDRTYPE_PUP;
+ case 5 : return ADDRTYPE_CHAOS;
+ case 6 : return ADDRTYPE_XNS;
+ case 7 : return ADDRTYPE_OSI;
+ //case 8 : return ADDRTYPE_ECMA;
+ //case 9 : return ADDRTYPE_DATAKIT;
+ //case 10 : return pADDRTYPE_CCITT;
+ //case 11 : return ADDRTYPE_SNA;
+ case 12 : return ADDRTYPE_DECNET;
+ //case 13 : return ADDRTYPE_DLI;
+ //case 14 : return ADDRTYPE_LAT;
+ //case 15 : return ADDRTYPE_HYLINK;
+ case 16 : return ADDRTYPE_APPLETALK;
+ //case 18 : return ADDRTYPE_VOICEVIEW;
+ //case 19 : return ADDRTYPE_FIREFOX;
+ case 20 : return ADDRTYPE_NETBIOS;
+ //case 21 : return ADDRTYPE_BAN;
+ //case 22 : return ADDRTYPE_ATM;
+ case 24 : return ADDRTYPE_INET6;
+ default : return NULL;
+ }
+ }
+
+
+ /**
+ * Returns the number associated with this host address type.
+ *
+ * @return The host address type ordinal.
+ */
+ public int getOrdinal()
+ {
+ return ordinal;
+ }
+
+ public String toString()
+ {
+ switch ( ordinal )
+ {
+ //case 1 : return "Unix" + "(" + ordinal + ")" ;
+ case 2 : return "Internet" + "(" + ordinal + ")" ;
+ case 3 : return "Arpanet" + "(" + ordinal + ")" ;
+ //case 4 : return "PUP" + "(" + ordinal + ")" ;
+ case 5 : return "CHAOS" + "(" + ordinal + ")" ;
+ case 6 : return "XEROX Network Services" + "(" + ordinal + ")" ;
+ case 7 : return "OSI" + "(" + ordinal + ")" ;
+ //case 8 : return "European Computer Manufacturers" + "(" + ordinal + ")" ;
+ //case 9 : return "Datakit" + "(" + ordinal + ")" ;
+ //case 10 : return "CCITT" + "(" + ordinal + ")" ;
+ //case 11 : return "SNA" + "(" + ordinal + ")" ;
+ case 12 : return "DECnet" + "(" + ordinal + ")" ;
+ //case 13 : return "Direct Data Link Interface" + "(" + ordinal + ")" ;
+ //case 14 : return "LAT" + "(" + ordinal + ")" ;
+ //case 15 : return "NSC Hyperchannel" + "(" + ordinal + ")" ;
+ //case 16 : return "AppleTalk" + "(" + ordinal + ")" ;
+ //case 18 : return "VoiceView" + "(" + ordinal + ")" ;
+ //case 19 : return "Firefox" + "(" + ordinal + ")" ;
+ case 20 : return "NetBios" + "(" + ordinal + ")" ;
+ //case 21 : return "Banyan" + "(" + ordinal + ")" ;
+ //case 22 : return "ATM" + "(" + ordinal + ")" ;
+ case 24 : return "Internet Protocol V6" + "(" + ordinal + ")" ;
+ default : return "null" + "(" + ordinal + ")" ;
+ }
+ }
+}
Added: directory/apacheds/branches/bigbang/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/value/HostAddressTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/value/HostAddressTest.java?rev=587242&view=auto
==============================================================================
--- directory/apacheds/branches/bigbang/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/value/HostAddressTest.java (added)
+++ directory/apacheds/branches/bigbang/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/value/HostAddressTest.java Mon Oct 22 13:42:40 2007
@@ -0,0 +1,81 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.directory.server.kerberos.shared.messages.value;
+
+
+import java.nio.ByteBuffer;
+import java.util.Arrays;
+
+import org.apache.directory.server.kerberos.shared.messages.value.types.HostAddrType;
+
+import junit.framework.TestCase;
+
+
+/**
+ * Test the HostAddress encoding and decoding
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: 542147 $, $Date: 2007-05-28 10:14:21 +0200 (Mon, 28 May 2007) $
+ */
+public class HostAddressTest extends TestCase
+{
+ public void testEncodingHostAddressIP() throws Exception
+ {
+ HostAddress ha = new HostAddress( HostAddrType.ADDRTYPE_INET, new byte[]
+ { 0x01, 0x02, 0x03, 0x04 } );
+
+ ByteBuffer encoded = ByteBuffer.allocate( ha.computeLength() );
+
+ ha.encode( encoded );
+
+ byte[] expectedResult = new byte[]
+ {
+ 0x30, 0x0d,
+ (byte)0xA0, 0x03,
+ 0x02, 0x01, 0x02,
+ (byte)0xA1, 0x06,
+ 0x04, 0x04,
+ 0x01, 0x02, 0x03, 0x04
+ };
+
+ assertTrue( Arrays.equals( expectedResult, encoded.array() ) );
+ }
+
+
+ public void testEncodingHostAddressIPNullAddress() throws Exception
+ {
+ HostAddress ha = new HostAddress( HostAddrType.ADDRTYPE_INET, null );
+
+ ByteBuffer encoded = ByteBuffer.allocate( ha.computeLength() );
+
+ ha.encode( encoded );
+
+ byte[] expectedResult = new byte[]
+ {
+ 0x30, 0x09,
+ (byte)0xA0, 0x03,
+ 0x02, 0x01, 0x02,
+ (byte)0xA1, 0x02,
+ 0x04, 0x00
+ };
+
+ assertTrue( Arrays.equals( expectedResult, encoded.array() ) );
+ }
+}