internal void Unmask() { if (this._mask != WebSocketSharp.Mask.Off) { this._mask = WebSocketSharp.Mask.Off; this._payloadData.Mask(this._maskingKey); this._maskingKey = WebSocket.EmptyBytes; } }
private static WebSocketFrame processHeader(byte[] header) { string str; if ((int)header.Length != 2) { throw new WebSocketException("The header of a frame cannot be read from the stream."); } WebSocketSharp.Fin fin = ((header[0] & 128) == 128 ? WebSocketSharp.Fin.Final : WebSocketSharp.Fin.More); Rsv rsv = ((header[0] & 64) == 64 ? Rsv.On : Rsv.Off); Rsv rsv1 = ((header[0] & 32) == 32 ? Rsv.On : Rsv.Off); Rsv rsv2 = ((header[0] & 16) == 16 ? Rsv.On : Rsv.Off); byte num = (byte)(header[0] & 15); WebSocketSharp.Mask mask = ((header[1] & 128) == 128 ? WebSocketSharp.Mask.On : WebSocketSharp.Mask.Off); byte num1 = (byte)(header[1] & 127); if (!num.IsSupported()) { str = "An unsupported opcode."; } else if (!num.IsData() && rsv == Rsv.On) { str = "A non data frame is compressed."; } else if (num.IsControl() && fin == WebSocketSharp.Fin.More) { str = "A control frame is fragmented."; } else if (!num.IsControl() || num1 <= 125) { str = null; } else { str = "A control frame has a long payload length."; } string str1 = str; if (str1 != null) { throw new WebSocketException(CloseStatusCode.ProtocolError, str1); } WebSocketFrame webSocketFrames = new WebSocketFrame() { _fin = fin, _rsv1 = rsv, _rsv2 = rsv1, _rsv3 = rsv2, _opcode = (WebSocketSharp.Opcode)num, _mask = mask, _payloadLength = num1 }; return(webSocketFrames); }
internal WebSocketFrame(WebSocketSharp.Fin fin, WebSocketSharp.Opcode opcode, WebSocketSharp.PayloadData payloadData, bool compressed, bool mask) { this._fin = fin; this._rsv1 = (opcode.IsData() & compressed ? Rsv.On : Rsv.Off); this._rsv2 = Rsv.Off; this._rsv3 = Rsv.Off; this._opcode = opcode; ulong length = payloadData.Length; if (length < (long)126) { this._payloadLength = (byte)length; this._extPayloadLength = WebSocket.EmptyBytes; } else if (length >= (long)65536) { this._payloadLength = 127; this._extPayloadLength = length.InternalToByteArray(ByteOrder.Big); } else { this._payloadLength = 126; this._extPayloadLength = ((ushort)length).InternalToByteArray(ByteOrder.Big); } if (!mask) { this._mask = WebSocketSharp.Mask.Off; this._maskingKey = WebSocket.EmptyBytes; } else { this._mask = WebSocketSharp.Mask.On; this._maskingKey = WebSocketFrame.createMaskingKey(); payloadData.Mask(this._maskingKey); } this._payloadData = payloadData; }
internal WebSocketFrame(WebSocketSharp.Fin fin, WebSocketSharp.Opcode opcode, WebSocketSharp.PayloadData payloadData, bool compressed, bool mask) { this._fin = fin; this._rsv1 = (!opcode.IsData() || !compressed) ? Rsv.Off : Rsv.On; this._rsv2 = Rsv.Off; this._rsv3 = Rsv.Off; this._opcode = opcode; ulong length = payloadData.Length; if (length < 0x7e) { this._payloadLength = (byte)length; this._extPayloadLength = WebSocket.EmptyBytes; } else if (length < 0x10000L) { this._payloadLength = 0x7e; this._extPayloadLength = ((ushort)length).InternalToByteArray(ByteOrder.Big); } else { this._payloadLength = 0x7f; this._extPayloadLength = length.InternalToByteArray(ByteOrder.Big); } if (!mask) { this._mask = WebSocketSharp.Mask.Off; this._maskingKey = WebSocket.EmptyBytes; } else { this._mask = WebSocketSharp.Mask.On; this._maskingKey = createMaskingKey(); payloadData.Mask(this._maskingKey); } this._payloadData = payloadData; }