Merge pull request #3224 from ludovic-henry/iolayer-extract-wait-handle
[mono.git] / mcs / class / corlib / System.Reflection / StrongNameKeyPair.cs
index eff73aecbb421a7efdec36154c8d8a9578fc032a..aff2ae187e6e69546a111e67f70b70a279f0ced9 100644 (file)
@@ -33,17 +33,16 @@ 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 {
 
-#if NET_2_0
        [ComVisible (true)]
-#endif
 [Serializable]
-public class StrongNameKeyPair 
+public class StrongNameKeyPair : ISerializable, IDeserializationCallback
 {              
        private byte[] _publicKey;
        private string _keyPairContainer;
@@ -88,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;
@@ -103,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;
        }