]>
nmode's Git Repositories - signal-cli/blob - src/main/java/org/asamk/signal/manager/GroupId.java
34e18e8e972150f4534abb66d41d9dc946543aec
1 package org
.asamk
.signal
.manager
;
3 import org
.whispersystems
.util
.Base64
;
5 import java
.util
.Arrays
;
7 public abstract class GroupId
{
9 private final byte[] id
;
11 public static GroupIdV1
v1(byte[] id
) {
12 return new GroupIdV1(id
);
15 public static GroupIdV2
v2(byte[] id
) {
16 return new GroupIdV2(id
);
19 public static GroupId
unknownVersion(byte[] id
) {
20 if (id
.length
== 16) {
21 return new GroupIdV1(id
);
22 } else if (id
.length
== 32) {
23 return new GroupIdV2(id
);
26 throw new AssertionError("Invalid group id of size " + id
.length
);
29 public static GroupId
fromBase64(String id
) throws GroupIdFormatException
{
31 return unknownVersion(java
.util
.Base64
.getDecoder().decode(id
));
32 } catch (Throwable e
) {
33 throw new GroupIdFormatException(id
, e
);
37 public GroupId(final byte[] id
) {
41 public byte[] serialize() {
45 public String
toBase64() {
46 return Base64
.encodeBytes(id
);
50 public boolean equals(final Object o
) {
51 if (this == o
) return true;
52 if (o
== null || getClass() != o
.getClass()) return false;
54 final GroupId groupId
= (GroupId
) o
;
56 return Arrays
.equals(id
, groupId
.id
);
60 public int hashCode() {
61 return Arrays
.hashCode(id
);