Skip to content

Commit

Permalink
Relese 2.7.5.2
Browse files Browse the repository at this point in the history
升级 SourceLink 包并移除 RecyclableMemoryStream
  • Loading branch information
hueifeng committed Sep 7, 2024
1 parent 69da777 commit 76adc09
Show file tree
Hide file tree
Showing 23 changed files with 81 additions and 119 deletions.
6 changes: 3 additions & 3 deletions common.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<Version>2.7.5.1</Version>
<Version>2.7.5.2</Version>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<NoWarn>1591</NoWarn>
Expand Down Expand Up @@ -30,9 +30,9 @@
<NoWarn>1701;1702;CS1591;CS1573</NoWarn>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1">
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
</Project>
5 changes: 3 additions & 2 deletions src/EPPlus/EPPlus/Compatibility/ImageCompat.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using OfficeOpenXml.Utils;
using System.IO;
using OfficeOpenXml.Utils;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Formats;

Expand All @@ -8,7 +9,7 @@ internal class ImageCompat
{
internal static byte[] GetImageAsByteArray(Image image, IImageFormat format)
{
using (var ms = RecyclableMemoryStream.GetStream())
using (var ms = new MemoryStream())
{
image.Save(ms, format);
return ms.ToArray();
Expand Down
44 changes: 22 additions & 22 deletions src/EPPlus/EPPlus/Encryption/EncryptionHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,23 +173,23 @@ private MemoryStream EncryptPackageAgile(byte[] package, ExcelEncryption encrypt
var VerifierHashKey = GetFinalHash(hashProvider, BlockKey_HashValue, baseHash);
var KeyValueKey = GetFinalHash(hashProvider, BlockKey_KeyValue, baseHash);

var ms = RecyclableMemoryStream.GetStream();
var ms = new MemoryStream();
EncryptAgileFromKey(encr, VerifierInputKey, encr.VerifierHashInput, 0, encr.VerifierHashInput.Length, encr.SaltValue, ms);
encr.EncryptedVerifierHashInput = ms.ToArray();

ms = RecyclableMemoryStream.GetStream();
ms = new MemoryStream();
EncryptAgileFromKey(encr, VerifierHashKey, encr.VerifierHash, 0, encr.VerifierHash.Length, encr.SaltValue, ms);
encr.EncryptedVerifierHash = ms.ToArray();

ms = RecyclableMemoryStream.GetStream();
ms = new MemoryStream();
EncryptAgileFromKey(encr, KeyValueKey, encr.KeyValue, 0, encr.KeyValue.Length, encr.SaltValue, ms);
encr.EncryptedKeyValue = ms.ToArray();

xml = encryptionInfo.Xml.OuterXml;

var byXml = Encoding.UTF8.GetBytes(xml);

ms = RecyclableMemoryStream.GetStream();
ms = new MemoryStream();
ms.Write(BitConverter.GetBytes((ushort)4), 0, 2); //Major Version
ms.Write(BitConverter.GetBytes((ushort)4), 0, 2); //Minor Version
ms.Write(BitConverter.GetBytes((uint)0x40), 0, 4); //Reserved
Expand All @@ -204,7 +204,7 @@ private MemoryStream EncryptPackageAgile(byte[] package, ExcelEncryption encrypt
//...and the encrypted package
doc.Storage.DataStreams.Add("EncryptedPackage", encrData);

ms = RecyclableMemoryStream.GetStream();
ms = new MemoryStream();
doc.Save(ms);
//ms.Write(e,0,e.Length);
return ms;
Expand All @@ -226,7 +226,7 @@ private byte[] EncryptDataAgile(byte[] data, EncryptionInfoAgile encryptionInfo,
int segment = 0;

//Encrypt the data
var ms = RecyclableMemoryStream.GetStream();
var ms = new MemoryStream();
ms.Write(BitConverter.GetBytes((ulong)data.Length), 0, 8);
while (pos < data.Length)
{
Expand All @@ -248,14 +248,14 @@ private byte[] EncryptDataAgile(byte[] data, EncryptionInfoAgile encryptionInfo,
private void SetHMAC(EncryptionInfoAgile ei, HashAlgorithm hashProvider, byte[] salt, byte[] data)
{
var iv = GetFinalHash(hashProvider, BlockKey_HmacKey, ei.KeyData.SaltValue);
var ms = RecyclableMemoryStream.GetStream();
var ms = new MemoryStream();
EncryptAgileFromKey(ei.KeyEncryptors[0], ei.KeyEncryptors[0].KeyValue, salt, 0L, salt.Length, iv, ms);
ei.DataIntegrity.EncryptedHmacKey = ms.ToArray();

var h = GetHmacProvider(ei.KeyEncryptors[0], salt);
var hmacValue = h.ComputeHash(data);

ms = RecyclableMemoryStream.GetStream();
ms = new MemoryStream();
iv = GetFinalHash(hashProvider, BlockKey_HmacValue, ei.KeyData.SaltValue);
EncryptAgileFromKey(ei.KeyEncryptors[0], ei.KeyEncryptors[0].KeyValue, hmacValue, 0L, hmacValue.Length, iv, ms);
ei.DataIntegrity.EncryptedHmacValue = ms.ToArray();
Expand Down Expand Up @@ -308,12 +308,12 @@ private MemoryStream EncryptPackageBinary(byte[] package, ExcelEncryption encryp

//Encrypt the package
byte[] encryptedPackage = EncryptData(encryptionKey, package, false);
MemoryStream ms = RecyclableMemoryStream.GetStream();
MemoryStream ms = new MemoryStream();
ms.Write(BitConverter.GetBytes((ulong)package.Length), 0, 8);
ms.Write(encryptedPackage, 0, encryptedPackage.Length);
doc.Storage.DataStreams.Add("EncryptedPackage", ms.ToArray());

var ret = RecyclableMemoryStream.GetStream();
var ret = new MemoryStream();
doc.Save(ret);

return ret;
Expand Down Expand Up @@ -341,7 +341,7 @@ private void CreateDataSpaces(CompoundDocument doc)
}
private byte[] CreateStrongEncryptionDataSpaceStream()
{
MemoryStream ms = RecyclableMemoryStream.GetStream();
MemoryStream ms = new MemoryStream();
BinaryWriter bw = new BinaryWriter(ms);

bw.Write((int)8); //HeaderLength
Expand All @@ -356,7 +356,7 @@ private byte[] CreateStrongEncryptionDataSpaceStream()
}
private byte[] CreateVersionStream()
{
MemoryStream ms = RecyclableMemoryStream.GetStream();
MemoryStream ms = new MemoryStream();
BinaryWriter bw = new BinaryWriter(ms);

bw.Write((short)0x3C); //Major
Expand All @@ -371,7 +371,7 @@ private byte[] CreateVersionStream()
}
private byte[] CreateDataSpaceMap()
{
MemoryStream ms = RecyclableMemoryStream.GetStream();
MemoryStream ms = new MemoryStream();
BinaryWriter bw = new BinaryWriter(ms);

bw.Write((int)8); //HeaderLength
Expand All @@ -391,7 +391,7 @@ private byte[] CreateDataSpaceMap()
}
private byte[] CreateTransformInfoPrimary()
{
MemoryStream ms = RecyclableMemoryStream.GetStream();
MemoryStream ms = new MemoryStream();
BinaryWriter bw = new BinaryWriter(ms);
string TransformID = "{FF9A3F03-56EF-4613-BDD5-5A41C1D07246}";
string TransformName = "Microsoft.Container.EncryptionTransform";
Expand Down Expand Up @@ -485,7 +485,7 @@ private byte[] EncryptData(byte[] key, byte[] data, bool useDataSize)

//Encrypt the data
var crypt = aes.CreateEncryptor(key, null);
var ms = RecyclableMemoryStream.GetStream();
var ms = new MemoryStream();
var cs = new CryptoStream(ms, crypt, CryptoStreamMode.Write);
cs.Write(data, 0, data.Length);

Expand All @@ -506,7 +506,7 @@ private byte[] EncryptData(byte[] key, byte[] data, bool useDataSize)
}
private MemoryStream GetStreamFromPackage(CompoundDocument doc, ExcelEncryption encryption)
{
//var ret = RecyclableMemoryStream.GetStream();
//var ret = new MemoryStream();
if (doc.Storage.DataStreams.ContainsKey("EncryptionInfo") ||
doc.Storage.DataStreams.ContainsKey("EncryptedPackage"))
{
Expand Down Expand Up @@ -553,7 +553,7 @@ private MemoryStream DecryptDocument(byte[] data, EncryptionInfo encryptionInfo,

private MemoryStream DecryptAgile(EncryptionInfoAgile encryptionInfo, string password, long size, byte[] encryptedData, byte[] data)
{
MemoryStream doc = RecyclableMemoryStream.GetStream();
MemoryStream doc = new MemoryStream();

if (encryptionInfo.KeyData.CipherAlgorithm == eCipherAlgorithm.AES)
{
Expand Down Expand Up @@ -665,7 +665,7 @@ private HashAlgorithm GetHashProvider(EncryptionInfoAgile.EncryptionKeyData encr
#endif
private MemoryStream DecryptBinary(EncryptionInfoBinary encryptionInfo, string password, long size, byte[] encryptedData)
{
MemoryStream doc = RecyclableMemoryStream.GetStream();
MemoryStream doc = new MemoryStream();

if (encryptionInfo.Header.AlgID == AlgorithmID.AES128 || (encryptionInfo.Header.AlgID == AlgorithmID.Flags && ((encryptionInfo.Flags & (Flags.fAES | Flags.fExternal | Flags.fCryptoAPI)) == (Flags.fAES | Flags.fCryptoAPI)))
||
Expand All @@ -690,7 +690,7 @@ private MemoryStream DecryptBinary(EncryptionInfoBinary encryptionInfo, string p
key,
null);

var dataStream = RecyclableMemoryStream.GetStream(encryptedData);
var dataStream = new MemoryStream(encryptedData);
var cryptoStream = new CryptoStream(dataStream,
decryptor,
CryptoStreamMode.Read);
Expand Down Expand Up @@ -730,14 +730,14 @@ private bool IsPasswordValid(byte[] key, EncryptionInfoBinary encryptionInfo)


//Decrypt the verifier
MemoryStream dataStream = RecyclableMemoryStream.GetStream(encryptionInfo.Verifier.EncryptedVerifier);
MemoryStream dataStream = new MemoryStream(encryptionInfo.Verifier.EncryptedVerifier);
CryptoStream cryptoStream = new CryptoStream(dataStream,
decryptor,
CryptoStreamMode.Read);
var decryptedVerifier = new byte[16];
cryptoStream.Read(decryptedVerifier, 0, 16);

dataStream = RecyclableMemoryStream.GetStream(encryptionInfo.Verifier.EncryptedVerifierHash);
dataStream = new MemoryStream(encryptionInfo.Verifier.EncryptedVerifierHash);

cryptoStream = new CryptoStream(dataStream,
decryptor,
Expand Down Expand Up @@ -803,7 +803,7 @@ private byte[] DecryptAgileFromKey(EncryptionInfoAgile.EncryptionKeyData encr, b
FixHashSize(iv, encr.BlockSize, 0x36));


MemoryStream dataStream = RecyclableMemoryStream.GetStream(encryptedData);
MemoryStream dataStream = new MemoryStream(encryptedData);

CryptoStream cryptoStream = new CryptoStream(dataStream,
decryptor,
Expand Down
2 changes: 1 addition & 1 deletion src/EPPlus/EPPlus/Encryption/EncryptionHeader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ internal class EncryptionHeader
internal string CSPName; //SHOULD<11> be set to either "Microsoft Enhanced RSA and AES Cryptographic Provider" or "Microsoft Enhanced RSA and AES Cryptographic Provider (Prototype)" as a null-terminated Unicode string.
internal byte[] WriteBinary()
{
MemoryStream ms = RecyclableMemoryStream.GetStream();
MemoryStream ms = new MemoryStream();
BinaryWriter bw = new BinaryWriter(ms);

bw.Write((int)Flags);
Expand Down
2 changes: 1 addition & 1 deletion src/EPPlus/EPPlus/Encryption/EncryptionInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ internal override void Read(byte[] data)
}
internal byte[] WriteBinary()
{
MemoryStream ms = RecyclableMemoryStream.GetStream();
MemoryStream ms = new MemoryStream();
BinaryWriter bw = new BinaryWriter(ms);

bw.Write(MajorVersion);
Expand Down
2 changes: 1 addition & 1 deletion src/EPPlus/EPPlus/Encryption/EncryptionVerifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ internal class EncryptionVerifier
internal byte[] EncryptedVerifierHash; //(variable): An array of bytes that contains the encrypted form of the hash of the randomly generated Verifier value. The length of the array MUST be the size of the encryption block size multiplied by the number of blocks needed to encrypt the hash of the Verifier. If the encryption algorithm is RC4, the length MUST be 20 bytes. If the encryption algorithm is AES, the length MUST be 32 bytes.
internal byte[] WriteBinary()
{
MemoryStream ms = RecyclableMemoryStream.GetStream();
MemoryStream ms = new MemoryStream();
BinaryWriter bw = new BinaryWriter(ms);

bw.Write(SaltSize);
Expand Down
18 changes: 9 additions & 9 deletions src/EPPlus/EPPlus/ExcelPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -555,8 +555,8 @@ private void CreateFromTemplate(FileInfo template, string password)
if (template != null) template.Refresh();
if (template.Exists)
{
if (_stream == null) _stream = RecyclableMemoryStream.GetStream();
var ms = RecyclableMemoryStream.GetStream();
if (_stream == null) _stream = new MemoryStream();
var ms = new MemoryStream();
if (password != null)
{
Encryption.IsEncrypted = true;
Expand Down Expand Up @@ -592,8 +592,8 @@ private void CreateFromTemplate(FileInfo template, string password)
}
private void ConstructNewFile(string password)
{
var ms = RecyclableMemoryStream.GetStream();
if (_stream == null) _stream = RecyclableMemoryStream.GetStream();
var ms = new MemoryStream();
if (_stream == null) _stream = new MemoryStream();
if (File != null) File.Refresh();
if (File != null && File.Exists)
{
Expand Down Expand Up @@ -842,7 +842,7 @@ public void Save()
{
if (Encryption.IsEncrypted)
{
var ms = RecyclableMemoryStream.GetStream();
var ms = new MemoryStream();
_package.Save(ms);
byte[] file = ms.ToArray();
EncryptedPackageHandler eph = new EncryptedPackageHandler();
Expand Down Expand Up @@ -999,7 +999,7 @@ internal void CloseStream()
_stream.Dispose();
}

_stream = RecyclableMemoryStream.GetStream();
_stream = new MemoryStream();
}
/// <summary>
/// The output stream. This stream is the not the encrypted package.
Expand Down Expand Up @@ -1166,7 +1166,7 @@ internal async Task<byte[]> GetAsByteArrayAsync(bool save)
/// <param name="input">The input.</param>
public void Load(Stream input)
{
Load(input, RecyclableMemoryStream.GetStream(), null);
Load(input, new MemoryStream(), null);
}
/// <summary>
/// Loads the specified package data from a stream.
Expand All @@ -1175,7 +1175,7 @@ public void Load(Stream input)
/// <param name="Password">The password to decrypt the document</param>
public void Load(Stream input, string Password)
{
Load(input, RecyclableMemoryStream.GetStream(), Password);
Load(input, new MemoryStream(), Password);
}
/// <summary>
///
Expand Down Expand Up @@ -1205,7 +1205,7 @@ private void Load(Stream input, Stream output, string Password)
}
else
{
Stream ms = RecyclableMemoryStream.GetStream();
Stream ms = new MemoryStream();
this._stream = output;
if (Password != null)
{
Expand Down
2 changes: 1 addition & 1 deletion src/EPPlus/EPPlus/ExcelWorksheet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -899,7 +899,7 @@ private void CreateXml()

// now release stream buffer (already converted whole Xml into XmlDocument Object and String)
stream.Dispose();
packPart.Stream = RecyclableMemoryStream.GetStream();
packPart.Stream = new MemoryStream();

//first char is invalid sometimes??
if (xml[0] != '<')
Expand Down
1 change: 0 additions & 1 deletion src/EPPlus/EPPlus/Magicodes.IE.EPPlus.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="3.1.0" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.IO.RecyclableMemoryStream" Version="2.1.1" />
<PackageReference Include="SkiaSharp" Version="2.88.6" />
</ItemGroup>

Expand Down
4 changes: 2 additions & 2 deletions src/EPPlus/EPPlus/Packaging/DotNetZip/ZipFile.AddUpdate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1199,7 +1199,7 @@ public ZipEntry AddEntry(string entryName, string content, System.Text.Encoding
{
// cannot employ a using clause here. We need the stream to
// persist after exit from this method.
var ms = RecyclableMemoryStream.GetStream();
var ms = new MemoryStream();

// cannot use a using clause here; StreamWriter takes
// ownership of the stream and Disposes it before we are ready.
Expand Down Expand Up @@ -1858,7 +1858,7 @@ private void RemoveEntryForUpdate(string entryName)
public ZipEntry AddEntry(string entryName, byte[] byteContent)
{
if (byteContent == null) throw new ArgumentException("bad argument", "byteContent");
var ms = RecyclableMemoryStream.GetStream(byteContent);
var ms = new MemoryStream(byteContent);
return AddEntry(entryName, ms);
}

Expand Down
4 changes: 2 additions & 2 deletions src/EPPlus/EPPlus/Packaging/DotNetZip/ZipFile.Save.cs
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ public void Save(String fileName)
/// zip.Password = "VerySecret.";
/// zip.Encryption = EncryptionAlgorithm.WinZipAes128;
/// zip.AddFile(sourceFileName);
/// MemoryStream output = RecyclableMemoryStream.GetStream();
/// MemoryStream output = new MemoryStream();
/// zip.Save(output);
///
/// byte[] zipbytes = output.ToArray();
Expand Down Expand Up @@ -606,7 +606,7 @@ public static bool WriteCentralDirectoryStructure(Stream s,
// write to a memory stream in order to keep the
// CDR contiguous
Int64 aLength = 0;
using (var ms = RecyclableMemoryStream.GetStream())
using (var ms = new MemoryStream())
{
foreach (ZipEntry e in entries)
{
Expand Down
6 changes: 3 additions & 3 deletions src/EPPlus/EPPlus/Packaging/DotNetZip/Zlib/GZipStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -946,7 +946,7 @@ private int EmitHeader()
/// <returns>The string in compressed form</returns>
public static byte[] CompressString(String s)
{
using (var ms = RecyclableMemoryStream.GetStream())
using (var ms = new MemoryStream())
{
System.IO.Stream compressor =
new GZipStream(ms, CompressionMode.Compress, CompressionLevel.BestCompression);
Expand Down Expand Up @@ -974,7 +974,7 @@ public static byte[] CompressString(String s)
/// <returns>The data in compressed form</returns>
public static byte[] CompressBuffer(byte[] b)
{
using (var ms = RecyclableMemoryStream.GetStream())
using (var ms = new MemoryStream())
{
System.IO.Stream compressor =
new GZipStream(ms, CompressionMode.Compress, CompressionLevel.BestCompression);
Expand All @@ -999,7 +999,7 @@ public static byte[] CompressBuffer(byte[] b)
/// <returns>The uncompressed string</returns>
public static String UncompressString(byte[] compressed)
{
using (var input = RecyclableMemoryStream.GetStream(compressed))
using (var input = new MemoryStream(compressed))
{
Stream decompressor = new GZipStream(input, CompressionMode.Decompress);
return ZlibBaseStream.UncompressString(compressed, decompressor);
Expand Down
Loading

0 comments on commit 76adc09

Please sign in to comment.