示例#1
0
        public void EncodeToBytes()
        {
            var request = new CreatePermissionRequest(
                new IPEndPoint(IPAddress.Parse("54.65.63.212"), 37005)
                )
            {
                TransactionId = new byte[]
                {
                    0xf8, 0x57, 0xe3, 0x50, 0x4c, 0x8f, 0xd3, 0x9d, 0xb8, 0xca,
                    0x69, 0x83,
                }
            };
            var ctx = new TestStunContext()
            {
                Username = "******",
                Password = "******",
                Realm    = "twilio.com",
                Nonce    = new byte[]
                {
                    0x64, 0x32, 0x34, 0x35, 0x39, 0x35, 0x35, 0x39, 0x61, 0x33,
                    0x38, 0x37, 0x34, 0x63, 0x39, 0x61,
                },
            };

            Assert.Equal(
                new byte[]
            {
                0x00, 0x08, 0x00, 0x94, 0x21, 0x12, 0xa4, 0x42, 0xf8, 0x57,
                0xe3, 0x50, 0x4c, 0x8f, 0xd3, 0x9d, 0xb8, 0xca, 0x69, 0x83,
                0x00, 0x12, 0x00, 0x08, 0x00, 0x01, 0xb1, 0x9f, 0x17, 0x53,
                0x9b, 0x96, 0x00, 0x06, 0x00, 0x40, 0x61, 0x65, 0x30, 0x36,
                0x33, 0x33, 0x63, 0x64, 0x35, 0x38, 0x62, 0x61, 0x30, 0x39,
                0x37, 0x61, 0x31, 0x31, 0x36, 0x37, 0x63, 0x36, 0x64, 0x32,
                0x63, 0x63, 0x34, 0x65, 0x32, 0x33, 0x36, 0x64, 0x62, 0x35,
                0x32, 0x32, 0x35, 0x36, 0x61, 0x34, 0x30, 0x64, 0x35, 0x36,
                0x35, 0x66, 0x31, 0x31, 0x65, 0x64, 0x66, 0x37, 0x36, 0x63,
                0x30, 0x32, 0x64, 0x31, 0x33, 0x64, 0x62, 0x39, 0x33, 0x63,
                0x00, 0x15, 0x00, 0x10, 0x64, 0x32, 0x34, 0x35, 0x39, 0x35,
                0x35, 0x39, 0x61, 0x33, 0x38, 0x37, 0x34, 0x63, 0x39, 0x61,
                0x00, 0x14, 0x00, 0x0a, 0x74, 0x77, 0x69, 0x6c, 0x69, 0x6f,
                0x2e, 0x63, 0x6f, 0x6d, 0x00, 0x00, 0x00, 0x08, 0x00, 0x14,
                0xe9, 0x4a, 0x95, 0x2a, 0x53, 0xb0, 0xdc, 0x8c, 0x3a, 0x42,
                0xd7, 0xfd, 0x21, 0xeb, 0x0c, 0xd4, 0x2f, 0x6c, 0x8d, 0x40,
                0x80, 0x28, 0x00, 0x04, 0x31, 0x5b, 0x2f, 0x0e,
            },
                request.Encode(ctx));
        }
示例#2
0
        public void EncodeToBytesWithCredential()
        {
            var request = new AllocateRequest(777)
            {
                TransactionId = new byte[]
                {
                    0xf5, 0xdb, 0xe7, 0xc1, 0x2a, 0x74, 0xbe, 0xf9, 0x8b, 0x16,
                    0x56, 0x3e,
                }
            };
            var ctx = new TestStunContext()
            {
                Username = "******",
                Password = "******",
                Realm    = "twilio.com",
                Nonce    = new byte[]
                {
                    0x37, 0x35, 0x64, 0x34, 0x35, 0x34, 0x31, 0x39, 0x63, 0x33,
                    0x39, 0x33, 0x34, 0x33, 0x66, 0x65,
                },
            };

            Assert.Equal(
                new byte[]
            {
                0x00, 0x03, 0x00, 0x98, 0x21, 0x12, 0xa4, 0x42, 0xf5, 0xdb,
                0xe7, 0xc1, 0x2a, 0x74, 0xbe, 0xf9, 0x8b, 0x16, 0x56, 0x3e,
                0x00, 0x19, 0x00, 0x04, 0x06, 0x00, 0x00, 0x00, 0x00, 0x0d,
                0x00, 0x04, 0x00, 0x00, 0x03, 0x09, 0x00, 0x06, 0x00, 0x40,
                0x61, 0x65, 0x30, 0x36, 0x33, 0x33, 0x63, 0x64, 0x35, 0x38,
                0x62, 0x61, 0x30, 0x39, 0x37, 0x61, 0x31, 0x31, 0x36, 0x37,
                0x63, 0x36, 0x64, 0x32, 0x63, 0x63, 0x34, 0x65, 0x32, 0x33,
                0x36, 0x64, 0x62, 0x35, 0x32, 0x32, 0x35, 0x36, 0x61, 0x34,
                0x30, 0x64, 0x35, 0x36, 0x35, 0x66, 0x31, 0x31, 0x65, 0x64,
                0x66, 0x37, 0x36, 0x63, 0x30, 0x32, 0x64, 0x31, 0x33, 0x64,
                0x62, 0x39, 0x33, 0x63, 0x00, 0x15, 0x00, 0x10, 0x37, 0x35,
                0x64, 0x34, 0x35, 0x34, 0x31, 0x39, 0x63, 0x33, 0x39, 0x33,
                0x34, 0x33, 0x66, 0x65, 0x00, 0x14, 0x00, 0x0a, 0x74, 0x77,
                0x69, 0x6c, 0x69, 0x6f, 0x2e, 0x63, 0x6f, 0x6d, 0x00, 0x00,
                0x00, 0x08, 0x00, 0x14, 0x77, 0xe8, 0xcf, 0x30, 0x9e, 0x85,
                0x6c, 0x22, 0x72, 0x53, 0xa3, 0xb7, 0xe0, 0x35, 0x7c, 0xc2,
                0x30, 0xfc, 0xbc, 0xf4, 0x80, 0x28, 0x00, 0x04, 0x98, 0x46,
                0x9c, 0x07,
            },
                request.Encode(ctx));
        }
        public void EncodeToBytes()
        {
            var connectionId = new byte[] { 0x1e, 0xe2, 0x38, 0x02 };
            var request      = new ConnectionBindRequest(connectionId)
            {
                TransactionId = new byte[]
                {
                    0x3d, 0x29, 0x0c, 0x81, 0x83, 0x69, 0xa5, 0x48, 0x36, 0xfa,
                    0x52, 0x6c,
                }
            };
            var ctx = new TestStunContext()
            {
                Username = "******",
                Password = "******",
                Realm    = "twilio.com",
                Nonce    = new byte[]
                {
                    0x64, 0x32, 0x34, 0x35, 0x39, 0x35, 0x35, 0x39, 0x61, 0x33,
                    0x38, 0x37, 0x34, 0x63, 0x39, 0x61,
                },
            };

            Assert.Equal(
                new byte[]
            {
                0x00, 0x0b, 0x00, 0x90, 0x21, 0x12, 0xa4, 0x42, 0x3d, 0x29,
                0x0c, 0x81, 0x83, 0x69, 0xa5, 0x48, 0x36, 0xfa, 0x52, 0x6c,
                0x00, 0x2a, 0x00, 0x04, 0x1e, 0xe2, 0x38, 0x02, 0x00, 0x06,
                0x00, 0x40, 0x61, 0x65, 0x30, 0x36, 0x33, 0x33, 0x63, 0x64,
                0x35, 0x38, 0x62, 0x61, 0x30, 0x39, 0x37, 0x61, 0x31, 0x31,
                0x36, 0x37, 0x63, 0x36, 0x64, 0x32, 0x63, 0x63, 0x34, 0x65,
                0x32, 0x33, 0x36, 0x64, 0x62, 0x35, 0x32, 0x32, 0x35, 0x36,
                0x61, 0x34, 0x30, 0x64, 0x35, 0x36, 0x35, 0x66, 0x31, 0x31,
                0x65, 0x64, 0x66, 0x37, 0x36, 0x63, 0x30, 0x32, 0x64, 0x31,
                0x33, 0x64, 0x62, 0x39, 0x33, 0x63, 0x00, 0x15, 0x00, 0x10,
                0x64, 0x32, 0x34, 0x35, 0x39, 0x35, 0x35, 0x39, 0x61, 0x33,
                0x38, 0x37, 0x34, 0x63, 0x39, 0x61, 0x00, 0x14, 0x00, 0x0a,
                0x74, 0x77, 0x69, 0x6c, 0x69, 0x6f, 0x2e, 0x63, 0x6f, 0x6d,
                0x00, 0x00, 0x00, 0x08, 0x00, 0x14, 0x5e, 0xc8, 0x5b, 0xaa,
                0x0c, 0x7e, 0x44, 0x0d, 0xca, 0x22, 0xa6, 0xaa, 0x3a, 0xf7,
                0x0f, 0x4b, 0x5f, 0xe3, 0x09, 0x63, 0x80, 0x28, 0x00, 0x04,
                0x22, 0x0e, 0x0e, 0x02,
            },
                request.Encode(ctx));
        }