int SrsHandshakeBytes::create_s0s1s2(const char* c1) { int ret = ERROR_SUCCESS; if (s0s1s2) { return ret; } s0s1s2 = new char[3073]; srs_random_generate(s0s1s2, 3073); // plain text required. SrsStream stream; if ((ret = stream.initialize(s0s1s2, 9)) != ERROR_SUCCESS) { return ret; } stream.write_1bytes(0x03); stream.write_4bytes(::time(NULL)); // s2 time2 copy from c1 if (c0c1) { stream.write_bytes(c0c1 + 1, 4); } // if c1 specified, copy c1 to s2. // @see: https://github.com/winlinvip/simple-rtmp-server/issues/46 if (c1) { memcpy(s0s1s2 + 1537, c1, 1536); } return ret; }
/** * test the stream utility, write 1bytes */ VOID TEST(KernelStreamTest, StreamWrite1Bytes) { SrsStream s; char data[1024]; EXPECT_TRUE(ERROR_SUCCESS == s.initialize(data, 1024)); s.write_1bytes(0x10); s.write_1bytes(0x11); s.write_1bytes(0x12); s.write_1bytes(0x13); s.skip(-1 * s.pos()); EXPECT_EQ(0x10, s.read_1bytes()); s.skip(2); EXPECT_EQ(0x13, s.read_1bytes()); }
int SrsHandshakeBytes::create_c0c1() { int ret = ERROR_SUCCESS; if (c0c1) { return ret; } c0c1 = new char[1537]; srs_random_generate(c0c1, 1537); // plain text required. static SrsStream stream; if ((ret = stream.initialize(c0c1, 9)) != ERROR_SUCCESS) { return ret; } stream.write_1bytes(0x03); stream.write_4bytes(::time(NULL)); stream.write_4bytes(0x00); return ret; }