Esempio n. 1
0
        private CommandLineApplication SetupKeygenCommand(CommandLineApplication app, CommandOption keyDirOption, string name)
        {
            return(app.Command(name, context =>
            {
                context.Out = _standardOut;
                context.Error = _standardError;
                context.Description = "generate a new EJSON keypair";
                context.HelpOption("--help");

                var writeOption = context.Option("-w", "writes to disk", CommandOptionType.NoValue);

                context.OnExecute(() =>
                {
                    string output;
                    if (writeOption.HasValue())
                    {
                        var keyDir = keyDirOption.Value();
                        output = _eJsonCrypto.SaveKeyPair(keyDir);
                    }
                    else
                    {
                        output = _eJsonCrypto.GenerateKeyPair();
                    }

                    context.Out.WriteLine(output);
                    return 0;
                });
            }));
        }
 internal static string SaveKeyPair(this IEJsonCrypto eJsonCrypto, string keyDir, IFileSystem fileSystem)
 {
     fileSystem = fileSystem ?? new FileSystemWrapper();
     return(eJsonCrypto.SaveKeyPair(new FileSystemPrivateKeyProvider(keyDir, fileSystem)));
 }