Merge pull request #3224 from ludovic-henry/iolayer-extract-wait-handle
[mono.git] / mcs / class / corlib / System.Reflection / StrongNameKeyPair.cs
index fdc129d3e1fce1d17ceebdc3d5b2faeaf468c1fe..aff2ae187e6e69546a111e67f70b70a279f0ced9 100644 (file)
 using System.IO;
 using System.Security.Cryptography;
 using System.Security.Permissions;
+using System.Runtime.InteropServices;
+using System.Runtime.Serialization;
 
 using Mono.Security;
 using Mono.Security.Cryptography;
 
 namespace System.Reflection {
 
+       [ComVisible (true)]
 [Serializable]
-public class StrongNameKeyPair 
+public class StrongNameKeyPair : ISerializable, IDeserializationCallback
 {              
        private byte[] _publicKey;
        private string _keyPairContainer;
@@ -84,7 +87,26 @@ public class StrongNameKeyPair
                _keyPairContainer = keyPairContainer;
                GetRSA ();
        }
-       
+       protected StrongNameKeyPair (SerializationInfo info, StreamingContext context)
+       {
+               _publicKey = (byte []) info.GetValue ("_publicKey", typeof (byte []));
+               _keyPairContainer = info.GetString ("_keyPairContainer");
+               _keyPairExported = info.GetBoolean ("_keyPairExported");
+               _keyPairArray = (byte []) info.GetValue ("_keyPairArray", typeof (byte []));
+       }
+
+       void ISerializable.GetObjectData (SerializationInfo info, StreamingContext context)
+       {
+               info.AddValue ("_publicKey", _publicKey, typeof (byte []));
+               info.AddValue ("_keyPairContainer", _keyPairContainer);
+               info.AddValue ("_keyPairExported", _keyPairExported);
+               info.AddValue ("_keyPairArray", _keyPairArray, typeof (byte []));
+       }
+
+       void IDeserializationCallback.OnDeserialization (object sender)
+       {
+       }
+
        private RSA GetRSA ()
        {
                if (_rsa != null) return _rsa;
@@ -99,11 +121,13 @@ public class StrongNameKeyPair
                                _keyPairArray = null;
                        }
                }
+#if !NET_2_1
                else if (_keyPairContainer != null) {
                        CspParameters csp = new CspParameters ();
                        csp.KeyContainerName = _keyPairContainer;
                        _rsa = new RSACryptoServiceProvider (csp);
                }
+#endif
                return _rsa;
        }
 
@@ -141,24 +165,24 @@ public class StrongNameKeyPair
 
                                byte[] blob = CryptoConvert.ToCapiKeyBlob (rsa, false);
                                _publicKey = new byte [blob.Length + 12];
-                               // The first 12 bytes are documented at:\r
-                               // http://msdn.microsoft.com/library/en-us/cprefadd/html/grfungethashfromfile.asp\r
-                               // ALG_ID - Signature\r
-                               _publicKey[0] = 0x00;\r
-                               _publicKey[1] = 0x24;   \r
-                               _publicKey[2] = 0x00;   \r
-                               _publicKey[3] = 0x00;   \r
-                               // ALG_ID - Hash\r
-                               _publicKey[4] = 0x04;\r
-                               _publicKey[5] = 0x80;\r
-                               _publicKey[6] = 0x00;\r
-                               _publicKey[7] = 0x00;\r
-                               // Length of Public Key (in bytes)\r
-                               int lastPart = blob.Length;\r
-                               _publicKey[8] = (byte)(lastPart % 256);\r
-                               _publicKey[9] = (byte)(lastPart / 256); // just in case\r
-                               _publicKey[10] = 0x00;\r
-                               _publicKey[11] = 0x00;\r
+                               // The first 12 bytes are documented at:
+                               // http://msdn.microsoft.com/library/en-us/cprefadd/html/grfungethashfromfile.asp
+                               // ALG_ID - Signature
+                               _publicKey[0] = 0x00;
+                               _publicKey[1] = 0x24;   
+                               _publicKey[2] = 0x00;   
+                               _publicKey[3] = 0x00;   
+                               // ALG_ID - Hash
+                               _publicKey[4] = 0x04;
+                               _publicKey[5] = 0x80;
+                               _publicKey[6] = 0x00;
+                               _publicKey[7] = 0x00;
+                               // Length of Public Key (in bytes)
+                               int lastPart = blob.Length;
+                               _publicKey[8] = (byte)(lastPart % 256);
+                               _publicKey[9] = (byte)(lastPart / 256); // just in case
+                               _publicKey[10] = 0x00;
+                               _publicKey[11] = 0x00;
 
                                Buffer.BlockCopy (blob, 0, _publicKey, 12, blob.Length);
                        }