+ // ordered to avoid possible integer overflow
+ int len = outputBuffer.Length - inputCount - outputOffset;
+#if MOONLIGHT
+ // only PKCS7 is supported Silverlight 2.0
+ if (KeepLastBlock) {
+#else
+ if (!encrypt && (0 > len) && ((algo.Padding == PaddingMode.None) || (algo.Padding == PaddingMode.Zeros))) {
+ throw new CryptographicException ("outputBuffer", Locale.GetText ("Overflow"));
+ } else if (KeepLastBlock) {
+#endif
+ if (0 > len + BlockSizeByte) {
+ throw new CryptographicException ("outputBuffer", Locale.GetText ("Overflow"));
+ }
+ } else {
+ if (0 > len) {
+ // there's a special case if this is the end of the decryption process
+ if (inputBuffer.Length - inputOffset - outputBuffer.Length == BlockSizeByte)
+ inputCount = outputBuffer.Length - outputOffset;
+ else
+ throw new CryptographicException ("outputBuffer", Locale.GetText ("Overflow"));
+ }
+ }