Refactor base64 decode function to simplify handling (#3411)
Refactored the decode function to simplify base64 decoding and improve handling of various base64 formats. Removed redundant code and improved clarity.
This commit is contained in:
@@ -97,14 +97,10 @@ object Utils {
|
||||
* base64 decode
|
||||
*/
|
||||
fun decode(text: String?): String {
|
||||
tryDecodeBase64(text)?.let { return it }
|
||||
if (text?.endsWith('=')==true) {
|
||||
// try again for some loosely formatted base64
|
||||
tryDecodeBase64(text.trimEnd('='))?.let { return it }
|
||||
}
|
||||
return ""
|
||||
return tryDecodeBase64(text) ?: text?.trimEnd('=')?.let { tryDecodeBase64(it) } ?: ""
|
||||
}
|
||||
|
||||
|
||||
fun tryDecodeBase64(text: String?): String? {
|
||||
try {
|
||||
return Base64.decode(text, Base64.NO_WRAP).toString(Charsets.UTF_8)
|
||||
|
||||
Reference in New Issue
Block a user