コード例 #1
0
        public static ScryptCommandLineArgs Parse(string[] args, out string verb)
        {
            if (args.Length == 0)
            {
                // Work around a bug in CommandLineParser that doesn't correctly support a custom 'help' verb.
                Console.WriteLine(HelpText.AutoBuild(new ScryptCommandLineArgs(), _ => { }, true));
                Environment.Exit(Parser.DefaultExitCodeFail);
            }

            string verbForClosure = null;

            var arguments = new ScryptCommandLineArgs();
            var parser = new Parser(settings => { settings.HelpWriter = null; });

            var parseSucceed = parser.ParseArguments(args, arguments,
                (foundVerb, subOptions) =>
                {
                    verbForClosure = foundVerb;
                });
            if (!parseSucceed)
            {
                Console.WriteLine(HelpText.AutoBuild(arguments, _ => { }, true));
                Environment.Exit(Parser.DefaultExitCodeFail);
            }

            verb = verbForClosure;

            return arguments;
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: vbfox/NetScrypt
        static void Help(ScryptCommandLineArgs parsedArgs)
        {
            var helpParams = parsedArgs.HelpVerb;
            var helpText = string.IsNullOrEmpty(helpParams.Verb)
                ? HelpText.AutoBuild(parsedArgs, _ => { }, true)
                : HelpText.AutoBuild(parsedArgs, helpParams.Verb);

            Console.WriteLine(helpText);
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: vbfox/NetScrypt
        static void Encrypt(ScryptCommandLineArgs parsedArgs)
        {
            var encryptParams = parsedArgs.EncryptVerb;

            if (string.IsNullOrEmpty(encryptParams.InputFile) || string.IsNullOrEmpty(encryptParams.OutputFile))
            {
                Console.WriteLine(HelpText.AutoBuild(parsedArgs, "enc"));
                Environment.Exit(Parser.DefaultExitCodeFail);
            }

            using (var input = ConsoleUtils.OpenStreamOrExit(encryptParams.InputFile, FileMode.Open, FileAccess.Read, "Cannot open input file"))
            using (var output = ConsoleUtils.OpenStreamOrExit(encryptParams.OutputFile, FileMode.Create, FileAccess.ReadWrite, "Cannot open output file"))
            {
                var password = ConsoleUtils.ReadPasswords("Please enter passphrase: ", "Please confirm passphrase: ");

                Console.WriteLine();

                var encryption = new ScryptEncryption(password, encryptParams.MaxMemoryBytes,
                    encryptParams.MaxMemoryPercentage,
                    TimeSpan.FromSeconds(encryptParams.MaxTimeSeconds));

                encryption.Encrypt(input, output);
            }
        }