@Override public <T extends Serializable> T getObject(String name, String key) { return this.storage.getObject(name, key); }
@Override public boolean putObject(String name, String key, Serializable o) { return this.storage.putObject(name, key, o); }
@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; }
@Before public void setup() { storage = new FilebasedStreamedStorageImpl(new InMemoryStorage()); }
@Test public void testDataSupplierModFoundTwice() { FilebasedStreamedStorageImpl storage = new FilebasedStreamedStorageImpl(new InMemoryStorage()); storage.putNext("valid" + SpdzStorageDataSupplier.MODULUS_KEY, BigInteger.ONE); SpdzStorageDataSupplier supplier = new SpdzStorageDataSupplier(storage, "valid", 2); supplier.getFieldDefinition(); supplier.getFieldDefinition(); }
@Test(expected = RuntimeException.class) public void testWriteAfterClose() throws NoMoreElementsException { String myObj1 = "Test1"; String myObj2 = "Test2"; boolean success1 = storage.putNext("bar", myObj1); Assert.assertTrue(success1); storage.shutdown(); storage.putNext("bar", myObj2); 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"); }
@Before public void setup() { memStore = new InMemoryStorage(); }
@Test public void testPutAndGetObjects() { memStore.putObject("TestStore", "Key1", "Foo"); assertEquals("Foo", memStore.getObject("TestStore", "Key1")); memStore.putObject("TestStore", "Key2", "Bar"); assertEquals("Bar", memStore.getObject("TestStore", "Key2")); memStore.putObject("TestStore", "Key2", "Baz"); assertEquals("Baz", memStore.getObject("TestStore", "Key2")); memStore.putObject("TestStore2", "Key2", "Fum"); assertEquals("Fum", memStore.getObject("TestStore2", "Key2")); assertNull(memStore.getObject("NonExistentStoreName", "Key")); assertNull(memStore.getObject("TestStore", "NonExistentKey")); }
@Test(expected = RuntimeException.class) public void testPutBadName() throws NoMoreElementsException { storage.putNext("\0", "data"); Assert.fail(); }
@Test(expected = IllegalArgumentException.class) public void testDataSupplierExpPipeNotFound() { SpdzStorageDataSupplier supplier = new SpdzStorageDataSupplier(new FilebasedStreamedStorageImpl(new InMemoryStorage()), "invalid", 2); supplier.getNextExpPipe(); }
@Test(expected = NoMoreElementsException.class) public void testGetNonExisting2() throws NoMoreElementsException { storage.getNext("test-obj-2"); Assert.fail(); }
/** * Tests that we successfully can initialize the InMemory version of the storage with spdz * preprocessed data. Cannot currently easily be used within an actual MPC test since we now only * support a streamed version. */ @Test public void testInitInMemoryStorageAndDoubleFetch() { InitializeStorage.initStorage(new Storage[]{new InMemoryStorage()}, 2, 10, 10, 100, 10); }
@Test(expected = IllegalArgumentException.class) public void testDataSupplierNextBitNotFound() { SpdzStorageDataSupplier supplier = new SpdzStorageDataSupplier(new FilebasedStreamedStorageImpl(new InMemoryStorage()), "invalid", 2); supplier.getNextBit(); }
@Test(expected = NoMoreElementsException.class) public void testGetNonExisting() throws NoMoreElementsException { storage.getNext("test-obj-2"); Assert.fail(); }
@Test(expected = IllegalArgumentException.class) public void testDataSupplierModNotFound() { SpdzStorageDataSupplier supplier = new SpdzStorageDataSupplier(new FilebasedStreamedStorageImpl(new InMemoryStorage()), "invalid", 2); supplier.getFieldDefinition(); }
@Test(expected = IllegalArgumentException.class) public void testDataSupplierInputMaskNotFound() { SpdzStorageDataSupplier supplier = new SpdzStorageDataSupplier(new FilebasedStreamedStorageImpl(new InMemoryStorage()), "invalid", 2); supplier.getNextInputMask(1); }
@Test(expected = IllegalArgumentException.class) public void testDataSupplierSskNotFound() { SpdzStorageDataSupplier supplier = new SpdzStorageDataSupplier(new FilebasedStreamedStorageImpl(new InMemoryStorage()), "invalid", 2); supplier.getSecretSharedKey(); }
@Test(expected = IllegalArgumentException.class) public void testDataSupplierTripleNotFound() { SpdzStorageDataSupplier supplier = new SpdzStorageDataSupplier(new FilebasedStreamedStorageImpl(new InMemoryStorage()), "invalid", 2); supplier.getNextTriple(); }
@Test(expected = IllegalArgumentException.class) public void testDataSupplierRandomElmNotFound() { SpdzStorageDataSupplier supplier = new SpdzStorageDataSupplier(new FilebasedStreamedStorageImpl(new InMemoryStorage()), "invalid", 2); supplier.getNextRandomFieldElement(); } }