Exemple #1
0
        void receive_status_message(Channel channel, EncKeys keys, string expected_extra_data)
        {
            Json       json      = new Json();
            PicoBuffer buf       = new PicoBuffer(0);
            PicoBuffer iv        = new PicoBuffer(0);
            PicoBuffer cleartext = new PicoBuffer(0);

            channel.read(buf);
            json.deserialize(buf);
            Assert.AreEqual(json.get_decimal("sessionId"), 0);
            Base64.decode(json.get_string("iv"), iv);
            buf.clear();
            Base64.decode(json.get_string("encryptedData"), buf);
            CryptoSupport.decrypt(keys.vEncKey, iv, buf, cleartext);

            PicoBuffer receivedExtraData = new PicoBuffer(0);

            byte[] status = new byte[2];
            cleartext.copy_to_array(status, 2);
            Assert.AreEqual(status[0], 0x00);
            cleartext.copy_lengthprepend(1, receivedExtraData);

            receivedExtraData.append(new byte[] { 0x00 });
            Assert.AreEqual(receivedExtraData.to_string(), expected_extra_data);

            json.delete();
            buf.delete();
            cleartext.delete();
            iv.delete();
            receivedExtraData.delete();
        }
Exemple #2
0
        void echo_main(string channel_name)
        {
            Channel    channel = Channel.connect(channel_name);
            PicoBuffer buf     = new PicoBuffer(0);
            PicoBuffer toSend  = new PicoBuffer(0);

            channel.read(buf);
            toSend.append_lengthprepend(buf);
            byte[] bytesToSend = new byte[toSend.get_pos() + 1];
            toSend.copy_to_array(bytesToSend);
            channel.write(bytesToSend, bytesToSend.Length);

            buf.delete();
            toSend.delete();
            channel.delete();
        }
Exemple #3
0
        public void length_prepend()
        {
            PicoBuffer b;
            PicoBuffer b2;

            b  = new PicoBuffer(3);
            b2 = new PicoBuffer(3);
            b2.append("67890");
            Assert.AreEqual(b2.get_pos(), 5);
            Assert.AreEqual(b2.get_size() % 3, 0);

            b.append_lengthprepend(b2);

            byte[] expected = new byte[] { 0x00, 0x00, 0x00, 0x05, Convert.ToByte('6'), Convert.ToByte('7'), Convert.ToByte('8'), Convert.ToByte('9'), Convert.ToByte('0'), 0x00 };
            byte[] ret      = new byte[10];
            b.copy_to_array(ret, 10);
            CollectionAssert.AreEqual(ret, expected);

            b.delete();
            b2.delete();
        }