From d71275d786e2e91d4f5df6d2e8ad6eafe9206b9a Mon Sep 17 00:00:00 2001 From: Chris Pearce Date: Wed, 21 Dec 2016 10:37:09 +1300 Subject: [PATCH] Bug 1324926 - Convert other EME/GMP byte logging from Base64 to Hex. r=gerald This is marginly more readable. MozReview-Commit-ID: DWJNFXxI7Vd --HG-- extra : rebase_source : bfc694c51a8f1de28a6a11155f0c3e6b723ff153 --- dom/media/eme/MediaKeySession.cpp | 22 +++++++++++----------- dom/media/gmp/GMPDecryptorParent.cpp | 8 ++++---- dom/media/gmp/GMPUtils.cpp | 19 ++++++------------- dom/media/gmp/GMPUtils.h | 4 ++-- 4 files changed, 23 insertions(+), 30 deletions(-) diff --git a/dom/media/eme/MediaKeySession.cpp b/dom/media/eme/MediaKeySession.cpp index 3bfa914436f1..b1ece29d5c83 100644 --- a/dom/media/eme/MediaKeySession.cpp +++ b/dom/media/eme/MediaKeySession.cpp @@ -156,7 +156,7 @@ MediaKeySession::UpdateKeyStatusMap() this, NS_ConvertUTF16toUTF8(mSessionId).get())); using IntegerType = typename std::underlying_type::type; for (const CDMCaps::KeyStatus& status : keyStatuses) { - message.Append(nsPrintfCString(" (%s,%s)", ToBase64(status.mId).get(), + message.Append(nsPrintfCString(" (%s,%s)", ToHexString(status.mId).get(), MediaKeyStatusValues::strings[static_cast(status.mStatus)].value)); } message.Append(" }"); @@ -318,10 +318,10 @@ MediaKeySession::GenerateRequest(const nsAString& aInitDataType, Telemetry::Accumulate(Telemetry::VIDEO_CDM_GENERATE_REQUEST_CALLED, ToCDMTypeTelemetryEnum(mKeySystem)); - // Convert initData to base64 for easier logging. + // Convert initData to hex for easier logging. // Note: CreateSession() Move()s the data out of the array, so we have // to copy it here. - nsAutoCString base64InitData(ToBase64(data)); + nsAutoCString hexInitData(ToHexString(data)); PromiseId pid = mKeys->StorePromise(promise); mKeys->ConnectPendingPromiseIdWithToken(pid, Token()); mKeys->GetCDMProxy()->CreateSession(Token(), @@ -330,11 +330,11 @@ MediaKeySession::GenerateRequest(const nsAString& aInitDataType, aInitDataType, data); EME_LOG("MediaKeySession[%p,'%s'] GenerateRequest() sent, " - "promiseId=%d initData(base64)='%s' initDataType='%s'", + "promiseId=%d initData='%s' initDataType='%s'", this, NS_ConvertUTF16toUTF8(mSessionId).get(), pid, - base64InitData.get(), + hexInitData.get(), NS_ConvertUTF16toUTF8(aInitDataType).get()); return promise.forget(); @@ -447,10 +447,10 @@ MediaKeySession::Update(const ArrayBufferViewOrArrayBuffer& aResponse, ErrorResu } - // Convert response to base64 for easier logging. + // Convert response to hex for easier logging. // Note: UpdateSession() Move()s the data out of the array, so we have // to copy it here. - nsAutoCString base64Response(ToBase64(data)); + nsAutoCString hexResponse(ToHexString(data)); PromiseId pid = mKeys->StorePromise(promise); mKeys->GetCDMProxy()->UpdateSession(mSessionId, @@ -458,11 +458,11 @@ MediaKeySession::Update(const ArrayBufferViewOrArrayBuffer& aResponse, ErrorResu data); EME_LOG("MediaKeySession[%p,'%s'] Update() sent to CDM, " - "promiseId=%d Response(base64)='%s'", + "promiseId=%d Response='%s'", this, NS_ConvertUTF16toUTF8(mSessionId).get(), pid, - base64Response.get()); + hexResponse.get()); return promise.forget(); } @@ -579,10 +579,10 @@ MediaKeySession::DispatchKeyMessage(MediaKeyMessageType aMessageType, const nsTArray& aMessage) { if (EME_LOG_ENABLED()) { - EME_LOG("MediaKeySession[%p,'%s'] DispatchKeyMessage() type=%s message(base64)='%s'", + EME_LOG("MediaKeySession[%p,'%s'] DispatchKeyMessage() type=%s message='%s'", this, NS_ConvertUTF16toUTF8(mSessionId).get(), MediaKeyMessageTypeValues::strings[uint32_t(aMessageType)].value, - ToBase64(aMessage).get()); + ToHexString(aMessage).get()); } RefPtr event( diff --git a/dom/media/gmp/GMPDecryptorParent.cpp b/dom/media/gmp/GMPDecryptorParent.cpp index b40f3f00a11f..34fa1416d195 100644 --- a/dom/media/gmp/GMPDecryptorParent.cpp +++ b/dom/media/gmp/GMPDecryptorParent.cpp @@ -78,7 +78,7 @@ GMPDecryptorParent::CreateSession(uint32_t aCreateSessionToken, GMPSessionType aSessionType) { LOGD(("GMPDecryptorParent[%p]::CreateSession(token=%u, promiseId=%u, aInitData='%s')", - this, aCreateSessionToken, aPromiseId, ToBase64(aInitData).get())); + this, aCreateSessionToken, aPromiseId, ToHexString(aInitData).get())); if (!mIsOpen) { NS_WARNING("Trying to use a dead GMP decrypter!"); @@ -110,7 +110,7 @@ GMPDecryptorParent::UpdateSession(uint32_t aPromiseId, const nsTArray& aResponse) { LOGD(("GMPDecryptorParent[%p]::UpdateSession(sessionId='%s', promiseId=%u response='%s')", - this, aSessionId.get(), aPromiseId, ToBase64(aResponse).get())); + this, aSessionId.get(), aPromiseId, ToHexString(aResponse).get())); if (!mIsOpen) { NS_WARNING("Trying to use a dead GMP decrypter!"); @@ -295,7 +295,7 @@ GMPDecryptorParent::RecvSessionMessage(const nsCString& aSessionId, nsTArray&& aMessage) { LOGD(("GMPDecryptorParent[%p]::RecvSessionMessage(sessionId='%s', type=%d, msg='%s')", - this, aSessionId.get(), aMessageType, ToBase64(aMessage).get())); + this, aSessionId.get(), aMessageType, ToHexString(aMessage).get())); if (!mIsOpen) { NS_WARNING("Trying to use a dead GMP decrypter!"); @@ -380,7 +380,7 @@ GMPDecryptorParent::RecvBatchedKeyStatusChanged(const nsCString& aSessionId, nsTArray cdmKeyInfos(aKeyInfos.Length()); for (uint32_t i = 0; i < aKeyInfos.Length(); i++) { LOGD(("GMPDecryptorParent[%p]::RecvBatchedKeyStatusChanged(keyId=%s, gmp-status=%d)", - this, ToBase64(aKeyInfos[i].keyId()).get(), aKeyInfos[i].status())); + this, ToHexString(aKeyInfos[i].keyId()).get(), aKeyInfos[i].status())); // If the status is kGMPUnknown, we're going to forget(remove) that key info. if (aKeyInfos[i].status() != kGMPUnknown) { auto status = ToMediaKeyStatus(aKeyInfos[i].status()); diff --git a/dom/media/gmp/GMPUtils.cpp b/dom/media/gmp/GMPUtils.cpp index 56270d9de7b0..1377dad40fcc 100644 --- a/dom/media/gmp/GMPUtils.cpp +++ b/dom/media/gmp/GMPUtils.cpp @@ -52,19 +52,6 @@ SplitAt(const char* aDelims, } } -nsCString -ToBase64(const nsTArray& aBytes) -{ - nsAutoCString base64; - nsDependentCSubstring raw(reinterpret_cast(aBytes.Elements()), - aBytes.Length()); - nsresult rv = Base64Encode(raw, base64); - if (NS_WARN_IF(NS_FAILED(rv))) { - return NS_LITERAL_CSTRING("[Base64EncodeFailed]"); - } - return base64; -} - nsCString ToHexString(const uint8_t * aBytes, uint32_t aLength) { @@ -85,6 +72,12 @@ ToHexString(const uint8_t * aBytes, uint32_t aLength) return str; } +nsCString +ToHexString(const nsTArray& aBytes) +{ + return ToHexString(aBytes.Elements(), aBytes.Length()); +} + bool FileExists(nsIFile* aFile) { diff --git a/dom/media/gmp/GMPUtils.h b/dom/media/gmp/GMPUtils.h index 7e3e4a950d13..3dc715866865 100644 --- a/dom/media/gmp/GMPUtils.h +++ b/dom/media/gmp/GMPUtils.h @@ -38,9 +38,9 @@ SplitAt(const char* aDelims, nsTArray& aOutTokens); nsCString -ToBase64(const nsTArray& aBytes); +ToHexString(const nsTArray& aBytes); -static nsCString +nsCString ToHexString(const uint8_t* aBytes, uint32_t aLength); bool