Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
CredentialCache.cs
Go to the documentation of this file.
4
5namespace System.Net;
6
8{
10 {
32
34 {
36
37 private bool _onThisEnumerator;
38
44
45 protected override bool MoveNext(out NetworkCredential current)
46 {
48 {
49 if (base.MoveNext(out current))
50 {
51 return true;
52 }
53 _onThisEnumerator = true;
54 }
55 return DictionaryEnumeratorHelper.MoveNext(ref _enumerator, out current);
56 }
57
58 public override void Reset()
59 {
60 _onThisEnumerator = false;
62 base.Reset();
63 }
64 }
65
66 private static class DictionaryEnumeratorHelper
67 {
68 internal static bool MoveNext<TKey, TValue>(ref Dictionary<TKey, TValue>.ValueCollection.Enumerator enumerator, out TValue current)
69 {
70 bool result = enumerator.MoveNext();
71 current = enumerator.Current;
72 return result;
73 }
74
75 internal static void Reset<TEnumerator>(ref TEnumerator enumerator) where TEnumerator : IEnumerator
76 {
77 try
78 {
79 enumerator.Reset();
80 }
82 {
83 }
84 }
85 }
86
87 private readonly CredentialCache _cache;
88
89 private readonly int _version;
90
91 private bool _enumerating;
92
94
95 public object Current
96 {
97 get
98 {
99 if (!_enumerating)
100 {
102 }
103 if (_version != _cache._version)
104 {
106 }
107 return _current;
108 }
109 }
110
112 {
113 if (cache._cache != null)
114 {
115 if (cache._cacheForHosts == null)
116 {
118 }
120 }
121 if (cache._cacheForHosts == null)
122 {
123 return new CredentialEnumerator(cache);
124 }
126 }
127
133
134 public bool MoveNext()
135 {
136 if (_version != _cache._version)
137 {
139 }
141 }
142
143 protected virtual bool MoveNext(out NetworkCredential current)
144 {
145 current = null;
146 return false;
147 }
148
149 public virtual void Reset()
150 {
151 _enumerating = false;
152 }
153 }
154
156
158
159 private int _version;
160
162
164
166 {
167 if (uriPrefix == null)
168 {
169 throw new ArgumentNullException("uriPrefix");
170 }
171 if (authType == null)
172 {
173 throw new ArgumentNullException("authType");
174 }
175 if (cred is SystemNetworkCredential && !string.Equals(authType, "NTLM", StringComparison.OrdinalIgnoreCase) && !string.Equals(authType, "Kerberos", StringComparison.OrdinalIgnoreCase) && !string.Equals(authType, "Negotiate", StringComparison.OrdinalIgnoreCase))
176 {
178 }
179 _version++;
181 if (NetEventSource.Log.IsEnabled())
182 {
183 NetEventSource.Info(this, $"Adding key:[{credentialKey}], cred:[{cred.Domain}],[{cred.UserName}]", "Add");
184 }
185 if (_cache == null)
186 {
188 }
190 }
191
192 public void Add(string host, int port, string authenticationType, NetworkCredential credential)
193 {
194 if (host == null)
195 {
196 throw new ArgumentNullException("host");
197 }
198 if (authenticationType == null)
199 {
200 throw new ArgumentNullException("authenticationType");
201 }
202 if (host.Length == 0)
203 {
204 throw new ArgumentException(System.SR.Format(System.SR.net_emptystringcall, "host"), "host");
205 }
206 if (port < 0)
207 {
208 throw new ArgumentOutOfRangeException("port");
209 }
210 if (credential is SystemNetworkCredential && !string.Equals(authenticationType, "NTLM", StringComparison.OrdinalIgnoreCase) && !string.Equals(authenticationType, "Kerberos", StringComparison.OrdinalIgnoreCase) && !string.Equals(authenticationType, "Negotiate", StringComparison.OrdinalIgnoreCase))
211 {
213 }
214 _version++;
216 if (NetEventSource.Log.IsEnabled())
217 {
218 NetEventSource.Info(this, $"Adding key:[{credentialHostKey}], cred:[{credential.Domain}],[{credential.UserName}]", "Add");
219 }
220 if (_cacheForHosts == null)
221 {
223 }
225 }
226
227 public void Remove(Uri? uriPrefix, string? authType)
228 {
229 if (uriPrefix == null || authType == null)
230 {
231 return;
232 }
233 if (_cache == null)
234 {
235 if (NetEventSource.Log.IsEnabled())
236 {
237 NetEventSource.Info(this, "Short-circuiting because the dictionary is null.", "Remove");
238 }
239 return;
240 }
241 _version++;
243 if (NetEventSource.Log.IsEnabled())
244 {
245 NetEventSource.Info(this, $"Removing key:[{credentialKey}]", "Remove");
246 }
248 }
249
250 public void Remove(string? host, int port, string? authenticationType)
251 {
252 if (host == null || authenticationType == null || port < 0)
253 {
254 return;
255 }
256 if (_cacheForHosts == null)
257 {
258 if (NetEventSource.Log.IsEnabled())
259 {
260 NetEventSource.Info(this, "Short-circuiting because the dictionary is null.", "Remove");
261 }
262 return;
263 }
264 _version++;
266 if (NetEventSource.Log.IsEnabled())
267 {
268 NetEventSource.Info(this, $"Removing key:[{credentialHostKey}]", "Remove");
269 }
271 }
272
274 {
275 if (uriPrefix == null)
276 {
277 throw new ArgumentNullException("uriPrefix");
278 }
279 if (authType == null)
280 {
281 throw new ArgumentNullException("authType");
282 }
283 if (_cache == null)
284 {
285 if (NetEventSource.Log.IsEnabled())
286 {
287 NetEventSource.Info(this, "CredentialCache::GetCredential short-circuiting because the dictionary is null.", "GetCredential");
288 }
289 return null;
290 }
291 int num = -1;
294 {
295 CredentialKey key = item.Key;
296 if (key.Match(uriPrefix, authType))
297 {
298 int uriPrefixLength = key.UriPrefixLength;
299 if (uriPrefixLength > num)
300 {
301 num = uriPrefixLength;
302 networkCredential = item.Value;
303 }
304 }
305 }
306 if (NetEventSource.Log.IsEnabled())
307 {
308 NetEventSource.Info(this, FormattableStringFactory.Create("Returning {0}", (networkCredential == null) ? "null" : ("(" + networkCredential.UserName + ":" + networkCredential.Domain + ")")), "GetCredential");
309 }
310 return networkCredential;
311 }
312
314 {
315 if (host == null)
316 {
317 throw new ArgumentNullException("host");
318 }
319 if (authenticationType == null)
320 {
321 throw new ArgumentNullException("authenticationType");
322 }
323 if (host.Length == 0)
324 {
325 throw new ArgumentException(System.SR.Format(System.SR.net_emptystringcall, "host"), "host");
326 }
327 if (port < 0)
328 {
329 throw new ArgumentOutOfRangeException("port");
330 }
331 if (_cacheForHosts == null)
332 {
333 if (NetEventSource.Log.IsEnabled())
334 {
335 NetEventSource.Info(this, "CredentialCache::GetCredential short-circuiting because the dictionary is null.", "GetCredential");
336 }
337 return null;
338 }
342 if (NetEventSource.Log.IsEnabled())
343 {
344 NetEventSource.Info(this, FormattableStringFactory.Create("Returning {0}", (value == null) ? "null" : ("(" + value.UserName + ":" + value.Domain + ")")), "GetCredential");
345 }
346 return value;
347 }
348
350 {
351 return CredentialEnumerator.Create(this);
352 }
353}
bool TryGetValue(TKey key, [MaybeNullWhen(false)] out TValue value)
bool ICollection< KeyValuePair< TKey, TValue > >. Remove(KeyValuePair< TKey, TValue > keyValuePair)
void Add(TKey key, TValue value)
static bool MoveNext< TKey, TValue >(ref Dictionary< TKey, TValue >.ValueCollection.Enumerator enumerator, out TValue current)
Dictionary< CredentialHostKey, NetworkCredential >.ValueCollection.Enumerator _enumerator
SingleTableCredentialEnumerator(CredentialCache cache, Dictionary< TKey, NetworkCredential > table)
Dictionary< TKey, NetworkCredential >.ValueCollection.Enumerator _enumerator
static CredentialEnumerator Create(CredentialCache cache)
virtual bool MoveNext(out NetworkCredential current)
Dictionary< CredentialHostKey, NetworkCredential > _cacheForHosts
NetworkCredential? GetCredential(Uri uriPrefix, string authType)
Dictionary< CredentialKey, NetworkCredential > _cache
void Remove(Uri? uriPrefix, string? authType)
NetworkCredential? GetCredential(string host, int port, string authenticationType)
void Remove(string? host, int port, string? authenticationType)
static ICredentials DefaultCredentials
static NetworkCredential DefaultNetworkCredentials
void Add(Uri uriPrefix, string authType, NetworkCredential cred)
void Add(string host, int port, string authenticationType, NetworkCredential credential)
static readonly System.Net.NetEventSource Log
static void Info(object thisOrContextObject, FormattableString formattableString=null, [CallerMemberName] string memberName=null)
static readonly SystemNetworkCredential s_defaultCredential
static FormattableString Create(string format, params object?[] arguments)
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string net_nodefaultcreds
Definition SR.cs:44
static string InvalidOperation_EnumFailedVersion
Definition SR.cs:44
static string net_emptystringcall
Definition SR.cs:14
static string InvalidOperation_EnumOpCantHappen
Definition SR.cs:48
Definition SR.cs:7