From 176743ab5faec2dd275b5efd3a2dd62c610f237a Mon Sep 17 00:00:00 2001 From: Oren Novotny Date: Wed, 26 Feb 2014 10:08:50 -0500 Subject: Add BouncyCastle PCL files --- Crypto/src/crypto/tls/TlsDeflateCompression.cs | 45 ++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 Crypto/src/crypto/tls/TlsDeflateCompression.cs (limited to 'Crypto/src/crypto/tls/TlsDeflateCompression.cs') diff --git a/Crypto/src/crypto/tls/TlsDeflateCompression.cs b/Crypto/src/crypto/tls/TlsDeflateCompression.cs new file mode 100644 index 000000000..146c961c7 --- /dev/null +++ b/Crypto/src/crypto/tls/TlsDeflateCompression.cs @@ -0,0 +1,45 @@ +using System; +using System.IO; + +using Org.BouncyCastle.Utilities.Zlib; + +namespace Org.BouncyCastle.Crypto.Tls +{ + public class TlsDeflateCompression + : TlsCompression + { + protected ZStream zIn, zOut; + + public TlsDeflateCompression() + { + this.zIn = new ZStream(); + this.zIn.inflateInit(); + + this.zOut = new ZStream(); + // TODO Allow custom setting + this.zOut.deflateInit(JZlib.Z_DEFAULT_COMPRESSION); + } + + public virtual Stream Compress(Stream output) + { + return new DeflateOutputStream(output, zOut, true); + } + + public virtual Stream Decompress(Stream output) + { + return new DeflateOutputStream(output, zIn, false); + } + + protected class DeflateOutputStream : ZOutputStream + { + public DeflateOutputStream(Stream output, ZStream z, bool compress) + : base(output) + { + this.z = z; + this.compress = compress; + // TODO http://www.bolet.org/~pornin/deflate-flush.html says we should use Z_SYNC_FLUSH + this.FlushMode = JZlib.Z_PARTIAL_FLUSH; + } + } + } +} -- cgit 1.5.1