private T GetStrongestDescriptor <T>(Stream baseStream, IAlgorithmContainer <T> container, IKeyExchangeAlgorithm exchangeAlgorithm) where T : IAlgorithmDescriptor
        {
            var localAlgorithms = container.SupportedAlgorithms.ToArray();

            WriteAlgorithms(baseStream, localAlgorithms, exchangeAlgorithm);
            var remoteAlgorithms = ReadRemoteAlgorithms(baseStream, exchangeAlgorithm);
            var strongestCommon  = GetStrongestCommonDescriptor(localAlgorithms.Cast <IAlgorithmDescriptor>(), remoteAlgorithms);

            if (null == strongestCommon)
            {
                throw new InvalidOperationException("The remote endpoint does not support any key exchange algorithms that the local endpoint supports");
            }
            return((T)strongestCommon);
        }
 public KeyExchangeLinkNegotiator(IAlgorithmContainer <IKeyExchangeAlgorithmDescriptor> keyExchangeBuilder,
                                  IAlgorithmContainer <ISymmetricAlgorithmDescriptor> transportAlgorithmBuilder)
 {
     this.keyExchangeBuilder        = Guard.IsNull(() => keyExchangeBuilder);
     this.transportAlgorithmBuilder = Guard.IsNull(() => transportAlgorithmBuilder);
 }