You've already forked linux-packaging-mono
Imported Upstream version 4.8.0.309
Former-commit-id: 5f9c6ae75f295e057a7d2971f3a6df4656fa8850
This commit is contained in:
parent
ee1447783b
commit
94b2861243
@@ -1,29 +1,11 @@
|
||||
//
|
||||
// AssemblyNameReference.cs
|
||||
//
|
||||
// Author:
|
||||
// Jb Evain (jbevain@gmail.com)
|
||||
//
|
||||
// Copyright (c) 2008 - 2011 Jb Evain
|
||||
// Copyright (c) 2008 - 2015 Jb Evain
|
||||
// Copyright (c) 2008 - 2011 Novell, Inc.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
// Licensed under the MIT/X11 license.
|
||||
//
|
||||
|
||||
using System;
|
||||
@@ -67,8 +49,8 @@ namespace Mono.Cecil {
|
||||
public Version Version {
|
||||
get { return version; }
|
||||
set {
|
||||
version = value;
|
||||
full_name = null;
|
||||
version = Mixin.CheckVersion (value);
|
||||
full_name = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,9 +94,10 @@ namespace Mono.Cecil {
|
||||
if (public_key_token.IsNullOrEmpty () && !public_key.IsNullOrEmpty ()) {
|
||||
var hash = HashPublicKey ();
|
||||
// we need the last 8 bytes in reverse order
|
||||
public_key_token = new byte [8];
|
||||
Array.Copy (hash, (hash.Length - 8), public_key_token, 0, 8);
|
||||
Array.Reverse (public_key_token, 0, 8);
|
||||
var local_public_key_token = new byte [8];
|
||||
Array.Copy (hash, (hash.Length - 8), local_public_key_token, 0, 8);
|
||||
Array.Reverse (local_public_key_token, 0, 8);
|
||||
public_key_token = local_public_key_token; // publish only once finished (required for thread-safety)
|
||||
}
|
||||
return public_key_token ?? Empty<byte>.Array;
|
||||
}
|
||||
@@ -126,29 +109,27 @@ namespace Mono.Cecil {
|
||||
|
||||
byte [] HashPublicKey ()
|
||||
{
|
||||
#if !PCL
|
||||
HashAlgorithm algorithm;
|
||||
|
||||
switch (hash_algorithm) {
|
||||
case AssemblyHashAlgorithm.Reserved:
|
||||
#if SILVERLIGHT
|
||||
throw new NotSupportedException ();
|
||||
#else
|
||||
algorithm = MD5.Create ();
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
// None default to SHA1
|
||||
#if SILVERLIGHT
|
||||
algorithm = new SHA1Managed ();
|
||||
break;
|
||||
#else
|
||||
algorithm = SHA1.Create ();
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
|
||||
using (algorithm)
|
||||
return algorithm.ComputeHash (public_key);
|
||||
#else
|
||||
if (hash_algorithm != AssemblyHashAlgorithm.SHA1)
|
||||
throw new NotSupportedException ();
|
||||
|
||||
return new SHA1Managed ().ComputeHash (public_key);
|
||||
#endif
|
||||
}
|
||||
|
||||
public virtual MetadataScopeType MetadataScopeType {
|
||||
@@ -164,11 +145,9 @@ namespace Mono.Cecil {
|
||||
|
||||
var builder = new StringBuilder ();
|
||||
builder.Append (name);
|
||||
if (version != null) {
|
||||
builder.Append (sep);
|
||||
builder.Append ("Version=");
|
||||
builder.Append (version.ToString ());
|
||||
}
|
||||
builder.Append (sep);
|
||||
builder.Append ("Version=");
|
||||
builder.Append (version.ToString (fieldCount: 4));
|
||||
builder.Append (sep);
|
||||
builder.Append ("Culture=");
|
||||
builder.Append (string.IsNullOrEmpty (culture) ? "neutral" : culture);
|
||||
@@ -183,6 +162,11 @@ namespace Mono.Cecil {
|
||||
} else
|
||||
builder.Append ("null");
|
||||
|
||||
if (IsRetargetable) {
|
||||
builder.Append (sep);
|
||||
builder.Append ("Retargetable=Yes");
|
||||
}
|
||||
|
||||
return full_name = builder.ToString ();
|
||||
}
|
||||
}
|
||||
@@ -213,7 +197,7 @@ namespace Mono.Cecil {
|
||||
name.Version = new Version (parts [1]);
|
||||
break;
|
||||
case "culture":
|
||||
name.Culture = parts [1];
|
||||
name.Culture = parts [1] == "neutral" ? "" : parts [1];
|
||||
break;
|
||||
case "publickeytoken":
|
||||
var pk_token = parts [1];
|
||||
@@ -248,6 +232,8 @@ namespace Mono.Cecil {
|
||||
|
||||
internal AssemblyNameReference ()
|
||||
{
|
||||
this.version = Mixin.ZeroVersion;
|
||||
this.token = new MetadataToken (TokenType.AssemblyRef);
|
||||
}
|
||||
|
||||
public AssemblyNameReference (string name, Version version)
|
||||
@@ -256,7 +242,7 @@ namespace Mono.Cecil {
|
||||
throw new ArgumentNullException ("name");
|
||||
|
||||
this.name = name;
|
||||
this.version = version;
|
||||
this.version = Mixin.CheckVersion (version);
|
||||
this.hash_algorithm = AssemblyHashAlgorithm.None;
|
||||
this.token = new MetadataToken (TokenType.AssemblyRef);
|
||||
}
|
||||
@@ -266,4 +252,23 @@ namespace Mono.Cecil {
|
||||
return this.FullName;
|
||||
}
|
||||
}
|
||||
|
||||
partial class Mixin {
|
||||
|
||||
public static Version ZeroVersion = new Version (0, 0, 0 ,0);
|
||||
|
||||
public static Version CheckVersion (Version version)
|
||||
{
|
||||
if (version == null)
|
||||
return ZeroVersion;
|
||||
|
||||
if (version.Build == -1)
|
||||
return new Version (version.Major, version.Minor, 0, 0);
|
||||
|
||||
if (version.Revision == -1)
|
||||
return new Version (version.Major, version.Minor, version.Build, 0);
|
||||
|
||||
return version;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user