use of com.google.nigori.common.NotFoundException in project nigori by ucam-cl-dtg.
the class DatabaseNigoriProtocol method getIndices.
@Override
public GetIndicesResponse getIndices(GetIndicesRequest request) throws IOException, NotFoundException, UnauthorisedException {
AuthenticateRequest auth = request.getAuth();
User user = authenticateUser(auth, MessageLibrary.REQUEST_GET_INDICES);
Collection<byte[]> value = database.getIndices(user);
if (value == null) {
throw new NotFoundException("Cannot find indices");
}
return MessageLibrary.getIndicesResponseAsProtobuf(value);
}
use of com.google.nigori.common.NotFoundException in project nigori by ucam-cl-dtg.
the class CryptoNigoriDatastore method getRevisions.
@Override
public List<Revision> getRevisions(Index index) throws NigoriCryptographyException, UnsupportedEncodingException, IOException, UnauthorisedException {
byte[] encIndex = keyManager.encryptDeterministically(index.getBytes());
try {
GetRevisionsResponse getResponse = protocol.getRevisions(MessageLibrary.getRevisionsRequestAsProtobuf(keyManager.getServerName(), keyManager.signer(), encIndex));
if (getResponse == null) {
return null;
}
List<ByteString> revisions = getResponse.getRevisionsList();
List<Revision> answer = new ArrayList<Revision>(revisions.size());
for (ByteString revision : revisions) {
answer.add(new Revision(keyManager.decrypt(revision.toByteArray())));
}
return answer;
} catch (NotFoundException e) {
return null;
}
}
use of com.google.nigori.common.NotFoundException in project nigori by ucam-cl-dtg.
the class CryptoNigoriDatastore method get.
/**
* Retrieve the value associated with {@code index} on the server.
*
* @param index
* @param revision
* @return a list of RevValues containing the data associated with {@code index} or {@code null}
* if no data exists. WARNING: there is no assurance that the value for the revision is a
* pair once specified by a valid client - the server can pair any value with any
* revision.
*/
private List<RevValue> get(byte[] encKey, Index index, Revision revision) throws IOException, NigoriCryptographyException, UnauthorisedException {
byte[] encIndex;
byte[] encRevision = null;
if (encKey == null) {
encIndex = keyManager.encryptDeterministically(index.getBytes());
if (revision != null) {
encRevision = keyManager.encryptDeterministically(revision.getBytes());
}
} else {
encIndex = keyManager.encryptDeterministically(encKey, index.getBytes());
if (revision != null) {
encRevision = keyManager.encryptDeterministically(encKey, revision.getBytes());
}
}
try {
GetResponse getResponse = protocol.get(MessageLibrary.getRequestAsProtobuf(keyManager.getServerName(), keyManager.signer(), encIndex, encRevision));
if (getResponse == null) {
return null;
}
List<RevisionValue> revisions = getResponse.getRevisionsList();
List<RevValue> answer = new ArrayList<RevValue>(revisions.size());
for (RevisionValue revisionValue : revisions) {
byte[] revisionciphertext = revisionValue.getRevision().toByteArray();
byte[] valueciphertext = revisionValue.getValue().toByteArray();
if (encKey == null) {
answer.add(new RevValue(keyManager.decrypt(revisionciphertext), keyManager.decrypt(valueciphertext)));
} else {
answer.add(new RevValue(keyManager.decrypt(encKey, revisionciphertext), keyManager.decrypt(encKey, valueciphertext)));
}
}
return answer;
} catch (NotFoundException e) {
return null;
}
}
use of com.google.nigori.common.NotFoundException in project nigori by ucam-cl-dtg.
the class DatabaseNigoriProtocol method delete.
@Override
public boolean delete(DeleteRequest request) throws IOException, NotFoundException, UnauthorisedException {
AuthenticateRequest auth = request.getAuth();
byte[] index = request.getKey().toByteArray();
User user = authenticateUser(auth, MessageLibrary.REQUEST_DELETE, index);
boolean exists = database.getRecord(user, index) != null;
if (!exists) {
throw new NotFoundException("No such index: " + Base64.encodeBase64(request.getKey().toByteArray()));
}
return database.deleteRecord(user, index);
}
use of com.google.nigori.common.NotFoundException in project nigori by ucam-cl-dtg.
the class DatabaseNigoriProtocol method getRevisions.
@Override
public GetRevisionsResponse getRevisions(GetRevisionsRequest request) throws IOException, NotFoundException, UnauthorisedException {
byte[] index = request.getKey().toByteArray();
AuthenticateRequest auth = request.getAuth();
User user = authenticateUser(auth, MessageLibrary.REQUEST_GET_REVISIONS, index);
Collection<byte[]> value = database.getRevisions(user, index);
if (value == null) {
throw new NotFoundException("Cannot find requested key");
}
return MessageLibrary.getRevisionsResponseAsProtobuf(value);
}
Aggregations