Loading drm/mediadrm/plugins/clearkey/InitDataParser.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -136,7 +136,7 @@ String8 InitDataParser::generateRequest(const Vector<const uint8_t*>& keyIds) { AString encodedId; for (size_t i = 0; i < keyIds.size(); ++i) { encodedId.clear(); android::encodeBase64(keyIds[i], kKeyIdSize, &encodedId); android::encodeBase64Url(keyIds[i], kKeyIdSize, &encodedId); if (i != 0) { request.append(","); } Loading drm/mediadrm/plugins/clearkey/tests/InitDataParserUnittest.cpp +1 −2 Original line number Diff line number Diff line Loading @@ -59,7 +59,7 @@ class InitDataParserTest : public ::testing::Test { (size_t)requestString.find(kRequestSuffix)); for (size_t i = 0; i < expectedKeys.size(); ++i) { AString encodedIdAString; android::encodeBase64(expectedKeys[i], kKeyIdSize, android::encodeBase64Url(expectedKeys[i], kKeyIdSize, &encodedIdAString); String8 encodedId(encodedIdAString.c_str()); encodedId.removeAll(kBase64Padding); Loading Loading @@ -231,5 +231,4 @@ TEST_F(InitDataParserTest, FailsForPsshBadKeyCount) { attemptParseExpectingFailure(initData, kCencMimeType); } } // namespace clearkeydrm drm/mediadrm/plugins/clearkey/tests/JsonWebKeyUnittest.cpp +5 −5 Original line number Diff line number Diff line Loading @@ -284,14 +284,14 @@ TEST_F(JsonWebKeyTest, ExtractKeys) { "\"keys\":" "[{" "\"kid\":\"Y2xlYXJrZXlrZXlpZDAx\"" "\"k\":\"SGVsbG8gRnJpZW5kISE\"" "\"k\":\"SGVsbG8gRnJpZW5kICE-Pw\"" "\"kty\":\"oct\"" "\"alg\":\"A128KW1\"" "}" "{" "\"kty\":\"oct\"" "\"alg\":\"A128KW2\"" "\"k\":\"SGVsbG8gRnJpZW5kIQ\"" "\"k\":\"SGVsbG8gRnJpZW5kICE_\"" "\"kid\":\"Y2xlYXJrZXlrZXlpZDAy\"" "}" "{" Loading @@ -303,7 +303,7 @@ TEST_F(JsonWebKeyTest, ExtractKeys) { "{" "\"alg\":\"A128KW3\"" "\"kid\":\"Y2xlYXJrZXlrZXlpZDAz\"" "\"k\":\"R29vZCBkYXkh\"" "\"k\":\"SGVsbG8gPz4-IEZyaWVuZCA_Pg\"" "\"kty\":\"oct\"" "}]" "}"); Loading @@ -313,8 +313,8 @@ TEST_F(JsonWebKeyTest, ExtractKeys) { EXPECT_TRUE(keys.size() == 3); const String8 clearKeys[] = { String8("Hello Friend!!"), String8("Hello Friend!"), String8("Good day!") }; { String8("Hello Friend !>?"), String8("Hello Friend !?"), String8("Hello ?>> Friend ?>") }; verifyKeys(keys, clearKeys); } Loading media/libstagefright/foundation/base64.cpp +25 −3 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ namespace android { sp<ABuffer> decodeBase64(const AString &s) { size_t n = s.size(); if ((n % 4) != 0) { return NULL; } Loading @@ -45,7 +46,6 @@ sp<ABuffer> decodeBase64(const AString &s) { size_t outLen = (n / 4) * 3 - padding; sp<ABuffer> buffer = new ABuffer(outLen); uint8_t *out = buffer->data(); if (out == NULL || buffer->size() < outLen) { return NULL; Loading @@ -61,9 +61,9 @@ sp<ABuffer> decodeBase64(const AString &s) { value = 26 + c - 'a'; } else if (c >= '0' && c <= '9') { value = 52 + c - '0'; } else if (c == '+') { } else if (c == '+' || c == '-') { value = 62; } else if (c == '/') { } else if (c == '/' || c == '_') { value = 63; } else if (c != '=') { return NULL; Loading Loading @@ -144,4 +144,26 @@ void encodeBase64( } } void encodeBase64Url( const void *_data, size_t size, AString *out) { encodeBase64(_data, size, out); if ((-1 != out->find("+")) || (-1 != out->find("/"))) { size_t outLen = out->size(); char *base64url = new char[outLen]; for (size_t i = 0; i < outLen; ++i) { if (out->c_str()[i] == '+') base64url[i] = '-'; else if (out->c_str()[i] == '/') base64url[i] = '_'; else base64url[i] = out->c_str()[i]; } out->setTo(base64url, outLen); delete[] base64url; } } } // namespace android media/libstagefright/foundation/include/media/stagefright/foundation/base64.h +2 −0 Original line number Diff line number Diff line Loading @@ -28,6 +28,8 @@ struct AString; sp<ABuffer> decodeBase64(const AString &s); void encodeBase64(const void *data, size_t size, AString *out); void encodeBase64Url(const void *data, size_t size, AString *out); } // namespace android #endif // BASE_64_H_ Loading
drm/mediadrm/plugins/clearkey/InitDataParser.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -136,7 +136,7 @@ String8 InitDataParser::generateRequest(const Vector<const uint8_t*>& keyIds) { AString encodedId; for (size_t i = 0; i < keyIds.size(); ++i) { encodedId.clear(); android::encodeBase64(keyIds[i], kKeyIdSize, &encodedId); android::encodeBase64Url(keyIds[i], kKeyIdSize, &encodedId); if (i != 0) { request.append(","); } Loading
drm/mediadrm/plugins/clearkey/tests/InitDataParserUnittest.cpp +1 −2 Original line number Diff line number Diff line Loading @@ -59,7 +59,7 @@ class InitDataParserTest : public ::testing::Test { (size_t)requestString.find(kRequestSuffix)); for (size_t i = 0; i < expectedKeys.size(); ++i) { AString encodedIdAString; android::encodeBase64(expectedKeys[i], kKeyIdSize, android::encodeBase64Url(expectedKeys[i], kKeyIdSize, &encodedIdAString); String8 encodedId(encodedIdAString.c_str()); encodedId.removeAll(kBase64Padding); Loading Loading @@ -231,5 +231,4 @@ TEST_F(InitDataParserTest, FailsForPsshBadKeyCount) { attemptParseExpectingFailure(initData, kCencMimeType); } } // namespace clearkeydrm
drm/mediadrm/plugins/clearkey/tests/JsonWebKeyUnittest.cpp +5 −5 Original line number Diff line number Diff line Loading @@ -284,14 +284,14 @@ TEST_F(JsonWebKeyTest, ExtractKeys) { "\"keys\":" "[{" "\"kid\":\"Y2xlYXJrZXlrZXlpZDAx\"" "\"k\":\"SGVsbG8gRnJpZW5kISE\"" "\"k\":\"SGVsbG8gRnJpZW5kICE-Pw\"" "\"kty\":\"oct\"" "\"alg\":\"A128KW1\"" "}" "{" "\"kty\":\"oct\"" "\"alg\":\"A128KW2\"" "\"k\":\"SGVsbG8gRnJpZW5kIQ\"" "\"k\":\"SGVsbG8gRnJpZW5kICE_\"" "\"kid\":\"Y2xlYXJrZXlrZXlpZDAy\"" "}" "{" Loading @@ -303,7 +303,7 @@ TEST_F(JsonWebKeyTest, ExtractKeys) { "{" "\"alg\":\"A128KW3\"" "\"kid\":\"Y2xlYXJrZXlrZXlpZDAz\"" "\"k\":\"R29vZCBkYXkh\"" "\"k\":\"SGVsbG8gPz4-IEZyaWVuZCA_Pg\"" "\"kty\":\"oct\"" "}]" "}"); Loading @@ -313,8 +313,8 @@ TEST_F(JsonWebKeyTest, ExtractKeys) { EXPECT_TRUE(keys.size() == 3); const String8 clearKeys[] = { String8("Hello Friend!!"), String8("Hello Friend!"), String8("Good day!") }; { String8("Hello Friend !>?"), String8("Hello Friend !?"), String8("Hello ?>> Friend ?>") }; verifyKeys(keys, clearKeys); } Loading
media/libstagefright/foundation/base64.cpp +25 −3 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ namespace android { sp<ABuffer> decodeBase64(const AString &s) { size_t n = s.size(); if ((n % 4) != 0) { return NULL; } Loading @@ -45,7 +46,6 @@ sp<ABuffer> decodeBase64(const AString &s) { size_t outLen = (n / 4) * 3 - padding; sp<ABuffer> buffer = new ABuffer(outLen); uint8_t *out = buffer->data(); if (out == NULL || buffer->size() < outLen) { return NULL; Loading @@ -61,9 +61,9 @@ sp<ABuffer> decodeBase64(const AString &s) { value = 26 + c - 'a'; } else if (c >= '0' && c <= '9') { value = 52 + c - '0'; } else if (c == '+') { } else if (c == '+' || c == '-') { value = 62; } else if (c == '/') { } else if (c == '/' || c == '_') { value = 63; } else if (c != '=') { return NULL; Loading Loading @@ -144,4 +144,26 @@ void encodeBase64( } } void encodeBase64Url( const void *_data, size_t size, AString *out) { encodeBase64(_data, size, out); if ((-1 != out->find("+")) || (-1 != out->find("/"))) { size_t outLen = out->size(); char *base64url = new char[outLen]; for (size_t i = 0; i < outLen; ++i) { if (out->c_str()[i] == '+') base64url[i] = '-'; else if (out->c_str()[i] == '/') base64url[i] = '_'; else base64url[i] = out->c_str()[i]; } out->setTo(base64url, outLen); delete[] base64url; } } } // namespace android
media/libstagefright/foundation/include/media/stagefright/foundation/base64.h +2 −0 Original line number Diff line number Diff line Loading @@ -28,6 +28,8 @@ struct AString; sp<ABuffer> decodeBase64(const AString &s); void encodeBase64(const void *data, size_t size, AString *out); void encodeBase64Url(const void *data, size_t size, AString *out); } // namespace android #endif // BASE_64_H_