public static void GetCiphertextLengthCfb_NoPaddingAndPlaintextSizeNotFeedbackAligned() { AnySizeAlgorithm alg = new AnySizeAlgorithm(); Assert.Throws <ArgumentException>("plaintextLength", () => alg.GetCiphertextLengthCfb(17, PaddingMode.None, feedbackSizeInBits: 128)); }
public static void GetCiphertextLengthCfb_ThrowsForNonByteFeedbackSize(PaddingMode mode) { AnySizeAlgorithm alg = new AnySizeAlgorithm(); AssertExtensions.Throws <ArgumentException>("feedbackSizeInBits", () => alg.GetCiphertextLengthCfb(16, mode, 7)); }
public static void GetCiphertextLengthCfb_ThrowsForOverflow(PaddingMode mode) { AnySizeAlgorithm alg = new AnySizeAlgorithm(); AssertExtensions.Throws <ArgumentOutOfRangeException>("plaintextLength", () => alg.GetCiphertextLengthCfb(0x7FFFFFFF, mode, feedbackSizeInBits: 128)); }
public static void GetCiphertextLengthBlock_ThrowsForNonByteBlockSize(PaddingMode mode) { AnySizeAlgorithm alg = new AnySizeAlgorithm { BlockSize = 5 }; Assert.Throws <InvalidOperationException>(() => alg.GetCiphertextLengthCbc(16, mode)); Assert.Throws <InvalidOperationException>(() => alg.GetCiphertextLengthEcb(16, mode)); }
public static void GetCiphertextLengthBlock_ThrowsForOverflow(PaddingMode mode) { AnySizeAlgorithm alg = new AnySizeAlgorithm { BlockSize = 128 }; AssertExtensions.Throws <ArgumentOutOfRangeException>("plaintextLength", () => alg.GetCiphertextLengthCbc(0x7FFFFFF1, mode)); AssertExtensions.Throws <ArgumentOutOfRangeException>("plaintextLength", () => alg.GetCiphertextLengthEcb(0x7FFFFFF1, mode)); }
public static void DecryptEcb_NotSupportedInDerived() { AnySizeAlgorithm alg = new AnySizeAlgorithm { BlockSize = 128 }; Assert.Throws <NotSupportedException>(() => alg.DecryptEcb(Array.Empty <byte>(), PaddingMode.None)); }
public static void GetCiphertextLengthBlock_NoPaddingAndPlaintextSizeNotBlockAligned() { AnySizeAlgorithm alg = new AnySizeAlgorithm { BlockSize = 128 }; Assert.Throws <ArgumentException>("plaintextLength", () => alg.GetCiphertextLengthCbc(17, PaddingMode.None)); Assert.Throws <ArgumentException>("plaintextLength", () => alg.GetCiphertextLengthEcb(17, PaddingMode.None)); }
public static void GetCiphertextLength_ThrowsForNegativeInput(PaddingMode mode) { AnySizeAlgorithm alg = new AnySizeAlgorithm { BlockSize = 128 }; AssertExtensions.Throws <ArgumentOutOfRangeException>("plaintextLength", () => alg.GetCiphertextLengthCbc(-1, mode)); AssertExtensions.Throws <ArgumentOutOfRangeException>("plaintextLength", () => alg.GetCiphertextLengthEcb(-1, mode)); AssertExtensions.Throws <ArgumentOutOfRangeException>("plaintextLength", () => alg.GetCiphertextLengthCfb(-1, mode)); }
public static void GetCiphertextLengthCfb_ValidInputs( PaddingMode mode, int plaintextSize, int expectedCiphertextSize, int alignmentSizeInBits) { AnySizeAlgorithm alg = new AnySizeAlgorithm(); int ciphertextSizeCfb = alg.GetCiphertextLengthCfb(plaintextSize, mode, alignmentSizeInBits); Assert.Equal(expectedCiphertextSize, ciphertextSizeCfb); }
public static void GetCiphertextLength_ThrowsForInvalidPaddingMode() { AnySizeAlgorithm alg = new AnySizeAlgorithm { BlockSize = 128 }; PaddingMode mode = (PaddingMode)(-1); Assert.Throws <ArgumentOutOfRangeException>("paddingMode", () => alg.GetCiphertextLengthCbc(16, mode)); Assert.Throws <ArgumentOutOfRangeException>("paddingMode", () => alg.GetCiphertextLengthEcb(16, mode)); Assert.Throws <ArgumentOutOfRangeException>("paddingMode", () => alg.GetCiphertextLengthCfb(16, mode)); }
public static void GetCiphertextLengthBlock_ValidInputs( PaddingMode mode, int plaintextSize, int expectedCiphertextSize, int alignmentSizeInBits) { AnySizeAlgorithm alg = new AnySizeAlgorithm { BlockSize = alignmentSizeInBits }; int ciphertextSizeCbc = alg.GetCiphertextLengthCbc(plaintextSize, mode); int ciphertextSizeEcb = alg.GetCiphertextLengthEcb(plaintextSize, mode); Assert.Equal(expectedCiphertextSize, ciphertextSizeCbc); Assert.Equal(expectedCiphertextSize, ciphertextSizeEcb); }