Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/AppCore.SigningTool/Commands/Sn/SnCreateKeyCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public int Execute(CommandLineApplication cmd)
try
{
if (File.Exists(keyFile) && !force)
throw new FileAreadyExistsException(keyFile);
throw new FileAlreadyExistsException(keyFile);

StrongNameKey key = _keyGenerator.Generate(keySize);
File.WriteAllBytes(keyFile, key.CreateStrongName());
Expand Down
41 changes: 23 additions & 18 deletions src/AppCore.SigningTool/Commands/Sn/SnExportPublicKeyCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,28 @@ public void Configure(CommandLineApplication cmd)

private AssemblyHashAlgorithm ParseAssemblyHashAlgorithm(string value)
{
var result = AssemblyHashAlgorithm.None;
switch (value.ToLowerInvariant())
var result = AssemblyHashAlgorithm.SHA1;

if (!string.IsNullOrEmpty(value))
{
case "sha1":
result = AssemblyHashAlgorithm.SHA1;
break;
case "sha256":
result = AssemblyHashAlgorithm.SHA_256;
break;
case "sha384":
result = AssemblyHashAlgorithm.SHA_384;
break;
case "sha512":
result = AssemblyHashAlgorithm.SHA_512;
break;
switch (value.ToLowerInvariant())
{
case "sha1":
result = AssemblyHashAlgorithm.SHA1;
break;
case "sha256":
result = AssemblyHashAlgorithm.SHA_256;
break;
case "sha384":
result = AssemblyHashAlgorithm.SHA_384;
break;
case "sha512":
result = AssemblyHashAlgorithm.SHA_512;
break;
default:
result = AssemblyHashAlgorithm.None;
break;
}
}

return result;
Expand All @@ -78,17 +85,15 @@ public int Execute(CommandLineApplication cmd)
{
bool force = _force.HasValue();

AssemblyHashAlgorithm hashAlgorithm = _hashAlgorithm.HasValue()
? ParseAssemblyHashAlgorithm(_hashAlgorithm.ParsedValue)
: AssemblyHashAlgorithm.SHA1;
AssemblyHashAlgorithm hashAlgorithm = ParseAssemblyHashAlgorithm(_hashAlgorithm.ParsedValue);

string keyFile = _keyFile.Value;
string publicKeyFile = _publicKeyFile.Value;

try
{
if (File.Exists(publicKeyFile) && !force)
throw new FileAreadyExistsException(publicKeyFile);
throw new FileAlreadyExistsException(publicKeyFile);

StrongNameKey key = _keyLoader.LoadKey(keyFile);

Expand Down
2 changes: 1 addition & 1 deletion src/AppCore.SigningTool/Commands/Sn/SnSignCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public int Execute(CommandLineApplication cmd)
try
{
if (File.Exists(outAssemblyFile) && !force)
throw new FileAreadyExistsException(outAssemblyFile);
throw new FileAlreadyExistsException(outAssemblyFile);

if (delaySign)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace AppCore.SigningTool.Exceptions
{
public class FileAreadyExistsException : IOException
public class FileAlreadyExistsException : IOException
{
public FileAreadyExistsException(string fileName)
public FileAlreadyExistsException(string fileName)
: base($"File {Path.GetFullPath(fileName)} already exists.")
{
}
Expand Down
17 changes: 11 additions & 6 deletions src/AppCore.SigningTool/ExitCodes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,27 @@ internal static class ExitCodes

public const int UnrecognizedCommandOrArgument = 1;

public const int FileNotFound = 2;
public const int DirectoryNotFound = 2;

public const int InvalidKey = 3;
public const int FileNotFound = 3;

public const int InvalidAssembly = 4;
public const int FileAlreadyExists = 4;

public const int FileAreadyExists = 5;
public const int InvalidKey = 5;

public const int InvalidAssembly = 6;

public const int Unknown = -1;

public static int FromException(Exception error)
{
switch (error)
{
case FileAreadyExistsException _:
return FileAreadyExists;
case FileAlreadyExistsException _:
return FileAlreadyExists;

case DirectoryNotFoundException _:
return DirectoryNotFound;

case FileNotFoundException _:
return FileNotFound;
Expand Down