PKCS5PaddingTest.cs 2.2 KB

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