/// <summary> /// SPNG Client Packet API, which is to generate SpngInitialNegToken /// </summary> /// <param name="payloadType">An enum parameter, indicates the inner payload type, /// e.g. PayloadType.NegInit is for NegTokenInit</param> /// <param name="negotiationState">Indicate the negotation status, e.g. incomplete, completed.</param> /// <param name="mechToken">Binary mechToken byte array, or responseToken. /// This field could be null when the first time invoked.</param> /// <param name="mechListMIC">This field, if present, contains an MIC token for /// the mechanism list in the initial negotiation message. /// This field could be null.</param> /// <returns>SpngInitialNegToken2 packet</returns> /// <exception cref="ArgumentOutOfRangeException">PayloadType is not in scope. </exception> public SpngInitialNegToken CreateInitialNegToken(SpngPayloadType payloadType, NegState negotiationState, byte[] mechToken, byte[] mechListMIC) { Asn1Object asn1Element; NegotiationToken negToken; Asn1OctetString asn10MechListMic = null; if (mechListMIC != null) { asn10MechListMic = new Asn1OctetString(mechListMIC); } switch (payloadType) { case SpngPayloadType.NegInit: asn1Element = new NegTokenInit(this.Config.MechList, this.Config.Asn1ContextAttributes, new Asn1.Asn1OctetString(mechToken), asn10MechListMic ); // save the initial MechType list. Will be used when computing MechListMIC this.Context.InitMechTypeList = (asn1Element as NegTokenInit).mechTypes; negToken = new NegotiationToken(NegotiationToken.negTokenInit, asn1Element); break; default: //throw exception here throw new ArgumentOutOfRangeException("payloadType"); } InitialNegToken intialToken = new InitialNegToken(new MechType(this.Config.SpngOidIntArray), negToken); return(new SpngInitialNegToken(intialToken)); }
/// <summary> /// SPNG Client Packet API, which is to generate SpngNegotiationToken. /// </summary> /// <param name="payloadType">An enum parameter, indicates the inner payload type, /// e.g. PayloadType.NegInit is for NegTokenInit</param> /// <param name="negotiationState">Indicate the negotation status, e.g. incomplete, completed.</param> /// <param name="responseToken">Byte array of responseToken. /// This field could be null when the first time invoked.</param> /// <param name="mechListMIC">This field, if present, contains an MIC token for /// the mechanism list in the initial negotiation message. /// This field could be null.</param> /// <returns>SpngNegotiationToken packet</returns> /// <exception cref="ArgumentOutOfRangeException">PayloadType is not in scope. </exception> public SpngNegotiationToken CreateNegotiationToken( SpngPayloadType payloadType, NegState negotiationState, byte[] responseToken, byte[] mechListMIC) { NegotiationToken token; switch (payloadType) { case SpngPayloadType.NegResp: SpngNegTokenResp negResp = CreateNegTokenResp(negotiationState, responseToken, mechListMIC); token = new NegotiationToken(NegotiationToken.negTokenResp, negResp.Asn1Token); break; case SpngPayloadType.NegInit: NegTokenInit negInit = new NegTokenInit( this.config.MechList, SpngUtility.ConvertUintToContextFlags(this.config.ContextAttributes), new Asn1OctetString(responseToken), new Asn1OctetString(mechListMIC) ); token = new NegotiationToken(NegotiationToken.negTokenInit, negInit); break; default: throw new ArgumentOutOfRangeException("payloadType"); } return(new SpngNegotiationToken(token)); }
/// <summary> /// SPNG Client Packet API, which is to generate SpngNegTokenInit. /// </summary> /// <param name="mechToken">Byte array of mechToken. /// This field could be null when the first time invoked.</param> /// <param name="mechListMIC">This field, if present, contains an MIC token for /// the mechanism list in the initial negotiation message. /// This field could be null.</param> /// <returns>SpngNegTokenInit packet</returns> public SpngNegTokenInit CreateNegTokenInit(byte[] mechToken, byte[] mechListMIC) { NegTokenInit negToken = new NegTokenInit(this.Config.MechList, this.Config.Asn1ContextAttributes, new Asn1.Asn1OctetString(mechToken), new Asn1.Asn1OctetString(mechListMIC) ); SpngNegTokenInit spngToken = new SpngNegTokenInit(negToken); return(spngToken); }