Files
android/libwvdrmengine/oemcrypto/test/fuzz_tests/oemcrypto_opk_dispatcher_fuzz.cc
Ian Benz 53fe55cb72 Clean up fuzz helper classes
- Remove OEMCrypto state changes hidden in constructors and destructors.
- Use composition instead of inheritance to structure classes.
- Avoid calling non-trivial destructors for objects with static
  lifetime.

Merged from https://widevine-internal-review.googlesource.com/168497
Merged from https://widevine-internal-review.googlesource.com/171170
Merged from https://widevine-internal-review.googlesource.com/171171
Merged from https://widevine-internal-review.googlesource.com/171870

Change-Id: I20476a7b1132d11f011b8650ec01e3c2dc3fc0e8
2024-01-26 13:40:22 -08:00

56 lines
1.9 KiB
C++

#include <vector>
#include "opk_dispatcher.h"
#include "opk_init.h"
namespace {
void OpenOEMCryptoTASession() {
uint8_t request_body[] = {
0x06, // TAG_UINT32
0x09, 0x00, 0x00, 0x00, // API value (0x09)
0x07, // TAG_UINT64
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Timestamp
0x01, // TAG_BOOL
0x00, // value (false)
0x0a // TAG_EOM
};
ODK_Message request = ODK_Message_Create(request_body, sizeof(request_body));
ODK_Message_SetSize(&request, sizeof(request_body));
ODK_Message response;
OPK_DispatchMessage(&request, &response);
}
void InitializeOEMCryptoTA() {
uint8_t request_body[] = {
0x06, // TAG_UINT32
0x01, 0x00, 0x00, 0x00, // API value (0x01)
0x07, // TAG_UINT64
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Timestamp
0x0a // TAG_EOM
};
ODK_Message request = ODK_Message_Create(request_body, sizeof(request_body));
ODK_Message_SetSize(&request, sizeof(request_body));
ODK_Message response;
OPK_DispatchMessage(&request, &response);
}
} // namespace
extern "C" int LLVMFuzzerInitialize(int* argc, char*** argv) {
OPK_Initialize();
InitializeOEMCryptoTA();
OpenOEMCryptoTASession();
return 0;
}
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
std::vector<uint8_t> request_body(data, data + size);
ODK_Message request =
ODK_Message_Create(request_body.data(), request_body.size());
ODK_Message_SetSize(&request, request_body.size());
ODK_Message response;
OPK_DispatchMessage(&request, &response);
return 0;
}