/** * Writes some bytes in Hexadecimal format * * @param bytes Bytes to format * @return Hex string */ public static String toHexString(byte[] bytes) { return toHexString(bytes, 0, bytes.length); }
@Test public void safeRegexMatch_incorrect() { assertFalse(Utils.safeRegexMatch("ab.*)", null)); assertFalse(Utils.safeRegexMatch("ab.*)", "")); assertFalse(Utils.safeRegexMatch("ab.*)", "abc")); assertFalse(Utils.safeRegexMatch("ab.*)", "acb")); }
@Test public void asList_one() { assertEquals( Arrays.asList("Test"), Utils.asList("Test") ); }
@Override public String getDiff(SVNRepository repository, String path, List<Long> revisions) { SVNRevision min = SVNRevision.create(revisions.stream().min(Long::compare).get() - 1); SVNRevision max = SVNRevision.create(revisions.stream().max(Long::compare).get()); ByteArrayOutputStream output = new ByteArrayOutputStream(); try { getDiffClient(repository).doDiff( SVNUtils.toURL(repository.getUrl(path)), max, min, max, SVNDepth.EMPTY, false, output ); } catch (SVNException ex) { throw translateSVNException(ex); } return Utils.toString(output.toByteArray()); }
@Test public void safeRegexMatch_correct() { assertFalse(Utils.safeRegexMatch("ab.*", null)); assertFalse(Utils.safeRegexMatch("ab.*", "")); assertTrue(Utils.safeRegexMatch("ab.*", "abc")); assertFalse(Utils.safeRegexMatch("ab.*", "acb")); }
@Test public void asList_two() { assertEquals( Arrays.asList("Test", "Second"), Utils.asList("Test\nSecond") ); }
public FileConfidentialStore(File rootDir) throws IOException { this.rootDir = rootDir; LoggerFactory.getLogger(FileConfidentialStore.class).info( "[key-store] Using file based key store at {}", rootDir.getAbsolutePath() ); File masterSecret = new File(rootDir, "master.key"); if (!masterSecret.exists()) { // we are only going to use small number of bits (since export control limits AES key length) // but let's generate a long enough key anyway FileUtils.write(masterSecret, Utils.toHexString(randomBytes(128)), ENCODING); } this.masterKey = SecurityUtils.toAes128Key(FileUtils.readFileToString(masterSecret, ENCODING)); }
@Test public void safeRegexMatch_blank() { assertFalse(Utils.safeRegexMatch(" ", null)); assertFalse(Utils.safeRegexMatch(" ", "")); assertFalse(Utils.safeRegexMatch(" ", "abc")); }
@Test public void asList_null() { assertTrue(Utils.asList(null).isEmpty()); }
@Test public void safeRegexMatch_null() { assertFalse(Utils.safeRegexMatch(null, null)); assertFalse(Utils.safeRegexMatch(null, "")); assertFalse(Utils.safeRegexMatch(null, "abc")); }
@Test public void asList_blank() { assertTrue(Utils.asList("").isEmpty()); }
@Test public void safeRegexMatch_empty() { assertFalse(Utils.safeRegexMatch("", null)); assertFalse(Utils.safeRegexMatch("", "")); assertFalse(Utils.safeRegexMatch("", "abc")); }