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 2005/05/12 01:34:04 UTC
svn commit: r169727 -
/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/spnego/pojo/SpnegoNegTokenInitPOJO.java
Author: elecharny
Date: Wed May 11 16:34:03 2005
New Revision: 169727
URL: http://svn.apache.org/viewcvs?rev=169727&view=rev
Log:
- Added two members : hasReqFlags and reqFlags, with their accessors
- Implemented an 'encode' method which creates a PDU from the instance.
Modified:
directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/spnego/pojo/SpnegoNegTokenInitPOJO.java
Modified: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/spnego/pojo/SpnegoNegTokenInitPOJO.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/spnego/pojo/SpnegoNegTokenInitPOJO.java?rev=169727&r1=169726&r2=169727&view=diff
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/spnego/pojo/SpnegoNegTokenInitPOJO.java (original)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/spnego/pojo/SpnegoNegTokenInitPOJO.java Wed May 11 16:34:03 2005
@@ -16,7 +16,11 @@
*/
package org.apache.asn1.spnego.pojo;
+import java.nio.ByteBuffer;
+
import org.apache.asn1.AbstractPOJO;
+import org.apache.asn1.ber.tlv.Length;
+import org.apache.asn1.codec.EncoderException;
import org.apache.asn1.primitives.OID;
import org.apache.asn1.primitives.OctetString;
@@ -49,6 +53,12 @@
/** The current number of mech types stored in the array */
private int mechTypeListCurrentSize;
+ /** A flag that tells if there is a reqFlag element */
+ private boolean hasReqFlags;
+
+ /** A storage for the flags */
+ private byte reqFlags;
+
/** The delegate flag */
private boolean delegFlag;
@@ -107,6 +117,8 @@
mechTypeListExpectedLength = 0;
// Sets the flag to false.
+ hasReqFlags = false;
+
delegFlag = false;
mutualFlag = false;
replayFlag = false;
@@ -163,6 +175,8 @@
mechListMICExpectedLength = 0;
// Resets the flag to false.
+ hasReqFlags = false;
+
delegFlag = false;
mutualFlag = false;
replayFlag = false;
@@ -481,5 +495,163 @@
*/
public void setMechListMICExpectedLength(int mechListMICExpectedLength) {
this.mechListMICExpectedLength = mechListMICExpectedLength;
+ }
+
+ /**
+ * @return Returns the hasReqFlags.
+ */
+ public boolean hasReqFlags() {
+ return hasReqFlags;
+ }
+
+ /**
+ * @param hasReqFlags Set the hasReqFlags.
+ */
+ public void setHasReqFlags(boolean hasReqFlags) {
+ this.hasReqFlags = hasReqFlags;
+ }
+
+ public Object encode(Object object) throws EncoderException
+ {
+ // Calculate the lengths we need :
+ // - a global length
+ int negTokenInitLength = 0;
+
+ // - a length for the NegTokenInit sequence
+ int negTokenInitSequenceLength = 0;
+
+ // - a length for the mechTypes
+ int mechTypesLength = 0;
+
+ // - a length for the mechTypeList which is the sum
+ // of all mechType
+ int mechTypeListLength = 0;
+
+ // calculate the mechTypeList Length
+ if ((mechTypeList != null) && (mechTypeList.length != 0))
+ {
+ for ( int i = 0; ( i < mechTypeList.length ) && ( mechTypeList[i] != null ); i++ )
+ {
+ int length = mechTypeList[i].getOIDLength();
+
+ // The length of the mechType equals the length of
+ // the data, plus the length of the Length plus 1 byte for the Tag
+ mechTypeListLength += length + Length.getNbBytes(length) + 1 ;
+ }
+
+ // then calculate the mechTypesLength
+ mechTypesLength = mechTypeListLength + Length.getNbBytes(mechTypeListLength) + 1;
+ negTokenInitSequenceLength = mechTypesLength + Length.getNbBytes(mechTypesLength) + 1;
+ }
+
+ // - a length for the reqFlags (it's 5 bytes long if there
+ // is a reqflag, 0 bytes if not).
+ int reqFlagsLength = (hasReqFlags ? 6 : 0);
+
+ negTokenInitSequenceLength += reqFlagsLength;
+
+ // - a length for the mechToken
+ int mechTokenLength = 0;
+
+ // calculate the mechToken length
+ if (mechToken != null)
+ {
+ int length = mechToken.getValue().length;
+ mechTokenLength = length + Length.getNbBytes(length) + 1;
+ negTokenInitSequenceLength += mechTokenLength + Length.getNbBytes(mechTokenLength) + 1;
+ }
+
+ // - a length for the mechListMIC
+ int mechListMICLength = 0;
+
+ // calculate the mechListMIC length
+ if (mechListMIC != null)
+ {
+ int length = mechListMIC.getLength();
+ mechListMICLength = length + Length.getNbBytes(length) + 1;
+ negTokenInitSequenceLength += mechListMICLength + Length.getNbBytes(mechListMICLength) + 1;
+ }
+
+ // Finish by the negTokenInit length
+ negTokenInitLength = negTokenInitSequenceLength + Length.getNbBytes(negTokenInitSequenceLength) + 1;
+
+ // Allocate the bytes buffer.
+ ByteBuffer bb = ByteBuffer.allocate(negTokenInitLength + Length.getNbBytes(negTokenInitSequenceLength) + 1 );
+
+ // Push the NegTokenInit Tag and Length
+ bb.put(NEG_TOKEN_INIT_BYTE);
+ bb.put(Length.getBytes(negTokenInitLength));
+
+ // Push the negTokenInitSequence Tag and Length
+ bb.put(NEG_TOKEN_SEQUENCE_BYTE);
+ bb.put(Length.getBytes(negTokenInitSequenceLength));
+
+ // Push the mechTypeList Tag and Length, if they exist
+ if ((mechTypeList != null) && (mechTypeList.length != 0))
+ {
+ // The mechTypes Tag and Length
+ bb.put(MECH_TYPES_BYTE);
+ bb.put(Length.getBytes(mechTypesLength));
+
+ // The mechTypeList Tag and Length
+ bb.put(NEG_TOKEN_SEQUENCE_BYTE);
+ bb.put(Length.getBytes(mechTypeListLength));
+
+ // Store the Tag, Length and Value
+ for ( int i = 0; ( i < mechTypeList.length ) && ( mechTypeList[i] != null ) ; i++ )
+ {
+ bb.put(OBJECT_IDENTIFIER_BYTE);
+
+ bb.put(Length.getBytes(mechTypeList[i].getOIDLength()));
+ bb.put(mechTypeList[i].getOID());
+ }
+ }
+
+ // store the reqFlags Tag, Length and Value
+ if (hasReqFlags)
+ {
+ bb.put(REQ_FLAGS_BYTES);
+ bb.put(reqFlags);
+ }
+
+ // store the mechToken Tag, Length and Value
+ if (mechToken != null)
+ {
+ bb.put(MECH_TOKEN_BYTE);
+ bb.put(Length.getBytes(mechTokenLength));
+
+ bb.put(OCTET_STRING_BYTE);
+ bb.put(Length.getBytes(mechToken.getLength()));
+ bb.put(mechToken.getValue(), 0, mechToken.getLength());
+ }
+
+ // store the mechToken Tag, Length and Value
+ if (mechListMIC != null)
+ {
+ bb.put(MECH_LIST_MIC_BYTE);
+ bb.put(Length.getBytes(mechListMICLength));
+
+ bb.put(OCTET_STRING_BYTE);
+ bb.put(Length.getBytes(mechListMIC.getLength()));
+ bb.put(mechListMIC.getValue(), 0, mechListMIC.getLength());
+ }
+
+ return bb;
+ }
+
+ /**
+ * @return Returns the reqFlags.
+ */
+ public byte getReqFlags()
+ {
+ return reqFlags;
+ }
+
+ /**
+ * @param reqFlags The reqFlags to set.
+ */
+ public void setReqFlags(byte reqFlags)
+ {
+ this.reqFlags = reqFlags;
}
}