internal StrongName(StrongNamePublicKeyBlob blob, string name, System.Version version, Assembly assembly)
 {
     if (name == null)
     {
         throw new ArgumentNullException("name");
     }
     if (string.IsNullOrEmpty(name))
     {
         throw new ArgumentException(Environment.GetResourceString("Argument_EmptyStrongName"));
     }
     if (blob == null)
     {
         throw new ArgumentNullException("blob");
     }
     if (version == null)
     {
         throw new ArgumentNullException("version");
     }
     RuntimeAssembly assembly2 = assembly as RuntimeAssembly;
     if ((assembly != null) && (assembly2 == null))
     {
         throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeAssembly"), "assembly");
     }
     this.m_publicKeyBlob = blob;
     this.m_name = name;
     this.m_version = version;
     this.m_assembly = assembly2;
 }
        // Convert an XML value into a permissions value.
        public override void FromXml(SecurityElement esd)
        {
            if (esd == null)
            {
                throw new ArgumentNullException("esd");
            }
            if (esd.Attribute("version") != "1")
            {
                throw new ArgumentException(_("Arg_PermissionVersion"));
            }
            name = esd.Attribute("Name");
            String value = esd.Attribute("Version");

            if (value != null)
            {
                version = new Version(value);
            }
            else
            {
                version = null;
            }
            value = esd.Attribute("PublicKeyBlob");
            if (value != null)
            {
                blob = new StrongNamePublicKeyBlob(value);
            }
            else
            {
                blob = null;
            }
        }
Example #3
0
        // Create a permission object that corresponds to this attribute.
        public override IPermission CreatePermission()
        {
            X509Certificate certificate;

            if (Unrestricted)
            {
                throw new ArgumentException(_("Arg_PermissionState"));
            }
            else if (certFile == null && signedFile == null && cert == null)
            {
                return(new PublisherIdentityPermission
                           (PermissionState.None));
            }
            else if (cert != null)
            {
                certificate = new X509Certificate
                                  (StrongNamePublicKeyBlob.FromHex(cert));
            }
            else if (certFile != null)
            {
                certificate =
                    System.Security.Cryptography.X509Certificates
                    .X509Certificate.CreateFromCertFile(certFile);
            }
            else
            {
                certificate =
                    System.Security.Cryptography.X509Certificates
                    .X509Certificate.CreateFromSignedFile(signedFile);
            }
            return(new PublisherIdentityPermission(certificate));
        }
Example #4
0
        /// <include file='doc\StrongNameIdentityPermission.uex' path='docs/doc[@for="StrongNameIdentityPermission.FromXml"]/*' />
        public override void FromXml(SecurityElement e)
        {
            CodeAccessPermission.ValidateElement(e, this);
            if (e == null)
            {
                throw new ArgumentNullException("e");
            }

            String elBlob = e.Attribute("PublicKeyBlob");

            if (elBlob != null)
            {
                m_publicKeyBlob = new StrongNamePublicKeyBlob(Hex.DecodeHexString(elBlob));
            }
            else
            {
                m_publicKeyBlob = null;
            }

            String elName = e.Attribute("Name");

            m_name = elName == null ? null : elName;

            String elVersion = e.Attribute("AssemblyVersion");

            m_version = elVersion == null ? null : new Version(elVersion);
        }
Example #5
0
 // Create a permission object that corresponds to this attribute.
 public override IPermission CreatePermission()
 {
     if (Unrestricted)
     {
         throw new ArgumentException(_("Arg_PermissionState"));
     }
     else if (blob == null && name == null && version == null)
     {
         return(new StrongNameIdentityPermission
                    (PermissionState.None));
     }
     else if (blob == null)
     {
         throw new ArgumentException(_("Arg_PublicKeyBlob"));
     }
     else
     {
         StrongNamePublicKeyBlob key;
         Version vers;
         key = new StrongNamePublicKeyBlob(blob);
         if (version != null && version != String.Empty)
         {
             vers = new Version(version);
         }
         else
         {
             vers = null;
         }
         return(new StrongNameIdentityPermission(key, name, vers));
     }
 }
 internal bool Equals( StrongNamePublicKeyBlob blob )
 {
     if (blob == null)
         return false;
     else 
         return CompareArrays( this.PublicKey, blob.PublicKey );
 }
	public void PublicKey () 
	{
		StrongNamePublicKeyBlob snpkb = new StrongNamePublicKeyBlob (pk);
		Assert.IsTrue (snpkb.Equals (snpkb), "Equals(Self)");
		Assert.IsFalse (snpkb.Equals (null), "Equals(null)");
		Assert.AreEqual ("00240000048000009400000006020000002400005253413100040000010001003DBD7208C62B0EA8C1C058072B635F7C9ABDCB22DB20B2A9DADAEFE800642F5D8DEB7802F7A5367728D7558D1468DBEB2409D02B131B926E2E59544AAC18CFC909023F4FA83E94001FC2F11A27477D1084F514B861621A0C66ABD24C4B9FC90F3CD8920FF5FFCED76E5C6FB1F57DD356F96727A4A5485B079344004AF8FFA4CB", snpkb.ToString (), "ToString(pk)");

		StrongNamePublicKeyBlob snpkb2 = new StrongNamePublicKeyBlob (pk);
		Assert.IsTrue (snpkb.Equals (snpkb2), "Equals()-true");
		StrongNamePublicKeyBlob snpkb3 = new StrongNamePublicKeyBlob (bad);
		Assert.IsFalse (snpkb.Equals (snpkb3), "Equals()-false");

		// non standard get hash code - why ???
		Assert.AreEqual (snpkb2.GetHashCode (), snpkb.GetHashCode (), "GetHashCode-0");

		// the first 4 bytes has code has been fixed in 2.0 beta 1

// Historical data:
// #elif NET_1_1
// 		// It seems to be the first four bytes of the public key data
// 		// which seems like non sense as all valid public key will have the same header ?
// 		Assert.AreEqual (2359296, snpkb.GetHashCode (), "GetHashCode-1");
// 		Assert.AreEqual (2359296, snpkb2.GetHashCode (), "GetHashCode-2");
// 		Assert.AreEqual (2989, snpkb3.GetHashCode (), "GetHashCode-3");
// 		byte[] header = { 0x00, 0x24, 0x00, 0x00 };
// 		StrongNamePublicKeyBlob snpkb4 = new StrongNamePublicKeyBlob (header);
// 		Assert.AreEqual (2359296, snpkb4.GetHashCode (), "GetHashCode-4");
// #endif
	}
        // Methods
        public override IPermission CreatePermission()
        {
#if NET_2_1
            return(null);
#else
            if (this.Unrestricted)
            {
                return(new StrongNameIdentityPermission(PermissionState.Unrestricted));
            }

            if ((name == null) && (key == null) && (version == null))
            {
                return(new StrongNameIdentityPermission(PermissionState.None));
            }

            if (key == null)
            {
                throw new ArgumentException(Locale.GetText(
                                                "PublicKey is required"));
            }
            StrongNamePublicKeyBlob blob = StrongNamePublicKeyBlob.FromString(key);

            Version v = null;
            if (version != null)
            {
                v = new Version(version);
            }

            return(new StrongNameIdentityPermission(blob, name, v));
#endif
        }
	// Convert an XML value into a permissions value.
	public override void FromXml(SecurityElement esd)
			{
				if(esd == null)
				{
					throw new ArgumentNullException("esd");
				}
				if(esd.Attribute("version") != "1")
				{
					throw new ArgumentException(_("Arg_PermissionVersion"));
				}
				name = esd.Attribute("Name");
				String value = esd.Attribute("Version");
				if(value != null)
				{
					version = new Version(value);
				}
				else
				{
					version = null;
				}
				value = esd.Attribute("PublicKeyBlob");
				if(value != null)
				{
					blob = new StrongNamePublicKeyBlob(value);
				}
				else
				{
					blob = null;
				}
			}
Example #10
0
        public override IPermission CreatePermission()
        {
            if (m_unrestricted)
            {
                return(new StrongNameIdentityPermission(PermissionState.Unrestricted));
            }
            else
            {
                if (m_blob == null && m_name == null && m_version == null)
                {
                    return(new StrongNameIdentityPermission(PermissionState.None));
                }

                if (m_blob == null)
                {
                    throw new ArgumentException(Environment.GetResourceString("ArgumentNull_Key"));
                }

                StrongNamePublicKeyBlob blob = new StrongNamePublicKeyBlob(m_blob);

                if (m_version == null || m_version.Equals(String.Empty))
                {
                    return(new StrongNameIdentityPermission(blob, m_name, null));
                }
                else
                {
                    return(new StrongNameIdentityPermission(blob, m_name, new Version(m_version)));
                }
            }
        }
Example #11
0
 internal bool Equals(StrongNamePublicKeyBlob blob)
 {
     if (blob == null)
     {
         return(false);
     }
     return(StrongNamePublicKeyBlob.CompareArrays(this.PublicKey, blob.PublicKey));
 }
		private StrongNameIdentityPermission GetUnion ()
		{
			StrongNamePublicKeyBlob blob = new StrongNamePublicKeyBlob (ecma);
			StrongNameIdentityPermission snip = new StrongNameIdentityPermission (blob, "mono", new Version (1, 2, 3, 4));
			StrongNamePublicKeyBlob blob2 = new StrongNamePublicKeyBlob (new byte[16]);
			StrongNameIdentityPermission diffPk = new StrongNameIdentityPermission (blob2, "mono", new Version (1, 2, 3, 4));
			return (StrongNameIdentityPermission)snip.Union (diffPk);
		}
        private StrongNameIdentityPermission.SNIP FromSecurityElement(SecurityElement se)
        {
            string name = se.Attribute("Name");
            StrongNamePublicKeyBlob pk = StrongNamePublicKeyBlob.FromString(se.Attribute("PublicKeyBlob"));
            string  text    = se.Attribute("AssemblyVersion");
            Version version = (text != null) ? new Version(text) : null;

            return(new StrongNameIdentityPermission.SNIP(pk, name, version));
        }
 /// <include file='doc\StrongNameIdentityPermission.uex' path='docs/doc[@for="StrongNameIdentityPermission.StrongNameIdentityPermission1"]/*' />
 public StrongNameIdentityPermission( StrongNamePublicKeyBlob blob, String name, Version version )
 {
     if (blob == null)
         throw new ArgumentNullException( "blob" );
 
     m_publicKeyBlob = blob;
     m_name = name;
     m_version = version;
 }
        private SNIP FromSecurityElement(SecurityElement se)
        {
            string name = se.Attribute("Name");
            StrongNamePublicKeyBlob publickey = StrongNamePublicKeyBlob.FromString(se.Attribute("PublicKeyBlob"));
            string  v = se.Attribute("AssemblyVersion");
            Version assemblyVersion = (v == null) ? null : new Version(v);

            return(new SNIP(publickey, name, assemblyVersion));
        }
        public StrongNameIdentityPermission(StrongNamePublicKeyBlob blob, string name, Version version)
        {
            if (blob == null)
            {
                throw new ArgumentNullException("blob");
            }

            _single = new SNIP(blob, name, version);
        }
                public StrongNameMembershipCondition (StrongNamePublicKeyBlob blob, string name, Version version)
                {
                        if (blob == null)
                                throw new ArgumentNullException ("blob");

                        this.blob = blob;
                        this.name = name;
			if (version != null)
	                        assemblyVersion = (Version) version.Clone ();
                }
 // Constructor.
 public StrongNameIdentityPermission(PermissionState state)
 {
     if (state != PermissionState.None)
     {
         throw new ArgumentException(_("Arg_PermissionState"));
     }
     blob    = null;
     name    = "";
     version = new Version();
 }
	// Constructor.
	public StrongNameIdentityPermission(PermissionState state)
			{
				if(state != PermissionState.None)
				{
					throw new ArgumentException(_("Arg_PermissionState"));
				}
				blob = null;
				name = "";
				version = new Version();
			}
	public StrongNameMembershipCondition
				(StrongNamePublicKeyBlob blob, String name, Version version)
			{
				if(blob == null)
				{
					throw new ArgumentNullException("blob");
				}
				this.blob = blob;
				this.name = name;
				this.version = version;
			}
 public StrongNameIdentityPermission(StrongNamePublicKeyBlob blob,
                                     String name, Version version)
 {
     if (blob == null)
     {
         throw new ArgumentNullException("blob");
     }
     this.blob    = blob;
     this.name    = name;
     this.version = version;
 }
Example #22
0
 public StrongNameIdentityPermission(StrongNamePublicKeyBlob blob, string name, System.Version version)
 {
     if (blob == null)
     {
         throw new ArgumentNullException("blob");
     }
     if ((name != null) && name.Equals(""))
     {
         throw new ArgumentException(Environment.GetResourceString("Argument_EmptyStrongName"));
     }
     this.m_unrestricted = false;
     this.m_strongNames  = new StrongName2[] { new StrongName2(blob, name, version) };
 }
 public StrongNameIdentityPermission(StrongNamePublicKeyBlob blob, string name, System.Version version)
 {
     if (blob == null)
     {
         throw new ArgumentNullException("blob");
     }
     if ((name != null) && name.Equals(""))
     {
         throw new ArgumentException(Environment.GetResourceString("Argument_EmptyStrongName"));
     }
     this.m_unrestricted = false;
     this.m_strongNames = new StrongName2[] { new StrongName2(blob, name, version) };
 }
Example #24
0
 public StrongNameIdentityPermission(StrongNamePublicKeyBlob blob, String name, Version version)
 {
     if (blob == null)
     {
         throw new ArgumentNullException("blob");
     }
     if (name != null && name.Equals(""))
     {
         throw new ArgumentException(Environment.GetResourceString("Argument_EmptyStrongName"));
     }
     m_unrestricted   = false;
     m_strongNames    = new StrongName2[1];
     m_strongNames[0] = new StrongName2(blob, name, version);
 }
	public StrongName (StrongNamePublicKeyBlob blob, string name, Version version) 
	{
		if (blob == null)
			throw new ArgumentNullException ("blob");
		if (name == null)
			throw new ArgumentNullException ("name");
		if (version == null)
			throw new ArgumentNullException ("version");
		if (name.Length == 0)
			throw new ArgumentException (Locale.GetText ("Empty"), "name");
		publickey = blob;
		this.name = name;
		this.version = version;
	}
 /// <summary>Initializes a new instance of the <see cref="T:System.Security.Permissions.StrongNameIdentityPermission" /> class for the specified strong name identity.</summary>
 /// <param name="blob">The public key defining the strong name identity namespace. </param>
 /// <param name="name">The simple name part of the strong name identity. This corresponds to the name of the assembly. </param>
 /// <param name="version">The version number of the identity. </param>
 /// <exception cref="T:System.ArgumentNullException">The <paramref name="blob" /> parameter is null. </exception>
 /// <exception cref="T:System.ArgumentException">The <paramref name="name" /> parameter is an empty string ("").</exception>
 public StrongNameIdentityPermission(StrongNamePublicKeyBlob blob, string name, Version version)
 {
     if (blob == null)
     {
         throw new ArgumentNullException("blob");
     }
     if (name != null && name.Length == 0)
     {
         throw new ArgumentException("name");
     }
     this._state = PermissionState.None;
     this._list  = new ArrayList();
     this._list.Add(new StrongNameIdentityPermission.SNIP(blob, name, version));
 }
 public StrongNameMembershipCondition(StrongNamePublicKeyBlob blob, string name, System.Version version)
 {
     if (blob == null)
     {
         throw new ArgumentNullException("blob");
     }
     if ((name != null) && name.Equals(""))
     {
         throw new ArgumentException(Environment.GetResourceString("Argument_EmptyStrongName"));
     }
     this.m_publicKeyBlob = blob;
     this.m_name = name;
     this.m_version = version;
 }
Example #28
0
        /// <include file='doc\StrongNameIdentityPermission.uex' path='docs/doc[@for="StrongNameIdentityPermission.StrongNameIdentityPermission1"]/*' />
        public StrongNameIdentityPermission(StrongNamePublicKeyBlob blob, String name, Version version)
        {
            if (blob == null)
            {
                throw new ArgumentNullException("blob");
            }

            // Add this in Whidbey
            // if (name != null && name.Equals( "" ))
            //     throw new ArgumentException( Environment.GetResourceString( "Argument_EmptyStrongName" ) );

            m_publicKeyBlob = blob;
            m_name          = name;
            m_version       = version;
        }
Example #29
0
 /// <include file='doc\StrongName.uex' path='docs/doc[@for="StrongName.StrongName1"]/*' />
 public StrongName( StrongNamePublicKeyBlob blob, String name, Version version )
 {
     if (name == null)
         throw new ArgumentNullException( "name" );
         
     if (blob == null)
         throw new ArgumentNullException( "blob" );
         
     if ((Object) version == null)
         throw new ArgumentNullException( "version" );
         
     m_publicKeyBlob = blob;
     m_name = name;
     m_version = version;
 }
Example #30
0
        //------------------------------------------------------
        //
        // PUBLIC CONSTRUCTORS
        //
        //------------------------------------------------------


        /// <include file='doc\StrongNameIdentityPermission.uex' path='docs/doc[@for="StrongNameIdentityPermission.StrongNameIdentityPermission"]/*' />
        public StrongNameIdentityPermission(PermissionState state)
        {
            if (state == PermissionState.Unrestricted)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_UnrestrictedIdentityPermission"));
            }
            else if (state == PermissionState.None)
            {
                m_publicKeyBlob = null;
                m_name          = "";
                m_version       = new Version();
            }
            else
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_InvalidPermissionState"));
            }
        }
  //------------------------------------------------------
  //
  // PUBLIC CONSTRUCTORS
  //
  //------------------------------------------------------
  
 
  /// <include file='doc\StrongNameIdentityPermission.uex' path='docs/doc[@for="StrongNameIdentityPermission.StrongNameIdentityPermission"]/*' />
  public StrongNameIdentityPermission(PermissionState state)
  {
      if (state == PermissionState.Unrestricted)
      {
          throw new ArgumentException(Environment.GetResourceString("Argument_UnrestrictedIdentityPermission"));
      }
      else if (state == PermissionState.None)
      {
          m_publicKeyBlob = null;
          m_name = "";
          m_version = new Version();
      }
      else
      {
          throw new ArgumentException(Environment.GetResourceString("Argument_InvalidPermissionState"));
      }
  }
        public StrongName( StrongNamePublicKeyBlob blob, String name, Version version )
        {
            if (name == null)
                throw new ArgumentNullException( "name" );
            if (name.Equals( "" ))
                throw new ArgumentException( Environment.GetResourceString( "Argument_EmptyStrongName" ) );      

            if (blob == null)
                throw new ArgumentNullException( "blob" );

            if (version == null)
                throw new ArgumentNullException( "version" );

            m_publicKeyBlob = blob;
            m_name = name;
            m_version = version;
        }
Example #33
0
        public static StrongName GetStrongName(Assembly assembly)
        {
            if (assembly == null)
                throw new ArgumentNullException("assembly");

            AssemblyName assemblyName = assembly.GetName();
            Debug.Assert(assemblyName != null, "Could not get assembly name");

            // Get the public key blob.
            byte[] publicKey = assemblyName.GetPublicKey();
            if (publicKey == null || publicKey.Length == 0)
                throw new InvalidOperationException("Assembly is not strongly named");

            var keyBlob = new StrongNamePublicKeyBlob(publicKey);

            // Return the strong name.
            return new StrongName(keyBlob, assemblyName.Name, assemblyName.Version);
        }
	// Constructor.
	public StrongName(StrongNamePublicKeyBlob blob,
					  String name, Version version)
			{
				if(blob == null)
				{
					throw new ArgumentNullException("blob");
				}
				if(name == null)
				{
					throw new ArgumentNullException("name");
				}
				if(version == null)
				{
					throw new ArgumentNullException("version");
				}
				this.blob = blob;
				this.name = name;
				this.version = version;
			}
 public override IPermission CreatePermission()
 {
     if (base.m_unrestricted)
     {
         return new StrongNameIdentityPermission(PermissionState.Unrestricted);
     }
     if (((this.m_blob == null) && (this.m_name == null)) && (this.m_version == null))
     {
         return new StrongNameIdentityPermission(PermissionState.None);
     }
     if (this.m_blob == null)
     {
         throw new ArgumentException(Environment.GetResourceString("ArgumentNull_Key"));
     }
     StrongNamePublicKeyBlob blob = new StrongNamePublicKeyBlob(this.m_blob);
     if ((this.m_version != null) && !this.m_version.Equals(string.Empty))
     {
         return new StrongNameIdentityPermission(blob, this.m_name, new System.Version(this.m_version));
     }
     return new StrongNameIdentityPermission(blob, this.m_name, null);
 }
Example #36
0
        // Determine if two objects are equal.
        public override bool Equals(Object obj)
        {
            StrongNamePublicKeyBlob key = (obj as StrongNamePublicKeyBlob);

            if (key != null && blob.Length == key.blob.Length)
            {
                int posn;
                for (posn = 0; posn < blob.Length; ++posn)
                {
                    if (blob[posn] != key.blob[posn])
                    {
                        return(false);
                    }
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }
        /// <summary>Gets or sets a value indicating whether the current public key blob is equal to the specified public key blob.</summary>
        /// <returns>true if the public key blob of the current object is equal to the public key blob of the <paramref name="obj" /> parameter; otherwise, false.</returns>
        /// <param name="obj">An object containing a public key blob. </param>
        public override bool Equals(object obj)
        {
            StrongNamePublicKeyBlob strongNamePublicKeyBlob = obj as StrongNamePublicKeyBlob;

            if (strongNamePublicKeyBlob == null)
            {
                return(false);
            }
            bool flag = this.pubkey.Length == strongNamePublicKeyBlob.pubkey.Length;

            if (flag)
            {
                for (int i = 0; i < this.pubkey.Length; i++)
                {
                    if (this.pubkey[i] != strongNamePublicKeyBlob.pubkey[i])
                    {
                        return(false);
                    }
                }
            }
            return(flag);
        }
        internal static StrongNamePublicKeyBlob FromString(string s)
        {
            if (s == null || s.Length == 0)
            {
                return(null);
            }
            int num = s.Length / 2;

            byte[] array = new byte[num];
            int    i     = 0;
            int    num2  = 0;

            while (i < s.Length)
            {
                byte b  = StrongNamePublicKeyBlob.CharToByte(s[i]);
                byte b2 = StrongNamePublicKeyBlob.CharToByte(s[i + 1]);
                array[num2] = Convert.ToByte((int)(b * 16 + b2));
                i          += 2;
                num2++;
            }
            return(new StrongNamePublicKeyBlob(array));
        }
        // Convert an XML value into a permissions value.
        public override void FromXml(SecurityElement esd)
        {
            if (esd == null)
            {
                throw new ArgumentNullException("esd");
            }
            if (esd.Attribute("version") != "1")
            {
                throw new ArgumentException(_("Arg_PermissionVersion"));
            }
            String value = esd.Attribute("X509v3Certificate");

            if (value != null)
            {
                certificate = new X509Certificate
                                  (StrongNamePublicKeyBlob.FromHex(value));
            }
            else
            {
                certificate = null;
            }
        }
Example #40
0
        public override IPermission CreatePermission()
        {
            if (base.m_unrestricted)
            {
                return(new StrongNameIdentityPermission(PermissionState.Unrestricted));
            }
            if (((this.m_blob == null) && (this.m_name == null)) && (this.m_version == null))
            {
                return(new StrongNameIdentityPermission(PermissionState.None));
            }
            if (this.m_blob == null)
            {
                throw new ArgumentException(Environment.GetResourceString("ArgumentNull_Key"));
            }
            StrongNamePublicKeyBlob blob = new StrongNamePublicKeyBlob(this.m_blob);

            if ((this.m_version != null) && !this.m_version.Equals(string.Empty))
            {
                return(new StrongNameIdentityPermission(blob, this.m_name, new System.Version(this.m_version)));
            }
            return(new StrongNameIdentityPermission(blob, this.m_name, null));
        }
Example #41
0
        public override bool Equals(object obj)
        {
            StrongNamePublicKeyBlob snpkb = (obj as StrongNamePublicKeyBlob);

            if (snpkb == null)
            {
                return(false);
            }

            bool result = (pubkey.Length == snpkb.pubkey.Length);

            if (result)
            {
                for (int i = 0; i < pubkey.Length; i++)
                {
                    if (pubkey[i] != snpkb.pubkey[i])
                    {
                        return(false);
                    }
                }
            }
            return(result);
        }
Example #42
0
        internal StrongName(StrongNamePublicKeyBlob blob, String name, Version version, Assembly assembly)
        {
            if (name == null)
                throw new ArgumentNullException(nameof(name));
            if (String.IsNullOrEmpty(name))
                throw new ArgumentException(Environment.GetResourceString("Argument_EmptyStrongName"));

            if (blob == null)
                throw new ArgumentNullException(nameof(blob));

            if (version == null)
                throw new ArgumentNullException(nameof(version));
            Contract.EndContractBlock();

            RuntimeAssembly rtAssembly = assembly as RuntimeAssembly;
            if (assembly != null && rtAssembly == null)
                throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeAssembly"), nameof(assembly));

            m_publicKeyBlob = blob;
            m_name = name;
            m_version = version;
            m_assembly = rtAssembly;
        }
 public StrongName2(StrongNamePublicKeyBlob publicKeyBlob, String name, Version version)
 {
     m_publicKeyBlob = publicKeyBlob;
     m_name = name;
     m_version = version;
 }
Example #44
0
 static IMembershipCondition StrongNameMembershipConditionHandler( PolicyLevel level, String[] args, int index, out int offset )
 {
     if (args[index].Equals( "__internal_usage__" ))
     {
         PauseCapableWriteLine( manager.GetString( "Help_MembershipCondition_Strong" ) );
         offset = 0;
         return null;
     }
 
     if (args.Length - index < 5)
     {
         ErrorMShip( args[0], manager.GetString( "MembershipConditionTable_Strong" ), manager.GetString( "Error_NotEnoughArgs" ), -1 );
     }
 
     StrongNamePublicKeyBlob publicKey = null;
     String assemblyName = null;
     String assemblyVersion = null;
     
     if (String.Compare( args[index+1], manager.GetString( "Misc_File" ), true, CultureInfo.InvariantCulture) == 0)
     {
         AssemblyName name = AssemblyName.GetAssemblyName( args[index+2] );
         publicKey = new StrongNamePublicKeyBlob( name.GetPublicKey() );
         assemblyName = args[index+3];
         assemblyVersion = args[index+4];
         offset = 5;
     }
     else
     {
         ErrorMShip( args[0], manager.GetString( "MembershipConditionTable_Strong" ), String.Format( manager.GetString( "Error_StrongName_InvalidOption" ), args[index+1] ), -1 );
         // not reached
         offset = 0;
     }
         
     if (String.Compare( assemblyName, manager.GetString( "Misc_NoName" ), true, CultureInfo.InvariantCulture) == 0)
     {
         assemblyName = null;
     }
             
     if (String.Compare( assemblyVersion, manager.GetString( "Misc_NoVersion" ), true, CultureInfo.InvariantCulture) == 0)
     {
         assemblyVersion = null;
     }
 
     Version asmVer = null;
 
     if (assemblyVersion != null)
     {
         try
         {
             asmVer = new Version( assemblyVersion );
         }
         catch (Exception)
         {
             ErrorMShip( args[0], manager.GetString( "MembershipConditionTable_Strong" ), manager.GetString( "Error_StrongName_ImproperlyFormattedVersion" ), -1 );
         }
     }
         
     return new StrongNameMembershipCondition( publicKey, assemblyName, asmVer );
 }         
 public StrongNameIdentityPermission( StrongNamePublicKeyBlob blob, String name, Version version )
 {
     if (blob == null)
         throw new ArgumentNullException( "blob" );
     if (name != null && name.Equals( "" ))
         throw new ArgumentException( Environment.GetResourceString( "Argument_EmptyStrongName" ) );      
     m_unrestricted = false;
     m_strongNames = new StrongName2[1];
     m_strongNames[0] = new StrongName2(blob, name, version);
 }
 internal StrongNamePublicKeyBlob(StrongNamePublicKeyBlob blob)
 {
     this.PublicKey = new byte[blob.PublicKey.Length];
     Array.Copy(blob.PublicKey, 0, this.PublicKey, 0, blob.PublicKey.Length);
 }
 public StrongName2(StrongNamePublicKeyBlob publicKeyBlob, String name, Version version)
 {
     m_publicKeyBlob = publicKeyBlob;
     m_name          = name;
     m_version       = version;
 }
 public StrongName2(StrongNamePublicKeyBlob publicKeyBlob, string name, Version version)
 {
     this.m_publicKeyBlob = publicKeyBlob;
     this.m_name          = name;
     this.m_version       = version;
 }
Example #49
0
		public void StrongName_GetRequiredSize ()
		{
			byte[] pk = { 0x00, 0x24, 0x00, 0x00, 0x04, 0x80, 0x00, 0x00, 0x94, 0x00, 0x00, 0x00, 0x06, 0x02, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x52, 0x53, 0x41, 0x31, 0x00, 0x04, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x3D, 0xBD, 0x72, 0x08, 0xC6, 0x2B, 0x0E, 0xA8, 0xC1, 0xC0, 0x58, 0x07, 0x2B, 0x63, 0x5F, 0x7C, 0x9A, 0xBD, 0xCB, 0x22, 0xDB, 0x20, 0xB2, 0xA9, 0xDA, 0xDA, 0xEF, 0xE8, 0x00, 0x64, 0x2F, 0x5D, 0x8D, 0xEB, 0x78, 0x02, 0xF7, 0xA5, 0x36, 0x77, 0x28, 0xD7, 0x55, 0x8D, 0x14, 0x68, 0xDB, 0xEB, 0x24, 0x09, 0xD0, 0x2B, 0x13, 0x1B, 0x92, 0x6E, 0x2E, 0x59, 0x54, 0x4A, 0xAC, 0x18, 0xCF, 0xC9, 0x09, 0x02, 0x3F, 0x4F, 0xA8, 0x3E, 0x94, 0x00, 0x1F, 0xC2, 0xF1, 0x1A, 0x27, 0x47, 0x7D, 0x10, 0x84, 0xF5, 0x14, 0xB8, 0x61, 0x62, 0x1A, 0x0C, 0x66, 0xAB, 0xD2, 0x4C, 0x4B, 0x9F, 0xC9, 0x0F, 0x3C, 0xD8, 0x92, 0x0F, 0xF5, 0xFF, 0xCE, 0xD7, 0x6E, 0x5C, 0x6F, 0xB1, 0xF5, 0x7D, 0xD3, 0x56, 0xF9, 0x67, 0x27, 0xA4, 0xA5, 0x48, 0x5B, 0x07, 0x93, 0x44, 0x00, 0x4A, 0xF8, 0xFF, 0xA4, 0xCB };
			StrongNamePublicKeyBlob snpkb = new StrongNamePublicKeyBlob (pk);
			StrongName sn = new StrongName (snpkb, "mono", new Version ());

			Assert.AreEqual (97, GetRequiredSize (sn, true), "GetRequiredSize-true");
			Assert.AreEqual (93, GetRequiredSize (sn, false), "GetRequiredSize-false");
		}
Example #50
0
 public StrongName( StrongNamePublicKeyBlob blob, String name, Version version ) : this(blob, name, version, null)
 {
 }
 /// <summary>Returns a hash code based on the public key.</summary>
 /// <returns>The hash code based on the public key.</returns>
 // Token: 0x0600264F RID: 9807 RVA: 0x0008AB94 File Offset: 0x00088D94
 public override int GetHashCode()
 {
     return(StrongNamePublicKeyBlob.GetByteArrayHashCode(this.PublicKey));
 }
		public StrongNameIdentityPermission (StrongNamePublicKeyBlob blob, string name, Version version) 
		{
			if (blob == null)
				throw new ArgumentNullException ("blob");
			if ((name != null) && (name.Length == 0))
				throw new ArgumentException ("name");

			_state = PermissionState.None;
			_list = new ArrayList ();
			_list.Add (new SNIP (blob, name, version));
		}
 internal SNIP(StrongNamePublicKeyBlob pk, string name, Version version)
 {
     PublicKey       = pk;
     Name            = name;
     AssemblyVersion = version;
 }
        public StrongNameIdentityPermission(StrongNamePublicKeyBlob blob, string name, Version version)
        {
            Contract.Requires(blob != null);

            return(default(StrongNameIdentityPermission));
        }
Example #55
0
        private StrongName GetStrongName(Assembly fullTrustAssembly)
        {
            var assemblyName = fullTrustAssembly.GetName();
              var publicKey = assemblyName.GetPublicKey();
              Debug.Assert(publicKey.Length == 0, "Full trust assembly must have public key.");

              var strongNamePublicKeyBlob = new StrongNamePublicKeyBlob(publicKey);
              return new StrongName(strongNamePublicKeyBlob, assemblyName.Name, assemblyName.Version);
        }
Example #56
0
		static Evidence CreateAssemblyEvidence(string fileName)
		{
			//HACK: I am unsure whether 'Hash' evidence is required - since this will be difficult to obtain, we will not supply it...
 
			Evidence newEvidence = new Evidence();

			//We must have zone evidence, or we will get a policy exception
			Zone zone = new Zone(SecurityZone.MyComputer);
			newEvidence.AddHost(zone);

			//If the assembly is strong-named, we must supply this evidence
			//for StrongNameIdentityPermission demands
			AssemblyName assemblyName = AssemblyName.GetAssemblyName(fileName);
			byte[] pk = assemblyName.GetPublicKey();
			if (pk!=null && pk.Length != 0)
			{
				StrongNamePublicKeyBlob blob = new StrongNamePublicKeyBlob(pk);
				StrongName strongName = new StrongName(blob, assemblyName.Name, assemblyName.Version);
				newEvidence.AddHost(strongName);
			}

			return newEvidence;
		}
			internal SNIP (StrongNamePublicKeyBlob pk, string name, Version version)
			{
				PublicKey = pk;
				Name = name;
				AssemblyVersion = version;
			}
 public override IPermission CreatePermission()
 {
     if (m_unrestricted)
     {
         return new StrongNameIdentityPermission( PermissionState.Unrestricted );
     }
     else
     {
         if (m_blob == null && m_name == null && m_version == null)
             return new StrongNameIdentityPermission( PermissionState.None );
     
         if (m_blob == null)
             throw new ArgumentException( Environment.GetResourceString("ArgumentNull_Key"));
             
         StrongNamePublicKeyBlob blob = new StrongNamePublicKeyBlob( m_blob );
         
         if (m_version == null || m_version.Equals(String.Empty))
             return new StrongNameIdentityPermission( blob, m_name, null );
         else    
             return new StrongNameIdentityPermission( blob, m_name, new Version( m_version ) );
     }
 }
Example #59
0
        internal void FromXml (SecurityElement element)
        {
            if (element == null)
                throw new ArgumentNullException(nameof(element));
            if (String.Compare(element.Tag, "StrongName", StringComparison.Ordinal) != 0)
                throw new ArgumentException(Environment.GetResourceString("Argument_InvalidXML"));
            Contract.EndContractBlock();

            m_publicKeyBlob = null;
            m_version = null;

            string key = element.Attribute("Key");
            if (key != null)
                m_publicKeyBlob = new StrongNamePublicKeyBlob(System.Security.Util.Hex.DecodeHexString(key));

            m_name = element.Attribute("Name");

            string version = element.Attribute("Version");
            if (version != null)
                m_version = new Version(version);
        }
 // Token: 0x0600264C RID: 9804 RVA: 0x0008AB2E File Offset: 0x00088D2E
 internal bool Equals(StrongNamePublicKeyBlob blob)
 {
     return(blob != null && StrongNamePublicKeyBlob.CompareArrays(this.PublicKey, blob.PublicKey));
 }