public void filter_users() { KeyPair keypair1 = new KeyPair(); KeyPair keypair2 = new KeyPair(); keypair1.generate(); keypair2.generate(); PicoBuffer expected = new PicoBuffer(0); PicoBuffer symmetricKey1 = new PicoBuffer(0); PicoBuffer symmetricKey2 = new PicoBuffer(0); PicoBuffer symmetricKey; CryptoSupport.generate_symmetric_key(symmetricKey1, CryptoSupport.AESKEY_SIZE); CryptoSupport.generate_symmetric_key(symmetricKey2, CryptoSupport.AESKEY_SIZE); Assert.IsFalse(symmetricKey1.equals(symmetricKey2)); IntPtr pub1 = keypair1.getpublickey(); IntPtr pub2 = keypair2.getpublickey(); Users users = new Users(); Assert.AreEqual(users.search_by_key(pub1).getIntPtr(), IntPtr.Zero); Assert.AreEqual(users.search_by_key(pub2).getIntPtr(), IntPtr.Zero); users.add_user("one", pub1, symmetricKey1); users.add_user("two", pub2, symmetricKey2); PicoBuffer user = users.search_by_key(pub1); expected.clear(); expected.append("one"); Assert.IsTrue(user.equals(expected)); user = users.search_by_key(pub2); expected.clear(); expected.append("two"); Assert.IsTrue(user.equals(expected)); Users filtered = new Users(); users.filter_by_name("one", filtered); Assert.AreEqual(filtered.search_by_key(pub2).getIntPtr(), IntPtr.Zero); user = users.search_by_key(pub1); expected.clear(); expected.append("one"); Assert.IsTrue(user.equals(expected)); // Check the correct symmetric keys are returned symmetricKey = users.search_symmetrickey_by_key(pub1); Assert.IsTrue(symmetricKey.equals(symmetricKey1)); symmetricKey = users.search_symmetrickey_by_key(pub2); Assert.IsTrue(symmetricKey.equals(symmetricKey2)); users.delete(); expected.delete(); filtered.delete(); keypair1.delete(); keypair2.delete(); }
public void equals() { PicoBuffer b = new PicoBuffer(3); PicoBuffer b2 = new PicoBuffer(3); b.append("1234"); b2.append("6789"); Assert.IsFalse(b.equals(b2)); b2.clear(); b2.append("1234"); Assert.IsTrue(b.equals(b2)); b.set_pos(10); Assert.IsFalse(b.equals(b2)); b.delete(); b2.delete(); }