aboutsummaryrefslogtreecommitdiff
path: root/SocketHttpListener/PayloadData.cs
diff options
context:
space:
mode:
authorAndrew Rabert <6550543+nvllsvm@users.noreply.github.com>2019-01-22 18:13:47 -0500
committerGitHub <noreply@github.com>2019-01-22 18:13:47 -0500
commit28483bdb54be96ae83e0fded097f534d7e26ba1e (patch)
treee7f4b92326417ebf55eecdf68a01d2c3b9e660d7 /SocketHttpListener/PayloadData.cs
parent920c39454c05e979eabe81877269cd4517a03ccf (diff)
parent8106c8393b711a7e1d40487e3caf2b014decbe28 (diff)
Merge pull request #651 from jellyfin/release-10.1.0
Release 10.1.0
Diffstat (limited to 'SocketHttpListener/PayloadData.cs')
-rw-r--r--SocketHttpListener/PayloadData.cs191
1 files changed, 86 insertions, 105 deletions
diff --git a/SocketHttpListener/PayloadData.cs b/SocketHttpListener/PayloadData.cs
index a6318da2b..6d15a6bcb 100644
--- a/SocketHttpListener/PayloadData.cs
+++ b/SocketHttpListener/PayloadData.cs
@@ -5,145 +5,126 @@ using System.Text;
namespace SocketHttpListener
{
- internal class PayloadData : IEnumerable<byte>
- {
- #region Private Fields
+ internal class PayloadData : IEnumerable<byte>
+ {
+ #region Private Fields
- private byte [] _applicationData;
- private byte [] _extensionData;
- private bool _masked;
+ private byte[] _applicationData;
+ private byte[] _extensionData;
+ private bool _masked;
- #endregion
+ #endregion
- #region Public Const Fields
+ #region Public Const Fields
- public const ulong MaxLength = long.MaxValue;
+ public const ulong MaxLength = long.MaxValue;
- #endregion
+ #endregion
- #region Public Constructors
+ #region Public Constructors
- public PayloadData ()
- : this (new byte [0], new byte [0], false)
- {
- }
+ public PayloadData()
+ : this(new byte[0], new byte[0], false)
+ {
+ }
- public PayloadData (byte [] applicationData)
- : this (new byte [0], applicationData, false)
- {
- }
+ public PayloadData(byte[] applicationData)
+ : this(new byte[0], applicationData, false)
+ {
+ }
- public PayloadData (string applicationData)
- : this (new byte [0], Encoding.UTF8.GetBytes (applicationData), false)
- {
- }
+ public PayloadData(string applicationData)
+ : this(new byte[0], Encoding.UTF8.GetBytes(applicationData), false)
+ {
+ }
- public PayloadData (byte [] applicationData, bool masked)
- : this (new byte [0], applicationData, masked)
- {
- }
+ public PayloadData(byte[] applicationData, bool masked)
+ : this(new byte[0], applicationData, masked)
+ {
+ }
- public PayloadData (byte [] extensionData, byte [] applicationData, bool masked)
- {
- _extensionData = extensionData;
- _applicationData = applicationData;
- _masked = masked;
- }
+ public PayloadData(byte[] extensionData, byte[] applicationData, bool masked)
+ {
+ _extensionData = extensionData;
+ _applicationData = applicationData;
+ _masked = masked;
+ }
- #endregion
+ #endregion
- #region Internal Properties
+ #region Internal Properties
- internal bool ContainsReservedCloseStatusCode {
- get {
- return _applicationData.Length > 1 &&
- _applicationData.SubArray (0, 2).ToUInt16 (ByteOrder.Big).IsReserved ();
- }
- }
+ internal bool ContainsReservedCloseStatusCode =>
+ _applicationData.Length > 1 &&
+ _applicationData.SubArray(0, 2).ToUInt16(ByteOrder.Big).IsReserved();
- #endregion
+ #endregion
- #region Public Properties
+ #region Public Properties
- public byte [] ApplicationData {
- get {
- return _applicationData;
- }
- }
+ public byte[] ApplicationData => _applicationData;
- public byte [] ExtensionData {
- get {
- return _extensionData;
- }
- }
+ public byte[] ExtensionData => _extensionData;
- public bool IsMasked {
- get {
- return _masked;
- }
- }
+ public bool IsMasked => _masked;
- public ulong Length {
- get {
- return (ulong) (_extensionData.Length + _applicationData.Length);
- }
- }
+ public ulong Length => (ulong)(_extensionData.Length + _applicationData.Length);
- #endregion
+ #endregion
- #region Private Methods
+ #region Private Methods
- private static void mask (byte [] src, byte [] key)
- {
- for (long i = 0; i < src.Length; i++)
- src [i] = (byte) (src [i] ^ key [i % 4]);
- }
+ private static void mask(byte[] src, byte[] key)
+ {
+ for (long i = 0; i < src.Length; i++)
+ src[i] = (byte)(src[i] ^ key[i % 4]);
+ }
- #endregion
+ #endregion
- #region Public Methods
+ #region Public Methods
- public IEnumerator<byte> GetEnumerator ()
- {
- foreach (byte b in _extensionData)
- yield return b;
+ public IEnumerator<byte> GetEnumerator()
+ {
+ foreach (byte b in _extensionData)
+ yield return b;
- foreach (byte b in _applicationData)
- yield return b;
- }
+ foreach (byte b in _applicationData)
+ yield return b;
+ }
- public void Mask (byte [] maskingKey)
- {
- if (_extensionData.Length > 0)
- mask (_extensionData, maskingKey);
+ public void Mask(byte[] maskingKey)
+ {
+ if (_extensionData.Length > 0)
+ mask(_extensionData, maskingKey);
- if (_applicationData.Length > 0)
- mask (_applicationData, maskingKey);
+ if (_applicationData.Length > 0)
+ mask(_applicationData, maskingKey);
- _masked = !_masked;
- }
+ _masked = !_masked;
+ }
- public byte [] ToByteArray ()
- {
- return _extensionData.Length > 0
- ? new List<byte> (this).ToArray ()
- : _applicationData;
- }
+ public byte[] ToByteArray()
+ {
+ return _extensionData.Length > 0
+ ? new List<byte>(this).ToArray()
+ : _applicationData;
+ }
- public override string ToString ()
- {
- return BitConverter.ToString (ToByteArray ());
- }
+ public override string ToString()
+ {
+ return BitConverter.ToString(ToByteArray());
+ }
- #endregion
+ #endregion
- #region Explicitly Implemented Interface Members
+ #region Explicitly Implemented Interface Members
- IEnumerator IEnumerable.GetEnumerator ()
- {
- return GetEnumerator ();
- }
+ IEnumerator IEnumerable.GetEnumerator()
+ {
+ return GetEnumerator();
+ }
- #endregion
- }
+ #endregion
+ }
}