// parse key block from c1s1. // if created, user must free it by srs_key_block_free // @c1s1_key_bytes the key start bytes, maybe c1s1 or c1s1+764 int srs_key_block_parse(key_block* key, char* c1s1_key_bytes) { int ret = ERROR_SUCCESS; char* pp = c1s1_key_bytes + 764; pp -= sizeof(int32_t); key->offset = __srs_stream_read_4bytes(pp); key->random0 = NULL; key->random1 = NULL; int offset = srs_key_block_get_offset(key); srs_assert(offset >= 0); pp = c1s1_key_bytes; key->random0_size = offset; if (key->random0_size > 0) { key->random0 = new char[key->random0_size]; memcpy(key->random0, pp, key->random0_size); } pp += key->random0_size; memcpy(key->key, pp, sizeof(key->key)); pp += sizeof(key->key); key->random1_size = 764 - offset - 128 - 4; if (key->random1_size > 0) { key->random1 = new char[key->random1_size]; memcpy(key->random1, pp, key->random1_size); } return ret; }
// create new key block data. // if created, user must free it by srs_key_block_free void srs_key_block_init(key_block* key) { key->offset = (int32_t)rand(); key->random0 = NULL; key->random1 = NULL; int offset = srs_key_block_get_offset(key); srs_assert(offset >= 0); key->random0_size = offset; if (key->random0_size > 0) { key->random0 = new char[key->random0_size]; srs_random_generate(key->random0, key->random0_size); snprintf(key->random0, key->random0_size, "%s", RTMP_SIG_SRS_HANDSHAKE); } srs_random_generate(key->key, sizeof(key->key)); key->random1_size = 764 - offset - 128 - 4; if (key->random1_size > 0) { key->random1 = new char[key->random1_size]; srs_random_generate(key->random1, key->random1_size); snprintf(key->random1, key->random1_size, "%s", RTMP_SIG_SRS_HANDSHAKE); } }
// create new key block data. // if created, user must free it by srs_key_block_free void srs_key_block_init(key_block *key) { key->offset = (int32_t)rand(); key->random0 = NULL; key->random1 = NULL; int offset = srs_key_block_get_offset(key); mAssert(offset >= 0); key->random0_size = offset; if (key->random0_size > 0) { key->random0 = new char[key->random0_size]; srs_random_generate(key->random0, key->random0_size); } srs_random_generate(key->key, sizeof(key->key)); key->random1_size = 764 - offset - 128 - 4; if (key->random1_size > 0) { key->random1 = new char[key->random1_size]; srs_random_generate(key->random1, key->random1_size); } }