public void VerifyLongDerStringRoundTrip() { string TestString = new string('A', 64000); Assert.AreEqual(TestString, DerUtils.DecodeString(DerUtils.EncodePrintableString(TestString)), "PrintableString should make encoding round trip unchanged"); Assert.AreEqual(TestString, DerUtils.DecodeString(DerUtils.EncodeBMPString(TestString)), "BMPString should make encoding round trip unchanged"); }
public void VerifyDerPrintableStringRoundTrip() { const string TestString = "this is a printable string"; Assert.AreEqual(TestString, DerUtils.DecodePrintableString(DerUtils.EncodePrintableString(TestString)), "string should make encoding round trip unchanged"); Assert.AreEqual(string.Empty, DerUtils.DecodePrintableString(DerUtils.EncodePrintableString(string.Empty)), "empty string should make encoding round trip unchanged"); }
public void VerifyDerEncodeStringNullCases() { Action[] testCases = new Action[] { () => DerUtils.EncodePrintableString(null), () => DerUtils.EncodeBMPString(null), }; foreach (Action test in testCases) { bool caught = false; try { test(); } catch (ArgumentNullException) { caught = true; } Assert.IsTrue(caught, "expected an ArgumentNullException"); } }
public void VerifyDerSequenceOfRoundTrip() { var testCases = new[] { new { entryData = new List <string>() { "data1" }, description = "single entry" }, new { entryData = new List <string>() { "data1", "data2", "data3" }, description = "multiple entries" }, new { entryData = new List <string>() { }, description = "no entries" }, }; foreach (var testCase in testCases) { // convert the input data from strings to der encoding, since that's the expected input format List <byte[]> derEntries = new List <byte[]>(); foreach (string entry in testCase.entryData) { derEntries.Add(DerUtils.EncodePrintableString(entry)); } List <byte[]> outputEntries = DerUtils.DecodeSequenceOf(DerUtils.EncodeSequenceOf(derEntries)); // verify the output matches the input Assert.AreEqual(testCase.entryData.Count, outputEntries.Count, "number of output entries should match the number of input entries for test case: " + testCase.description); for (int i = 0; i < outputEntries.Count; i++) { Assert.AreEqual(testCase.entryData[i], DerUtils.DecodeString(outputEntries[i]), "Output data should match input data for test case: " + testCase.description); } } }