private SortedSet <AccountInfo> TryUnmarsal(byte[] data, string pwd) { using (MemoryStream mem = new MemoryStream(data)) { var storeGet = VaultMarshal.Unmarshal(mem, pwd); return(storeGet); } }
public void TestMarshal() { string pwd = "kc123"; SortedSet <AccountInfo> store = new SortedSet <AccountInfo>(); byte[] data = null; using (MemoryStream mem = new MemoryStream()) { VaultMarshal.Marshal(pwd, store, mem); data = mem.ToArray(); } Assert.AreNotEqual(null, data); TryUnmarsal(data, pwd); try { var corrupted = new byte[data.Length]; data.CopyTo(corrupted, 0); Assert.AreNotSame(corrupted, data); corrupted[0] ^= 0x44; corrupted[corrupted.Length - 2] ^= 0x44; TryUnmarsal(corrupted, pwd); Assert.Fail("Checksum didn't work"); } catch (DataCorruptedException) { // keep silence } try { string fakePwd = "kckckc"; TryUnmarsal(data, fakePwd); Assert.Fail("HMAC validation didn't work"); } catch (IncorrectPassword) { // keep silence } }