Skip to content

Commit

Permalink
.NET7 (#8)
Browse files Browse the repository at this point in the history
* net7.0

* Update packages
  • Loading branch information
Rans4ckeR authored Nov 25, 2022
1 parent 61c97a4 commit 92f2c5b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Setup .NET Core SDK
uses: actions/setup-dotnet@main
with:
dotnet-version: '6.x.x'
dotnet-version: '7.x.x'
- name: Install GitVersion
uses: gittools/actions/gitversion/setup@main
with:
Expand Down
4 changes: 2 additions & 2 deletions Rampastring.Tools.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net48;net6.0</TargetFrameworks>
<TargetFrameworks>net7.0;net48</TargetFrameworks>
<Title>Rampastring.Tools</Title>
<Description>Rampastring's Generally Useful Library</Description>
<Company>Rampastring</Company>
Expand Down Expand Up @@ -34,7 +34,7 @@
<None Include="README.md" Pack="true" PackagePath="\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.2.63-beta" PrivateAssets="All" />
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.2.138-beta" PrivateAssets="All" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
</ItemGroup>
</Project>
24 changes: 15 additions & 9 deletions Utilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,15 @@ public static string CalculateSHA1ForFile(string path)
if (!fileInfo.Exists)
return string.Empty;

#pragma warning disable CA5350 // Do Not Use Weak Cryptographic Algorithms
using SHA1 sha1 = new SHA1CryptoServiceProvider();
#pragma warning restore CA5350 // Do Not Use Weak Cryptographic Algorithms
using Stream stream = fileInfo.OpenRead();
#pragma warning disable CA5350 // Do Not Use Weak Cryptographic Algorithms
#if NETFRAMEWORK
using SHA1 sha1 = SHA1.Create();
byte[] hash = sha1.ComputeHash(stream);
#else
byte[] hash = SHA1.HashData(stream);
#endif
#pragma warning restore CA5350 // Do Not Use Weak Cryptographic Algorithms

return BytesToString(hash);
}
Expand All @@ -41,14 +45,16 @@ public static string CalculateSHA1ForFile(string path)
/// <returns>A string that represents the input string's SHA1.</returns>
public static string CalculateSHA1ForString(string str)
{
byte[] buffer = Encoding.ASCII.GetBytes(str);
#pragma warning disable CA5350 // Do Not Use Weak Cryptographic Algorithms
using (SHA1 sha1 = new SHA1CryptoServiceProvider())
{
byte[] buffer = Encoding.ASCII.GetBytes(str);
byte[] hash = sha1.ComputeHash(buffer);
return BytesToString(hash);
}
#if NETFRAMEWORK
using SHA1 sha1 = SHA1.Create();
byte[] hash = sha1.ComputeHash(buffer);
#else
byte[] hash = SHA1.HashData(buffer);
#endif
#pragma warning restore CA5350 // Do Not Use Weak Cryptographic Algorithms
return BytesToString(hash);
}

private static string BytesToString(byte[] bytes)
Expand Down

0 comments on commit 92f2c5b

Please sign in to comment.