Clear Content Copy

Copy from Widevine repository of http://go/wvgerrit/13841

This CL adds a nonblocking CopyBuffer to OEMCrypto, its unit tests,
and plumbs it up to the cdm CryptoSession and CdmEngine.

b/19543782

Change-Id: I4c88bd2f8d7f67ecccb549c1934b7c0da15a8429
This commit is contained in:
Fred Gylys-Colwell
2015-03-31 09:15:38 -07:00
parent 582eb32661
commit a7d2f57bfb
7 changed files with 150 additions and 64 deletions

View File

@@ -1928,6 +1928,41 @@ TEST_F(OEMCryptoClientTest, GenerateDerivedKeys) {
s.GenerateDerivedKeys();
}
TEST_F(OEMCryptoClientTest, ClearCopyTest) {
const int kDataSize = 256;
uint8_t input_buffer[kDataSize];
OEMCrypto_GetRandom(input_buffer, sizeof(input_buffer));
uint8_t output_buffer[kDataSize];
OEMCrypto_DestBufferDesc dest_buffer;
dest_buffer.type = OEMCrypto_BufferType_Clear;
dest_buffer.buffer.clear.address = output_buffer;
dest_buffer.buffer.clear.max_length = sizeof(output_buffer);
ASSERT_EQ(OEMCrypto_SUCCESS,
OEMCrypto_CopyBuffer(input_buffer, sizeof(input_buffer),
&dest_buffer, OEMCrypto_FirstSubsample
| OEMCrypto_LastSubsample));
ASSERT_EQ(0, memcmp(input_buffer, output_buffer, sizeof(input_buffer)));
ASSERT_EQ(OEMCrypto_ERROR_INVALID_CONTEXT,
OEMCrypto_CopyBuffer(NULL, sizeof(input_buffer),
&dest_buffer, OEMCrypto_FirstSubsample
| OEMCrypto_LastSubsample));
ASSERT_EQ(OEMCrypto_ERROR_INVALID_CONTEXT,
OEMCrypto_CopyBuffer(input_buffer, sizeof(input_buffer),
NULL, OEMCrypto_FirstSubsample
| OEMCrypto_LastSubsample));
dest_buffer.buffer.clear.address = NULL;
ASSERT_EQ(OEMCrypto_ERROR_INVALID_CONTEXT,
OEMCrypto_CopyBuffer(input_buffer, sizeof(input_buffer),
&dest_buffer, OEMCrypto_FirstSubsample
| OEMCrypto_LastSubsample));
dest_buffer.buffer.clear.address = output_buffer;
dest_buffer.buffer.clear.max_length = sizeof(output_buffer) - 1;
ASSERT_EQ(OEMCrypto_ERROR_SHORT_BUFFER,
OEMCrypto_CopyBuffer(input_buffer, sizeof(input_buffer),
&dest_buffer, OEMCrypto_FirstSubsample
| OEMCrypto_LastSubsample));
}
//
// AddKey Tests
//