Exemple #1
0
        public bool ValidateChecksum(IChecksumAlgorithm algorithm)
        {
            var recieved = RemoveLastBytes(algorithm.ChecksumSize);
            var computed = algorithm.ComputeChecksum(Content);

            return(recieved.SequenceEqual(computed));
        }
Exemple #2
0
        public Message ComputeChecksum(IChecksumAlgorithm algorithm)
        {
            var checksum = algorithm.ComputeChecksum(Content);

            AddBytes(checksum);
            return(this);
        }
Exemple #3
0
 internal CompressedStream(
     Stream baseStream,
     StreamOperationMode mode,
     ICompressionAlgorithm compressionAlgorithm,
     IChecksumAlgorithm checksumAlgorithm)
     : base(baseStream, mode)
 {
     if (compressionAlgorithm == null)
     {
         throw new ArgumentNullException(nameof(compressionAlgorithm));
     }
     this.Initialize(baseStream, compressionAlgorithm, checksumAlgorithm);
 }
Exemple #4
0
        public CompressedStream(
            Stream baseStream,
            StreamOperationMode mode,
            CompressionSettings settings,
            bool useCrc32,
            EncryptionSettings encryptionSettings)
            : base(baseStream, mode)
        {
            baseStream = encryptionSettings != null ? (Stream) new CryptoStream(baseStream, mode, PlatformSettings.Manager.GetCryptoProvider(encryptionSettings)) : baseStream;
            ICompressionAlgorithm compressionAlgorithm = ZipHelper.GetCompressionAlgorithm(settings);
            IChecksumAlgorithm    checksumAlgorithm    = useCrc32 ? (IChecksumAlgorithm) new Crc32() : (IChecksumAlgorithm) new Adler32();

            this.Initialize(baseStream, compressionAlgorithm, checksumAlgorithm);
        }
Exemple #5
0
        private void Initialize(
            Stream baseStream,
            ICompressionAlgorithm compressionAlgorithm,
            IChecksumAlgorithm checksumAlgorithm)
        {
            this.BaseStream        = baseStream;
            this.algorithm         = compressionAlgorithm;
            this.ChecksumAlgorithm = checksumAlgorithm;
            switch (this.Mode)
            {
            case StreamOperationMode.Read:
                this.Transform = this.algorithm.CreateDecompressor();
                break;

            case StreamOperationMode.Write:
                this.Transform = this.algorithm.CreateCompressor();
                break;
            }
        }