PKCS7PaddingTest.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using Microsoft.VisualStudio.TestTools.UnitTesting;
  2. using Renci.SshNet.Security.Cryptography.Ciphers.Paddings;
  3. namespace Renci.SshNet.Tests.Classes.Security.Cryptography.Ciphers.Paddings
  4. {
  5. [TestClass]
  6. public class PKCS7PaddingTest
  7. {
  8. private PKCS7Padding _padding;
  9. [TestInitialize]
  10. public void SetUp()
  11. {
  12. _padding = new PKCS7Padding();
  13. }
  14. [TestMethod]
  15. public void Pad_BlockSizeAndInput_LessThanBlockSize()
  16. {
  17. var input = new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05 };
  18. var expected = new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x03, 0x03, 0x03 };
  19. var actual = _padding.Pad(8, input);
  20. Assert.IsTrue(expected.IsEqualTo(actual));
  21. }
  22. [TestMethod]
  23. public void Pad_BlockSizeAndInput_MoreThanBlockSizeButNoMultipleOfBlockSize()
  24. {
  25. var input = new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09 };
  26. var expected = new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07 };
  27. var actual = _padding.Pad(8, input);
  28. Assert.IsTrue(expected.IsEqualTo(actual));
  29. }
  30. [TestMethod]
  31. public void Pad_BlockSizeAndInputAndOffsetAndLength_LessThanBlockSize()
  32. {
  33. var input = new byte[] { 0x0f, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 };
  34. var expected = new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x03, 0x03, 0x03 };
  35. var actual = _padding.Pad(8, input, 1, input.Length - 2);
  36. Assert.IsTrue(expected.IsEqualTo(actual));
  37. }
  38. [TestMethod]
  39. public void Pad_BlockSizeAndInputAndOffsetAndLength_MoreThanBlockSizeButNoMultipleOfBlockSize()
  40. {
  41. var input = new byte[] { 0x0f, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10 };
  42. var expected = new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07 };
  43. var actual = _padding.Pad(8, input, 1, input.Length - 2);
  44. Assert.IsTrue(expected.IsEqualTo(actual));
  45. }
  46. }
  47. }