This is a cherry pick of recent changes to OEMCrypto and ODK. Most of these are part of the document migration to doxygen. See http://go/wvgerrit/106005 and its parents for code reviews. Bug: 144715340 Bug: 148232693 Bug: 167580674 Change-Id: I658f99c8117b974faed97322d61fac0f382283af
90 lines
2.8 KiB
C
90 lines
2.8 KiB
C
// Copyright 2019 Google LLC. All rights reserved. This file and proprietary
|
|
// source code may only be used and distributed under the Widevine Master
|
|
// License Agreement.
|
|
|
|
#ifndef WIDEVINE_ODK_SRC_SERIALIZATION_BASE_H_
|
|
#define WIDEVINE_ODK_SRC_SERIALIZATION_BASE_H_
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
#include <stddef.h>
|
|
#include <stdint.h>
|
|
|
|
#include "OEMCryptoCENCCommon.h"
|
|
|
|
#define SIZE_OF_MESSAGE_STRUCT 64
|
|
|
|
/*
|
|
* Description:
|
|
* Point |msg| to stack-array |blk|.
|
|
* |blk| is guaranteed large enough to hold a |Message| struct.
|
|
* |blk| cannot be used in the same scope as a variable name.
|
|
* |msg| points to valid memory in the same scope |AllocateMessage| is used.
|
|
* Parameters:
|
|
* msg: pointer to pointer to |Message| struct
|
|
* blk: variable name for stack-array
|
|
*/
|
|
#define AllocateMessage(msg, blk) \
|
|
uint8_t blk[SIZE_OF_MESSAGE_STRUCT]; \
|
|
*(msg) = (Message*)(blk)
|
|
|
|
typedef struct _Message Message;
|
|
|
|
typedef enum {
|
|
MESSAGE_STATUS_OK,
|
|
MESSAGE_STATUS_UNKNOWN_ERROR,
|
|
MESSAGE_STATUS_OVERFLOW_ERROR,
|
|
MESSAGE_STATUS_UNDERFLOW_ERROR,
|
|
MESSAGE_STATUS_PARSE_ERROR,
|
|
MESSAGE_STATUS_NULL_POINTER_ERROR,
|
|
MESSAGE_STATUS_API_VALUE_ERROR
|
|
} MessageStatus;
|
|
|
|
bool ValidMessage(Message* message);
|
|
|
|
void Pack_enum(Message* message, int value);
|
|
void Pack_bool(Message* message, const bool* value);
|
|
void Pack_uint16_t(Message* message, const uint16_t* value);
|
|
void Pack_uint32_t(Message* message, const uint32_t* value);
|
|
void Pack_uint64_t(Message* message, const uint64_t* value);
|
|
void PackArray(Message* message, const uint8_t* base, size_t size);
|
|
void Pack_OEMCrypto_Substring(Message* msg, const OEMCrypto_Substring* obj);
|
|
|
|
int Unpack_enum(Message* message);
|
|
void Unpack_bool(Message* message, bool* value);
|
|
void Unpack_uint16_t(Message* message, uint16_t* value);
|
|
void Unpack_uint32_t(Message* message, uint32_t* value);
|
|
void Unpack_uint64_t(Message* message, uint64_t* value);
|
|
void UnpackArray(Message* message, uint8_t* address,
|
|
size_t size); /* copy out */
|
|
void Unpack_OEMCrypto_Substring(Message* msg, OEMCrypto_Substring* obj);
|
|
|
|
/*
|
|
* Initialize a message structure to reference a separate buffer. The caller
|
|
* is responsible for ensuring that the buffer remains allocated for the
|
|
* lifetime of the message.
|
|
*/
|
|
void InitMessage(Message* message, uint8_t* buffer, size_t capacity);
|
|
|
|
/*
|
|
* Reset an existing the message to an empty state
|
|
*/
|
|
void ResetMessage(Message* message);
|
|
uint8_t* GetBase(Message* message);
|
|
size_t GetCapacity(Message* message);
|
|
size_t GetSize(Message* message);
|
|
void SetSize(Message* message, size_t size);
|
|
MessageStatus GetStatus(Message* message);
|
|
void SetStatus(Message* message, MessageStatus status);
|
|
size_t GetOffset(Message* message);
|
|
|
|
size_t SizeOfMessageStruct();
|
|
|
|
#ifdef __cplusplus
|
|
} // extern "C"
|
|
#endif
|
|
|
|
#endif // WIDEVINE_ODK_SRC_SERIALIZATION_BASE_H_
|