Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7b408737 authored by Edwin Wong's avatar Edwin Wong Committed by android-build-merger
Browse files

Merge "Fix ClearKey Drm base64 en/decoding to use base64url." into oc-mr1-dev am: 3b224af5

am: eb68f293

Change-Id: Ie436596031a865f833c7a31ba8d49319a8d5bbb9
parents 0888c849 eb68f293
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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(",");
        }
+1 −2
Original line number Diff line number Diff line
@@ -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);
@@ -231,5 +231,4 @@ TEST_F(InitDataParserTest, FailsForPsshBadKeyCount) {

    attemptParseExpectingFailure(initData, kCencMimeType);
}

}  // namespace clearkeydrm
+5 −5
Original line number Diff line number Diff line
@@ -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\""
                    "}"
                    "{"
@@ -303,7 +303,7 @@ TEST_F(JsonWebKeyTest, ExtractKeys) {
                    "{"
                        "\"alg\":\"A128KW3\""
                        "\"kid\":\"Y2xlYXJrZXlrZXlpZDAz\""
                        "\"k\":\"R29vZCBkYXkh\""
                        "\"k\":\"SGVsbG8gPz4-IEZyaWVuZCA_Pg\""
                        "\"kty\":\"oct\""
                    "}]"
            "}");
@@ -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);
}

+25 −3
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ namespace android {

sp<ABuffer> decodeBase64(const AString &s) {
    size_t n = s.size();

    if ((n % 4) != 0) {
        return NULL;
    }
@@ -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;
@@ -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;
@@ -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
+2 −0
Original line number Diff line number Diff line
@@ -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