Move to .NET 5.0

This commit is contained in:
Alex Barney 2020-11-15 14:53:08 -07:00
parent 46be7259d0
commit 25f8115600
20 changed files with 67 additions and 102 deletions

View file

@ -1 +1 @@
3.1.402
5.0.100

View file

@ -69,6 +69,19 @@ try {
}
}
# Make sure we have a 3.1 runtime. At the time of writing GitVersion doesn't have a 5.0 build
# Remove when a 5.0 build is available
if((& $env:DOTNET_EXE --list-runtimes | Out-String) -notlike "*Microsoft.NETCore.App 3.1.*") {
# Download install script
$DotNetInstallFile = "$TempDirectory\dotnet-install.ps1"
New-Item -ItemType Directory -Path $TempDirectory -Force | Out-Null
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
(New-Object System.Net.WebClient).DownloadFile($DotNetInstallUrl, $DotNetInstallFile)
ExecSafe { & $DotNetInstallFile -InstallDir $DotNetDirectory -Channel 3.1 -Runtime dotnet -NoPath }
}
Write-Output "Microsoft (R) .NET Core SDK version $(& $env:DOTNET_EXE --version)"
ExecSafe { & $env:DOTNET_EXE run --project $BuildProjectFile -- $BuildArguments }

View file

@ -74,6 +74,22 @@ elif [[ ! (-x "$DOTNET_EXE" && (-z ${DOTNET_VERSION+x} || $($DOTNET_EXE --versio
fi
fi
# Make sure we have a 3.1 runtime. At the time of writing GitVersion doesn't have a 5.0 build
# Remove when a 5.0 build is available
if [[ $($DOTNET_EXE --list-runtimes) != *"Microsoft.NETCore.App 3.1."* ]]; then
# Download install script
DOTNET_INSTALL_FILE="$TEMP_DIRECTORY/dotnet-install.sh"
mkdir -p "$TEMP_DIRECTORY"
if [ ! -x "$DOTNET_INSTALL_FILE" ]; then
curl -Lsfo "$DOTNET_INSTALL_FILE" "$DOTNET_INSTALL_URL"
chmod +x "$DOTNET_INSTALL_FILE"
fi
"$DOTNET_INSTALL_FILE" --install-dir "$DOTNET_DIRECTORY" --channel 3.1 --runtime dotnet --no-path
fi
echo "Microsoft (R) .NET Core SDK version $("$DOTNET_EXE" --version)"
"$DOTNET_EXE" run --project "$BUILD_PROJECT_FILE" -- ${BUILD_ARGUMENTS[@]}

View file

@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
@ -44,7 +43,7 @@ namespace LibHacBuild
AbsolutePath ArtifactsDirectory => RootDirectory / "artifacts";
AbsolutePath SignedArtifactsDirectory => ArtifactsDirectory / "signed";
AbsolutePath TempDirectory => RootDirectory / ".tmp";
AbsolutePath CliCoreDir => TempDirectory / "hactoolnet_netcoreapp3.1";
AbsolutePath CliCoreDir => TempDirectory / "hactoolnet_net5.0";
AbsolutePath CliNativeDir => TempDirectory / $"hactoolnet_{HostOsName}";
AbsolutePath CliNativeExe => CliNativeDir / $"hactoolnet{NativeProgramExtension}";
AbsolutePath CliCoreZip => ArtifactsDirectory / $"hactoolnet-{VersionString}-netcore.zip";
@ -221,7 +220,7 @@ namespace LibHacBuild
DotNetPublish(s => publishSettings
.SetProject(HactoolnetProject)
.SetFramework("netcoreapp3.1")
.SetFramework("net5.0")
.SetOutput(CliCoreDir)
.SetNoBuild(true)
.SetProperties(VersionProps));
@ -273,7 +272,7 @@ namespace LibHacBuild
.EnableNoBuild()
.SetConfiguration(Configuration);
if (EnvironmentInfo.IsUnix) settings = settings.SetProperty("TargetFramework", "netcoreapp3.1");
if (EnvironmentInfo.IsUnix) settings = settings.SetProperty("TargetFramework", "net5.0");
DotNetTest(s => settings);
});
@ -366,7 +365,6 @@ namespace LibHacBuild
}
}
[SuppressMessage("ReSharper", "PossibleNullReferenceException")]
public void BuildNative()
{
string buildType = Untrimmed ? "native-untrimmed" : "native";
@ -614,7 +612,7 @@ namespace LibHacBuild
SignAssemblies(password, toSign.Select(x => x.ToString()).ToArray());
// Avoid having multiple signed versions of the same file
File.Copy(nupkgDir / "lib" / "netcoreapp3.0" / "LibHac.dll", coreFxDir / "LibHac.dll", true);
File.Copy(nupkgDir / "lib" / "net5.0" / "LibHac.dll", coreFxDir / "LibHac.dll", true);
ZipDirectory(SignedArtifactsDirectory / Path.GetFileName(nupkgFile), nupkgDir, pkgFileList);
ZipDirectory(SignedArtifactsDirectory / Path.GetFileName(CliCoreZip), coreFxDir);

View file

@ -2,7 +2,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net5.0</TargetFramework>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<RootNamespace>LibHacBuild.CodeGen</RootNamespace>
<IsPackable>False</IsPackable>

View file

@ -2,7 +2,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net5.0</TargetFramework>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<RootNamespace>LibHacBuild</RootNamespace>
<IsPackable>False</IsPackable>

View file

@ -1,12 +1,10 @@
// ReSharper disable AssignmentIsFullyDiscarded
using System;
using System.Runtime.CompilerServices;
using LibHac.Diag;
#if HAS_INTRINSICS
using LibHac.Crypto.Detail;
using LibHac.Diag;
using AesNi = System.Runtime.Intrinsics.X86.Aes;
#endif
namespace LibHac.Crypto
{
@ -17,108 +15,95 @@ namespace LibHac.Crypto
public static bool IsAesNiSupported()
{
#if HAS_INTRINSICS
return AesNi.IsSupported;
#else
return false;
#endif
}
public static ICipher CreateEcbDecryptor(ReadOnlySpan<byte> key, bool preferDotNetCrypto = false)
{
#if HAS_INTRINSICS
if (IsAesNiSupported() && !preferDotNetCrypto)
{
return new AesEcbDecryptorNi(key);
}
#endif
return new AesEcbDecryptor(key);
}
public static ICipher CreateEcbEncryptor(ReadOnlySpan<byte> key, bool preferDotNetCrypto = false)
{
#if HAS_INTRINSICS
if (IsAesNiSupported() && !preferDotNetCrypto)
{
return new AesEcbEncryptorNi(key);
}
#endif
return new AesEcbEncryptor(key);
}
public static ICipher CreateCbcDecryptor(ReadOnlySpan<byte> key, ReadOnlySpan<byte> iv, bool preferDotNetCrypto = false)
{
#if HAS_INTRINSICS
if (IsAesNiSupported() && !preferDotNetCrypto)
{
return new AesCbcDecryptorNi(key, iv);
}
#endif
return new AesCbcDecryptor(key, iv);
}
public static ICipher CreateCbcEncryptor(ReadOnlySpan<byte> key, ReadOnlySpan<byte> iv, bool preferDotNetCrypto = false)
{
#if HAS_INTRINSICS
if (IsAesNiSupported() && !preferDotNetCrypto)
{
return new AesCbcEncryptorNi(key, iv);
}
#endif
return new AesCbcEncryptor(key, iv);
}
public static ICipherWithIv CreateCtrDecryptor(ReadOnlySpan<byte> key, ReadOnlySpan<byte> iv, bool preferDotNetCrypto = false)
{
#if HAS_INTRINSICS
if (IsAesNiSupported() && !preferDotNetCrypto)
{
return new AesCtrCipherNi(key, iv);
}
#endif
// Encryption and decryption in counter mode is the same operation
return CreateCtrEncryptor(key, iv, preferDotNetCrypto);
}
public static ICipherWithIv CreateCtrEncryptor(ReadOnlySpan<byte> key, ReadOnlySpan<byte> iv, bool preferDotNetCrypto = false)
{
#if HAS_INTRINSICS
if (IsAesNiSupported() && !preferDotNetCrypto)
{
return new AesCtrCipherNi(key, iv);
}
#endif
return new AesCtrCipher(key, iv);
}
public static ICipherWithIv CreateXtsDecryptor(ReadOnlySpan<byte> key1, ReadOnlySpan<byte> key2,
ReadOnlySpan<byte> iv, bool preferDotNetCrypto = false)
{
#if HAS_INTRINSICS
if (IsAesNiSupported() && !preferDotNetCrypto)
{
return new AesXtsDecryptorNi(key1, key2, iv);
}
#endif
return new AesXtsDecryptor(key1, key2, iv);
}
public static ICipherWithIv CreateXtsEncryptor(ReadOnlySpan<byte> key1, ReadOnlySpan<byte> key2,
ReadOnlySpan<byte> iv, bool preferDotNetCrypto = false)
{
#if HAS_INTRINSICS
if (IsAesNiSupported() && !preferDotNetCrypto)
{
return new AesXtsEncryptorNi(key1, key2, iv);
}
#endif
return new AesXtsEncryptor(key1, key2, iv);
}
public static void EncryptEcb128(ReadOnlySpan<byte> input, Span<byte> output, ReadOnlySpan<byte> key,
bool preferDotNetCrypto = false)
{
#if HAS_INTRINSICS
if (IsAesNiSupported() && !preferDotNetCrypto)
{
AesEcbModeNi cipherNi;
@ -128,7 +113,7 @@ namespace LibHac.Crypto
cipherNi.Encrypt(input, output);
return;
}
#endif
ICipher cipher = CreateEcbEncryptor(key, preferDotNetCrypto);
cipher.Transform(input, output);
@ -138,7 +123,6 @@ namespace LibHac.Crypto
public static void DecryptEcb128(ReadOnlySpan<byte> input, Span<byte> output, ReadOnlySpan<byte> key,
bool preferDotNetCrypto = false)
{
#if HAS_INTRINSICS
if (IsAesNiSupported() && !preferDotNetCrypto)
{
AesEcbModeNi cipherNi;
@ -148,7 +132,7 @@ namespace LibHac.Crypto
cipherNi.Decrypt(input, output);
return;
}
#endif
ICipher cipher = CreateEcbDecryptor(key, preferDotNetCrypto);
cipher.Transform(input, output);
@ -157,7 +141,6 @@ namespace LibHac.Crypto
public static void EncryptCbc128(ReadOnlySpan<byte> input, Span<byte> output, ReadOnlySpan<byte> key,
ReadOnlySpan<byte> iv, bool preferDotNetCrypto = false)
{
#if HAS_INTRINSICS
if (IsAesNiSupported() && !preferDotNetCrypto)
{
AesCbcModeNi cipherNi;
@ -167,7 +150,7 @@ namespace LibHac.Crypto
cipherNi.Encrypt(input, output);
return;
}
#endif
ICipher cipher = CreateCbcEncryptor(key, iv, preferDotNetCrypto);
cipher.Transform(input, output);
@ -176,7 +159,6 @@ namespace LibHac.Crypto
public static void DecryptCbc128(ReadOnlySpan<byte> input, Span<byte> output, ReadOnlySpan<byte> key,
ReadOnlySpan<byte> iv, bool preferDotNetCrypto = false)
{
#if HAS_INTRINSICS
if (IsAesNiSupported() && !preferDotNetCrypto)
{
AesCbcModeNi cipherNi;
@ -186,7 +168,7 @@ namespace LibHac.Crypto
cipherNi.Decrypt(input, output);
return;
}
#endif
ICipher cipher = CreateCbcDecryptor(key, iv, preferDotNetCrypto);
cipher.Transform(input, output);
@ -195,7 +177,6 @@ namespace LibHac.Crypto
public static void EncryptCtr128(ReadOnlySpan<byte> input, Span<byte> output, ReadOnlySpan<byte> key,
ReadOnlySpan<byte> iv, bool preferDotNetCrypto = false)
{
#if HAS_INTRINSICS
if (IsAesNiSupported() && !preferDotNetCrypto)
{
AesCtrModeNi cipherNi;
@ -205,7 +186,7 @@ namespace LibHac.Crypto
cipherNi.Transform(input, output);
return;
}
#endif
ICipher cipher = CreateCtrEncryptor(key, iv, preferDotNetCrypto);
cipher.Transform(input, output);
@ -214,7 +195,6 @@ namespace LibHac.Crypto
public static void DecryptCtr128(ReadOnlySpan<byte> input, Span<byte> output, ReadOnlySpan<byte> key,
ReadOnlySpan<byte> iv, bool preferDotNetCrypto = false)
{
#if HAS_INTRINSICS
if (IsAesNiSupported() && !preferDotNetCrypto)
{
AesCtrModeNi cipherNi;
@ -224,7 +204,7 @@ namespace LibHac.Crypto
cipherNi.Transform(input, output);
return;
}
#endif
ICipher cipher = CreateCtrDecryptor(key, iv, preferDotNetCrypto);
cipher.Transform(input, output);
@ -233,7 +213,6 @@ namespace LibHac.Crypto
public static void EncryptXts128(ReadOnlySpan<byte> input, Span<byte> output, ReadOnlySpan<byte> key1,
ReadOnlySpan<byte> key2, ReadOnlySpan<byte> iv, bool preferDotNetCrypto = false)
{
#if HAS_INTRINSICS
if (IsAesNiSupported() && !preferDotNetCrypto)
{
AesXtsModeNi cipherNi;
@ -243,7 +222,7 @@ namespace LibHac.Crypto
cipherNi.Encrypt(input, output);
return;
}
#endif
ICipher cipher = CreateXtsEncryptor(key1, key2, iv, preferDotNetCrypto);
cipher.Transform(input, output);
@ -252,7 +231,6 @@ namespace LibHac.Crypto
public static void DecryptXts128(ReadOnlySpan<byte> input, Span<byte> output, ReadOnlySpan<byte> key1,
ReadOnlySpan<byte> key2, ReadOnlySpan<byte> iv, bool preferDotNetCrypto = false)
{
#if HAS_INTRINSICS
if (IsAesNiSupported() && !preferDotNetCrypto)
{
AesXtsModeNi cipherNi;
@ -262,7 +240,7 @@ namespace LibHac.Crypto
cipherNi.Decrypt(input, output);
return;
}
#endif
ICipher cipher = CreateXtsDecryptor(key1, key2, iv, preferDotNetCrypto);
cipher.Transform(input, output);

View file

@ -1,5 +1,4 @@
#if HAS_INTRINSICS
using System;
using System;
using System.Runtime.CompilerServices;
using System.Runtime.Intrinsics;
using LibHac.Common;
@ -43,4 +42,3 @@ namespace LibHac.Crypto
}
}
}
#endif

View file

@ -1,5 +1,4 @@
#if HAS_INTRINSICS
using System;
using System;
using System.Runtime.CompilerServices;
using System.Runtime.Intrinsics;
using LibHac.Common;
@ -25,4 +24,3 @@ namespace LibHac.Crypto
}
}
}
#endif

View file

@ -1,5 +1,4 @@
#if HAS_INTRINSICS
using System;
using System;
using LibHac.Crypto.Detail;
namespace LibHac.Crypto
@ -36,4 +35,3 @@ namespace LibHac.Crypto
}
}
}
#endif

View file

@ -1,5 +1,4 @@
#if HAS_INTRINSICS
using System;
using System;
using System.Runtime.CompilerServices;
using System.Runtime.Intrinsics;
using LibHac.Common;
@ -43,4 +42,3 @@ namespace LibHac.Crypto
}
}
}
#endif

View file

@ -1,5 +1,4 @@
#if HAS_INTRINSICS
using System;
using System;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
@ -10,9 +9,7 @@ namespace LibHac.Crypto.Detail
{
public struct AesCbcModeNi
{
#pragma warning disable 649
private AesCoreNi _aesCore;
#pragma warning restore 649
public Vector128<byte> Iv;
@ -110,4 +107,3 @@ namespace LibHac.Crypto.Detail
}
}
}
#endif

View file

@ -1,5 +1,4 @@
#if HAS_INTRINSICS
using System;
using System;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
@ -578,4 +577,3 @@ namespace LibHac.Crypto.Detail
}
}
}
#endif

View file

@ -1,5 +1,4 @@
#if HAS_INTRINSICS
using System;
using System;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
@ -10,9 +9,7 @@ namespace LibHac.Crypto.Detail
{
public struct AesCtrModeNi
{
#pragma warning disable 649
private AesCoreNi _aesCore;
#pragma warning restore 649
public Vector128<byte> Iv;
@ -126,4 +123,3 @@ namespace LibHac.Crypto.Detail
}
}
}
#endif

View file

@ -1,13 +1,10 @@
#if HAS_INTRINSICS
using System;
using System;
namespace LibHac.Crypto.Detail
{
public struct AesEcbModeNi
{
#pragma warning disable 649
private AesCoreNi _aesCore;
#pragma warning restore 649
public void Initialize(ReadOnlySpan<byte> key, bool isDecrypting)
{
@ -25,4 +22,3 @@ namespace LibHac.Crypto.Detail
}
}
}
#endif

View file

@ -1,5 +1,4 @@
#if HAS_INTRINSICS
using System;
using System;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
@ -11,10 +10,8 @@ namespace LibHac.Crypto.Detail
{
public struct AesXtsModeNi
{
#pragma warning disable 649
private AesCoreNi _dataAesCore;
private AesCoreNi _tweakAesCore;
#pragma warning restore 649
public Vector128<byte> Iv;
@ -256,4 +253,3 @@ namespace LibHac.Crypto.Detail
}
}
}
#endif

View file

@ -3,8 +3,7 @@
<PropertyGroup>
<OutputType>Library</OutputType>
<VersionPrefix>0.12.0</VersionPrefix>
<TargetFrameworks>netcoreapp3.0;netstandard2.1</TargetFrameworks>
<LangVersion>8.0</LangVersion>
<TargetFramework>net5.0</TargetFramework>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
@ -27,17 +26,9 @@
<PathMap Condition=" '$(BuildType)' == 'Release' and '$(HasGitDir)' == 'false' ">$(MSBuildProjectDirectory)=C:/LibHac/</PathMap>
<DeterministicSourcePaths Condition=" '$(BuildType)' == 'Release' and '$(HasGitDir)' == 'true' ">true</DeterministicSourcePaths>
<NoWarn>$(NoWarn);1591;NU5105</NoWarn>
<NoWarn>$(NoWarn);1591</NoWarn>
</PropertyGroup>
<PropertyGroup Condition=" '$(TargetFramework)' == 'netcoreapp3.0' ">
<DefineConstants>$(DefineConstants);HAS_INTRINSICS</DefineConstants>
</PropertyGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.1' ">
<PackageReference Include="System.Memory" Version="4.5.3" />
</ItemGroup>
<ItemGroup>
<Compile Condition="Exists('ResultNameResolver.Generated.cs')" Remove="ResultNameResolver.Archive.cs" />
<Compile Condition="Exists('Common\Keys\DefaultKeySet.Generated.cs')" Remove="Common\Keys\DefaultKeySet.Empty.cs" />
@ -45,7 +36,6 @@
<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="5.0.0" />
</ItemGroup>
</Project>

View file

@ -16,11 +16,8 @@ namespace hactoolnet
{
if (Run(args))
{
// Console.ReadKey();
return 0;
}
}
catch (MissingKeyException ex)
{

View file

@ -2,8 +2,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<LangVersion>8.0</LangVersion>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<PropertyGroup>

View file

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net5.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>