using System;
using System.Collections;
namespace System.Net
{
/// Provides storage for multiple credentials.
// Token: 0x0200020A RID: 522
public class CredentialCache : IEnumerable, ICredentials, ICredentialsByHost
{
/// Creates a new instance of the class.
// Token: 0x060011CB RID: 4555 RVA: 0x00034E94 File Offset: 0x00033094
public CredentialCache()
{
this.cache = new Hashtable();
this.cacheForHost = new Hashtable();
}
/// Gets the system credentials of the application.
/// An that represents the system credentials of the application.
///
///
///
// Token: 0x170005D3 RID: 1491
// (get) Token: 0x060011CD RID: 4557 RVA: 0x00034ED0 File Offset: 0x000330D0
[global::System.MonoTODO("Need EnvironmentPermission implementation first")]
public static ICredentials DefaultCredentials
{
get
{
return CredentialCache.empty;
}
}
/// Gets the network credentials of the current security context.
/// An that represents the network credentials of the current user or application.
// Token: 0x170005D4 RID: 1492
// (get) Token: 0x060011CE RID: 4558 RVA: 0x00034ED8 File Offset: 0x000330D8
public static NetworkCredential DefaultNetworkCredentials
{
get
{
return CredentialCache.empty;
}
}
/// Returns the instance associated with the specified Uniform Resource Identifier (URI) and authentication type.
/// A or, if there is no matching credential in the cache, null.
/// A that specifies the URI prefix of the resources that the credential grants access to.
/// The authentication scheme used by the resource named in .
///
/// or is null.
// Token: 0x060011CF RID: 4559 RVA: 0x00034EE0 File Offset: 0x000330E0
public NetworkCredential GetCredential(global::System.Uri uriPrefix, string authType)
{
int num = -1;
NetworkCredential networkCredential = null;
if (uriPrefix == null || authType == null)
{
return null;
}
string text = uriPrefix.AbsolutePath;
text = text.Substring(0, text.LastIndexOf('/'));
IDictionaryEnumerator enumerator = this.cache.GetEnumerator();
while (enumerator.MoveNext())
{
CredentialCache.CredentialCacheKey credentialCacheKey = enumerator.Key as CredentialCache.CredentialCacheKey;
if (credentialCacheKey.Length > num)
{
if (string.Compare(credentialCacheKey.AuthType, authType, true) == 0)
{
global::System.Uri uriPrefix2 = credentialCacheKey.UriPrefix;
if (!(uriPrefix2.Scheme != uriPrefix.Scheme))
{
if (uriPrefix2.Port == uriPrefix.Port)
{
if (!(uriPrefix2.Host != uriPrefix.Host))
{
if (text.StartsWith(credentialCacheKey.AbsPath))
{
num = credentialCacheKey.Length;
networkCredential = (NetworkCredential)enumerator.Value;
}
}
}
}
}
}
}
return networkCredential;
}
/// Returns an enumerator that can iterate through the instance.
/// An for the .
// Token: 0x060011D0 RID: 4560 RVA: 0x00034FF4 File Offset: 0x000331F4
public IEnumerator GetEnumerator()
{
return this.cache.Values.GetEnumerator();
}
/// Adds a instance to the credential cache for use with protocols other than SMTP and associates it with a Uniform Resource Identifier (URI) prefix and authentication protocol.
/// A that specifies the URI prefix of the resources that the credential grants access to.
/// The authentication scheme used by the resource named in .
/// The to add to the credential cache.
///
/// is null. -or- is null.
/// The same credentials are added more than once.
// Token: 0x060011D1 RID: 4561 RVA: 0x00035008 File Offset: 0x00033208
public void Add(global::System.Uri uriPrefix, string authType, NetworkCredential cred)
{
if (uriPrefix == null)
{
throw new ArgumentNullException("uriPrefix");
}
if (authType == null)
{
throw new ArgumentNullException("authType");
}
this.cache.Add(new CredentialCache.CredentialCacheKey(uriPrefix, authType), cred);
}
/// Deletes a instance from the cache if it is associated with the specified Uniform Resource Identifier (URI) prefix and authentication protocol.
/// A that specifies the URI prefix of the resources that the credential is used for.
/// The authentication scheme used by the host named in .
// Token: 0x060011D2 RID: 4562 RVA: 0x00035048 File Offset: 0x00033248
public void Remove(global::System.Uri uriPrefix, string authType)
{
if (uriPrefix == null)
{
throw new ArgumentNullException("uriPrefix");
}
if (authType == null)
{
throw new ArgumentNullException("authType");
}
this.cache.Remove(new CredentialCache.CredentialCacheKey(uriPrefix, authType));
}
/// Returns the instance associated with the specified host, port, and authentication protocol.
/// A or, if there is no matching credential in the cache, null.
/// A that identifies the host computer.
/// A that specifies the port to connect to on .
/// A that identifies the authentication scheme used when connecting to . See Remarks.
///
/// is null. -or- is null.
///
/// not an accepted value. See Remarks. -or- is equal to the empty string ("").
///
/// is less than zero.
// Token: 0x060011D3 RID: 4563 RVA: 0x00035090 File Offset: 0x00033290
public NetworkCredential GetCredential(string host, int port, string authenticationType)
{
NetworkCredential networkCredential = null;
if (host == null || port < 0 || authenticationType == null)
{
return null;
}
IDictionaryEnumerator enumerator = this.cacheForHost.GetEnumerator();
while (enumerator.MoveNext())
{
CredentialCache.CredentialCacheForHostKey credentialCacheForHostKey = enumerator.Key as CredentialCache.CredentialCacheForHostKey;
if (string.Compare(credentialCacheForHostKey.AuthType, authenticationType, true) == 0)
{
if (!(credentialCacheForHostKey.Host != host))
{
if (credentialCacheForHostKey.Port == port)
{
networkCredential = (NetworkCredential)enumerator.Value;
}
}
}
}
return networkCredential;
}
/// Adds a instance for use with SMTP to the credential cache and associates it with a host computer, port, and authentication protocol. Credentials added using this method are valid for SMTP only. This method does not work for HTTP or FTP requests.
/// A that identifies the host computer.
/// A that specifies the port to connect to on .
/// A that identifies the authentication scheme used when connecting to using . See Remarks.
/// The to add to the credential cache.
///
/// is null. -or- is null.
///
/// not an accepted value. See Remarks.
///
/// is less than zero.
// Token: 0x060011D4 RID: 4564 RVA: 0x00035128 File Offset: 0x00033328
public void Add(string host, int port, string authenticationType, NetworkCredential credential)
{
if (host == null)
{
throw new ArgumentNullException("host");
}
if (port < 0)
{
throw new ArgumentOutOfRangeException("port");
}
if (authenticationType == null)
{
throw new ArgumentOutOfRangeException("authenticationType");
}
this.cacheForHost.Add(new CredentialCache.CredentialCacheForHostKey(host, port, authenticationType), credential);
}
/// Deletes a instance from the cache if it is associated with the specified host, port, and authentication protocol.
/// A that identifies the host computer.
/// A that specifies the port to connect to on .
/// A that identifies the authentication scheme used when connecting to . See Remarks.
// Token: 0x060011D5 RID: 4565 RVA: 0x00035180 File Offset: 0x00033380
public void Remove(string host, int port, string authenticationType)
{
if (host == null)
{
return;
}
if (authenticationType == null)
{
return;
}
this.cacheForHost.Remove(new CredentialCache.CredentialCacheForHostKey(host, port, authenticationType));
}
// Token: 0x04000F94 RID: 3988
private static NetworkCredential empty = new NetworkCredential(string.Empty, string.Empty, string.Empty);
// Token: 0x04000F95 RID: 3989
private Hashtable cache;
// Token: 0x04000F96 RID: 3990
private Hashtable cacheForHost;
// Token: 0x0200020B RID: 523
private class CredentialCacheKey
{
// Token: 0x060011D6 RID: 4566 RVA: 0x000351A4 File Offset: 0x000333A4
internal CredentialCacheKey(global::System.Uri uriPrefix, string authType)
{
this.uriPrefix = uriPrefix;
this.authType = authType;
this.absPath = uriPrefix.AbsolutePath;
this.absPath = this.absPath.Substring(0, this.absPath.LastIndexOf('/'));
this.len = uriPrefix.AbsoluteUri.Length;
this.hash = uriPrefix.GetHashCode() + authType.GetHashCode();
}
// Token: 0x170005D5 RID: 1493
// (get) Token: 0x060011D7 RID: 4567 RVA: 0x00035214 File Offset: 0x00033414
public int Length
{
get
{
return this.len;
}
}
// Token: 0x170005D6 RID: 1494
// (get) Token: 0x060011D8 RID: 4568 RVA: 0x0003521C File Offset: 0x0003341C
public string AbsPath
{
get
{
return this.absPath;
}
}
// Token: 0x170005D7 RID: 1495
// (get) Token: 0x060011D9 RID: 4569 RVA: 0x00035224 File Offset: 0x00033424
public global::System.Uri UriPrefix
{
get
{
return this.uriPrefix;
}
}
// Token: 0x170005D8 RID: 1496
// (get) Token: 0x060011DA RID: 4570 RVA: 0x0003522C File Offset: 0x0003342C
public string AuthType
{
get
{
return this.authType;
}
}
// Token: 0x060011DB RID: 4571 RVA: 0x00035234 File Offset: 0x00033434
public override int GetHashCode()
{
return this.hash;
}
// Token: 0x060011DC RID: 4572 RVA: 0x0003523C File Offset: 0x0003343C
public override bool Equals(object obj)
{
CredentialCache.CredentialCacheKey credentialCacheKey = obj as CredentialCache.CredentialCacheKey;
return credentialCacheKey != null && this.hash == credentialCacheKey.hash;
}
// Token: 0x060011DD RID: 4573 RVA: 0x00035268 File Offset: 0x00033468
public override string ToString()
{
return string.Concat(new object[] { this.absPath, " : ", this.authType, " : len=", this.len });
}
// Token: 0x04000F97 RID: 3991
private global::System.Uri uriPrefix;
// Token: 0x04000F98 RID: 3992
private string authType;
// Token: 0x04000F99 RID: 3993
private string absPath;
// Token: 0x04000F9A RID: 3994
private int len;
// Token: 0x04000F9B RID: 3995
private int hash;
}
// Token: 0x0200020C RID: 524
private class CredentialCacheForHostKey
{
// Token: 0x060011DE RID: 4574 RVA: 0x000352A8 File Offset: 0x000334A8
internal CredentialCacheForHostKey(string host, int port, string authType)
{
this.host = host;
this.port = port;
this.authType = authType;
this.hash = host.GetHashCode() + port.GetHashCode() + authType.GetHashCode();
}
// Token: 0x170005D9 RID: 1497
// (get) Token: 0x060011DF RID: 4575 RVA: 0x000352EC File Offset: 0x000334EC
public string Host
{
get
{
return this.host;
}
}
// Token: 0x170005DA RID: 1498
// (get) Token: 0x060011E0 RID: 4576 RVA: 0x000352F4 File Offset: 0x000334F4
public int Port
{
get
{
return this.port;
}
}
// Token: 0x170005DB RID: 1499
// (get) Token: 0x060011E1 RID: 4577 RVA: 0x000352FC File Offset: 0x000334FC
public string AuthType
{
get
{
return this.authType;
}
}
// Token: 0x060011E2 RID: 4578 RVA: 0x00035304 File Offset: 0x00033504
public override int GetHashCode()
{
return this.hash;
}
// Token: 0x060011E3 RID: 4579 RVA: 0x0003530C File Offset: 0x0003350C
public override bool Equals(object obj)
{
CredentialCache.CredentialCacheForHostKey credentialCacheForHostKey = obj as CredentialCache.CredentialCacheForHostKey;
return credentialCacheForHostKey != null && this.hash == credentialCacheForHostKey.hash;
}
// Token: 0x060011E4 RID: 4580 RVA: 0x00035338 File Offset: 0x00033538
public override string ToString()
{
return this.host + " : " + this.authType;
}
// Token: 0x04000F9C RID: 3996
private string host;
// Token: 0x04000F9D RID: 3997
private int port;
// Token: 0x04000F9E RID: 3998
private string authType;
// Token: 0x04000F9F RID: 3999
private int hash;
}
}
}