use of org.signal.zkgroup.groups.GroupMasterKey in project Signal-Android by WhisperSystems.
the class SignalServiceContent method createGroupV2Info.
private static SignalServiceGroupV2 createGroupV2Info(SignalServiceProtos.DataMessage content) throws InvalidMessageStructureException {
if (!content.hasGroupV2())
return null;
SignalServiceProtos.GroupContextV2 groupV2 = content.getGroupV2();
if (!groupV2.hasMasterKey()) {
throw new InvalidMessageStructureException("No GV2 master key on message");
}
if (!groupV2.hasRevision()) {
throw new InvalidMessageStructureException("No GV2 revision on message");
}
SignalServiceGroupV2.Builder builder;
try {
builder = SignalServiceGroupV2.newBuilder(new GroupMasterKey(groupV2.getMasterKey().toByteArray())).withRevision(groupV2.getRevision());
} catch (InvalidInputException e) {
throw new InvalidMessageStructureException("Invalid GV2 input!");
}
if (groupV2.hasGroupChange() && !groupV2.getGroupChange().isEmpty()) {
builder.withSignedGroupChange(groupV2.getGroupChange().toByteArray());
}
return builder.build();
}
use of org.signal.zkgroup.groups.GroupMasterKey in project Signal-Android by WhisperSystems.
the class SignalServiceGroupV2 method fromProtobuf.
/**
* Creates a context model populated from a protobuf group V2 context.
*/
public static SignalServiceGroupV2 fromProtobuf(SignalServiceProtos.GroupContextV2 groupContextV2) {
GroupMasterKey masterKey;
try {
masterKey = new GroupMasterKey(groupContextV2.getMasterKey().toByteArray());
} catch (InvalidInputException e) {
throw new AssertionError(e);
}
Builder builder = newBuilder(masterKey);
if (groupContextV2.hasGroupChange() && !groupContextV2.getGroupChange().isEmpty()) {
builder.withSignedGroupChange(groupContextV2.getGroupChange().toByteArray());
}
return builder.withRevision(groupContextV2.getRevision()).build();
}
use of org.signal.zkgroup.groups.GroupMasterKey in project Signal-Android by WhisperSystems.
the class GroupInviteLinkUrl method fromUri.
/**
* @return null iff not a group url.
* @throws InvalidGroupLinkException If group url, but cannot be parsed.
*/
@Nullable
public static GroupInviteLinkUrl fromUri(@NonNull String urlString) throws InvalidGroupLinkException, UnknownGroupLinkVersionException {
URI uri = getGroupUrl(urlString);
if (uri == null) {
return null;
}
try {
if (!"/".equals(uri.getPath()) && uri.getPath().length() > 0) {
throw new InvalidGroupLinkException("No path was expected in uri");
}
String encoding = uri.getFragment();
if (encoding == null || encoding.length() == 0) {
throw new InvalidGroupLinkException("No reference was in the uri");
}
byte[] bytes = Base64UrlSafe.decodePaddingAgnostic(encoding);
GroupInviteLink groupInviteLink = GroupInviteLink.parseFrom(bytes);
// noinspection SwitchStatementWithTooFewBranches
switch(groupInviteLink.getContentsCase()) {
case V1CONTENTS:
{
GroupInviteLink.GroupInviteLinkContentsV1 groupInviteLinkContentsV1 = groupInviteLink.getV1Contents();
GroupMasterKey groupMasterKey = new GroupMasterKey(groupInviteLinkContentsV1.getGroupMasterKey().toByteArray());
GroupLinkPassword password = GroupLinkPassword.fromBytes(groupInviteLinkContentsV1.getInviteLinkPassword().toByteArray());
return new GroupInviteLinkUrl(groupMasterKey, password);
}
default:
throw new UnknownGroupLinkVersionException("Url contains no known group link content");
}
} catch (InvalidInputException | IOException e) {
throw new InvalidGroupLinkException(e);
}
}
Aggregations