@Test void testInvalidFingerprintAddedToFile(@TempDirectory Path tempFolder) throws IOException { FileBackedFingerprintRepository repo = new FileBackedFingerprintRepository(tempFolder.resolve("repo-bad2")); Bytes fingerprint = generateFingerprint(); Files.write( tempFolder.resolve("repo-bad2"), ("bar " + fingerprint.slice(8).toHexString().substring(2) + "GGG").getBytes(UTF_8)); assertThrows(TLSEnvironmentException.class, () -> repo.addFingerprint("foo", fingerprint)); }
@Override public void addFingerprint(String identifier, Bytes fingerprint) { if (!contains(identifier, fingerprint)) { synchronized (this) { if (!contains(identifier, fingerprint)) { HashMap<String, Bytes> fingerprintsCopy = new HashMap<>(fingerprints); fingerprintsCopy.put(identifier, fingerprint); fingerprints = writeFingerprintFile(fingerprintFile, fingerprintsCopy); } } } }
FileBackedFingerprintRepository implements FingerprintRepository { @Override public void addFingerprint(String identifier, Bytes fingerprint) { if (!contains(identifier, fingerprint)) { synchronized (this) { if (!contains(identifier, fingerprint)) { HashMap<String, Bytes> fingerprintsCopy = new HashMap<>(fingerprints); fingerprintsCopy.put(identifier, fingerprint); fingerprints = writeFingerprintFile(fingerprintFile, fingerprintsCopy); } } } } }
FileBackedFingerprintRepository implements FingerprintRepository { @Override public void addFingerprint(String identifier, Bytes fingerprint) { if (!contains(identifier, fingerprint)) { synchronized (this) { if (!contains(identifier, fingerprint)) { HashMap<String, Bytes> fingerprintsCopy = new HashMap<>(fingerprints); fingerprintsCopy.put(identifier, fingerprint); fingerprints = writeFingerprintFile(fingerprintFile, fingerprintsCopy); } } } } FileBackedFingerprintRepository(Path fingerprintFile); }
FileBackedFingerprintRepository implements FingerprintRepository { @Override public void addFingerprint(String identifier, Bytes fingerprint) { if (!contains(identifier, fingerprint)) { synchronized (this) { if (!contains(identifier, fingerprint)) { HashMap<String, Bytes> fingerprintsCopy = new HashMap<>(fingerprints); fingerprintsCopy.put(identifier, fingerprint); fingerprints = writeFingerprintFile(fingerprintFile, fingerprintsCopy); } } } } FileBackedFingerprintRepository(Path fingerprintFile); @Override boolean contains(String identifier); @Override boolean contains(String identifier, Bytes fingerprint); @Override void addFingerprint(String identifier, Bytes fingerprint); }
FileBackedFingerprintRepository implements FingerprintRepository { @Override public void addFingerprint(String identifier, Bytes fingerprint) { if (!contains(identifier, fingerprint)) { synchronized (this) { if (!contains(identifier, fingerprint)) { HashMap<String, Bytes> fingerprintsCopy = new HashMap<>(fingerprints); fingerprintsCopy.put(identifier, fingerprint); fingerprints = writeFingerprintFile(fingerprintFile, fingerprintsCopy); } } } } FileBackedFingerprintRepository(Path fingerprintFile); @Override boolean contains(String identifier); @Override boolean contains(String identifier, Bytes fingerprint); @Override void addFingerprint(String identifier, Bytes fingerprint);  }