/// <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 SpngNegTokenResp. /// </summary> /// <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>SpngNegTokenResp packet</returns> public SpngNegTokenResp CreateNegTokenResp(NegState negotiationState, byte[] responseToken, byte[] mechListMIC) { Asn1OctetString asn1RespToken = null; Asn1OctetString asn1MechListMIC = null; if (responseToken != null) { asn1RespToken = new Asn1OctetString(responseToken); } if (mechListMIC != null) { asn1MechListMIC = new Asn1OctetString(mechListMIC); } NegTokenResp negToken = new NegTokenResp(negotiationState, this.Context.NegotiatedMechType, asn1RespToken, asn1MechListMIC); SpngNegTokenResp spngToken = new SpngNegTokenResp(negToken); return(spngToken); }