Skip to content

Commit

Permalink
[ClearKey] Moved padding method to BASE64 utils
Browse files Browse the repository at this point in the history
  • Loading branch information
CastagnaIT committed Aug 25, 2024
1 parent d3a097e commit 3ac84ff
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
22 changes: 3 additions & 19 deletions src/decrypters/clearkey/ClearKeyCencSingleSampleDecrypter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,26 +270,10 @@ bool CClearKeyCencSingleSampleDecrypter::ParseLicenseResponse(std::string data)
if (!b64Key.empty() && !b64KeyId.empty())
{
CkB64Decode(b64Key);
CkB64Decode(b64KeyId);
BASE64::AddPadding(b64Key);

// pad b64
int left = 4 - (b64Key.length() % 4);
if (b64Key.length() % 4)
{
for (int i = 0; i < left; i++)
{
b64Key.push_back('=');
}
}

left = 4 - (b64KeyId.length() % 4);
if (b64KeyId.length() % 4)
{
for (int i = 0; i < left; i++)
{
b64KeyId.push_back('=');
}
}
CkB64Decode(b64KeyId);
BASE64::AddPadding(b64KeyId);

m_keyPairs.emplace(b64KeyId, b64Key);
break;
Expand Down
14 changes: 14 additions & 0 deletions src/utils/Base64Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,3 +217,17 @@ bool UTILS::BASE64::IsValidBase64(const std::string& input)
std::regex base64Regex(REGEX.data());
return std::regex_match(input, base64Regex);
}

bool UTILS::BASE64::AddPadding(std::string& base64str)
{
const int mod = static_cast<int>(base64str.length() % 4);
if (mod > 0)
{
for (int i = 4 - mod; i > 0; --i)
{
base64str.push_back(PADDING);
}
return true;
}
return false;
}
2 changes: 2 additions & 0 deletions src/utils/Base64Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,7 @@ std::string DecodeToStr(std::string_view input);

bool IsValidBase64(const std::string& input);

bool AddPadding(std::string& base64str);

} // namespace BASE64
} // namespace UTILS

0 comments on commit 3ac84ff

Please sign in to comment.