[docs] Import of Microsoft BCL Documentation.
[mono.git] / mcs / class / corlib / System.Security.Cryptography / SymmetricAlgorithm.cs
index 036f78fbe2b77d8cbb48e2329872befe818b77f2..ba713e8c6e5a3b41374f05672ec3e3421147f111 100644 (file)
@@ -6,7 +6,7 @@
 //   Sebastien Pouliot <sebastien@ximian.com>
 //
 // Portions (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
-// Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2004-2006 Novell, Inc (http://www.novell.com)
 //
 // Permission is hereby granted, free of charge, to any person obtaining
 // a copy of this software and associated documentation files (the
@@ -34,42 +34,38 @@ 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; 
+               protected int FeedbackSizeValue;
+               protected CipherMode ModeValue;
+               protected PaddingMode PaddingValue;
                private bool m_disposed;
 
-               public SymmetricAlgorithm () 
+               protected SymmetricAlgorithm ()
                {
                        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) 
@@ -107,14 +103,14 @@ 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"));
                                }
+                               if ((value & 3) != 0) {
+                                       throw new CryptographicException (
+                                               Locale.GetText ("feedback size must be a multiple of 8 (bits)"));
+                               }
                                this.FeedbackSizeValue = value;
                        }
                }
@@ -129,18 +125,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 ();
                        }
                }
@@ -237,7 +226,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)