diff --git a/src/SharpCompress/Archive/Rar/SeekableFilePart.cs b/src/SharpCompress/Archive/Rar/SeekableFilePart.cs index d89fb1ba..f052f22a 100644 --- a/src/SharpCompress/Archive/Rar/SeekableFilePart.cs +++ b/src/SharpCompress/Archive/Rar/SeekableFilePart.cs @@ -20,10 +20,12 @@ namespace SharpCompress.Archive.Rar internal override Stream GetCompressedStream() { stream.Position = FileHeader.DataStartPosition; +#if !NO_CRYPTO if (FileHeader.Salt != null) { return new RarCryptoWrapper(stream, password, FileHeader.Salt); } +#endif return stream; } diff --git a/src/SharpCompress/Common/Rar/Headers/FileHeader.cs b/src/SharpCompress/Common/Rar/Headers/FileHeader.cs index c76c005d..99e135f0 100644 --- a/src/SharpCompress/Common/Rar/Headers/FileHeader.cs +++ b/src/SharpCompress/Common/Rar/Headers/FileHeader.cs @@ -161,7 +161,7 @@ namespace SharpCompress.Common.Rar.Headers private static string ConvertPath(string path, HostOS os) { -#if DOTNET51 +#if NO_FILE return path.Replace('\\', '/'); #else switch (os) diff --git a/src/SharpCompress/Common/Rar/Headers/RarHeaderFactory.cs b/src/SharpCompress/Common/Rar/Headers/RarHeaderFactory.cs index ed803e82..bd83874f 100644 --- a/src/SharpCompress/Common/Rar/Headers/RarHeaderFactory.cs +++ b/src/SharpCompress/Common/Rar/Headers/RarHeaderFactory.cs @@ -117,6 +117,7 @@ namespace SharpCompress.Common.Rar.Headers private RarHeader ReadNextHeader(Stream stream) { +#if !NO_CRYPTO var reader = new RarCryptoBinaryReader(stream, Password); if (IsEncrypted) @@ -129,6 +130,10 @@ namespace SharpCompress.Common.Rar.Headers byte[] salt = reader.ReadBytes(8); reader.InitializeAes(salt); } +#else + var reader = new MarkingBinaryReader(stream); + +#endif RarHeader header = RarHeader.Create(reader); if (header == null) @@ -218,7 +223,11 @@ namespace SharpCompress.Common.Rar.Headers } else { +#if !NO_CRYPTO fh.PackedStream = new RarCryptoWrapper(ms, Password, fh.Salt); +#else + throw new NotSupportedException("RarCrypto not supported"); +#endif } } break; diff --git a/src/SharpCompress/Common/Rar/RarCryptoBinaryReader.cs b/src/SharpCompress/Common/Rar/RarCryptoBinaryReader.cs index 952c015a..0dabc175 100644 --- a/src/SharpCompress/Common/Rar/RarCryptoBinaryReader.cs +++ b/src/SharpCompress/Common/Rar/RarCryptoBinaryReader.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +#if !NO_CRYPTO +using System.Collections.Generic; using System.IO; using SharpCompress.IO; @@ -78,4 +79,5 @@ namespace SharpCompress.Common.Rar ClearQueue(); } } -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/src/SharpCompress/Common/Rar/RarCryptoWrapper.cs b/src/SharpCompress/Common/Rar/RarCryptoWrapper.cs index af3b9d9b..aaa93a8e 100644 --- a/src/SharpCompress/Common/Rar/RarCryptoWrapper.cs +++ b/src/SharpCompress/Common/Rar/RarCryptoWrapper.cs @@ -1,3 +1,4 @@ +#if !NO_CRYPTO using System; using System.Collections.Generic; using System.IO; @@ -105,4 +106,5 @@ namespace SharpCompress.Common.Rar base.Dispose(disposing); } } -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/src/SharpCompress/Common/Rar/RarRijndael.cs b/src/SharpCompress/Common/Rar/RarRijndael.cs index e8986473..d30be5ab 100644 --- a/src/SharpCompress/Common/Rar/RarRijndael.cs +++ b/src/SharpCompress/Common/Rar/RarRijndael.cs @@ -1,4 +1,5 @@ -using System; +#if !NO_CRYPTO +using System; using System.Collections.Generic; using System.Linq; using System.Security.Cryptography; @@ -110,4 +111,5 @@ namespace SharpCompress.Common.Rar { } } -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/src/SharpCompress/Common/Zip/Headers/ZipFileEntry.cs b/src/SharpCompress/Common/Zip/Headers/ZipFileEntry.cs index 42b49734..164ac332 100644 --- a/src/SharpCompress/Common/Zip/Headers/ZipFileEntry.cs +++ b/src/SharpCompress/Common/Zip/Headers/ZipFileEntry.cs @@ -54,7 +54,7 @@ namespace SharpCompress.Common.Zip.Headers internal List Extra { get; set; } internal PkwareTraditionalEncryptionData PkwareTraditionalEncryptionData { get; set; } -#if !DOTNET51 +#if !NO_CRYPTO internal WinzipAesEncryptionData WinzipAesEncryptionData { get; set; } #endif diff --git a/src/SharpCompress/Common/Zip/WinzipAesCryptoStream.cs b/src/SharpCompress/Common/Zip/WinzipAesCryptoStream.cs index 30f9017b..415c0e97 100644 --- a/src/SharpCompress/Common/Zip/WinzipAesCryptoStream.cs +++ b/src/SharpCompress/Common/Zip/WinzipAesCryptoStream.cs @@ -1,3 +1,4 @@ +#if !NO_CRYPTO using System; using System.IO; using System.Security.Cryptography; @@ -178,3 +179,4 @@ namespace SharpCompress.Common.Zip } } } +#endif \ No newline at end of file diff --git a/src/SharpCompress/Common/Zip/WinzipAesEncryptionData.cs b/src/SharpCompress/Common/Zip/WinzipAesEncryptionData.cs index e5070dfd..fb6ea6e1 100644 --- a/src/SharpCompress/Common/Zip/WinzipAesEncryptionData.cs +++ b/src/SharpCompress/Common/Zip/WinzipAesEncryptionData.cs @@ -1,3 +1,4 @@ +#if !NO_CRYPTO using System; using System.Security.Cryptography; using System.Text; @@ -72,3 +73,4 @@ namespace SharpCompress.Common.Zip } } } +#endif \ No newline at end of file diff --git a/src/SharpCompress/Common/Zip/ZipFilePart.cs b/src/SharpCompress/Common/Zip/ZipFilePart.cs index cc73e1d5..fcd678cb 100644 --- a/src/SharpCompress/Common/Zip/ZipFilePart.cs +++ b/src/SharpCompress/Common/Zip/ZipFilePart.cs @@ -133,7 +133,7 @@ namespace SharpCompress.Common.Zip protected Stream GetCryptoStream(Stream plainStream) { if ((Header.CompressedSize == 0) -#if !DOTNET51 +#if !NO_CRYPTO && ((Header.PkwareTraditionalEncryptionData != null) || (Header.WinzipAesEncryptionData != null))) #else @@ -156,7 +156,7 @@ namespace SharpCompress.Common.Zip return new PkwareTraditionalCryptoStream(plainStream, Header.PkwareTraditionalEncryptionData, CryptoMode.Decrypt); } -#if !DOTNET51 +#if !NO_FILE if (Header.WinzipAesEncryptionData != null) { //only read 10 less because the last ten are auth bytes diff --git a/src/SharpCompress/Common/Zip/ZipHeaderFactory.cs b/src/SharpCompress/Common/Zip/ZipHeaderFactory.cs index dce9bab4..3275e345 100644 --- a/src/SharpCompress/Common/Zip/ZipHeaderFactory.cs +++ b/src/SharpCompress/Common/Zip/ZipHeaderFactory.cs @@ -132,7 +132,7 @@ namespace SharpCompress.Common.Zip } else { -#if DOTNET51 +#if NO_CRYPTO throw new NotSupportedException("Cannot decrypt Winzip AES with Silverlight or WP7."); #else diff --git a/src/SharpCompress/Compressor/LZMA/AesDecoderStream.cs b/src/SharpCompress/Compressor/LZMA/AesDecoderStream.cs index b3e61b92..83ef801b 100644 --- a/src/SharpCompress/Compressor/LZMA/AesDecoderStream.cs +++ b/src/SharpCompress/Compressor/LZMA/AesDecoderStream.cs @@ -1,4 +1,5 @@ -using System; +#if !NO_CRYPTO +using System; using System.IO; using System.Security.Cryptography; using System.Text; @@ -8,7 +9,7 @@ namespace SharpCompress.Compressor.LZMA { internal class AesDecoderStream : DecoderStream2 { - #region Variables +#region Variables private Stream mStream; private ICryptoTransform mDecoder; @@ -20,9 +21,9 @@ namespace SharpCompress.Compressor.LZMA private int mUnderflow; private bool isDisposed; - #endregion +#endregion - #region Stream Methods +#region Stream Methods public AesDecoderStream(Stream input, byte[] info, IPasswordProvider pass, long limit) { @@ -130,9 +131,9 @@ namespace SharpCompress.Compressor.LZMA return processed; } - #endregion +#endregion - #region Private Methods +#region Private Methods private void Init(byte[] info, out int numCyclesPower, out byte[] salt, out byte[] iv) { @@ -185,7 +186,7 @@ namespace SharpCompress.Compressor.LZMA } else { -#if DOTNET51 || DNXCORE50 +#if NO_FILE || DNXCORE50 using (IncrementalHash sha = IncrementalHash.CreateHash(HashAlgorithmName.SHA256)) { byte[] counter = new byte[8]; @@ -251,4 +252,5 @@ namespace SharpCompress.Compressor.LZMA #endregion } -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/src/SharpCompress/Compressor/LZMA/Log.cs b/src/SharpCompress/Compressor/LZMA/Log.cs index f4231c94..82a7ae4c 100644 --- a/src/SharpCompress/Compressor/LZMA/Log.cs +++ b/src/SharpCompress/Compressor/LZMA/Log.cs @@ -31,7 +31,7 @@ namespace SharpCompress.Compressor.LZMA if (_needsIndent) { _needsIndent = false; -#if !DOTNET51 +#if !NO_FILE System.Diagnostics.Debug.Write(_indent.Peek()); #endif } @@ -40,7 +40,7 @@ namespace SharpCompress.Compressor.LZMA public static void Write(object value) { EnsureIndent(); -#if !DOTNET51 +#if !NO_FILE System.Diagnostics.Debug.Write(value); #endif } @@ -48,7 +48,7 @@ namespace SharpCompress.Compressor.LZMA public static void Write(string text) { EnsureIndent(); -#if !DOTNET51 +#if !NO_FILE System.Diagnostics.Debug.Write(text); #endif } @@ -56,7 +56,7 @@ namespace SharpCompress.Compressor.LZMA public static void Write(string format, params object[] args) { EnsureIndent(); -#if !DOTNET51 +#if !NO_FILE System.Diagnostics.Debug.Write(string.Format(format, args)); #endif } diff --git a/src/SharpCompress/Compressor/LZMA/Registry.cs b/src/SharpCompress/Compressor/LZMA/Registry.cs index c80b6ab3..9f0c6723 100644 --- a/src/SharpCompress/Compressor/LZMA/Registry.cs +++ b/src/SharpCompress/Compressor/LZMA/Registry.cs @@ -33,7 +33,7 @@ namespace SharpCompress.Compressor.LZMA case k_LZMA: case k_LZMA2: return new LzmaStream(info, inStreams.Single(), -1, limit); -#if !DOTNET51 +#if !NO_CRYPTO case CMethodId.kAESId: return new AesDecoderStream(inStreams.Single(), info, pass, limit); #endif diff --git a/src/SharpCompress/project.json b/src/SharpCompress/project.json index 44a12660..b46296fa 100644 --- a/src/SharpCompress/project.json +++ b/src/SharpCompress/project.json @@ -22,7 +22,7 @@ }, ".NETPortable,Version=v4.5,Profile=Profile259": { "compilationOptions": { - "define": [ "PROFILE259", "NO_FILE" ] + "define": [ "PROFILE259", "NO_FILE", "NO_CRYPTO" ] }, "frameworkAssemblies": { "Microsoft.CSharp": "",