Initial v17 Release
Headers and Unit tests have been updated to match the v17 spec. Documentation can be found here: https://developers.devsite.corp.google.com/widevine/drm/client/oemcrypto/v17
This commit is contained in:
@@ -10,7 +10,7 @@
|
||||
|
||||
#include "string_conversions.h"
|
||||
|
||||
namespace wvcdm {
|
||||
namespace wvutil {
|
||||
|
||||
// Advance an IV according to ISO-CENC's CTR modes. The lower half of the IV is
|
||||
// split off and treated as an unsigned 64-bit integer, then incremented by the
|
||||
@@ -41,6 +41,6 @@ inline void AdvanceIvCtr(uint8_t (*subsample_iv)[16], size_t bytes) {
|
||||
memcpy(&(*subsample_iv)[kCounterIndex], &counter, kCounterSize);
|
||||
}
|
||||
|
||||
} // namespace wvcdm
|
||||
} // namespace wvutil
|
||||
|
||||
#endif // WVCDM_UTIL_ADVANCE_IV_CTR_H_
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
namespace wvcdm {
|
||||
namespace wvutil {
|
||||
|
||||
// Returns the size of a fixed-length array.
|
||||
template <typename T, size_t N>
|
||||
@@ -15,6 +15,6 @@ constexpr size_t ArraySize(const T (&)[N]) {
|
||||
return N;
|
||||
}
|
||||
|
||||
} // namespace wvcdm
|
||||
} // namespace wvutil
|
||||
|
||||
#endif // WVCDM_UTIL_ARRAYSIZE_H_
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#include <random>
|
||||
#include <string>
|
||||
|
||||
namespace wvcdm {
|
||||
namespace wvutil {
|
||||
|
||||
// CdmRandomGenerator is a thread safe, pseudo-random number generator.
|
||||
// It's purpose is to simplified interface for C++11's <random> library.
|
||||
@@ -112,6 +112,6 @@ class CdmRandom {
|
||||
static CdmRandomGenerator* GetInstance();
|
||||
};
|
||||
|
||||
} // namespace wvcdm
|
||||
} // namespace wvutil
|
||||
|
||||
#endif // WVCDM_CORE_CDM_RANDOM_H_
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
namespace wvcdm {
|
||||
namespace wvutil {
|
||||
|
||||
// Provides time related information. The implementation is platform dependent.
|
||||
class Clock {
|
||||
@@ -21,6 +21,6 @@ class Clock {
|
||||
virtual int64_t GetCurrentTime();
|
||||
};
|
||||
|
||||
} // namespace wvcdm
|
||||
} // namespace wvutil
|
||||
|
||||
#endif // WVCDM_UTIL_CLOCK_H_
|
||||
|
||||
@@ -5,12 +5,12 @@
|
||||
#ifndef WVCDM_UTIL_DISALLOW_COPY_AND_ASSIGN_H_
|
||||
#define WVCDM_UTIL_DISALLOW_COPY_AND_ASSIGN_H_
|
||||
|
||||
namespace wvcdm {
|
||||
namespace wvutil {
|
||||
|
||||
#define CORE_DISALLOW_COPY_AND_ASSIGN(TypeName) \
|
||||
TypeName(const TypeName&); \
|
||||
void operator=(const TypeName&)
|
||||
|
||||
} // namespace wvcdm
|
||||
} // namespace wvutil
|
||||
|
||||
#endif // WVCDM_UTIL_DISALLOW_COPY_AND_ASSIGN_H_
|
||||
|
||||
@@ -16,7 +16,16 @@
|
||||
#include "platform.h"
|
||||
#include "util_common.h"
|
||||
|
||||
namespace wvcdm {
|
||||
namespace wvutil {
|
||||
|
||||
static const std::string kAtscCertificateFileName = "atsccert.bin";
|
||||
static const std::string kCertificateFileName = "cert1.bin";
|
||||
static const std::string kCertificateFileNameExt = ".bin";
|
||||
static const std::string kCertificateFileNamePrefix = "cert1_";
|
||||
static const std::string kLegacyCertificateFileName = "cert.bin";
|
||||
static const std::string kLegacyCertificateFileNamePrefix = "cert";
|
||||
static const std::string kOemCertificateFileName = "oemcert.bin";
|
||||
static const std::string kOemCertificateFileNamePrefix = "oemcert_";
|
||||
|
||||
// File class. The implementation is platform dependent.
|
||||
class CORE_UTIL_EXPORT File {
|
||||
@@ -72,6 +81,6 @@ class CORE_UTIL_EXPORT FileSystem {
|
||||
CORE_DISALLOW_COPY_AND_ASSIGN(FileSystem);
|
||||
};
|
||||
|
||||
} // namespace wvcdm
|
||||
} // namespace wvutil
|
||||
|
||||
#endif // WVCDM_UTIL_FILE_STORE_H_
|
||||
|
||||
@@ -7,9 +7,15 @@
|
||||
#ifndef WVCDM_UTIL_LOG_H_
|
||||
#define WVCDM_UTIL_LOG_H_
|
||||
|
||||
#include <cstdint>
|
||||
#include <deque>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "util_common.h"
|
||||
|
||||
namespace wvcdm {
|
||||
namespace wvutil {
|
||||
|
||||
// Simple logging class. The implementation is platform dependent.
|
||||
|
||||
@@ -27,15 +33,53 @@ typedef enum {
|
||||
|
||||
extern LogPriority g_cutoff;
|
||||
|
||||
struct LogMessage {
|
||||
uint32_t uid_;
|
||||
int64_t time_ms_;
|
||||
LogPriority priority_;
|
||||
std::string message_;
|
||||
};
|
||||
|
||||
class LogBuffer {
|
||||
public:
|
||||
static const int MAX_CAPACITY = 100;
|
||||
void addLog(const LogMessage& log);
|
||||
std::vector<LogMessage> getLogs();
|
||||
|
||||
private:
|
||||
std::deque<LogMessage> buffer_;
|
||||
std::mutex mutex_;
|
||||
};
|
||||
|
||||
extern LogBuffer g_logbuf;
|
||||
|
||||
static const uint32_t UNKNOWN_UID = ~0;
|
||||
|
||||
#ifdef __ANDROID__
|
||||
void SetLoggingUid(const uint32_t);
|
||||
void ClearLoggingUid();
|
||||
uint32_t GetLoggingUid();
|
||||
uint32_t GetIpcCallingUid();
|
||||
#else
|
||||
static inline void SetLoggingUid(const uint32_t) {}
|
||||
static inline void ClearLoggingUid() {}
|
||||
static inline uint32_t GetLoggingUid() { return UNKNOWN_UID; }
|
||||
static inline uint32_t GetIpcCallingUid() { return UNKNOWN_UID; }
|
||||
#endif
|
||||
|
||||
struct LoggingUidSetter {
|
||||
LoggingUidSetter() {}
|
||||
LoggingUidSetter(uint32_t uid) { SetLoggingUid(uid); }
|
||||
virtual ~LoggingUidSetter() { ClearLoggingUid(); }
|
||||
};
|
||||
|
||||
// Enable/disable verbose logging (LOGV).
|
||||
// This function is supplied for cases where the system layer does not
|
||||
// initialize logging. This is also needed to initialize logging in
|
||||
// unit tests.
|
||||
CORE_UTIL_EXPORT void InitLogging();
|
||||
|
||||
// Only enable format specifier warnings on LP64 systems. There is
|
||||
// no easy portable method to handle format specifiers for int64_t.
|
||||
#if (defined(__GNUC__) || defined(__clang__)) && defined(__LP64__)
|
||||
#ifdef __GNUC__
|
||||
[[gnu::format(printf, 5, 6)]] CORE_UTIL_EXPORT void Log(const char* file,
|
||||
const char* function,
|
||||
int line,
|
||||
@@ -49,16 +93,16 @@ CORE_UTIL_EXPORT void Log(const char* file, const char* function, int line,
|
||||
// Log APIs
|
||||
#ifndef LOGE
|
||||
# define LOGE(...) \
|
||||
Log(__FILE__, __func__, __LINE__, wvcdm::LOG_ERROR, __VA_ARGS__)
|
||||
Log(__FILE__, __func__, __LINE__, wvutil::LOG_ERROR, __VA_ARGS__)
|
||||
# define LOGW(...) \
|
||||
Log(__FILE__, __func__, __LINE__, wvcdm::LOG_WARN, __VA_ARGS__)
|
||||
Log(__FILE__, __func__, __LINE__, wvutil::LOG_WARN, __VA_ARGS__)
|
||||
# define LOGI(...) \
|
||||
Log(__FILE__, __func__, __LINE__, wvcdm::LOG_INFO, __VA_ARGS__)
|
||||
Log(__FILE__, __func__, __LINE__, wvutil::LOG_INFO, __VA_ARGS__)
|
||||
# define LOGD(...) \
|
||||
Log(__FILE__, __func__, __LINE__, wvcdm::LOG_DEBUG, __VA_ARGS__)
|
||||
Log(__FILE__, __func__, __LINE__, wvutil::LOG_DEBUG, __VA_ARGS__)
|
||||
# define LOGV(...) \
|
||||
Log(__FILE__, __func__, __LINE__, wvcdm::LOG_VERBOSE, __VA_ARGS__)
|
||||
Log(__FILE__, __func__, __LINE__, wvutil::LOG_VERBOSE, __VA_ARGS__)
|
||||
#endif
|
||||
} // namespace wvcdm
|
||||
} // namespace wvutil
|
||||
|
||||
#endif // WVCDM_UTIL_LOG_H_
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
#include "disallow_copy_and_assign.h"
|
||||
#include "util_common.h"
|
||||
|
||||
namespace wvcdm {
|
||||
namespace wvutil {
|
||||
|
||||
// A simple reader-writer mutex implementation that mimics the one from C++17
|
||||
class CORE_UTIL_EXPORT shared_mutex {
|
||||
@@ -60,6 +60,6 @@ class shared_lock {
|
||||
CORE_DISALLOW_COPY_AND_ASSIGN(shared_lock);
|
||||
};
|
||||
|
||||
} // namespace wvcdm
|
||||
} // namespace wvutil
|
||||
|
||||
#endif // WVCDM_UTIL_RW_LOCK_H_
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
// Copyright 2018 Google LLC. All Rights Reserved. This file and proprietary
|
||||
// source code may only be used and distributed under the Widevine License
|
||||
// Agreement.
|
||||
|
||||
#ifndef WVCDM_UTIL_STRING_CONVERSIONS_H_
|
||||
#define WVCDM_UTIL_STRING_CONVERSIONS_H_
|
||||
|
||||
@@ -13,32 +12,52 @@
|
||||
|
||||
#include "util_common.h"
|
||||
|
||||
namespace wvcdm {
|
||||
namespace wvutil {
|
||||
|
||||
// ASCII hex to Binary conversion.
|
||||
CORE_UTIL_EXPORT std::vector<uint8_t> a2b_hex(const std::string& b);
|
||||
CORE_UTIL_EXPORT std::vector<uint8_t> a2b_hex(const std::string& label,
|
||||
const std::string& b);
|
||||
CORE_UTIL_EXPORT std::string a2bs_hex(const std::string& b);
|
||||
|
||||
// Binary to ASCII hex conversion.
|
||||
CORE_UTIL_EXPORT std::string b2a_hex(const std::vector<uint8_t>& b);
|
||||
CORE_UTIL_EXPORT std::string b2a_hex(const std::string& b);
|
||||
CORE_UTIL_EXPORT std::string HexEncode(const uint8_t* bytes, size_t size);
|
||||
|
||||
// Base64 encoding/decoding.
|
||||
// Converts binary data into the ASCII Base64 character set and vice
|
||||
// versa using the encoding rules defined in RFC4648 section 4.
|
||||
CORE_UTIL_EXPORT std::string Base64Encode(
|
||||
const std::vector<uint8_t>& bin_input);
|
||||
CORE_UTIL_EXPORT std::string Base64Encode(const std::string& bin_input);
|
||||
CORE_UTIL_EXPORT std::vector<uint8_t> Base64Decode(
|
||||
const std::string& bin_input);
|
||||
|
||||
// URL-Safe Base64 encoding/decoding.
|
||||
// Converts binary data into the URL/Filename safe ASCII Base64
|
||||
// character set and vice versa using the encoding rules defined in
|
||||
// RFC4648 section 5.
|
||||
CORE_UTIL_EXPORT std::string Base64SafeEncode(
|
||||
const std::vector<uint8_t>& bin_input);
|
||||
CORE_UTIL_EXPORT std::string Base64SafeEncodeNoPad(
|
||||
const std::vector<uint8_t>& bin_input);
|
||||
CORE_UTIL_EXPORT std::string Base64SafeEncode(const std::string& bin_input);
|
||||
CORE_UTIL_EXPORT std::vector<uint8_t> Base64SafeDecode(
|
||||
const std::string& bin_input);
|
||||
CORE_UTIL_EXPORT std::string HexEncode(const uint8_t* bytes, unsigned size);
|
||||
CORE_UTIL_EXPORT std::string IntToString(int value);
|
||||
// URL-Safe Base64 encoding without padding.
|
||||
// Similar to Base64SafeEncode(), without any padding character '='
|
||||
// at the end.
|
||||
CORE_UTIL_EXPORT std::string Base64SafeEncodeNoPad(
|
||||
const std::vector<uint8_t>& bin_input);
|
||||
CORE_UTIL_EXPORT std::string Base64SafeEncodeNoPad(
|
||||
const std::string& bin_input);
|
||||
|
||||
// Host to Network/Network to Host conversion.
|
||||
CORE_UTIL_EXPORT int64_t htonll64(int64_t x);
|
||||
CORE_UTIL_EXPORT inline int64_t ntohll64(int64_t x) { return htonll64(x); }
|
||||
CORE_UTIL_EXPORT std::string BytesToString(const uint8_t* bytes, unsigned size);
|
||||
// Encode unsigned integer into a big endian formatted string
|
||||
CORE_UTIL_EXPORT std::string EncodeUint32(unsigned int u);
|
||||
|
||||
} // namespace wvcdm
|
||||
// Encode unsigned integer into a big endian formatted string.
|
||||
CORE_UTIL_EXPORT std::string EncodeUint32(uint32_t u);
|
||||
|
||||
} // namespace wvutil
|
||||
|
||||
#endif // WVCDM_UTIL_STRING_CONVERSIONS_H_
|
||||
|
||||
@@ -5,18 +5,53 @@
|
||||
#ifndef WVCDM_UTIL_UTIL_COMMON_H_
|
||||
#define WVCDM_UTIL_UTIL_COMMON_H_
|
||||
|
||||
// This section deals with defines that are platform-specific.
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
# ifdef CORE_UTIL_IMPLEMENTATION
|
||||
# define CORE_UTIL_EXPORT __declspec(dllexport)
|
||||
# else
|
||||
# define CORE_UTIL_EXPORT __declspec(dllimport)
|
||||
# endif
|
||||
|
||||
# define CORE_UTIL_IGNORE_DEPRECATED
|
||||
# define CORE_UTIL_RESTORE_WARNINGS
|
||||
|
||||
#else
|
||||
|
||||
# ifdef CORE_UTIL_IMPLEMENTATION
|
||||
# define CORE_UTIL_EXPORT __attribute__((visibility("default")))
|
||||
# else
|
||||
# define CORE_UTIL_EXPORT
|
||||
# endif
|
||||
|
||||
# ifdef __GNUC__
|
||||
# define CORE_UTIL_IGNORE_DEPRECATED \
|
||||
_Pragma("GCC diagnostic push") \
|
||||
_Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
|
||||
# define CORE_UTIL_RESTORE_WARNINGS _Pragma("GCC diagnostic pop")
|
||||
# else
|
||||
# define CORE_UTIL_IGNORE_DEPRECATED
|
||||
# define CORE_UTIL_RESTORE_WARNINGS
|
||||
# endif
|
||||
|
||||
#endif
|
||||
|
||||
// This section deals with attribute-detection and is platform-agnostic.
|
||||
|
||||
#if !defined(__has_cpp_attribute)
|
||||
# define __has_cpp_attribute(x) 0
|
||||
#endif
|
||||
|
||||
#if __has_cpp_attribute(fallthrough)
|
||||
# define CORE_UTIL_FALLTHROUGH [[fallthrough]]
|
||||
#elif __has_cpp_attribute(clang::fallthrough)
|
||||
# define CORE_UTIL_FALLTHROUGH [[clang::fallthrough]]
|
||||
#elif __has_cpp_attribute(gnu::fallthrough)
|
||||
# define CORE_UTIL_FALLTHROUGH [[gnu::fallthrough]]
|
||||
#else
|
||||
# define CORE_UTIL_FALLTHROUGH
|
||||
#endif
|
||||
|
||||
#endif // WVCDM_UTIL_UTIL_COMMON_H_
|
||||
|
||||
16
util/include/wv_attributes.h
Normal file
16
util/include/wv_attributes.h
Normal file
@@ -0,0 +1,16 @@
|
||||
// Copyright 2021 Google LLC. All rights reserved. This file and proprietary
|
||||
// source code may only be used and distributed under the Widevine
|
||||
// License Agreement.
|
||||
|
||||
#ifndef WVCDM_UTIL_WV_ATTRIBUTES_H_
|
||||
#define WVCDM_UTIL_WV_ATTRIBUTES_H_
|
||||
|
||||
#ifndef UNUSED
|
||||
# if defined(__GNUC__) || defined(__clang__)
|
||||
# define UNUSED __attribute__((__unused__))
|
||||
# else
|
||||
# define UNUSED
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#endif // WVCDM_UTIL_WV_ATTRIBUTES_H_
|
||||
Reference in New Issue
Block a user