the only reason i'm committing this is because i have to leave

ere
This commit is contained in:
Malloc of Kuzkycyziklistan 2017-04-29 08:06:20 -05:00
parent a4ae814932
commit bb8c0647ff

View file

@ -18,21 +18,42 @@ namespace Kneesocks {
public kOpcode Opcode { get; set; } public kOpcode Opcode { get; set; }
public bool IsFinal { get; set; } public bool IsFinal { get; set; }
public bool IsMasked { get; set; } public bool IsMasked { get; set; }
public byte[] Mask { get; set; } public byte[] Mask { get; set; } = new byte[] { 0, 0, 0, 0 };
public byte Reserved { get; set; } public byte Reserved { get; set; }
public byte[] Content { get; set; } public byte[] Content { get; set; }
public byte[] MaskedContent { public byte[] MaskedContent {
get { get {
byte[] ret = new byte[Content.Length]; byte[] returnValue = new byte[Content.Length];
for(var i = 0; i < Content.Length; ++i) for(var i = 0; i < Content.Length; ++i)
ret[i] = (byte)(Content[i] ^ Mask[i % 4]); returnValue[i] = (byte)(Content[i] ^ Mask[i % 4]);
return ret; return returnValue;
} }
} }
public static FromRaw(byte[] raw) { public static Frame FromRaw(byte[] raw) {
if(raw.Length < ) if(raw.Length < 2)
throw new FormatException("Websocket frame cannot be less than two bytes long");
var rawOpcode = raw[0] & 0x0F;
if(!Enum.IsDefined(typeof(kOpcode), rawOpcode))
throw new FormatException("Opcode '"+ rawOpcode.ToString("0x{0:X}") +"' not understood");
var returnFrame = new Frame {
IsFinal = (raw[0] & 0x80) != 0,
Opcode = (kOpcode)rawOpcode,
IsMasked = (raw[1] & 0x80) != 0,
Reserved = (byte)((raw[0] & 0x70) >> 4)
};
UInt64 frameLength = raw[1] & 0x7Ful;
int lengthOffset =
frameLength < 126
? 1
: (frameLength == 126 ? 3 : 9);
if()
return returnFrame;
} }
} }
} }