public OTRMessage ExtractMessage(byte[] in_message_byte_array) { int _next_index = 0; _otr_message = null; _temp_buffer = null; _message_type = OTR_MESSAGE_TYPE.INVALID; //get protocol version _next_index = Utility.DecodeShortFromBytes(in_message_byte_array, _next_index, ref _temp_buffer_2); OTR_VERSION _otr_version = Utility.GetOTRVersion(_temp_buffer_2); if (_otr_version == OTR_VERSION.INVALID) throw new ArgumentException("ExtractMessage:OTR version is invalid"); _otr_message = new OTRMessage(); _otr_message.SetProtocolVersion(_otr_version); // get message type _temp_buffer_2 = _temp_buffer = null; _next_index = Utility.DecodeByteFromBytes(in_message_byte_array, _next_index, ref _temp_buffer_2); _message_type = GetMessageType(_temp_buffer_2[0]); if (_message_type == OTR_MESSAGE_TYPE.INVALID) throw new ArgumentException("ExtractMessage:OTR message type is invalid"); _otr_message.SetMessageType(_message_type); //get instance tags if (_otr_version != OTR_VERSION.VERSION_2) { _temp_buffer_2 = _temp_buffer = null; _next_index = Utility.DecodeIntFromBytes(in_message_byte_array, _next_index, ref _temp_buffer_2); _otr_message.SetSenderInstanceTag(_temp_buffer_2); if (_otr_message.GetSenderInstanceTag() < 4) throw new ArgumentException("ExtractMessage:The Sender's instance tag cannot be less than 4"); if (_buddy_instance_tag == 0) _buddy_instance_tag = _otr_message.GetSenderInstanceTag(); if (_buddy_instance_tag != 0 && _otr_message.GetSenderInstanceTag() != _buddy_instance_tag) throw new ArgumentException("ExtractMessage:The Sender's instance tag is invalid"); _temp_buffer_2 = _temp_buffer = null; _next_index = Utility.DecodeIntFromBytes(in_message_byte_array, _next_index, ref _temp_buffer_2); _otr_message.SetReceiverInstanceTag(_temp_buffer_2); } if (_message_type == OTR_MESSAGE_TYPE.DATA) return ExtractData(in_message_byte_array, _next_index); else if (_message_type == OTR_MESSAGE_TYPE.DH_COMMIT) return ExtractDHCommit(in_message_byte_array, _next_index); else if (_message_type == OTR_MESSAGE_TYPE.DH_KEY) return ExtractDHKey(in_message_byte_array, _next_index); else if (_message_type == OTR_MESSAGE_TYPE.REVEAL_SIGNATURE) return ExtractRevealSig(in_message_byte_array, _next_index); else if (_message_type == OTR_MESSAGE_TYPE.SIGNATURE) return ExtractSignature(in_message_byte_array, _next_index); return null; }