예제 #1
0
        /// <summary>
        /// Opens an existing stream and optionally verifies the stream
        /// </summary>
        /// <param name="stream">The stream to open</param>
        /// <param name="mode">The verification to use</param>
        public AssuredStream(Stream stream, VerificationMode mode)
            : this(stream, false)
        {
            _header = new AssuredStreamHeader(stream, mode);

            if (mode == VerificationMode.Full)
            {
                if (!_seekable)
                {
                    throw new InvalidOperationException("Can't fully verify unseekable streams");
                }

                _basePosition = stream.Position;
                if (!_header.VerifyHash(stream))
                {
                    throw new CryptographicException("Invalid hash value");
                }

                stream.Position = _basePosition;
            }
            else
            {
                _basePosition = stream.CanSeek ? stream.Position : 0;
            }
        }
예제 #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AssuredStream"/> class.
        /// </summary>
        /// <param name="stream">The stream.</param>
        /// <param name="args">The args.</param>
        public AssuredStream(Stream stream, AssuredStreamCreateArgs args)
            : this(stream, true)
        {
            if (args == null)
            {
                throw new ArgumentNullException("args");
            }

            args.VerifyArgs("args");

            long pos = stream.Position;

            _header = new AssuredStreamHeader(args);
            _header.WriteHeader(stream);

            _basePosition = stream.Position;
        }