use of com.google.nigori.common.Revision 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.Revision in project nigori by ucam-cl-dtg.
the class ConcurrencyTest method singleUserConcurrency.
/**
* Test that one user can do lots of things at the same time.
*
* @throws NigoriCryptographyException
* @throws IOException
* @throws UnauthorisedException
*/
@Test
public void singleUserConcurrency() throws NigoriCryptographyException, IOException, UnauthorisedException {
failed = false;
Thread[] threads = new Thread[THREADS];
final NigoriDatastore nigori = getStore();
assertTrue("Not registered", nigori.register());
try {
final List<Throwable> exceptionList = Collections.synchronizedList(new LinkedList<Throwable>());
for (int j = 0; j < THREADS; ++j) {
threads[j] = new Thread() {
@Override
public void run() {
boolean succeeded = false;
try {
Random r = new Random();
for (int i = 0; i < AcceptanceTests.REPEAT * REPEAT_FACTOR; ++i) {
// check we can do this more than once
for (IndexValue iv : SetGetDeleteTest.testCases) {
// once round for each
final Index index = new Index(new byte[16]);
// need to generate some different indices
r.nextBytes(index.getBytes());
final byte[] value = iv.revvalue.getValue();
final Revision revision = iv.revvalue.getRevision();
assertTrue("Not put" + i, nigori.put(index, revision, value));
try {
assertArrayEquals("Got different" + i, value, nigori.getRevision(index, revision));
} finally {
assertTrue("Not deleted" + i, nigori.delete(index, NULL_DELETE_TOKEN));
}
assertNull("Not deleted" + i, nigori.get(index));
}
}
succeeded = true;
} catch (Throwable e) {
exceptionList.add(e);
} finally {
if (!succeeded && !failed) {
failed = true;
}
}
}
};
}
startThenJoinThreads(threads);
ifFailedPrintFailures(failed, exceptionList);
} finally {
assertTrue(nigori.unregister());
}
}
use of com.google.nigori.common.Revision in project nigori by ucam-cl-dtg.
the class SetGetDeleteTest method setGetDelete.
@Test
public void setGetDelete() throws NigoriCryptographyException, IOException, UnauthorisedException {
NigoriDatastore nigori = getStore();
for (int i = 0; i < AcceptanceTests.REPEAT; ++i) {
// check we can do this more than once
try {
assertTrue("Not registered" + i, nigori.register());
assertTrue("Not a clean store " + i, nigori.getIndices().isEmpty());
for (IndexValue iv : testCases) {
// once round for each
final Index index = iv.index;
final Revision revision = iv.revvalue.getRevision();
final byte[] value = iv.revvalue.getValue();
assertTrue("Not put " + i, nigori.put(index, revision, value));
List<RevValue> revs = nigori.get(index);
assertFalse("Revisions must exist" + i, revs.isEmpty());
assertThat(revs, hasItem(iv.revvalue));
assertEquals("Not one revision " + i, 1, revs.size());
assertTrue("Not deleted" + i, nigori.delete(index, NULL_DELETE_TOKEN));
assertNull("Not deleted" + i, nigori.get(index));
assertFalse("Could redelete", nigori.delete(index, NULL_DELETE_TOKEN));
}
// allow them to accumulate
for (IndexValue iv : testCases) {
final Index index = iv.index;
final byte[] value = iv.revvalue.getValue();
final Revision revision = iv.revvalue.getRevision();
assertTrue("Not put" + i, nigori.put(index, revision, value));
}
try {
for (IndexValue iv : testCases) {
final Index index = iv.index;
final byte[] value = iv.revvalue.getValue();
final Revision revision = iv.revvalue.getRevision();
assertArrayEquals("Got different" + i, value, nigori.getRevision(index, revision));
}
} finally {
for (IndexValue iv : testCases) {
final Index index = iv.index;
if (!iv.later) {
assertTrue("Not deleted" + i, nigori.delete(index, NULL_DELETE_TOKEN));
} else {
// should have already been deleted
assertFalse("Not deleted" + i, nigori.delete(index, NULL_DELETE_TOKEN));
}
}
}
for (IndexValue iv : testCases) {
final Index index = iv.index;
assertNull("Still there after deletion " + i, nigori.get(index));
}
} finally {
assertTrue("Not unregistered", nigori.unregister());
}
}
}
Aggregations