Skip to content
This repository has been archived by the owner on Sep 6, 2023. It is now read-only.

Commit

Permalink
Merge pull request #49 from LuccaSA/FixPassFileAgrs
Browse files Browse the repository at this point in the history
Fix du déchiffrement avec un mot de passe par fichier
  • Loading branch information
renardguill authored Mar 9, 2023
2 parents 69e19b4 + 2a73adb commit 6c6da7b
Showing 1 changed file with 25 additions and 19 deletions.
44 changes: 25 additions & 19 deletions TCC.Lib/Dependencies/CompressionCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,33 +136,39 @@ public string DecompressCommand(DecompressionBlock block, TccOption option)
cmd.Append($" | {_ext.Tar()} xf - ");
break;
default:
throw new ArgumentOutOfRangeException(nameof(option));
throw new ArgumentOutOfRangeException(nameof(option), "Unknown PasswordMode");
}
return cmd.ToString();
}

private static string PasswordCommand(TccOption option, Block block)
{
string passwdCommand;
if (option.PasswordOption.PasswordMode == PasswordMode.InlinePassword
&& option.PasswordOption is InlinePasswordOption inlinePassword)
{
if (String.IsNullOrWhiteSpace(inlinePassword.Password))
{
throw new CommandLineException("Password missing");
}
passwdCommand = "-k " + inlinePassword.Password;
}
else

switch (option.PasswordOption.PasswordMode)
{
if (String.IsNullOrWhiteSpace(block.BlockPasswordFile))
{
throw new CommandLineException("Password file missing");
}
passwdCommand = "-kfile " + block.BlockPasswordFile.Escape();
case PasswordMode.None:
return string.Empty;
case PasswordMode.InlinePassword when option.PasswordOption is InlinePasswordOption inlinePassword:
if (string.IsNullOrWhiteSpace(inlinePassword.Password))
{
throw new CommandLineException("Password missing");
}
return "-k " + inlinePassword.Password;
case PasswordMode.PasswordFile when option.PasswordOption is PasswordFileOption passwordFile:
if (string.IsNullOrWhiteSpace(passwordFile.PasswordFile))
{
throw new CommandLineException("Password file missing");
}
return "-kfile " + passwordFile.PasswordFile.Escape();
case PasswordMode.PublicKey:
if (string.IsNullOrWhiteSpace(block.BlockPasswordFile))
{
throw new CommandLineException("Password file missing");
}
return "-kfile " + block.BlockPasswordFile.Escape();
default:
throw new NotSupportedException($"PasswordMode: {option.PasswordOption.PasswordMode} is not supported");
}

return passwdCommand;
}
}
}

0 comments on commit 6c6da7b

Please sign in to comment.