2003-10-18 Zoltan Varga <vargaz@freemail.hu>
authorZoltan Varga <vargaz@gmail.com>
Sat, 18 Oct 2003 15:34:26 +0000 (15:34 -0000)
committerZoltan Varga <vargaz@gmail.com>
Sat, 18 Oct 2003 15:34:26 +0000 (15:34 -0000)
* AssemblyBuilder.cs (SetCustomAttribute): Extract the public key from
the keyfile.

svn path=/trunk/mcs/; revision=19162

mcs/class/corlib/System.Reflection.Emit/AssemblyBuilder.cs
mcs/class/corlib/System.Reflection.Emit/ChangeLog

index bd7deb2e53372079c69ca561b6ce8e356b20d826..cca5fe490c05a2df359b21ece6f1a1c6aa40fa33 100755 (executable)
@@ -17,6 +17,9 @@ using System.Globalization;
 using System.Runtime.CompilerServices;
 using System.Collections;
 using System.Runtime.InteropServices;
+using System.Security.Cryptography;
+
+using Mono.Security.Cryptography;
 
 namespace System.Reflection.Emit {
 
@@ -442,10 +445,24 @@ namespace System.Reflection.Emit {
                                        byte[] snkeypair = new byte [fs.Length];
                                        fs.Read (snkeypair, 0, snkeypair.Length);
 
-                                       /* FIXME: Extract public key from the keypair */
-                                       public_key = snkeypair;
+                                       // this will import public or private/public keys
+                                       RSA rsa = CryptoConvert.FromCapiKeyBlob (snkeypair);
+                                       // and export only the public part
+                                       public_key = CryptoConvert.ToCapiPublicKeyBlob (rsa);
                                }
                                return;
+                       } else if (attrname == "System.Reflection.AssemblyKeyNameAttribute") {
+                               data = customBuilder.Data;
+                               pos = 2;
+                               len = CustomAttributeBuilder.decode_len (data, pos, out pos);
+                               string key_name = CustomAttributeBuilder.string_from_bytes (data, pos, len);
+                               if (key_name == String.Empty)
+                                       return;
+                               CspParameters csparam = new CspParameters ();
+                               csparam.KeyContainerName = key_name;
+                               RSA rsacsp = new RSACryptoServiceProvider (csparam);
+                               public_key = CryptoConvert.ToCapiPublicKeyBlob (rsacsp);
+                               return;
                        } else if (attrname == "System.Reflection.AssemblyCultureAttribute") {
                                data = customBuilder.Data;
                                pos = 2;
index 6e73c271f3692911886aa74de511daa7c7d7f59d..0d7ddbeb26c8cfe04f49801661f4a4ff1acabf4a 100644 (file)
@@ -1,3 +1,8 @@
+2003-10-18  Zoltan Varga  <vargaz@freemail.hu>
+
+       * AssemblyBuilder.cs (SetCustomAttribute): Extract the public key from
+       the keyfile.
+
 2003-10-17  Zoltan Varga  <vargaz@freemail.hu>
 
        * AssemblyBuilder.cs (SetCustomAttribute): Ignore empty keyfile name.