Replace Makefile with Android.bp. Remove duplication of protos in proto directory. Since we are now building the metrics_dump tool under Android, use frameworks metrics.proto directly. Also, reference cdm's wv_metrics.proto from the cdm directory instead of creating a subset in proto directory. bug: 161783052 bug: 170607430 Test: build m -j128 metrics_dump Test: metrics_dump [bugreport from adt-3-r.zip] Test: metrics_dump [bugreport from sabrina-q.gz] Test: metrics_dump --widevine [adb shell dumpsys media.metrics output] Change-Id: I82c7e723453ac2a6335cb2bb732a376d535b9ea3
90 lines
1.8 KiB
C++
90 lines
1.8 KiB
C++
// Copyright 2018 Google LLC. All Rights Reserved. This file and proprietary
|
|
// source code may only be used and distributed under the Widevine License
|
|
// Agreement.
|
|
//
|
|
// simple base64 decoder
|
|
|
|
#include "base64decode.h"
|
|
|
|
#include <iostream>
|
|
#include <memory>
|
|
#include <string>
|
|
|
|
namespace base64 {
|
|
|
|
using namespace std;
|
|
|
|
string Base64::Decode(const string &encoded) {
|
|
string s = encoded;
|
|
|
|
while (s.size() % 4 != 0) {
|
|
s.append("=");
|
|
}
|
|
|
|
size_t n = s.size();
|
|
|
|
size_t padding = 0;
|
|
if (n >= 1 && s[n - 1] == '=') {
|
|
padding = 1;
|
|
|
|
if (n >= 2 && s[n - 2] == '=') {
|
|
padding = 2;
|
|
|
|
if (n >= 3 && s[n - 3] == '=') {
|
|
padding = 3;
|
|
}
|
|
}
|
|
}
|
|
|
|
// We divide first to avoid overflow. It's OK to do this because we
|
|
// already made sure that n % 4 == 0.
|
|
size_t outLen = (n / 4) * 3 - padding;
|
|
|
|
std::unique_ptr<uint8_t> buffer(new uint8_t[outLen]);
|
|
if (!buffer) {
|
|
return "";
|
|
}
|
|
uint8_t *out = buffer.get();
|
|
size_t j = 0;
|
|
uint32_t accum = 0;
|
|
for (size_t i = 0; i < n; ++i) {
|
|
char c = s[i];
|
|
unsigned value;
|
|
if (c >= 'A' && c <= 'Z') {
|
|
value = c - 'A';
|
|
} else if (c >= 'a' && c <= 'z') {
|
|
value = 26 + c - 'a';
|
|
} else if (c >= '0' && c <= '9') {
|
|
value = 52 + c - '0';
|
|
} else if (c == '+' || c == '-') {
|
|
value = 62;
|
|
} else if (c == '/' || c == '_') {
|
|
value = 63;
|
|
} else {
|
|
if (c != '=') {
|
|
std::cerr << "unexpected character in base64 decode:" << c << std::endl;
|
|
}
|
|
value = 0;
|
|
}
|
|
|
|
accum = (accum << 6) | value;
|
|
|
|
if (((i + 1) % 4) == 0) {
|
|
if (j < outLen) {
|
|
out[j++] = (accum >> 16);
|
|
}
|
|
if (j < outLen) {
|
|
out[j++] = (accum >> 8) & 0xff;
|
|
}
|
|
if (j < outLen) {
|
|
out[j++] = accum & 0xff;
|
|
}
|
|
|
|
accum = 0;
|
|
}
|
|
}
|
|
return string((char *)buffer.get(), outLen);
|
|
}
|
|
|
|
} // namespace base64
|