public bool ValidateChecksum(IChecksumAlgorithm algorithm) { var recieved = RemoveLastBytes(algorithm.ChecksumSize); var computed = algorithm.ComputeChecksum(Content); return(recieved.SequenceEqual(computed)); }
public Message ComputeChecksum(IChecksumAlgorithm algorithm) { var checksum = algorithm.ComputeChecksum(Content); AddBytes(checksum); return(this); }
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); }
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); }
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; } }