mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-05-02 14:43:09 +01:00
Unify our Base64 utilities.
This commit is contained in:
committed by
Cody Henthorne
parent
e636e38ba1
commit
4fe6d79fff
File diff suppressed because it is too large
Load Diff
@@ -1,34 +0,0 @@
|
||||
package org.whispersystems.util;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public final class Base64UrlSafe {
|
||||
|
||||
private Base64UrlSafe() {
|
||||
}
|
||||
|
||||
public static byte[] decode(String s) throws IOException {
|
||||
return Base64.decode(s, Base64.URL_SAFE);
|
||||
}
|
||||
|
||||
public static byte[] decodePaddingAgnostic(String s) throws IOException {
|
||||
switch (s.length() % 4) {
|
||||
case 1:
|
||||
case 3: s = s + "="; break;
|
||||
case 2: s = s + "=="; break;
|
||||
}
|
||||
return decode(s);
|
||||
}
|
||||
|
||||
public static String encodeBytes(byte[] source) {
|
||||
try {
|
||||
return Base64.encodeBytes(source, Base64.URL_SAFE);
|
||||
} catch (IOException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static String encodeBytesWithoutPadding(byte[] source) {
|
||||
return encodeBytes(source).replace("=", "");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user