Search in sources :

Example 1 with GroupInviteLink

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);
    }
}
Also used : InvalidInputException(org.signal.zkgroup.InvalidInputException) GroupInviteLink(org.signal.storageservice.protos.groups.GroupInviteLink) GroupMasterKey(org.signal.zkgroup.groups.GroupMasterKey) ByteString(com.google.protobuf.ByteString) IOException(java.io.IOException) URI(java.net.URI) Nullable(androidx.annotation.Nullable)

Example 2 with GroupInviteLink

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;
}
Also used : GroupInviteLink(org.signal.storageservice.protos.groups.GroupInviteLink) ByteString(com.google.protobuf.ByteString) NonNull(androidx.annotation.NonNull)

Example 3 with GroupInviteLink

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);
    }
}
Also used : InvalidInputException(org.signal.zkgroup.InvalidInputException) GroupInviteLink(org.signal.storageservice.protos.groups.GroupInviteLink) GroupMasterKey(org.signal.zkgroup.groups.GroupMasterKey) ByteString(com.google.protobuf.ByteString) IOException(java.io.IOException) URI(java.net.URI) Nullable(androidx.annotation.Nullable)

Example 4 with GroupInviteLink

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;
}
Also used : GroupInviteLink(org.signal.storageservice.protos.groups.GroupInviteLink) ByteString(com.google.protobuf.ByteString) NonNull(androidx.annotation.NonNull)

Aggregations

ByteString (com.google.protobuf.ByteString)4 GroupInviteLink (org.signal.storageservice.protos.groups.GroupInviteLink)4 NonNull (androidx.annotation.NonNull)2 Nullable (androidx.annotation.Nullable)2 IOException (java.io.IOException)2 URI (java.net.URI)2 InvalidInputException (org.signal.zkgroup.InvalidInputException)2 GroupMasterKey (org.signal.zkgroup.groups.GroupMasterKey)2