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_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_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); }
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 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)); }