[runtime] Fix handling of ECMA key when parsing assembly name.
authorMarek Habersack <grendel@twistedcode.net>
Mon, 2 May 2011 13:09:46 +0000 (15:09 +0200)
committerMarek Habersack <grendel@twistedcode.net>
Mon, 2 May 2011 13:47:25 +0000 (15:47 +0200)
This fixes mcs InternalsVisibleTo support for assemblies signed with the ECMA (ecma.pub)
key. Previously the key token would be returned as the assembly's key, which caused mcs
to fail to match friend assemblies.

mono/metadata/assembly.c

index 621e450dba68574d9324196223bf33abebce4d20..de1eff2a1da69caf77267a09c32df9af1836ea22 100644 (file)
@@ -1672,7 +1672,7 @@ mono_assembly_name_free (MonoAssemblyName *aname)
 }
 
 static gboolean
-parse_public_key (const gchar *key, gchar** pubkey)
+parse_public_key (const gchar *key, gchar** pubkey, gboolean *is_ecma)
 {
        const gchar *pkey;
        gchar header [16], val, *arr;
@@ -1685,11 +1685,12 @@ parse_public_key (const gchar *key, gchar** pubkey)
        /* allow the ECMA standard key */
        if (strcmp (key, "00000000000000000400000000000000") == 0) {
                if (pubkey) {
-                       arr = g_strdup ("b77a5c561934e089");
-                       *pubkey = arr;
+                       *pubkey = g_strdup (key);
+                       *is_ecma = TRUE;
                }
                return TRUE;
        }
+       *is_ecma = FALSE;
        val = g_ascii_xdigit_value (key [0]) << 4;
        val |= g_ascii_xdigit_value (key [1]);
        switch (val) {
@@ -1812,10 +1813,20 @@ build_assembly_name (const char *name, const char *version, const char *culture,
        }
 
        if (key) {
-               if (strcmp (key, "null") == 0 || !parse_public_key (key, &pkey)) {
+               gboolean is_ecma;
+               if (strcmp (key, "null") == 0 || !parse_public_key (key, &pkey, &is_ecma)) {
                        mono_assembly_name_free (aname);
                        return FALSE;
                }
+
+               if (is_ecma) {
+                       if (save_public_key)
+                               aname->public_key = (guint8*)pkey;
+                       else
+                               g_free (pkey);
+                       g_strlcpy ((gchar*)aname->public_key_token, "b77a5c561934e089", MONO_PUBLIC_KEY_TOKEN_LENGTH);
+                       return TRUE;
+               }
                
                len = mono_metadata_decode_blob_size ((const gchar *) pkey, (const gchar **) &pkeyptr);
                // We also need to generate the key token