Search in sources :

Example 6 with NotFoundException

use of com.google.nigori.common.NotFoundException in project nigori by ucam-cl-dtg.

the class DatabaseNigoriProtocol method get.

@Override
public GetResponse get(GetRequest request) throws IOException, NotFoundException, UnauthorisedException {
    byte[] index = request.getKey().toByteArray();
    AuthenticateRequest auth = request.getAuth();
    User user;
    byte[] revision = null;
    if (request.hasRevision()) {
        revision = request.getRevision().toByteArray();
        user = authenticateUser(auth, MessageLibrary.REQUEST_GET, index, revision);
    } else {
        user = authenticateUser(auth, MessageLibrary.REQUEST_GET, index);
    }
    Collection<RevValue> value;
    if (request.hasRevision()) {
        value = new ArrayList<RevValue>(1);
        RevValue revVal = database.getRevision(user, index, revision);
        if (revVal == null) {
            throw new NotFoundException("Cannot find requested index with revision");
        }
        value.add(revVal);
    } else {
        value = database.getRecord(user, index);
    }
    if (value == null) {
        throw new NotFoundException("No value for that index");
    }
    return MessageLibrary.getResponseAsProtobuf(value);
}
Also used : AuthenticateRequest(com.google.nigori.common.NigoriMessages.AuthenticateRequest) RevValue(com.google.nigori.common.RevValue) NotFoundException(com.google.nigori.common.NotFoundException)

Example 7 with NotFoundException

use of com.google.nigori.common.NotFoundException in project nigori by ucam-cl-dtg.

the class CryptoNigoriDatastore method getIndices.

@Override
public List<Index> getIndices() throws NigoriCryptographyException, IOException, UnauthorisedException {
    try {
        GetIndicesResponse getResponse = protocol.getIndices(MessageLibrary.getIndicesRequestAsProtobuf(keyManager.getServerName(), keyManager.signer()));
        if (getResponse == null) {
            return null;
        }
        List<ByteString> indices = getResponse.getIndicesList();
        List<Index> answer = new ArrayList<Index>(indices.size());
        for (ByteString index : indices) {
            answer.add(new Index(keyManager.decrypt(index.toByteArray())));
        }
        return answer;
    } catch (NotFoundException e) {
        return null;
    }
}
Also used : GetIndicesResponse(com.google.nigori.common.NigoriMessages.GetIndicesResponse) ByteString(com.google.protobuf.ByteString) ArrayList(java.util.ArrayList) NotFoundException(com.google.nigori.common.NotFoundException) Index(com.google.nigori.common.Index)

Aggregations

NotFoundException (com.google.nigori.common.NotFoundException)7 AuthenticateRequest (com.google.nigori.common.NigoriMessages.AuthenticateRequest)4 ArrayList (java.util.ArrayList)3 RevValue (com.google.nigori.common.RevValue)2 ByteString (com.google.protobuf.ByteString)2 Index (com.google.nigori.common.Index)1 GetIndicesResponse (com.google.nigori.common.NigoriMessages.GetIndicesResponse)1 GetResponse (com.google.nigori.common.NigoriMessages.GetResponse)1 GetRevisionsResponse (com.google.nigori.common.NigoriMessages.GetRevisionsResponse)1 RevisionValue (com.google.nigori.common.NigoriMessages.RevisionValue)1 Revision (com.google.nigori.common.Revision)1