Beispiel #1
0
        public static SignatureMessage FromSignatureMessageBlock(ArraySegment <byte> message, IExchangeDecrypt privateKey)
        {
            if (message.Array == null)
            {
                throw new ArgumentNullException("message.Array");
            }
            if (privateKey == null)
            {
                throw new ArgumentNullException("privateKey");
            }

            try
            {
                using (Stream typeStream = new MemoryStream(message.Array, message.Offset, message.Count))
                    using (Stream cryptoStream = ContentConverter.RemoveType(typeStream, "SignatureMessage"))
                        using (Stream hashStream = ContentConverter.Decrypt(cryptoStream, privateKey))
                            using (Stream paddingStream = ContentConverter.RemoveHash(hashStream))
                                using (Stream compressStream = ContentConverter.RemovePadding(paddingStream))
                                    using (Stream messageStream = ContentConverter.Decompress(compressStream))
                                    {
                                        return(SignatureMessage.Import(messageStream, _bufferManager));
                                    }
            }
            catch (Exception)
            {
                return(null);
            }
        }
Beispiel #2
0
        public static ChatMessage FromChatMessageBlock(ArraySegment <byte> message)
        {
            if (message.Array == null)
            {
                throw new ArgumentNullException("message.Array");
            }

            try
            {
                using (Stream typeStream = new MemoryStream(message.Array, message.Offset, message.Count))
                    using (Stream compressStream = ContentConverter.RemoveType(typeStream, "ChatMessage"))
                        using (Stream messageStream = ContentConverter.Decompress(compressStream))
                        {
                            return(ChatMessage.Import(messageStream, _bufferManager));
                        }
            }
            catch (Exception)
            {
                return(null);
            }
        }