Refactor addDeviceLink method

This commit is contained in:
AsamK 2023-05-21 22:54:51 +02:00
parent e5a67d6ce1
commit ff162cb44d
9 changed files with 24 additions and 19 deletions

View file

@ -4,6 +4,7 @@ import org.asamk.signal.manager.api.AlreadyReceivingException;
import org.asamk.signal.manager.api.AttachmentInvalidException;
import org.asamk.signal.manager.api.Configuration;
import org.asamk.signal.manager.api.Device;
import org.asamk.signal.manager.api.DeviceLinkUrl;
import org.asamk.signal.manager.api.Group;
import org.asamk.signal.manager.api.GroupId;
import org.asamk.signal.manager.api.GroupInviteLinkUrl;
@ -42,7 +43,6 @@ import java.io.Closeable;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.time.Duration;
import java.util.Collection;
import java.util.List;
@ -116,7 +116,7 @@ public interface Manager extends Closeable {
void removeLinkedDevices(int deviceId) throws IOException;
void addDeviceLink(URI linkUri) throws IOException, InvalidDeviceLinkException;
void addDeviceLink(DeviceLinkUrl linkUri) throws IOException, InvalidDeviceLinkException;
void setRegistrationLockPin(Optional<String> pin) throws IOException, NotPrimaryDeviceException;

View file

@ -1,6 +1,5 @@
package org.asamk.signal.manager.internal;
package org.asamk.signal.manager.api;
import org.asamk.signal.manager.api.InvalidDeviceLinkException;
import org.asamk.signal.manager.util.Utils;
import org.signal.libsignal.protocol.InvalidKeyException;
import org.signal.libsignal.protocol.ecc.Curve;
@ -14,9 +13,9 @@ import java.util.Base64;
import static org.whispersystems.signalservice.internal.util.Util.isEmpty;
public record DeviceLinkInfo(String deviceIdentifier, ECPublicKey deviceKey) {
public record DeviceLinkUrl(String deviceIdentifier, ECPublicKey deviceKey) {
public static DeviceLinkInfo parseDeviceLinkUri(URI linkUri) throws InvalidDeviceLinkException {
public static DeviceLinkUrl parseDeviceLinkUri(URI linkUri) throws InvalidDeviceLinkException {
final var rawQuery = linkUri.getRawQuery();
if (isEmpty(rawQuery)) {
throw new RuntimeException("Invalid device link uri");
@ -43,7 +42,7 @@ public record DeviceLinkInfo(String deviceIdentifier, ECPublicKey deviceKey) {
throw new InvalidDeviceLinkException("Invalid device link", e);
}
return new DeviceLinkInfo(deviceIdentifier, deviceKey);
return new DeviceLinkUrl(deviceIdentifier, deviceKey);
}
public URI createDeviceLinkUri() {

View file

@ -1,12 +1,12 @@
package org.asamk.signal.manager.helper;
import org.asamk.signal.manager.api.CaptchaRequiredException;
import org.asamk.signal.manager.api.DeviceLinkUrl;
import org.asamk.signal.manager.api.IncorrectPinException;
import org.asamk.signal.manager.api.InvalidDeviceLinkException;
import org.asamk.signal.manager.api.NonNormalizedPhoneNumberException;
import org.asamk.signal.manager.api.PinLockedException;
import org.asamk.signal.manager.api.RateLimitException;
import org.asamk.signal.manager.internal.DeviceLinkInfo;
import org.asamk.signal.manager.internal.SignalDependencies;
import org.asamk.signal.manager.storage.SignalAccount;
import org.asamk.signal.manager.util.KeyUtils;
@ -267,7 +267,7 @@ public class AccountHelper {
dependencies.getAccountManager().setAccountAttributes(account.getAccountAttributes(null));
}
public void addDevice(DeviceLinkInfo deviceLinkInfo) throws IOException, InvalidDeviceLinkException {
public void addDevice(DeviceLinkUrl deviceLinkInfo) throws IOException, InvalidDeviceLinkException {
var verificationCode = dependencies.getAccountManager().getNewDeviceVerificationCode();
try {

View file

@ -21,6 +21,7 @@ import org.asamk.signal.manager.api.AlreadyReceivingException;
import org.asamk.signal.manager.api.AttachmentInvalidException;
import org.asamk.signal.manager.api.Configuration;
import org.asamk.signal.manager.api.Device;
import org.asamk.signal.manager.api.DeviceLinkUrl;
import org.asamk.signal.manager.api.Group;
import org.asamk.signal.manager.api.GroupId;
import org.asamk.signal.manager.api.GroupInviteLinkUrl;
@ -91,7 +92,6 @@ import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.time.Duration;
import java.util.ArrayList;
@ -359,9 +359,8 @@ public class ManagerImpl implements Manager {
}
@Override
public void addDeviceLink(URI linkUri) throws IOException, InvalidDeviceLinkException {
var deviceLinkInfo = DeviceLinkInfo.parseDeviceLinkUri(linkUri);
context.getAccountHelper().addDevice(deviceLinkInfo);
public void addDeviceLink(DeviceLinkUrl linkUrl) throws IOException, InvalidDeviceLinkException {
context.getAccountHelper().addDevice(linkUrl);
}
@Override

View file

@ -19,6 +19,7 @@ package org.asamk.signal.manager.internal;
import org.asamk.signal.manager.Manager;
import org.asamk.signal.manager.ProvisioningManager;
import org.asamk.signal.manager.Settings;
import org.asamk.signal.manager.api.DeviceLinkUrl;
import org.asamk.signal.manager.api.UserAlreadyExistsException;
import org.asamk.signal.manager.config.ServiceConfig;
import org.asamk.signal.manager.config.ServiceEnvironmentConfig;
@ -97,7 +98,7 @@ public class ProvisioningManagerImpl implements ProvisioningManager {
public URI getDeviceLinkUri() throws TimeoutException, IOException {
var deviceUuid = accountManager.getNewDeviceUuid();
return new DeviceLinkInfo(deviceUuid, tempIdentityKey.getPublicKey().getPublicKey()).createDeviceLinkUri();
return new DeviceLinkUrl(deviceUuid, tempIdentityKey.getPublicKey().getPublicKey()).createDeviceLinkUri();
}
@Override