public void CSBadDeserializeFieldZqElementArrayTest() { FieldZqElement[] input = StaticHelperClass.GenerateRandomExponents(10, paramIndex); string[] serialized = CryptoSerializer.SerializeFieldZqElementArray(input, 3, 4, "blah"); Assert.AreEqual(4, serialized.Length, "serialized array length"); StaticHelperClass.TryBodyDelegate negativeStartIndex = new StaticHelperClass.TryBodyDelegate( () => { FieldZqElement[] output = CryptoSerializer.DeserializeFieldZqElementArray(serialized, -1, 10, "blah", crypto.Group); }); StaticHelperClass.AssertThrowsException(negativeStartIndex, typeof(Exception), "negative start index"); StaticHelperClass.TryBodyDelegate startIndexTooLarge = new StaticHelperClass.TryBodyDelegate( () => { FieldZqElement[] output = CryptoSerializer.DeserializeFieldZqElementArray(serialized, 8, 10, "blah", crypto.Group); }); StaticHelperClass.AssertThrowsException(startIndexTooLarge, typeof(Exception), "start index too large"); StaticHelperClass.TryBodyDelegate startIndexWaytooLarge = new StaticHelperClass.TryBodyDelegate( () => { FieldZqElement[] output = CryptoSerializer.DeserializeFieldZqElementArray(serialized, 11, 10, "blah", crypto.Group); }); StaticHelperClass.AssertThrowsException(startIndexWaytooLarge, typeof(Exception), "start index greater than output length "); }
public void CSFieldZqElementArrayTest() { FieldZqElement[] input = StaticHelperClass.GenerateRandomExponents(10, paramIndex); string[] output = CryptoSerializer.SerializeFieldZqElementArray(input, "blah"); Assert.AreEqual(input.Length, output.Length, "serialized array length different."); FieldZqElement[] deserialized = CryptoSerializer.DeserializeFieldZqElementArray(output, "blah", crypto.Group); StaticHelperClass.AssertArraysAreEqual(input, deserialized, "deserialized"); }
public void CSFieldZqElementArrayTest2() { FieldZqElement[] input = StaticHelperClass.GenerateRandomExponents(10, paramIndex); string[] serialized = CryptoSerializer.SerializeFieldZqElementArray(input, 3, 4, "blah"); Assert.AreEqual(4, serialized.Length, "serialized array length"); FieldZqElement[] output = CryptoSerializer.DeserializeFieldZqElementArray(serialized, 3, 10, "output", crypto.Group); FieldZqElement[] expectedOutput = new FieldZqElement[10] { null, null, null, input[3], input[4], input[5], input[6], null, null, null }; StaticHelperClass.AssertArraysAreEqual(expectedOutput, output, "output"); FieldZqElement[] output2 = CryptoSerializer.DeserializeFieldZqElementArray(serialized, 0, 10, "output2", crypto.Group); FieldZqElement[] expectedOutput2 = new FieldZqElement[10] { input[3], input[4], input[5], input[6], null, null, null, null, null, null }; StaticHelperClass.AssertArraysAreEqual(expectedOutput2, output2, "output2"); FieldZqElement[] output3 = CryptoSerializer.DeserializeFieldZqElementArray(serialized, 6, 10, "output3", crypto.Group); FieldZqElement[] expectedOutput3 = new FieldZqElement[10] { null, null, null, null, null, null, input[3], input[4], input[5], input[6] }; StaticHelperClass.AssertArraysAreEqual(expectedOutput3, output3, "output3"); }
public void CSBadSerializeFieldZqElementArrayTest() { FieldZqElement[] input = StaticHelperClass.GenerateRandomExponents(10, paramIndex); StaticHelperClass.TryBodyDelegate negativeLength = new StaticHelperClass.TryBodyDelegate( () => { string[] serialized = CryptoSerializer.SerializeFieldZqElementArray(input, 3, -1, "blah"); }); StaticHelperClass.AssertThrowsException(negativeLength, typeof(Exception), "negative output length"); // zero output length string[] output = CryptoSerializer.SerializeFieldZqElementArray(input, 3, 0, "blah"); Assert.AreEqual(0, output.Length, "output.Length."); // output length too long StaticHelperClass.TryBodyDelegate outputLengthTooLarge = new StaticHelperClass.TryBodyDelegate( () => { string[] serialized = CryptoSerializer.SerializeFieldZqElementArray(input, 3, 9, "blah"); }); StaticHelperClass.AssertThrowsException(outputLengthTooLarge, typeof(Exception), "Output length too large"); // copy index negative StaticHelperClass.TryBodyDelegate startIndexNegative = new StaticHelperClass.TryBodyDelegate( () => { string[] serialized = CryptoSerializer.SerializeFieldZqElementArray(input, -1, 4, "blah"); }); StaticHelperClass.AssertThrowsException(startIndexNegative, typeof(Exception), "Start index is negative."); string[] jsonStrings = new string[32]; StaticHelperClass.AssertThrowsException( () => { CryptoSerializer.DeserializeFieldZqElementArray(jsonStrings, 0, 0, "field", null); }, typeof(SerializationException), "Group is null."); }