@Override public FieldElement getSecretSharedKey() { if (this.ssk != null) { return this.ssk; } try { this.ssk = this.storage.getNext(storageName + SSK_KEY); } catch (NoMoreElementsException e) { throw new IllegalArgumentException("SSK was not present in the storage " + storageName + SSK_KEY); } return this.ssk; }
@Override public SpdzTriple getNextTriple() { SpdzTriple trip; try { trip = this.storage.getNext(storageName + TRIPLE_STORAGE); } catch (NoMoreElementsException e) { logger.error("Triple no. " + tripleCounter + " was not present in the storage: " + storageName + TRIPLE_STORAGE); throw new IllegalArgumentException( "Triple no. " + tripleCounter + " was not present in the storage: " + storageName + TRIPLE_STORAGE, e); } tripleCounter++; return trip; }
@Override public SpdzSInt[] getNextExpPipe() { SpdzSInt[] expPipe; try { expPipe = this.storage.getNext(storageName + EXP_PIPE_STORAGE); } catch (NoMoreElementsException e) { logger.error("expPipe no. " + expPipeCounter + " was not present in the storage: " + storageName + EXP_PIPE_STORAGE); throw new IllegalArgumentException( "expPipe no. " + expPipeCounter + " was not present in the storage: " + storageName + EXP_PIPE_STORAGE, e); } expPipeCounter++; return expPipe; }
@Override public SpdzSInt getNextBit() { SpdzSInt bit; try { bit = this.storage.getNext(storageName + BIT_STORAGE); } catch (NoMoreElementsException e) { logger.warn("Bit no. " + bitCounter + " was not present in the storage: " + storageName + BIT_STORAGE); throw new IllegalArgumentException( "Bit no. " + bitCounter + " was not present in the storage: " + storageName + BIT_STORAGE, e); } bitCounter++; return bit; }
@Override public SpdzInputMask getNextInputMask(int towardPlayerId) { SpdzInputMask mask; try { mask = this.storage.getNext(storageName + INPUT_STORAGE + towardPlayerId); } catch (NoMoreElementsException e) { logger.error("Mask no. " + inputMaskCounters[towardPlayerId - 1] + " towards player " + towardPlayerId + " was not present in the storage " + (storageName + INPUT_STORAGE + towardPlayerId)); throw new IllegalArgumentException("Mask no. " + inputMaskCounters[towardPlayerId - 1] + " towards player " + towardPlayerId + " was not present in the storage " + (storageName + INPUT_STORAGE + towardPlayerId), e); } inputMaskCounters[towardPlayerId - 1]++; return mask; }
@Override public FieldDefinition getFieldDefinition() { if (this.definition != null) { return this.definition; } try { this.definition = new BigIntegerFieldDefinition( this.storage.<BigInteger>getNext(storageName + MODULUS_KEY)); } catch (NoMoreElementsException e) { throw new IllegalArgumentException("Modulus was not present in the storage " + storageName + MODULUS_KEY); } return this.definition; }
@Test(expected = NoMoreElementsException.class) public void testEmptyFile() throws NoMoreElementsException { try { (new FileOutputStream("foo")).close(); } catch (IOException e) { e.printStackTrace(); } storage.getNext("foo"); fail("Should not be reachable"); }
@Test(expected = RuntimeException.class) public void testClassNotFound() throws NoMoreElementsException { try { // A representation of a class we no longer know String stringRep = "aced000573720038646b2e616c6578616e6472" + "612e66726573636f2e6672616d65776f726b" + "2e7363652e7265736f7572" + "6365732e73746f726167652e4861636b" + "1e61559c1df507160200007870"; FileOutputStream fos = new FileOutputStream("foo"); fos.write(hexStringToByteArray(stringRep)); fos.close(); } catch (IOException e) { e.printStackTrace(); } storage.getNext("foo"); fail("Should not be reachable"); }
@Test(expected = NoMoreElementsException.class) public void testGetNonExisting2() throws NoMoreElementsException { storage.getNext("test-obj-2"); Assert.fail(); }
@Test(expected = NoMoreElementsException.class) public void testGetNonExisting() throws NoMoreElementsException { storage.getNext("test-obj-2"); Assert.fail(); }
@Test(expected = NoMoreElementsException.class) public void testMultipleReadWrites() throws NoMoreElementsException { String myObj = "This is a test"; boolean success = storage.putNext("test-obj", myObj); Assert.assertTrue(success); success = storage.putNext("test-obj", "This-is-second-test"); Assert.assertTrue(success); Serializable s = storage.getNext("test-obj"); Assert.assertThat(s, Is.is(myObj)); s = storage.getNext("test-obj"); Assert.assertThat(s, Is.is("This-is-second-test")); storage.getNext("test-obj"); Assert.fail(); }
@Test public void testPutAndGetNext() throws NoMoreElementsException { String myObj = "This is a test"; boolean success = storage.putNext("test-obj", myObj); Assert.assertTrue(success); String s = storage.getNext("test-obj"); storage.shutdown(); Assert.assertThat(s, Is.is(myObj)); }
.getNext(SpdzStorageDataSupplier.STORAGE_NAME_PREFIX + noOfThreads + "_" + 1 + "_" + 0 + "_" + SpdzStorageDataSupplier.MODULUS_KEY); if (next != null) {