diff --git a/src/SharpCompress/Archives/Rar/SeekableFilePart.cs b/src/SharpCompress/Archives/Rar/SeekableFilePart.cs index 13048d4c..97822d90 100644 --- a/src/SharpCompress/Archives/Rar/SeekableFilePart.cs +++ b/src/SharpCompress/Archives/Rar/SeekableFilePart.cs @@ -6,8 +6,8 @@ namespace SharpCompress.Archives.Rar; internal class SeekableFilePart : RarFilePart { - private readonly Stream stream; - private readonly string? password; + private readonly Stream _stream; + private readonly string? _password; internal SeekableFilePart( MarkHeader mh, @@ -18,27 +18,27 @@ internal class SeekableFilePart : RarFilePart ) : base(mh, fh, index) { - this.stream = stream; - this.password = password; + _stream = stream; + _password = password; } internal override Stream GetCompressedStream() { - stream.Position = FileHeader.DataStartPosition; + _stream.Position = FileHeader.DataStartPosition; if (FileHeader.R4Salt != null) { - var cryptKey = new CryptKey3(password!); - return new RarCryptoWrapper(stream, FileHeader.R4Salt, cryptKey); + var cryptKey = new CryptKey3(_password!); + return new RarCryptoWrapper(_stream, FileHeader.R4Salt, cryptKey); } if (FileHeader.Rar5CryptoInfo != null) { - var cryptKey = new CryptKey5(password!, FileHeader.Rar5CryptoInfo); - return new RarCryptoWrapper(stream, FileHeader.Rar5CryptoInfo.Salt, cryptKey); + var cryptKey = new CryptKey5(_password!, FileHeader.Rar5CryptoInfo); + return new RarCryptoWrapper(_stream, FileHeader.Rar5CryptoInfo.Salt, cryptKey); } - return stream; + return _stream; } internal override string FilePartName => "Unknown Stream - File Entry: " + FileHeader.FileName; diff --git a/src/SharpCompress/Common/ArchiveEncoding.cs b/src/SharpCompress/Common/ArchiveEncoding.cs index f66044d3..3701a93b 100644 --- a/src/SharpCompress/Common/ArchiveEncoding.cs +++ b/src/SharpCompress/Common/ArchiveEncoding.cs @@ -8,12 +8,12 @@ public class ArchiveEncoding /// /// Default encoding to use when archive format doesn't specify one. /// - public Encoding Default { get; set; } + public Encoding? Default { get; set; } /// /// ArchiveEncoding used by encryption schemes which don't comply with RFC 2898. /// - public Encoding Password { get; set; } + public Encoding? Password { get; set; } /// /// Set this encoding when you want to force it for all encoding operations. @@ -50,6 +50,8 @@ public class ArchiveEncoding public Encoding GetEncoding() => Forced ?? Default ?? Encoding.UTF8; + public Encoding GetPasswordEncoding() => Password ?? Encoding.UTF8; + public Func GetDecoder() => CustomDecoder ?? ((bytes, index, count) => GetEncoding().GetString(bytes, index, count)); } diff --git a/src/SharpCompress/Common/Tar/TarEntry.cs b/src/SharpCompress/Common/Tar/TarEntry.cs index ae49e1fc..2597b837 100644 --- a/src/SharpCompress/Common/Tar/TarEntry.cs +++ b/src/SharpCompress/Common/Tar/TarEntry.cs @@ -57,17 +57,17 @@ public class TarEntry : Entry ArchiveEncoding archiveEncoding ) { - foreach (var h in TarHeaderFactory.ReadHeader(mode, stream, archiveEncoding)) + foreach (var header in TarHeaderFactory.ReadHeader(mode, stream, archiveEncoding)) { - if (h != null) + if (header != null) { if (mode == StreamingMode.Seekable) { - yield return new TarEntry(new TarFilePart(h, stream), compressionType); + yield return new TarEntry(new TarFilePart(header, stream), compressionType); } else { - yield return new TarEntry(new TarFilePart(h, null), compressionType); + yield return new TarEntry(new TarFilePart(header, null), compressionType); } } else diff --git a/src/SharpCompress/Common/Zip/PkwareTraditionalEncryptionData.cs b/src/SharpCompress/Common/Zip/PkwareTraditionalEncryptionData.cs index b5d4b0fb..7b517857 100644 --- a/src/SharpCompress/Common/Zip/PkwareTraditionalEncryptionData.cs +++ b/src/SharpCompress/Common/Zip/PkwareTraditionalEncryptionData.cs @@ -103,7 +103,7 @@ internal class PkwareTraditionalEncryptionData internal byte[] StringToByteArray(string value) { - var a = _archiveEncoding.Password.GetBytes(value); + var a = _archiveEncoding.GetPasswordEncoding().GetBytes(value); return a; }