/// <summary>
 /// Creates a realtime crypto stream reader.
 /// </summary>
 /// <param name="source">The <see cref="IWireStreamReaderStrategy"/> to decorate.</param>
 /// <param name="sessionCrypto"></param>
 /// <param name="count">The amount of bytes to be read immediately.</param>
 public OneTimeCryptoStreamReader([NotNull] TStreamType source, [NotNull] ISessionPacketCryptoService sessionCrypto, int count)
     : base(new DefaultStreamReaderStrategy(new LazyCryptoStreamReader <TStreamType>(source, sessionCrypto).ReadBytes(count)) as TStreamType, sessionCrypto)            //Reads count many bytes and decrypts and creates a default reader around it
 {
     if (count < 0)
     {
         throw new ArgumentOutOfRangeException(nameof(count));
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Creates a realtime crypto stream reader.
        /// </summary>
        /// <param name="sessionCryptoService"></param>
        protected CryptoStreamService([NotNull] ISessionPacketCryptoService sessionCryptoService)
        {
            if (sessionCryptoService == null)
            {
                throw new ArgumentNullException(nameof(sessionCryptoService));
            }

            SessionCryptoService = sessionCryptoService;
        }
        /// <summary>
        /// Creates a realtime crypto stream reader.
        /// </summary>
        /// <param name="dest">The <see cref="IWireStreamWriterStrategy"/> to decorate.</param>
        /// <param name="sessionCrypto"></param>
        protected CryptoStreamWriter([NotNull] IWireStreamWriterStrategy dest, [NotNull] ISessionPacketCryptoService sessionCrypto)
            : base(sessionCrypto)
        {
            //We don't implement the writing ourselves because it could be a default behavior
            //our we may need network stream reading, which may block, or anything under the sun
            if (dest == null)
            {
                throw new ArgumentNullException(nameof(dest));
            }

            Dest = dest;
        }
        /// <summary>
        /// Creates a realtime crypto stream reader.
        /// </summary>
        /// <param name="source">The <see cref="TStreamType"/> to decorate.</param>
        /// <param name="sessionCrypto"></param>
        protected CryptoStreamReader([NotNull] TStreamType source, [NotNull] ISessionPacketCryptoService sessionCrypto)
            : base(sessionCrypto)
        {
            //We don't implement the reading ourselves because it could be a default behavior
            //our we may need network stream reading, which may block, or anything under the sun
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            Source = source;
        }
Exemplo n.º 5
0
        public OneTimeCryptoStreamWriter([NotNull] IWireStreamWriterStrategy dest, [NotNull] ISessionPacketCryptoService sessionCrypto)
            : base(dest, sessionCrypto)
        {
            //The starting state is default
            //The writer can only write when it's in default state.
            WriterState = State.Default;

            //Lazily encrypt the stream's bytes.
            //This means it can ONLY be done once.
            CryptoByteRepresentation = new Lazy <byte[]>(() =>
            {
                WriterState = State.Crypted;
                return(sessionCrypto.ProcessBytes(dest.GetBytes(), 0));
            }, true);
        }
 /// <summary>
 /// Creates a realtime crypto stream reader.
 /// </summary>
 /// <param name="dest">The <see cref="IWireStreamWriterStrategy"/> to decorate.</param>
 /// <param name="sessionCrypto"></param>
 public RealtimeCryptoStreamWriter([NotNull] IWireStreamWriterStrategy dest, [NotNull] ISessionPacketCryptoService sessionCrypto)
     : base(dest, sessionCrypto)
 {
 }
Exemplo n.º 7
0
 /// <summary>
 /// Creates a realtime crypto stream reader.
 /// </summary>
 /// <param name="source">The <see cref="IWireStreamReaderStrategy"/> to decorate.</param>
 /// <param name="sessionCrypto"></param>
 public LazyCryptoStreamReader([NotNull] TReaderType source, [NotNull] ISessionPacketCryptoService sessionCrypto)
     : base(source, sessionCrypto)
 {
 }
        /// <summary>
        /// Decorates the stream with async peek only functionality.
        /// This forces the decorated reader to peek for every peek or read.
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="cryptoService"></param>
        /// <returns></returns>
        public static IWireStreamReaderStrategyAsync WithLazyCryptoAsync <TReaderType>(this TReaderType reader, [NotNull] ISessionPacketCryptoService cryptoService)
            where TReaderType : IWireStreamReaderStrategy, IWireStreamReaderStrategyAsync
        {
            if (cryptoService == null)
            {
                throw new ArgumentNullException(nameof(cryptoService));
            }

            return(new LazyCryptoStreamReaderAsync(reader, cryptoService));
        }
 /// <inheritdoc />
 public LazyCryptoStreamReaderAsync([NotNull] IWireStreamReaderStrategyAsync source, [NotNull] ISessionPacketCryptoService sessionCrypto)
     : base(source, sessionCrypto)
 {
 }