mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-29 21:15:22 +00:00
28 lines
698 B
Java
28 lines
698 B
Java
|
package org.thoughtcrime.securesms.util;
|
||
|
|
||
|
import org.whispersystems.textsecure.util.Hex;
|
||
|
|
||
|
import java.io.IOException;
|
||
|
|
||
|
public class GroupUtil {
|
||
|
|
||
|
private static final String ENCODED_GROUP_PREFIX = "__textsecure_group__!";
|
||
|
|
||
|
public static String getEncodedId(byte[] groupId) {
|
||
|
return ENCODED_GROUP_PREFIX + Hex.toStringCondensed(groupId);
|
||
|
}
|
||
|
|
||
|
public static byte[] getDecodedId(String groupId) throws IOException {
|
||
|
if (!isEncodedGroup(groupId)) {
|
||
|
throw new IOException("Invalid encoding");
|
||
|
}
|
||
|
|
||
|
return Hex.fromStringCondensed(groupId.split("!", 2)[1]);
|
||
|
}
|
||
|
|
||
|
public static boolean isEncodedGroup(String groupId) {
|
||
|
return groupId.startsWith(ENCODED_GROUP_PREFIX);
|
||
|
}
|
||
|
|
||
|
}
|