@Test public void testWithoutCostFactorButSaltShouldReturnNull() { assertNull(CLIParser.parse(asArgArray("'" + defaultPw + "' -" + CLIParser.ARG_HASH + " 490d9611ab0930a9d9ef87768553366f"))); assertNull(CLIParser.parse(asArgArray("'" + defaultPw + "' -" + CLIParser.ARG_HASH + "490d9611ab0930a9d9ef87768553366f 12"))); }
public static Arg parse(String[] inputArgs) { Options options = setupOptions(); CommandLineParser parser = new DefaultParser(); Arg argument = new Arg(); try { CommandLine commandLine = parser.parse(options, inputArgs); if (commandLine.hasOption("h") || commandLine.hasOption("help")) { printHelp(options); return null; } if (commandLine.hasOption("v") || commandLine.hasOption("version")) { System.out.println("Version: " + CLIParser.class.getPackage().getImplementationVersion()); return null; } if (commandLine.getArgs().length <= 0) { throw new IllegalArgumentException("First parameter must be password (e.g. bcrypt 'mysecretpassword' -" + ARG_HASH + " 12)"); } char[] password = commandLine.getArgs()[0].toCharArray(); if (commandLine.hasOption(ARG_HASH)) { return handleHash(commandLine, password); } else if (commandLine.hasOption(ARG_CHECK)) { return handleCheck(commandLine, password); } } catch (Exception e) { String msg = e.getMessage(); System.err.println(msg.length() > 80 ? msg.substring(0, 80) + "..." : msg); CLIParser.printHelp(options); argument = null; } return argument; }
CLIParser { public static Arg parse(String[] inputArgs) { Options options = setupOptions(); CommandLineParser parser = new DefaultParser(); Arg argument = new Arg(); try { CommandLine commandLine = parser.parse(options, inputArgs); if (commandLine.hasOption("h") || commandLine.hasOption("help")) { printHelp(options); return null; } if (commandLine.hasOption("v") || commandLine.hasOption("version")) { System.out.println("Version: " + CLIParser.class.getPackage().getImplementationVersion()); return null; } if (commandLine.getArgs().length <= 0) { throw new IllegalArgumentException("First parameter must be password (e.g. bcrypt 'mysecretpassword' -" + ARG_HASH + " 12)"); } char[] password = commandLine.getArgs()[0].toCharArray(); if (commandLine.hasOption(ARG_HASH)) { return handleHash(commandLine, password); } else if (commandLine.hasOption(ARG_CHECK)) { return handleCheck(commandLine, password); } } catch (Exception e) { String msg = e.getMessage(); System.err.println(msg.length() > 80 ? msg.substring(0, 80) + "..." : msg); CLIParser.printHelp(options); argument = null; } return argument; } }
CLIParser { public static Arg parse(String[] inputArgs) { Options options = setupOptions(); CommandLineParser parser = new DefaultParser(); Arg argument = new Arg(); try { CommandLine commandLine = parser.parse(options, inputArgs); if (commandLine.hasOption("h") || commandLine.hasOption("help")) { printHelp(options); return null; } if (commandLine.hasOption("v") || commandLine.hasOption("version")) { System.out.println("Version: " + CLIParser.class.getPackage().getImplementationVersion()); return null; } if (commandLine.getArgs().length <= 0) { throw new IllegalArgumentException("First parameter must be password (e.g. bcrypt 'mysecretpassword' -" + ARG_HASH + " 12)"); } char[] password = commandLine.getArgs()[0].toCharArray(); if (commandLine.hasOption(ARG_HASH)) { return handleHash(commandLine, password); } else if (commandLine.hasOption(ARG_CHECK)) { return handleCheck(commandLine, password); } } catch (Exception e) { String msg = e.getMessage(); System.err.println(msg.length() > 80 ? msg.substring(0, 80) + "..." : msg); CLIParser.printHelp(options); argument = null; } return argument; } private  CLIParser(); }
CLIParser { public static Arg parse(String[] inputArgs) { Options options = setupOptions(); CommandLineParser parser = new DefaultParser(); Arg argument = new Arg(); try { CommandLine commandLine = parser.parse(options, inputArgs); if (commandLine.hasOption("h") || commandLine.hasOption("help")) { printHelp(options); return null; } if (commandLine.hasOption("v") || commandLine.hasOption("version")) { System.out.println("Version: " + CLIParser.class.getPackage().getImplementationVersion()); return null; } if (commandLine.getArgs().length <= 0) { throw new IllegalArgumentException("First parameter must be password (e.g. bcrypt 'mysecretpassword' -" + ARG_HASH + " 12)"); } char[] password = commandLine.getArgs()[0].toCharArray(); if (commandLine.hasOption(ARG_HASH)) { return handleHash(commandLine, password); } else if (commandLine.hasOption(ARG_CHECK)) { return handleCheck(commandLine, password); } } catch (Exception e) { String msg = e.getMessage(); System.err.println(msg.length() > 80 ? msg.substring(0, 80) + "..." : msg); CLIParser.printHelp(options); argument = null; } return argument; } private  CLIParser(); static Arg parse(String[] inputArgs); }
CLIParser { public static Arg parse(String[] inputArgs) { Options options = setupOptions(); CommandLineParser parser = new DefaultParser(); Arg argument = new Arg(); try { CommandLine commandLine = parser.parse(options, inputArgs); if (commandLine.hasOption("h") || commandLine.hasOption("help")) { printHelp(options); return null; } if (commandLine.hasOption("v") || commandLine.hasOption("version")) { System.out.println("Version: " + CLIParser.class.getPackage().getImplementationVersion()); return null; } if (commandLine.getArgs().length <= 0) { throw new IllegalArgumentException("First parameter must be password (e.g. bcrypt 'mysecretpassword' -" + ARG_HASH + " 12)"); } char[] password = commandLine.getArgs()[0].toCharArray(); if (commandLine.hasOption(ARG_HASH)) { return handleHash(commandLine, password); } else if (commandLine.hasOption(ARG_CHECK)) { return handleCheck(commandLine, password); } } catch (Exception e) { String msg = e.getMessage(); System.err.println(msg.length() > 80 ? msg.substring(0, 80) + "..." : msg); CLIParser.printHelp(options); argument = null; } return argument; } private  CLIParser(); static Arg parse(String[] inputArgs); static final String ARG_HASH; static final String ARG_CHECK; }