mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-05-02 22:53:09 +01:00
Move libsignal-service up a directory.
This commit is contained in:
committed by
Cody Henthorne
parent
6134244244
commit
4968db750b
2098
libsignal-service/src/main/java/org/whispersystems/util/Base64.java
Normal file
2098
libsignal-service/src/main/java/org/whispersystems/util/Base64.java
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,34 @@
|
||||
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("=", "");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package org.whispersystems.util;
|
||||
|
||||
public final class ByteArrayUtil {
|
||||
|
||||
private ByteArrayUtil() {
|
||||
}
|
||||
|
||||
public static byte[] xor(byte[] a, byte[] b) {
|
||||
if (a.length != b.length) {
|
||||
throw new AssertionError("XOR length mismatch");
|
||||
}
|
||||
|
||||
byte[] out = new byte[a.length];
|
||||
|
||||
for (int i = a.length - 1; i >= 0; i--) {
|
||||
out[i] = (byte) (a[i] ^ b[i]);
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
public static byte[] concat(byte[] a, byte[] b) {
|
||||
byte[] result = new byte[a.length + b.length];
|
||||
System.arraycopy(a, 0, result, 0, a.length);
|
||||
System.arraycopy(b, 0, result, a.length, b.length);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package org.whispersystems.util;
|
||||
|
||||
public final class FlagUtil {
|
||||
|
||||
private FlagUtil() {}
|
||||
|
||||
/**
|
||||
* Left shift 1 by 'flag' - 1 spaces.
|
||||
*
|
||||
* Examples:
|
||||
* 1 -> 0001
|
||||
* 2 -> 0010
|
||||
* 3 -> 0100
|
||||
* 4 -> 1000
|
||||
*/
|
||||
public static int toBinaryFlag(int flag) {
|
||||
return 1 << (flag - 1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package org.whispersystems.util;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public final class StringUtil {
|
||||
|
||||
private StringUtil() {
|
||||
}
|
||||
|
||||
public static byte[] utf8(String string) {
|
||||
return string.getBytes(StandardCharsets.UTF_8);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user