use of org.signal.storageservice.protos.groups.GroupInviteLink 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);
}
}
use of org.signal.storageservice.protos.groups.GroupInviteLink in project Signal-Android by WhisperSystems.
the class GroupInviteLinkUrl method createUrl.
@NonNull
protected static String createUrl(@NonNull GroupMasterKey groupMasterKey, @NonNull GroupLinkPassword password) {
GroupInviteLink groupInviteLink = GroupInviteLink.newBuilder().setV1Contents(GroupInviteLink.GroupInviteLinkContentsV1.newBuilder().setGroupMasterKey(ByteString.copyFrom(groupMasterKey.serialize())).setInviteLinkPassword(ByteString.copyFrom(password.serialize()))).build();
String encoding = Base64UrlSafe.encodeBytesWithoutPadding(groupInviteLink.toByteArray());
return GROUP_URL_PREFIX + encoding;
}
use of org.signal.storageservice.protos.groups.GroupInviteLink in project Signal-Android by signalapp.
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);
}
}
use of org.signal.storageservice.protos.groups.GroupInviteLink in project Signal-Android by signalapp.
the class GroupInviteLinkUrl method createUrl.
@NonNull
protected static String createUrl(@NonNull GroupMasterKey groupMasterKey, @NonNull GroupLinkPassword password) {
GroupInviteLink groupInviteLink = GroupInviteLink.newBuilder().setV1Contents(GroupInviteLink.GroupInviteLinkContentsV1.newBuilder().setGroupMasterKey(ByteString.copyFrom(groupMasterKey.serialize())).setInviteLinkPassword(ByteString.copyFrom(password.serialize()))).build();
String encoding = Base64UrlSafe.encodeBytesWithoutPadding(groupInviteLink.toByteArray());
return GROUP_URL_PREFIX + encoding;
}
Aggregations