Skip to content

Commit

Permalink
Try wrapping like gzip
Browse files Browse the repository at this point in the history
  • Loading branch information
jbtule committed Nov 20, 2024
1 parent 08b35b1 commit f34b58c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Keyczar/Keyczar/Crypter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public void Decrypt(Stream input, Stream output, long inputLength = -1)
if(Compression == CompressionType.Gzip){
wrapper = new WriteDecompressGzipStream(baseStream);
}else if(Compression == CompressionType.Zlib){
wrapper = new InflaterInputStream (baseStream, new Inflater(false)){IsStreamOwner = false};
wrapper = new WriteDecompressZlibStream (baseStream);
}

//Perform Decryption
Expand Down
24 changes: 21 additions & 3 deletions Keyczar/Keyczar/Util/WriteDecompressGzipStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,30 @@
using System;
using System.IO;
using System.IO.Compression;
using ICSharpCode.SharpZipLib.Zip.Compression;
using ICSharpCode.SharpZipLib.Zip.Compression.Streams;

namespace Keyczar.Util
{

public class WriteDecompressGzipStream : WriteDecompressStreamWrapper
{
public WriteDecompressGzipStream(Stream stream) : base(stream, s => new GZipStream(s, CompressionMode.Decompress, true))
{
}
}

public class WriteDecompressZlibStream : WriteDecompressStreamWrapper
{
public WriteDecompressZlibStream(Stream stream) : base(stream, s => new InflaterInputStream(s, new Inflater()){ IsStreamOwner = false})
{
}
}

/// <summary>
/// Decompress a giz
/// </summary>
public class WriteDecompressGzipStream : Stream
public class WriteDecompressStreamWrapper : Stream
{
private Stream _stream;
private Stream _tempStream;
Expand All @@ -33,10 +50,11 @@ public class WriteDecompressGzipStream : Stream
/// Initializes a new instance of the <see cref="WriteDecompressGzipStream"/> class.
/// </summary>
/// <param name="stream">The stream.</param>
public WriteDecompressGzipStream(Stream stream) : base()
/// <param name="constructor">Function to construct the inflating stream</param>
public WriteDecompressStreamWrapper(Stream stream, Func<Stream,Stream> constructor) : base()
{
_tempStream = new MemoryStream();
_gzipread = new GZipStream(_tempStream, CompressionMode.Decompress, true);
_gzipread = constructor(_tempStream);
_stream = stream;
}

Expand Down

0 comments on commit f34b58c

Please sign in to comment.