/// <summary>Read SASL message and negotiated cipher option from server.</summary>
 /// <param name="in">stream to read</param>
 /// <returns>
 /// SaslResponseWithNegotiatedCipherOption SASL message and
 /// negotiated cipher option
 /// </returns>
 /// <exception cref="System.IO.IOException">for any error</exception>
 public static SaslResponseWithNegotiatedCipherOption ReadSaslMessageAndNegotiatedCipherOption
     (InputStream @in)
 {
     DataTransferProtos.DataTransferEncryptorMessageProto proto = DataTransferProtos.DataTransferEncryptorMessageProto
                                                                  .ParseFrom(PBHelper.VintPrefixed(@in));
     if (proto.GetStatus() == DataTransferProtos.DataTransferEncryptorMessageProto.DataTransferEncryptorStatus
         .ErrorUnknownKey)
     {
         throw new InvalidEncryptionKeyException(proto.GetMessage());
     }
     else
     {
         if (proto.GetStatus() == DataTransferProtos.DataTransferEncryptorMessageProto.DataTransferEncryptorStatus
             .Error)
         {
             throw new IOException(proto.GetMessage());
         }
         else
         {
             byte[] response = proto.GetPayload().ToByteArray();
             IList <CipherOption> options = PBHelper.ConvertCipherOptionProtos(proto.GetCipherOptionList
                                                                                   ());
             CipherOption option = null;
             if (options != null && !options.IsEmpty())
             {
                 option = options[0];
             }
             return(new SaslResponseWithNegotiatedCipherOption(response, option));
         }
     }
 }