Move libsignal-service up a directory.

This commit is contained in:
Greyson Parrelli
2023-10-06 11:34:51 -04:00
committed by Cody Henthorne
parent 6134244244
commit 4968db750b
483 changed files with 1 additions and 3 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -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("=", "");
}
}

View File

@@ -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;
}
}

View File

@@ -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);
}
}

View File

@@ -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);
}
}