Differences From Artifact [033c6ce89c]:
- File ScryptPWGen.m — part of check-in [4772cb8670] at 2016-10-08 12:24:32 on branch trunk — Add a license (user: js, size: 4323) [annotate] [blame] [check-ins using]
To Artifact [982ba32868]:
- File
ScryptPWGen.m
— part of check-in
[7691951aca]
at
2016-10-08 12:24:43
on branch trunk
— Add new generation algorithm
The scrypt-genpass compatible one is now the legacy algorithm
(activated with -L or --legacy). (user: js, size: 4629) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #include <unistd.h> #import "ScryptPWGen.h" #import "LegacyPasswordGenerator.h" OF_APPLICATION_DELEGATE(ScryptPWGen) static void showHelp(OFStream *output, bool verbose) { [output writeFormat: @"Usage: %@ [-hlr] site\n", [OFApplication programName]]; if (verbose) [output writeString: @"\n" @"Options:\n" @" -h --help Show this help\n" @" -l --length Length for the derived password\n" @" -r --repeat Repeat input\n"]; } @implementation ScryptPWGen - (void)applicationDidFinishLaunching { OFString *lengthStr; const of_options_parser_option_t options[] = { { 'h', @"help", 0, NULL, NULL }, { 'l', @"length", 1, NULL, &lengthStr }, { 'r', @"repeat", 0, &_repeat, NULL }, { '\0', nil, 0, NULL, NULL } }; OFOptionsParser *optionsParser = [OFOptionsParser parserWithOptions: options]; of_unichar_t option; | > > > > < | 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #include <unistd.h> #import "ScryptPWGen.h" #import "NewPasswordGenerator.h" #import "LegacyPasswordGenerator.h" OF_APPLICATION_DELEGATE(ScryptPWGen) static void showHelp(OFStream *output, bool verbose) { [output writeFormat: @"Usage: %@ [-hlr] site\n", [OFApplication programName]]; if (verbose) [output writeString: @"\n" @"Options:\n" @" -h --help Show this help\n" @" -l --length Length for the derived password\n" @" -L --legacy Use the legacy algorithm " @"(compatible with scrypt-genpass)\n" @" -r --repeat Repeat input\n"]; } @implementation ScryptPWGen - (void)applicationDidFinishLaunching { OFString *lengthStr; const of_options_parser_option_t options[] = { { 'h', @"help", 0, NULL, NULL }, { 'l', @"length", 1, NULL, &lengthStr }, { 'L', @"legacy", 0, &_legacy, NULL }, { 'r', @"repeat", 0, &_repeat, NULL }, { '\0', nil, 0, NULL, NULL } }; OFOptionsParser *optionsParser = [OFOptionsParser parserWithOptions: options]; of_unichar_t option; char *passphrase; OFString *site, *prompt; while ((option = [optionsParser nextOption]) != '\0') { switch (option) { case 'h': showHelp(of_stdout, true); |
︙ | ︙ | |||
94 95 96 97 98 99 100 101 102 | optionsParser.lastOption]; [OFApplication terminateWithStatus: 1]; break; } } if (lengthStr != nil) { @try { | > > > > > > > > > > > > > > > > > | > > > > | | < | < < < < < < < < < < < < < < | 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 | optionsParser.lastOption]; [OFApplication terminateWithStatus: 1]; break; } } if ([[optionsParser remainingArguments] count] != 1) { showHelp(of_stderr, false); [OFApplication terminateWithStatus: 1]; } site = [[optionsParser remainingArguments] firstObject]; prompt = [OFString stringWithFormat: @"Passphrase for site \"%@\": ", site]; id <PasswordGenerator> generator = (_legacy ? [LegacyPasswordGenerator generator] : [NewPasswordGenerator generator]); generator.site = [[optionsParser remainingArguments] firstObject]; if (lengthStr != nil) { bool invalid = false; @try { generator.length = (size_t)[lengthStr decimalValue]; } @catch (OFInvalidArgumentException *e) { invalid = true; } @catch (OFInvalidFormatException *e) { invalid = true; } if (invalid) { [of_stderr writeFormat: @"%@: Invalid length: %@\n", [OFApplication programName], lengthStr]; [OFApplication terminateWithStatus: 1]; } } passphrase = getpass( [prompt cStringWithEncoding: [OFSystemInfo native8BitEncoding]]); @try { generator.passphrase = passphrase; [generator derivePassword]; @try { |
︙ | ︙ |