/** * Returns the reference key of this data store. Synchronized to * control concurrent access to the cached {@link #referenceKey} value. * * @return reference key * @throws DataStoreException if the key is not available */ private synchronized byte[] getReferenceKey() throws DataStoreException { if (referenceKey == null) { referenceKey = getOrCreateReferenceKey(); } return referenceKey; }
public String getReference() { return store.getReferenceFromIdentifier(identifier); }
protected String getReferenceFromIdentifier(DataIdentifier identifier) { try { String id = identifier.toString(); Mac mac = Mac.getInstance(ALGORITHM); mac.init(new SecretKeySpec(getReferenceKey(), ALGORITHM)); byte[] hash = mac.doFinal(id.getBytes(StandardCharsets.UTF_8)); return id + ':' + encodeHexString(hash); } catch (Exception e) { LOG.error("Failed to hash identifier using MAC (Message Authentication Code) algorithm.", e); } return null; }
public DataRecord getRecordFromReference(String reference) throws DataStoreException { if (reference != null) { int colon = reference.indexOf(':'); if (colon != -1) { DataIdentifier identifier = new DataIdentifier(reference.substring(0, colon)); if (reference.equals(getReferenceFromIdentifier(identifier))) { return getRecordIfStored(identifier); } } } return null; }
public DataRecord getRecord(DataIdentifier identifier) throws DataStoreException { DataRecord record = getRecordIfStored(identifier); if (record != null) { return record; } else { throw new DataStoreException( "Record " + identifier + " does not exist"); } }
protected String getReferenceFromIdentifier(DataIdentifier identifier) { try { String id = identifier.toString(); Mac mac = Mac.getInstance(ALGORITHM); mac.init(new SecretKeySpec(getReferenceKey(), ALGORITHM)); byte[] hash = mac.doFinal(id.getBytes(StandardCharsets.UTF_8)); return id + ':' + encodeHexString(hash); } catch (Exception e) { LOG.error("Failed to hash identifier using MAC (Message Authentication Code) algorithm.", e); } return null; }
public DataRecord getRecordFromReference(String reference) throws DataStoreException { if (reference != null) { int colon = reference.indexOf(':'); if (colon != -1) { DataIdentifier identifier = new DataIdentifier(reference.substring(0, colon)); if (reference.equals(getReferenceFromIdentifier(identifier))) { return getRecordIfStored(identifier); } } } return null; }
public DataRecord getRecord(DataIdentifier identifier) throws DataStoreException { DataRecord record = getRecordIfStored(identifier); if (record != null) { return record; } else { throw new DataStoreException( "Record " + identifier + " does not exist"); } }
protected String getReferenceFromIdentifier(DataIdentifier identifier) { try { String id = identifier.toString(); Mac mac = Mac.getInstance(ALGORITHM); mac.init(new SecretKeySpec(getReferenceKey(), ALGORITHM)); byte[] hash = mac.doFinal(id.getBytes(StandardCharsets.UTF_8)); return id + ':' + encodeHexString(hash); } catch (Exception e) { LOG.error("Failed to hash identifier using MAC (Message Authentication Code) algorithm.", e); } return null; }
public DataRecord getRecordFromReference(String reference) throws DataStoreException { if (reference != null) { int colon = reference.indexOf(':'); if (colon != -1) { DataIdentifier identifier = new DataIdentifier(reference.substring(0, colon)); if (reference.equals(getReferenceFromIdentifier(identifier))) { return getRecordIfStored(identifier); } } } return null; }
/** * Returns the reference key of this data store. Synchronized to * control concurrent access to the cached {@link #referenceKey} value. * * @return reference key * @throws DataStoreException if the key is not available */ private synchronized byte[] getReferenceKey() throws DataStoreException { if (referenceKey == null) { referenceKey = getOrCreateReferenceKey(); } return referenceKey; }
public DataRecord getRecord(DataIdentifier identifier) throws DataStoreException { DataRecord record = getRecordIfStored(identifier); if (record != null) { return record; } else { throw new DataStoreException( "Record " + identifier + " does not exist"); } }
public String getReference() { return store.getReferenceFromIdentifier(identifier); }
/** * Returns the reference key of this data store. Synchronized to * control concurrent access to the cached {@link #referenceKey} value. * * @return reference key * @throws DataStoreException if the key is not available */ private synchronized byte[] getReferenceKey() throws DataStoreException { if (referenceKey == null) { referenceKey = getOrCreateReferenceKey(); } return referenceKey; }
public String getReference() { return store.getReferenceFromIdentifier(identifier); }
@Override protected byte[] getOrCreateReferenceKey() throws DataStoreException { File file = new File(directory, "reference.key"); try { if (file.exists()) { return FileUtils.readFileToByteArray(file); } else { byte[] key = super.getOrCreateReferenceKey(); FileUtils.writeByteArrayToFile(file, key); return key; } } catch (IOException e) { throw new DataStoreException( "Unable to access reference key file " + file.getPath(), e); } }
@Override protected byte[] getOrCreateReferenceKey() throws DataStoreException { File file = new File(directory, "reference.key"); try { if (file.exists()) { return FileUtils.readFileToByteArray(file); } else { byte[] key = super.getOrCreateReferenceKey(); FileUtils.writeByteArrayToFile(file, key); return key; } } catch (IOException e) { throw new DataStoreException( "Unable to access reference key file " + file.getPath(), e); } }
@Override protected byte[] getOrCreateReferenceKey() throws DataStoreException { File file = new File(directory, "reference.key"); try { if (file.exists()) { return FileUtils.readFileToByteArray(file); } else { byte[] key = super.getOrCreateReferenceKey(); FileUtils.writeByteArrayToFile(file, key); return key; } } catch (IOException e) { throw new DataStoreException( "Unable to access reference key file " + file.getPath(), e); } }