Imported Upstream version 4.0.0~alpha1

Former-commit-id: 806294f5ded97629b74c85c09952f2a74fe182d9
This commit is contained in:
Jo Shields
2015-04-07 09:35:12 +01:00
parent 283343f570
commit 3c1f479b9d
22469 changed files with 2931443 additions and 869343 deletions

View File

@@ -0,0 +1,152 @@
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
// <OWNER>[....]</OWNER>
//
//
// Config.cs
//
namespace System.Security.Util {
using System;
using System.Security.Util;
using System.Security.Policy;
using System.Security.Permissions;
using System.Collections;
using System.IO;
using System.Reflection;
using System.Globalization;
using System.Text;
#if FEATURE_SERIALIZATION
using System.Runtime.Serialization.Formatters.Binary;
#endif // FEATURE_SERIALIZATION
using System.Threading;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
// Duplicated in vm\COMSecurityConfig.h
[Serializable]
[Flags]
internal enum QuickCacheEntryType
{
FullTrustZoneMyComputer = 0x1000000,
FullTrustZoneIntranet = 0x2000000,
FullTrustZoneInternet = 0x4000000,
FullTrustZoneTrusted = 0x8000000,
FullTrustZoneUntrusted = 0x10000000,
FullTrustAll = 0x20000000,
}
internal static class Config {
private static volatile string m_machineConfig;
private static volatile string m_userConfig;
[System.Security.SecurityCritical] // auto-generated
[ResourceExposure(ResourceScope.None)]
[ResourceConsumption(ResourceScope.Machine, ResourceScope.Machine)]
private static void GetFileLocales()
{
if (m_machineConfig == null)
{
string machineConfig = null;
GetMachineDirectory(JitHelpers.GetStringHandleOnStack(ref machineConfig));
m_machineConfig = machineConfig;
}
if (m_userConfig == null)
{
string userConfig = null;
GetUserDirectory(JitHelpers.GetStringHandleOnStack(ref userConfig));
m_userConfig = userConfig;
}
}
internal static string MachineDirectory
{
[System.Security.SecurityCritical] // auto-generated
[ResourceExposure(ResourceScope.Machine)]
get
{
GetFileLocales();
return m_machineConfig;
}
}
internal static string UserDirectory
{
[System.Security.SecurityCritical] // auto-generated
[ResourceExposure(ResourceScope.Machine)]
get
{
GetFileLocales();
return m_userConfig;
}
}
#if FEATURE_CAS_POLICY
[System.Security.SecurityCritical] // auto-generated
[ResourceExposure(ResourceScope.Machine)]
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode), SuppressUnmanagedCodeSecurity]
internal static extern int SaveDataByte(string path, [In] byte[] data, int length);
[System.Security.SecurityCritical] // auto-generated
[ResourceExposure(ResourceScope.None)]
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode), SuppressUnmanagedCodeSecurity]
internal static extern bool RecoverData(ConfigId id);
[System.Security.SecurityCritical] // auto-generated
[ResourceExposure(ResourceScope.None)]
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode), SuppressUnmanagedCodeSecurity]
internal static extern void SetQuickCache(ConfigId id, QuickCacheEntryType quickCacheFlags);
[System.Security.SecurityCritical] // auto-generated
[ResourceExposure(ResourceScope.None)]
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode), SuppressUnmanagedCodeSecurity]
private static extern bool GetCacheEntry(ConfigId id, int numKey, [In] byte[] key, int keyLength, ObjectHandleOnStack retData);
[System.Security.SecurityCritical] // auto-generated
internal static bool GetCacheEntry(ConfigId id, int numKey, byte[] key, out byte[] data)
{
byte[] retData = null;
bool ret = GetCacheEntry(id, numKey, key, key.Length, JitHelpers.GetObjectHandleOnStack(ref retData));
data = retData;
return ret;
}
[System.Security.SecurityCritical] // auto-generated
[ResourceExposure(ResourceScope.None)]
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode), SuppressUnmanagedCodeSecurity]
private static extern void AddCacheEntry(ConfigId id, int numKey, [In] byte[] key, int keyLength, byte[] data, int dataLength);
[System.Security.SecurityCritical] // auto-generated
internal static void AddCacheEntry(ConfigId id, int numKey, byte[] key, byte[] data)
{
AddCacheEntry(id, numKey, key, key.Length, data, data.Length);
}
[System.Security.SecurityCritical] // auto-generated
[ResourceExposure(ResourceScope.None)]
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode), SuppressUnmanagedCodeSecurity]
internal static extern void ResetCacheData(ConfigId id);
#endif
[System.Security.SecurityCritical] // auto-generated
[ResourceExposure(ResourceScope.Machine)]
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode), SuppressUnmanagedCodeSecurity]
private static extern void GetMachineDirectory(StringHandleOnStack retDirectory);
[System.Security.SecurityCritical] // auto-generated
[ResourceExposure(ResourceScope.Machine)]
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode), SuppressUnmanagedCodeSecurity]
private static extern void GetUserDirectory(StringHandleOnStack retDirectory);
[System.Security.SecurityCritical] // auto-generated
[ResourceExposure(ResourceScope.None)]
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode), SuppressUnmanagedCodeSecurity]
internal static extern bool WriteToEventLog(string message);
}
}

View File

@@ -0,0 +1,130 @@
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
/*
* Hex.cs
//
// <OWNER>[....]</OWNER>
*
* Operations to convert to and from Hex
*
*/
namespace System.Security.Util
{
using System;
using System.Security;
using System.Diagnostics.Contracts;
internal static class Hex
{
// converts number to hex digit. Does not do any range checks.
static char HexDigit(int num) {
return (char)((num < 10) ? (num + '0') : (num + ('A' - 10)));
}
public static String EncodeHexString(byte[] sArray)
{
String result = null;
if(sArray != null) {
char[] hexOrder = new char[sArray.Length * 2];
int digit;
for(int i = 0, j = 0; i < sArray.Length; i++) {
digit = (int)((sArray[i] & 0xf0) >> 4);
hexOrder[j++] = HexDigit(digit);
digit = (int)(sArray[i] & 0x0f);
hexOrder[j++] = HexDigit(digit);
}
result = new String(hexOrder);
}
return result;
}
internal static string EncodeHexStringFromInt(byte[] sArray) {
String result = null;
if(sArray != null) {
char[] hexOrder = new char[sArray.Length * 2];
int i = sArray.Length;
int digit, j=0;
while (i-- > 0) {
digit = (sArray[i] & 0xf0) >> 4;
hexOrder[j++] = HexDigit(digit);
digit = sArray[i] & 0x0f;
hexOrder[j++] = HexDigit(digit);
}
result = new String(hexOrder);
}
return result;
}
public static int ConvertHexDigit(Char val)
{
if (val <= '9' && val >= '0')
return (val - '0');
else if (val >= 'a' && val <= 'f')
return ((val - 'a') + 10);
else if (val >= 'A' && val <= 'F')
return ((val - 'A') + 10);
else
throw new ArgumentException( Environment.GetResourceString( "ArgumentOutOfRange_Index" ) );
}
public static byte[] DecodeHexString(String hexString)
{
if (hexString == null)
throw new ArgumentNullException( "hexString" );
Contract.EndContractBlock();
bool spaceSkippingMode = false;
int i = 0;
int length = hexString.Length;
if ((length >= 2) &&
(hexString[0] == '0') &&
( (hexString[1] == 'x') || (hexString[1] == 'X') ))
{
length = hexString.Length - 2;
i = 2;
}
// Hex strings must always have 2N or (3N - 1) entries.
if (length % 2 != 0 && length % 3 != 2)
{
throw new ArgumentException( Environment.GetResourceString( "Argument_InvalidHexFormat" ) );
}
byte[] sArray;
if (length >=3 && hexString[i + 2] == ' ')
{
spaceSkippingMode = true;
// Each hex digit will take three spaces, except the first (hence the plus 1).
sArray = new byte[length / 3 + 1];
}
else
{
// Each hex digit will take two spaces
sArray = new byte[length / 2];
}
int digit;
int rawdigit;
for (int j = 0; i < hexString.Length; i += 2, j++) {
rawdigit = ConvertHexDigit(hexString[i]);
digit = ConvertHexDigit(hexString[i+1]);
sArray[j] = (byte) (digit | (rawdigit << 4));
if (spaceSkippingMode)
i++;
}
return(sArray);
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,295 @@
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
// SiteString
//
// <OWNER>[....]</OWNER>
//
namespace System.Security.Util {
using System;
using System.Collections;
using System.Globalization;
using System.Diagnostics.Contracts;
[Serializable]
internal class SiteString
{
protected String m_site;
protected ArrayList m_separatedSite;
protected static char[] m_separators = { '.' };
protected internal SiteString()
{
// Only call this in derived classes when you know what you're doing.
}
public SiteString( String site )
{
m_separatedSite = CreateSeparatedSite( site );
m_site = site;
}
private SiteString(String site, ArrayList separatedSite)
{
m_separatedSite = separatedSite;
m_site = site;
}
private static ArrayList CreateSeparatedSite(String site)
{
if (site == null || site.Length == 0)
{
throw new ArgumentException( Environment.GetResourceString("Argument_InvalidSite" ));
}
Contract.EndContractBlock();
ArrayList list = new ArrayList();
int braIndex = -1;
int ketIndex = -1;
braIndex = site.IndexOf('[');
if (braIndex == 0)
ketIndex = site.IndexOf(']', braIndex+1);
if (ketIndex != -1)
{
// Found an IPv6 address. Special case that
String ipv6Addr = site.Substring(braIndex+1, ketIndex-braIndex-1);
list.Add(ipv6Addr);
return list;
}
// Regular hostnames or IPv4 addresses
// We dont need to do this for IPv4 addresses, but it's easier to do it anyway
String[] separatedArray = site.Split( m_separators );
for (int index = separatedArray.Length-1; index > -1; --index)
{
if (separatedArray[index] == null)
{
throw new ArgumentException( Environment.GetResourceString("Argument_InvalidSite" ));
}
else if (separatedArray[index].Equals( "" ))
{
if (index != separatedArray.Length-1)
{
throw new ArgumentException( Environment.GetResourceString("Argument_InvalidSite" ));
}
}
else if (separatedArray[index].Equals( "*" ))
{
if (index != 0)
{
throw new ArgumentException( Environment.GetResourceString("Argument_InvalidSite" ));
}
list.Add( separatedArray[index] );
}
else if (!AllLegalCharacters( separatedArray[index] ))
{
throw new ArgumentException( Environment.GetResourceString("Argument_InvalidSite" ));
}
else
{
list.Add( separatedArray[index] );
}
}
return list;
}
// KB# Q188997 - http://support.microsoft.com/default.aspx?scid=KB;EN-US;Q188997& gives the list of allowed characters in
// a NETBIOS name. DNS names are a subset of that (alphanumeric or '-').
private static bool AllLegalCharacters( String str )
{
for (int i = 0; i < str.Length; ++i)
{
char c = str[i];
if (IsLegalDNSChar(c) ||
IsNetbiosSplChar(c))
{
continue;
}
else
{
return false;
}
}
return true;
}
private static bool IsLegalDNSChar(char c)
{
if ((c >= 'a' && c <= 'z') ||
(c >= 'A' && c <= 'Z') ||
(c >= '0' && c <= '9') ||
(c == '-'))
return true;
else
return false;
}
private static bool IsNetbiosSplChar(char c)
{
// ! @ # $ % ^ & ( ) - _ ' { } . ~ are OK
switch (c) {
case '-':
case '_':
case '@':
case '!':
case '#':
case '$':
case '%':
case '^':
case '&':
case '(':
case ')':
case '\'':
case '{':
case '}':
case '.':
case '~':
return true;
default:
return false;
}
}
public override String ToString()
{
return m_site;
}
public override bool Equals(Object o)
{
if (o == null || !(o is SiteString))
return false;
else
return this.Equals( (SiteString)o, true );
}
public override int GetHashCode()
{
TextInfo info = CultureInfo.InvariantCulture.TextInfo;
return info.GetCaseInsensitiveHashCode( this.m_site );
}
internal bool Equals( SiteString ss, bool ignoreCase )
{
if (this.m_site == null)
return ss.m_site == null;
if (ss.m_site == null)
return false;
return this.IsSubsetOf(ss, ignoreCase) && ss.IsSubsetOf(this, ignoreCase);
}
public virtual SiteString Copy()
{
return new SiteString( m_site, m_separatedSite );
}
public virtual bool IsSubsetOf( SiteString operand )
{
return this.IsSubsetOf( operand, true );
}
public virtual bool IsSubsetOf( SiteString operand, bool ignoreCase )
{
StringComparison strComp = (ignoreCase? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal);
if (operand == null)
{
return false;
}
else if (this.m_separatedSite.Count == operand.m_separatedSite.Count &&
this.m_separatedSite.Count == 0)
{
return true;
}
else if (this.m_separatedSite.Count < operand.m_separatedSite.Count - 1)
{
return false;
}
else if (this.m_separatedSite.Count > operand.m_separatedSite.Count &&
operand.m_separatedSite.Count > 0 &&
!operand.m_separatedSite[operand.m_separatedSite.Count - 1].Equals("*"))
{
return false;
}
else if (String.Compare( this.m_site, operand.m_site, strComp) == 0)
{
return true;
}
for (int index = 0; index < operand.m_separatedSite.Count - 1; ++index)
{
if (String.Compare((String)this.m_separatedSite[index], (String)operand.m_separatedSite[index], strComp) != 0)
{
return false;
}
}
if (this.m_separatedSite.Count < operand.m_separatedSite.Count)
{
return operand.m_separatedSite[operand.m_separatedSite.Count - 1].Equals("*");
}
else if (this.m_separatedSite.Count == operand.m_separatedSite.Count)
{
// last item must be the same or operand must have a * in its last item
return (String.Compare((String)this.m_separatedSite[this.m_separatedSite.Count - 1],
(String)operand.m_separatedSite[this.m_separatedSite.Count - 1],
strComp ) == 0 ||
operand.m_separatedSite[operand.m_separatedSite.Count - 1].Equals("*"));
}
else
return true;
}
public virtual SiteString Intersect( SiteString operand )
{
if (operand == null)
{
return null;
}
else if (this.IsSubsetOf( operand ))
{
return this.Copy();
}
else if (operand.IsSubsetOf( this ))
{
return operand.Copy();
}
else
{
return null;
}
}
public virtual SiteString Union( SiteString operand )
{
if (operand == null)
{
return this;
}
else if (this.IsSubsetOf( operand ))
{
return operand.Copy();
}
else if (operand.IsSubsetOf( this ))
{
return this.Copy();
}
else
{
return null;
}
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,473 @@
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
// <OWNER>[....]</OWNER>
//
//
// TokenBasedSet.cs
//
namespace System.Security.Util
{
using System;
using System.Collections;
using System.Security.Permissions;
using System.Runtime.Serialization;
using System.Threading;
using System.Diagnostics.Contracts;
using System.Diagnostics.CodeAnalysis;
[Serializable]
internal class TokenBasedSet
{
// Following 3 fields are used only for serialization compat purposes: DO NOT USE THESE EVER!
#pragma warning disable 414
private int m_initSize = 24;
private int m_increment = 8;
#pragma warning restore 414
private Object[] m_objSet;
// END -> Serialization only fields
[OptionalField(VersionAdded = 2)]
private volatile Object m_Obj;
[OptionalField(VersionAdded = 2)]
private volatile Object[] m_Set;
private int m_cElt;
private volatile int m_maxIndex;
[OnDeserialized]
private void OnDeserialized(StreamingContext ctx)
{
OnDeserializedInternal();
}
private void OnDeserializedInternal()
{
if (m_objSet != null) //v1.x case
{
if (m_cElt == 1)
m_Obj = m_objSet[m_maxIndex];
else
m_Set = m_objSet;
m_objSet = null;
}
// Nothing to do for the v2.0 and beyond case
}
[OnSerializing]
private void OnSerializing(StreamingContext ctx)
{
if ((ctx.State & ~(StreamingContextStates.Clone|StreamingContextStates.CrossAppDomain)) != 0)
{
//Nothing special for the v2 and beyond case
// for the v1.x case, we need to create m_objSet if necessary
if (m_cElt == 1)
{
m_objSet = new Object[m_maxIndex+1];
m_objSet[m_maxIndex] = m_Obj;
}
else if (m_cElt > 0)
{
// Array case:
m_objSet = m_Set;
}
}
}
[OnSerialized]
private void OnSerialized(StreamingContext ctx)
{
if ((ctx.State & ~(StreamingContextStates.Clone|StreamingContextStates.CrossAppDomain)) != 0)
{
m_objSet = null;
}
}
internal bool MoveNext(ref TokenBasedSetEnumerator e)
{
switch (m_cElt)
{
case 0:
return false;
case 1:
if (e.Index == -1)
{
e.Index = m_maxIndex;
e.Current = m_Obj;
return true;
}
else
{
e.Index = (short)(m_maxIndex+1);
e.Current = null;
return false;
}
default:
while (++e.Index <= m_maxIndex)
{
e.Current = Volatile.Read(ref m_Set[e.Index]);
if (e.Current != null)
return true;
}
e.Current = null;
return false;
}
}
internal TokenBasedSet()
{
Reset();
}
[SuppressMessage("Microsoft.Concurrency", "CA8001", Justification = "Reviewed for thread safety")]
internal TokenBasedSet(TokenBasedSet tbSet)
{
if (tbSet == null)
{
Reset();
return;
}
if (tbSet.m_cElt > 1)
{
Object[] aObj = tbSet.m_Set;
int aLen = aObj.Length;
Object[] aNew = new Object[aLen];
System.Array.Copy(aObj, 0, aNew, 0, aLen);
m_Set = aNew;
}
else
{
m_Obj = tbSet.m_Obj;
}
m_cElt = tbSet.m_cElt;
m_maxIndex = tbSet.m_maxIndex;
}
internal void Reset()
{
m_Obj = null;
m_Set = null;
m_cElt = 0;
m_maxIndex = -1;
}
internal void SetItem(int index, Object item)
{
Object[] aObj = null;
if (item == null)
{
RemoveItem(index);
return;
}
switch (m_cElt)
{
case 0:
// on the first item, we don't create an array, we merely remember it's index and value
// this this the 99% case
m_cElt = 1;
m_maxIndex = (short)index;
m_Obj = item;
break;
case 1:
// we have to decide if a 2nd item has indeed been added and create the array
// if it has
if (index == m_maxIndex)
{
// replacing the one existing item
m_Obj = item;
}
else
{
// adding a second distinct permission
Object objSaved = m_Obj;
int iMax = Math.Max(m_maxIndex, index);
aObj = new Object[iMax+1];
aObj[m_maxIndex] = objSaved;
aObj[index] = item;
m_maxIndex = (short)iMax;
m_cElt = 2;
m_Set = aObj;
m_Obj = null;
}
break;
default:
// this is the general case code for when there is really an array
aObj = m_Set;
// we are now adding an item, check if we need to grow
if (index >= aObj.Length)
{
Object[] newset = new Object[index+1];
System.Array.Copy(aObj, 0, newset, 0, m_maxIndex+1);
m_maxIndex = (short)index;
newset[index] = item;
m_Set = newset;
m_cElt++;
}
else
{
if (aObj[index] == null)
m_cElt++;
aObj[index] = item;
if (index > m_maxIndex)
m_maxIndex = (short)index;
}
break;
}
}
[SuppressMessage("Microsoft.Concurrency", "CA8001", Justification = "Reviewed for thread-safety")]
internal Object GetItem(int index)
{
switch (m_cElt)
{
case 0:
return null;
case 1:
if (index == m_maxIndex)
return m_Obj;
else
return null;
default:
if (index < m_Set.Length)
return Volatile.Read(ref m_Set[index]);
else
return null;
}
}
internal Object RemoveItem(int index)
{
Object ret = null;
switch (m_cElt)
{
case 0:
ret = null;
break;
case 1:
if (index != m_maxIndex)
{
// removing a permission we don't have ignore it
ret = null;
}
else
{
// removing the permission we have at the moment
ret = m_Obj;
Reset();
}
break;
default:
// this is the general case code for when there is really an array
// we are removing an item
if (index < m_Set.Length && (ret = Volatile.Read(ref m_Set[index])) != null)
{
// ok we really deleted something at this point
Volatile.Write(ref m_Set[index], null);
m_cElt--;
if (index == m_maxIndex)
ResetMaxIndex(m_Set);
// collapse the array
if (m_cElt == 1)
{
m_Obj = Volatile.Read(ref m_Set[m_maxIndex]);
m_Set = null;
}
}
break;
}
return ret;
}
private void ResetMaxIndex(Object[] aObj)
{
int i;
// Start at the end of the array, and
// scan backwards for the first non-null
// slot. That is the new maxIndex.
for (i = aObj.Length - 1; i >= 0; i--)
{
if (aObj[i] != null)
{
m_maxIndex = (short)i;
return;
}
}
m_maxIndex = -1;
}
internal int GetStartingIndex()
{
if (m_cElt <= 1)
return m_maxIndex;
return 0;
}
internal int GetCount()
{
return m_cElt;
}
internal int GetMaxUsedIndex()
{
return m_maxIndex;
}
internal bool FastIsEmpty()
{
return m_cElt == 0;
}
// Used to merge two distinct TokenBasedSets (used currently only in PermissionSet Deserialization)
internal TokenBasedSet SpecialUnion(TokenBasedSet other)
{
// This gets called from PermissionSet.OnDeserialized and it's possible that the TokenBasedSets have
// not been subjected to VTS callbacks yet
OnDeserializedInternal();
TokenBasedSet unionSet = new TokenBasedSet();
int maxMax;
if (other != null)
{
other.OnDeserializedInternal();
maxMax = this.GetMaxUsedIndex() > other.GetMaxUsedIndex() ? this.GetMaxUsedIndex() : other.GetMaxUsedIndex();
}
else
maxMax = this.GetMaxUsedIndex();
for (int i = 0; i <= maxMax; ++i)
{
Object thisObj = this.GetItem( i );
IPermission thisPerm = thisObj as IPermission;
#if FEATURE_CAS_POLICY
ISecurityElementFactory thisElem = thisObj as ISecurityElementFactory;
#endif // FEATURE_CAS_POLICY
Object otherObj = (other != null)?other.GetItem( i ):null;
IPermission otherPerm = otherObj as IPermission;
#if FEATURE_CAS_POLICY
ISecurityElementFactory otherElem = otherObj as ISecurityElementFactory;
#endif // FEATURE_CAS_POLICY
if (thisObj == null && otherObj == null)
continue;
if (thisObj == null)
{
#if FEATURE_CAS_POLICY
if (otherElem != null)
{
otherPerm = PermissionSet.CreatePerm(otherElem, false);
}
#endif // FEATURE_CAS_POLICY
PermissionToken token = PermissionToken.GetToken(otherPerm);
if (token == null)
{
throw new SerializationException(Environment.GetResourceString("Serialization_InsufficientState"));
}
unionSet.SetItem(token.m_index, otherPerm);
}
else if (otherObj == null)
{
#if FEATURE_CAS_POLICY
if (thisElem != null)
{
thisPerm = PermissionSet.CreatePerm(thisElem, false);
}
#endif // FEATURE_CAS_POLICY
PermissionToken token = PermissionToken.GetToken(thisPerm);
if (token == null)
{
throw new SerializationException(Environment.GetResourceString("Serialization_InsufficientState"));
}
unionSet.SetItem( token.m_index, thisPerm);
}
else
{
Contract.Assert( (thisObj == null || otherObj == null), "Permission cannot be in both TokenBasedSets" );
}
}
return unionSet;
}
internal void SpecialSplit(ref TokenBasedSet unrestrictedPermSet, ref TokenBasedSet normalPermSet, bool ignoreTypeLoadFailures)
{
int maxIndex = GetMaxUsedIndex();
for (int i = GetStartingIndex(); i <= maxIndex; ++i)
{
Object obj = GetItem( i );
if (obj != null)
{
IPermission perm = obj as IPermission;
#if FEATURE_CAS_POLICY
if (perm == null)
perm = PermissionSet.CreatePerm(obj, ignoreTypeLoadFailures);
#endif // FEATURE_CAS_POLICY
PermissionToken token = PermissionToken.GetToken(perm);
if (perm == null || token == null)
continue;
if (perm is IUnrestrictedPermission)
{
// Add to unrestrictedPermSet
if (unrestrictedPermSet == null)
unrestrictedPermSet = new TokenBasedSet();
unrestrictedPermSet.SetItem(token.m_index, perm);
}
else
{
// Add to normalPermSet
if (normalPermSet == null)
normalPermSet = new TokenBasedSet();
normalPermSet.SetItem(token.m_index, perm);
}
}
}
}
}
}

View File

@@ -0,0 +1,42 @@
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
// TokenBasedSetEnumerator.cs
//
// <OWNER>[....]</OWNER>
//
namespace System.Security.Util
{
using System;
using System.Collections;
internal struct TokenBasedSetEnumerator
{
public Object Current;
public int Index;
private TokenBasedSet _tb;
public bool MoveNext()
{
return _tb != null ? _tb.MoveNext(ref this) : false;
}
public void Reset()
{
Index = -1;
Current = null;
}
public TokenBasedSetEnumerator(TokenBasedSet tb)
{
Index = -1;
Current = null;
_tb = tb;
}
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff