Merge pull request #495 from nicolas-raoul/fix-for-issue2907-with-no-formatting-changes
[mono.git] / mcs / class / corlib / System.Security.Cryptography / SymmetricAlgorithm.cs
index 0962a8081c8b0604c899a9aaabc22b21c99c7e1a..60b57e7e7536b33dd99ebfab6ab36f4be80bae13 100644 (file)
@@ -34,46 +34,45 @@ using Mono.Security.Cryptography;
 
 namespace System.Security.Cryptography {
 
-#if NET_2_0
        [ComVisible (true)]
-#endif
        public abstract class SymmetricAlgorithm : IDisposable {
                protected int BlockSizeValue; 
-               protected int FeedbackSizeValue; 
                protected byte[] IVValue; 
                protected int KeySizeValue; 
                protected byte[] KeyValue; 
                protected KeySizes[] LegalBlockSizesValue; 
                protected KeySizes[] LegalKeySizesValue; 
-               protected CipherMode ModeValue; 
-               protected PaddingMode PaddingValue; 
+#if MOONLIGHT
+               // Silverlight 2.0 only supports CBC
+               internal int FeedbackSizeValue;
+               internal CipherMode ModeValue;
+               internal PaddingMode PaddingValue;
+#else
+               protected int FeedbackSizeValue;
+               protected CipherMode ModeValue;
+               protected PaddingMode PaddingValue;
+#endif
                private bool m_disposed;
 
-#if NET_2_0
                protected SymmetricAlgorithm ()
-#else
-               public SymmetricAlgorithm ()
-#endif
                {
                        ModeValue = CipherMode.CBC;
                        PaddingValue = PaddingMode.PKCS7;
-                       m_disposed = false;
-               }
-               
-               ~SymmetricAlgorithm () 
-               {
-                       Dispose (false);
                }
 
-               public void Clear() 
+#if NET_4_0
+               public void Dispose ()
+#else
+               void IDisposable.Dispose () 
+#endif
                {
                        Dispose (true);
+                       GC.SuppressFinalize (this);  // Finalization is now unnecessary
                }
 
-               void IDisposable.Dispose () 
+               public void Clear() 
                {
                        Dispose (true);
-                       GC.SuppressFinalize (this);  // Finalization is now unnecessary
                }
 
                protected virtual void Dispose (bool disposing) 
@@ -111,11 +110,7 @@ namespace System.Security.Cryptography {
                public virtual int FeedbackSize {
                        get { return this.FeedbackSizeValue; }
                        set {
-#if NET_2_0
                                if ((value <= 0) || (value > this.BlockSizeValue)) {
-#else
-                               if (value > this.BlockSizeValue) {
-#endif
                                        throw new CryptographicException (
                                                Locale.GetText ("feedback size larger than block size"));
                                }
@@ -133,18 +128,11 @@ namespace System.Security.Cryptography {
                        set {
                                if (value == null)
                                        throw new ArgumentNullException ("IV");
-#if NET_2_0
                                // 2.0 is stricter for IV length - which is bad for IV-less stream ciphers like RC4
                                if ((value.Length << 3) != this.BlockSizeValue) {
                                        throw new CryptographicException (
                                                Locale.GetText ("IV length is different than block size"));
                                }
-#else                                  
-                               if ((value.Length << 3) > this.BlockSizeValue) {
-                                       throw new CryptographicException (
-                                               Locale.GetText ("IV length cannot be larger than block size"));
-                               }
-#endif
                                this.IVValue = (byte[]) value.Clone ();
                        }
                }
@@ -241,7 +229,11 @@ namespace System.Security.Cryptography {
                // LAMESPEC: Default is Rijndael - not TripleDES
                public static SymmetricAlgorithm Create () 
                {
+#if FULL_AOT_RUNTIME
+                       return new System.Security.Cryptography.RijndaelManaged ();
+#else
                        return Create ("System.Security.Cryptography.SymmetricAlgorithm");
+#endif
                }
 
                public static SymmetricAlgorithm Create (string algName)