Fix null sessions in HttpContextWrapper.Session
[mono.git] / mcs / class / corlib / System.Security.Cryptography / ToBase64Transform.cs
index 382db461c5550a493348b901112fffb4282568cc..0f0f05a54d15c8e71edf6515982097ca6b984752 100644 (file)
@@ -32,11 +32,11 @@ using System.Runtime.InteropServices;
 
 namespace System.Security.Cryptography {
 
-#if NET_2_0
        [ComVisible (true)]
-#endif
        public class ToBase64Transform : ICryptoTransform {
 
+               private const int inputBlockSize = 3;
+               private const int outputBlockSize = 4;
                private bool m_disposed;
 
                public ToBase64Transform ()
@@ -57,11 +57,11 @@ namespace System.Security.Cryptography {
                }
 
                public int InputBlockSize {
-                       get { return 3; }
+                       get { return inputBlockSize; }
                }
 
                public int OutputBlockSize {
-                       get { return 4; }
+                       get { return outputBlockSize; }
                }
 
                public void Clear() 
@@ -69,7 +69,11 @@ namespace System.Security.Cryptography {
                        Dispose (true);
                }
 
+#if NET_4_0
+               public void Dispose ()
+#else
                void IDisposable.Dispose () 
+#endif
                {
                        Dispose (true);
                        GC.SuppressFinalize (this);  // Finalization is now unnecessary
@@ -107,19 +111,20 @@ namespace System.Security.Cryptography {
                        if (inputOffset > inputBuffer.Length - inputCount)
                                throw new ArgumentException ("inputOffset", Locale.GetText ("Overflow"));
                        // ordered to avoid possible integer overflow
-#if NET_2_0
                        if (outputOffset < 0)
                                throw new ArgumentOutOfRangeException ("outputOffset", "< 0");
                        if (outputOffset > outputBuffer.Length - inputCount)
                                throw new ArgumentException ("outputOffset", Locale.GetText ("Overflow"));
-#else
-                       if ((outputOffset < 0) || (outputOffset > outputBuffer.Length - inputCount))
-                               throw new IndexOutOfRangeException ("outputOffset");
-#endif
 /// To match MS implementation
 //                     if (inputCount != this.InputBlockSize)
 //                             throw new CryptographicException (Locale.GetText ("Invalid input length"));
 
+                       InternalTransformBlock (inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset);
+                       return this.OutputBlockSize;
+               }
+
+               internal static void InternalTransformBlock (byte[] inputBuffer, int inputOffset, int inputCount, byte[] outputBuffer, int outputOffset)
+               {
                        byte[] lookup = Base64Constants.EncodeTable;
 
                        int b1 = inputBuffer [inputOffset];
@@ -130,8 +135,6 @@ namespace System.Security.Cryptography {
                        outputBuffer [outputOffset+1] = lookup [((b1 << 4) & 0x30) | (b2 >> 4)];
                        outputBuffer [outputOffset+2] = lookup [((b2 << 2) & 0x3c) | (b3 >> 6)];
                        outputBuffer [outputOffset+3] = lookup [b3 & 0x3f];
-
-                       return this.OutputBlockSize;
                }
 
                public byte[] TransformFinalBlock (byte[] inputBuffer, int inputOffset, int inputCount)
@@ -151,10 +154,10 @@ namespace System.Security.Cryptography {
                }
                
                // Mono System.Convert depends on the ability to process multiple blocks                
-               internal byte[] InternalTransformFinalBlock (byte[] inputBuffer, int inputOffset, int inputCount)
+               internal static byte[] InternalTransformFinalBlock (byte[] inputBuffer, int inputOffset, int inputCount)
                {
-                       int blockLen = this.InputBlockSize;
-                       int outLen = this.OutputBlockSize;
+                       int blockLen = inputBlockSize;
+                       int outLen = outputBlockSize;
                        int fullBlocks = inputCount / blockLen;
                        int tail = inputCount % blockLen;
 
@@ -165,10 +168,7 @@ namespace System.Security.Cryptography {
                        int outputOffset = 0;
 
                        for (int i = 0; i < fullBlocks; i++) {
-
-                               TransformBlock (inputBuffer, inputOffset,
-                                               blockLen, res, outputOffset);
-
+                               InternalTransformBlock (inputBuffer, inputOffset, blockLen, res, outputOffset);
                                inputOffset += blockLen;
                                outputOffset += outLen;
                        }