Skip to content

Commit 0a21fdb

Browse files
authored
Merge pull request #3 from AppCoreNet/features/extend-error-codes
Fix error codes
2 parents 7326a7c + cb9ca2c commit 0a21fdb

File tree

5 files changed

+38
-28
lines changed

5 files changed

+38
-28
lines changed

src/AppCore.SigningTool/Commands/Sn/SnCreateKeyCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public int Execute(CommandLineApplication cmd)
4848
try
4949
{
5050
if (File.Exists(keyFile) && !force)
51-
throw new FileAreadyExistsException(keyFile);
51+
throw new FileAlreadyExistsException(keyFile);
5252

5353
StrongNameKey key = _keyGenerator.Generate(keySize);
5454
File.WriteAllBytes(keyFile, key.CreateStrongName());

src/AppCore.SigningTool/Commands/Sn/SnExportPublicKeyCommand.cs

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -54,21 +54,28 @@ public void Configure(CommandLineApplication cmd)
5454

5555
private AssemblyHashAlgorithm ParseAssemblyHashAlgorithm(string value)
5656
{
57-
var result = AssemblyHashAlgorithm.None;
58-
switch (value.ToLowerInvariant())
57+
var result = AssemblyHashAlgorithm.SHA1;
58+
59+
if (!string.IsNullOrEmpty(value))
5960
{
60-
case "sha1":
61-
result = AssemblyHashAlgorithm.SHA1;
62-
break;
63-
case "sha256":
64-
result = AssemblyHashAlgorithm.SHA_256;
65-
break;
66-
case "sha384":
67-
result = AssemblyHashAlgorithm.SHA_384;
68-
break;
69-
case "sha512":
70-
result = AssemblyHashAlgorithm.SHA_512;
71-
break;
61+
switch (value.ToLowerInvariant())
62+
{
63+
case "sha1":
64+
result = AssemblyHashAlgorithm.SHA1;
65+
break;
66+
case "sha256":
67+
result = AssemblyHashAlgorithm.SHA_256;
68+
break;
69+
case "sha384":
70+
result = AssemblyHashAlgorithm.SHA_384;
71+
break;
72+
case "sha512":
73+
result = AssemblyHashAlgorithm.SHA_512;
74+
break;
75+
default:
76+
result = AssemblyHashAlgorithm.None;
77+
break;
78+
}
7279
}
7380

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

81-
AssemblyHashAlgorithm hashAlgorithm = _hashAlgorithm.HasValue()
82-
? ParseAssemblyHashAlgorithm(_hashAlgorithm.ParsedValue)
83-
: AssemblyHashAlgorithm.SHA1;
88+
AssemblyHashAlgorithm hashAlgorithm = ParseAssemblyHashAlgorithm(_hashAlgorithm.ParsedValue);
8489

8590
string keyFile = _keyFile.Value;
8691
string publicKeyFile = _publicKeyFile.Value;
8792

8893
try
8994
{
9095
if (File.Exists(publicKeyFile) && !force)
91-
throw new FileAreadyExistsException(publicKeyFile);
96+
throw new FileAlreadyExistsException(publicKeyFile);
9297

9398
StrongNameKey key = _keyLoader.LoadKey(keyFile);
9499

src/AppCore.SigningTool/Commands/Sn/SnSignCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public int Execute(CommandLineApplication cmd)
5959
try
6060
{
6161
if (File.Exists(outAssemblyFile) && !force)
62-
throw new FileAreadyExistsException(outAssemblyFile);
62+
throw new FileAlreadyExistsException(outAssemblyFile);
6363

6464
if (delaySign)
6565
{

src/AppCore.SigningTool/Exceptions/FileAreadyExistsException.cs renamed to src/AppCore.SigningTool/Exceptions/FileAlreadyExistsException.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
namespace AppCore.SigningTool.Exceptions
44
{
5-
public class FileAreadyExistsException : IOException
5+
public class FileAlreadyExistsException : IOException
66
{
7-
public FileAreadyExistsException(string fileName)
7+
public FileAlreadyExistsException(string fileName)
88
: base($"File {Path.GetFullPath(fileName)} already exists.")
99
{
1010
}

src/AppCore.SigningTool/ExitCodes.cs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,27 @@ internal static class ExitCodes
1414

1515
public const int UnrecognizedCommandOrArgument = 1;
1616

17-
public const int FileNotFound = 2;
17+
public const int DirectoryNotFound = 2;
1818

19-
public const int InvalidKey = 3;
19+
public const int FileNotFound = 3;
2020

21-
public const int InvalidAssembly = 4;
21+
public const int FileAlreadyExists = 4;
2222

23-
public const int FileAreadyExists = 5;
23+
public const int InvalidKey = 5;
24+
25+
public const int InvalidAssembly = 6;
2426

2527
public const int Unknown = -1;
2628

2729
public static int FromException(Exception error)
2830
{
2931
switch (error)
3032
{
31-
case FileAreadyExistsException _:
32-
return FileAreadyExists;
33+
case FileAlreadyExistsException _:
34+
return FileAlreadyExists;
35+
36+
case DirectoryNotFoundException _:
37+
return DirectoryNotFound;
3338

3439
case FileNotFoundException _:
3540
return FileNotFound;

0 commit comments

Comments
 (0)