private static void ExtractPasswordInfo(BaseCmdOptions opts, TccOption option, Mode mode) { if (!String.IsNullOrEmpty(opts.Password)) { ExtractInlinePassword(opts, option); } if (!String.IsNullOrEmpty(opts.PasswordFile)) { ExtractPasswordFile(opts, option); } if (!String.IsNullOrEmpty(opts.PasswordKey)) { ExtractAsymetricFile(opts, option, mode); } }
private static int ExtractThreads(BaseCmdOptions opts) { if (string.IsNullOrEmpty(opts.Threads)) { return(1); } if (string.Equals(opts.Threads, "all", StringComparison.InvariantCultureIgnoreCase)) { return(Environment.ProcessorCount); } if (int.TryParse(opts.Threads, out var nbThread)) { return(nbThread); } throw new CommandLineException("Maximum threads need to be either numeric, or \"all\" "); }
private static void ExtractInlinePassword(BaseCmdOptions opts, TccOption option) { if (option.PasswordOption != NoPasswordOption.Nop) { throw new CommandLineException("Only one password mode allowed"); } if (string.IsNullOrEmpty(opts.Password)) { throw new CommandLineException("Password must be specified"); } option.PasswordOption = new InlinePasswordOption { Password = opts.Password }; }
private static void ExtractPasswordFile(BaseCmdOptions opts, TccOption option) { if (option.PasswordOption != NoPasswordOption.Nop) { throw new CommandLineException("Only one password mode allowed"); } if (string.IsNullOrEmpty(opts.PasswordFile)) { throw new CommandLineException("Password file must be specified"); } if (!File.Exists(opts.PasswordFile)) { throw new CommandLineException("Password file doesn't exists"); } option.PasswordOption = new PasswordFileOption { PasswordFile = opts.PasswordFile }; }
private static void ExtractAsymetricFile(BaseCmdOptions opts, TccOption option, Mode mode) { if (option.PasswordOption != NoPasswordOption.Nop) { throw new CommandLineException("Only one password mode allowed"); } if (string.IsNullOrEmpty(opts.PasswordKey)) { throw new CommandLineException("Public or private key must be specified"); } if (!File.Exists(opts.PasswordKey)) { throw new CommandLineException("Public or private key file doesn't exists"); } switch (mode) { case Mode.Compress: option.PasswordOption = new PublicKeyPasswordOption { PublicKeyFile = opts.PasswordKey }; break; case Mode.Decompress: option.PasswordOption = new PrivateKeyPasswordOption { PrivateKeyFile = opts.PasswordKey }; break; default: throw new ArgumentOutOfRangeException(nameof(mode), mode, null); } }