Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
SslApplicationProtocol.cs
Go to the documentation of this file.
2using System.Text;
3
4namespace System.Net.Security;
5
6public readonly struct SslApplicationProtocol : IEquatable<SslApplicationProtocol>
7{
9
10 private static readonly byte[] s_http3Utf8 = new byte[2] { 104, 51 };
11
12 private static readonly byte[] s_http2Utf8 = new byte[2] { 104, 50 };
13
14 private static readonly byte[] s_http11Utf8 = new byte[8] { 104, 116, 116, 112, 47, 49, 46, 49 };
15
16 public static readonly SslApplicationProtocol Http3 = new SslApplicationProtocol(s_http3Utf8, copy: false);
17
18 public static readonly SslApplicationProtocol Http2 = new SslApplicationProtocol(s_http2Utf8, copy: false);
19
20 public static readonly SslApplicationProtocol Http11 = new SslApplicationProtocol(s_http11Utf8, copy: false);
21
22 private readonly byte[] _readOnlyProtocol;
23
25
26 internal SslApplicationProtocol(byte[] protocol, bool copy)
27 {
28 if (protocol.Length == 0 || protocol.Length > 255)
29 {
31 }
32 _readOnlyProtocol = (copy ? protocol.AsSpan().ToArray() : protocol);
33 }
34
35 public SslApplicationProtocol(byte[] protocol)
36 : this(protocol ?? throw new ArgumentNullException("protocol"), copy: true)
37 {
38 }
39
40 public SslApplicationProtocol(string protocol)
41 : this(s_utf8.GetBytes(protocol ?? throw new ArgumentNullException("protocol")), copy: false)
42 {
43 }
44
46 {
47 return ((ReadOnlySpan<byte>)_readOnlyProtocol).SequenceEqual((ReadOnlySpan<byte>)other._readOnlyProtocol);
48 }
49
50 public override bool Equals([NotNullWhen(true)] object? obj)
51 {
53 {
54 return Equals(other);
55 }
56 return false;
57 }
58
59 public override int GetHashCode()
60 {
61 byte[] readOnlyProtocol = _readOnlyProtocol;
62 if (readOnlyProtocol == null)
63 {
64 return 0;
65 }
66 int num = 0;
67 for (int i = 0; i < readOnlyProtocol.Length; i++)
68 {
69 num = ((num << 5) + num) ^ readOnlyProtocol[i];
70 }
71 return num;
72 }
73
74 public override string ToString()
75 {
76 byte[] readOnlyProtocol = _readOnlyProtocol;
77 try
78 {
79 return (readOnlyProtocol == null) ? string.Empty : ((readOnlyProtocol == s_http3Utf8) ? "h3" : ((readOnlyProtocol == s_http2Utf8) ? "h2" : ((readOnlyProtocol == s_http11Utf8) ? "http/1.1" : s_utf8.GetString(readOnlyProtocol))));
80 }
81 catch
82 {
83 char[] array = new char[readOnlyProtocol.Length * 5];
84 int num = 0;
85 for (int i = 0; i < array.Length; i += 5)
86 {
87 byte b = readOnlyProtocol[num++];
88 array[i] = '0';
89 array[i + 1] = 'x';
90 array[i + 2] = System.HexConverter.ToCharLower(b >> 4);
92 array[i + 4] = ' ';
93 }
94 return new string(array, 0, array.Length - 1);
95 }
96 }
97
99 {
100 return left.Equals(right);
101 }
102
104 {
105 return !(left == right);
106 }
107}
static char ToCharLower(int value)
static string net_ssl_app_protocol_invalid
Definition SR.cs:114
Definition SR.cs:7
static DecoderFallback ExceptionFallback
static EncoderFallback ExceptionFallback
static Encoding UTF8
Definition Encoding.cs:526
static Encoding GetEncoding(int codepage)
Definition Encoding.cs:593
static readonly SslApplicationProtocol Http2
override bool Equals([NotNullWhen(true)] object? obj)
static bool operator!=(SslApplicationProtocol left, SslApplicationProtocol right)
static readonly SslApplicationProtocol Http3
bool Equals(SslApplicationProtocol other)
static bool operator==(SslApplicationProtocol left, SslApplicationProtocol right)
static readonly SslApplicationProtocol Http11