Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
Claim.cs
Go to the documentation of this file.
2using System.IO;
3
5
6public class Claim
7{
8 private enum SerializationMask
9 {
10 None = 0,
11 NameClaimType = 1,
12 RoleClaimType = 2,
13 StringType = 4,
14 Issuer = 8,
16 OriginalIssuer = 0x20,
17 HasProperties = 0x40,
18 UserData = 0x80
19 }
20
21 private readonly byte[] _userSerializationData;
22
23 private readonly string _issuer;
24
25 private readonly string _originalIssuer;
26
28
29 private readonly ClaimsIdentity _subject;
30
31 private readonly string _type;
32
33 private readonly string _value;
34
35 private readonly string _valueType;
36
37 protected virtual byte[]? CustomSerializationData => _userSerializationData;
38
39 public string Issuer => _issuer;
40
42
44 {
45 get
46 {
47 if (_properties == null)
48 {
50 }
51 return _properties;
52 }
53 }
54
56
57 public string Type => _type;
58
59 public string Value => _value;
60
61 public string ValueType => _valueType;
62
63 public Claim(BinaryReader reader)
64 : this(reader, null)
65 {
66 }
67
69 {
70 if (reader == null)
71 {
72 throw new ArgumentNullException("reader");
73 }
76 int num = 1;
77 int num2 = reader.ReadInt32();
78 _value = reader.ReadString();
79 if ((serializationMask & SerializationMask.NameClaimType) == SerializationMask.NameClaimType)
80 {
81 _type = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name";
82 }
83 else if ((serializationMask & SerializationMask.RoleClaimType) == SerializationMask.RoleClaimType)
84 {
85 _type = "http://schemas.microsoft.com/ws/2008/06/identity/claims/role";
86 }
87 else
88 {
89 _type = reader.ReadString();
90 num++;
91 }
92 if ((serializationMask & SerializationMask.StringType) == SerializationMask.StringType)
93 {
94 _valueType = reader.ReadString();
95 num++;
96 }
97 else
98 {
99 _valueType = "http://www.w3.org/2001/XMLSchema#string";
100 }
102 {
103 _issuer = reader.ReadString();
104 num++;
105 }
106 else
107 {
108 _issuer = "LOCAL AUTHORITY";
109 }
110 if ((serializationMask & SerializationMask.OriginalIssuerEqualsIssuer) == SerializationMask.OriginalIssuerEqualsIssuer)
111 {
113 }
114 else if ((serializationMask & SerializationMask.OriginalIssuer) == SerializationMask.OriginalIssuer)
115 {
116 _originalIssuer = reader.ReadString();
117 num++;
118 }
119 else
120 {
121 _originalIssuer = "LOCAL AUTHORITY";
122 }
123 if ((serializationMask & SerializationMask.HasProperties) == SerializationMask.HasProperties)
124 {
125 int num3 = reader.ReadInt32();
126 num++;
127 for (int i = 0; i < num3; i++)
128 {
129 Properties.Add(reader.ReadString(), reader.ReadString());
130 }
131 }
132 if ((serializationMask & SerializationMask.UserData) == SerializationMask.UserData)
133 {
134 int count = reader.ReadInt32();
136 num++;
137 }
138 for (int j = num; j < num2; j++)
139 {
140 reader.ReadString();
141 }
142 }
143
144 public Claim(string type, string value)
145 : this(type, value, "http://www.w3.org/2001/XMLSchema#string", "LOCAL AUTHORITY", "LOCAL AUTHORITY", null)
146 {
147 }
148
149 public Claim(string type, string value, string? valueType)
150 : this(type, value, valueType, "LOCAL AUTHORITY", "LOCAL AUTHORITY", null)
151 {
152 }
153
154 public Claim(string type, string value, string? valueType, string? issuer)
156 {
157 }
158
159 public Claim(string type, string value, string? valueType, string? issuer, string? originalIssuer)
161 {
162 }
163
164 public Claim(string type, string value, string? valueType, string? issuer, string? originalIssuer, ClaimsIdentity? subject)
166 {
167 }
168
169 internal Claim(string type, string value, string valueType, string issuer, string originalIssuer, ClaimsIdentity subject, string propertyKey, string propertyValue)
170 {
171 if (type == null)
172 {
173 throw new ArgumentNullException("type");
174 }
175 if (value == null)
176 {
177 throw new ArgumentNullException("value");
178 }
179 _type = type;
180 _value = value;
181 _valueType = (string.IsNullOrEmpty(valueType) ? "http://www.w3.org/2001/XMLSchema#string" : valueType);
182 _issuer = (string.IsNullOrEmpty(issuer) ? "LOCAL AUTHORITY" : issuer);
183 _originalIssuer = (string.IsNullOrEmpty(originalIssuer) ? _issuer : originalIssuer);
185 if (propertyKey != null)
186 {
189 }
190 }
191
192 protected Claim(Claim other)
194 {
195 }
196
198 {
199 if (other == null)
200 {
201 throw new ArgumentNullException("other");
202 }
203 _issuer = other._issuer;
204 _originalIssuer = other._originalIssuer;
206 _type = other._type;
207 _value = other._value;
208 _valueType = other._valueType;
209 if (other._properties != null)
210 {
212 }
213 if (other._userSerializationData != null)
214 {
215 _userSerializationData = other._userSerializationData.Clone() as byte[];
216 }
217 }
218
219 public virtual Claim Clone()
220 {
221 return Clone(null);
222 }
223
224 public virtual Claim Clone(ClaimsIdentity? identity)
225 {
226 return new Claim(this, identity);
227 }
228
229 public virtual void WriteTo(BinaryWriter writer)
230 {
231 WriteTo(writer, null);
232 }
233
234 protected virtual void WriteTo(BinaryWriter writer, byte[]? userData)
235 {
236 if (writer == null)
237 {
238 throw new ArgumentNullException("writer");
239 }
240 int num = 1;
242 if (string.Equals(_type, "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name"))
243 {
244 serializationMask |= SerializationMask.NameClaimType;
245 }
246 else if (string.Equals(_type, "http://schemas.microsoft.com/ws/2008/06/identity/claims/role"))
247 {
248 serializationMask |= SerializationMask.RoleClaimType;
249 }
250 else
251 {
252 num++;
253 }
254 if (!string.Equals(_valueType, "http://www.w3.org/2001/XMLSchema#string", StringComparison.Ordinal))
255 {
256 num++;
258 }
259 if (!string.Equals(_issuer, "LOCAL AUTHORITY", StringComparison.Ordinal))
260 {
261 num++;
263 }
264 if (string.Equals(_originalIssuer, _issuer, StringComparison.Ordinal))
265 {
266 serializationMask |= SerializationMask.OriginalIssuerEqualsIssuer;
267 }
268 else if (!string.Equals(_originalIssuer, "LOCAL AUTHORITY"))
269 {
270 num++;
271 serializationMask |= SerializationMask.OriginalIssuer;
272 }
273 if (_properties != null && _properties.Count > 0)
274 {
275 num++;
276 serializationMask |= SerializationMask.HasProperties;
277 }
278 if (userData != null && userData.Length != 0)
279 {
280 num++;
282 }
283 writer.Write((int)serializationMask);
284 writer.Write(num);
285 writer.Write(_value);
286 if ((serializationMask & SerializationMask.NameClaimType) != SerializationMask.NameClaimType && (serializationMask & SerializationMask.RoleClaimType) != SerializationMask.RoleClaimType)
287 {
288 writer.Write(_type);
289 }
290 if ((serializationMask & SerializationMask.StringType) == SerializationMask.StringType)
291 {
292 writer.Write(_valueType);
293 }
295 {
296 writer.Write(_issuer);
297 }
298 if ((serializationMask & SerializationMask.OriginalIssuer) == SerializationMask.OriginalIssuer)
299 {
300 writer.Write(_originalIssuer);
301 }
302 if ((serializationMask & SerializationMask.HasProperties) == SerializationMask.HasProperties)
303 {
304 writer.Write(_properties.Count);
306 {
307 writer.Write(property.Key);
308 writer.Write(property.Value);
309 }
310 }
311 if ((serializationMask & SerializationMask.UserData) == SerializationMask.UserData)
312 {
313 writer.Write(userData.Length);
314 writer.Write(userData);
315 }
316 writer.Flush();
317 }
318
319 public override string ToString()
320 {
321 return _type + ": " + _value;
322 }
323}
virtual string ReadString()
virtual int ReadInt32()
virtual byte[] ReadBytes(int count)
Claim(string type, string value)
Definition Claim.cs:144
virtual Claim Clone(ClaimsIdentity? identity)
Definition Claim.cs:224
Dictionary< string, string > _properties
Definition Claim.cs:27
Claim(string type, string value, string? valueType, string? issuer, string? originalIssuer, ClaimsIdentity? subject)
Definition Claim.cs:164
readonly ClaimsIdentity _subject
Definition Claim.cs:29
virtual ? byte[] CustomSerializationData
Definition Claim.cs:37
readonly string _valueType
Definition Claim.cs:35
readonly string _value
Definition Claim.cs:33
ClaimsIdentity? Subject
Definition Claim.cs:55
readonly string _issuer
Definition Claim.cs:23
Claim(string type, string value, string? valueType, string? issuer)
Definition Claim.cs:154
Claim(BinaryReader reader)
Definition Claim.cs:63
readonly string _originalIssuer
Definition Claim.cs:25
Claim(string type, string value, string valueType, string issuer, string originalIssuer, ClaimsIdentity subject, string propertyKey, string propertyValue)
Definition Claim.cs:169
Claim(string type, string value, string? valueType)
Definition Claim.cs:149
Claim(Claim other, ClaimsIdentity? subject)
Definition Claim.cs:197
virtual void WriteTo(BinaryWriter writer)
Definition Claim.cs:229
readonly string _type
Definition Claim.cs:31
IDictionary< string, string > Properties
Definition Claim.cs:44
Claim(BinaryReader reader, ClaimsIdentity? subject)
Definition Claim.cs:68
readonly byte[] _userSerializationData
Definition Claim.cs:21
Claim(string type, string value, string? valueType, string? issuer, string? originalIssuer)
Definition Claim.cs:159
override string ToString()
Definition Claim.cs:319
virtual void WriteTo(BinaryWriter writer, byte[]? userData)
Definition Claim.cs:234
virtual Claim Clone()
Definition Claim.cs:219
void Add(object key, object? value)