]> nmode's Git Repositories - signal-cli/blobdiff - lib/src/main/java/org/asamk/signal/manager/util/NumberVerificationUtils.java
Update dependencies
[signal-cli] / lib / src / main / java / org / asamk / signal / manager / util / NumberVerificationUtils.java
index 03b1c03a8468628e0240cddd66235b5f3800d0f5..388333adb7b9f84dd7beded5fb2d03d6c8ac398a 100644 (file)
@@ -11,9 +11,9 @@ import org.asamk.signal.manager.helper.PinHelper;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.whispersystems.signalservice.api.kbs.MasterKey;
+import org.whispersystems.signalservice.api.push.exceptions.ChallengeRequiredException;
 import org.whispersystems.signalservice.api.push.exceptions.NoSuchSessionException;
 import org.whispersystems.signalservice.api.push.exceptions.NonSuccessfulResponseCodeException;
-import org.whispersystems.signalservice.api.push.exceptions.PushChallengeRequiredException;
 import org.whispersystems.signalservice.api.push.exceptions.TokenNotAcceptedException;
 import org.whispersystems.signalservice.api.registration.RegistrationApi;
 import org.whispersystems.signalservice.internal.push.LockedException;
@@ -39,8 +39,7 @@ public class NumberVerificationUtils {
         RegistrationSessionMetadataResponse sessionResponse;
         try {
             sessionResponse = getValidSession(registrationApi, sessionId);
-        } catch (PushChallengeRequiredException |
-                 org.whispersystems.signalservice.api.push.exceptions.CaptchaRequiredException e) {
+        } catch (ChallengeRequiredException e) {
             if (captcha != null) {
                 sessionResponse = submitCaptcha(registrationApi, sessionId, captcha);
             } else {
@@ -88,7 +87,9 @@ public class NumberVerificationUtils {
     }
 
     public static void requestVerificationCode(
-            RegistrationApi registrationApi, String sessionId, boolean voiceVerification
+            RegistrationApi registrationApi,
+            String sessionId,
+            boolean voiceVerification
     ) throws IOException, CaptchaRequiredException, NonNormalizedPhoneNumberException {
         final var locale = Utils.getDefaultLocale(Locale.US);
         final var response = registrationApi.requestSmsVerificationCode(sessionId,
@@ -97,7 +98,7 @@ public class NumberVerificationUtils {
                 voiceVerification ? VerificationCodeTransport.VOICE : VerificationCodeTransport.SMS);
         try {
             Utils.handleResponseException(response);
-        } catch (org.whispersystems.signalservice.api.push.exceptions.CaptchaRequiredException e) {
+        } catch (ChallengeRequiredException e) {
             throw new CaptchaRequiredException(e.getMessage(), e);
         } catch (org.whispersystems.signalservice.api.push.exceptions.NonNormalizedPhoneNumberException e) {
             throw new NonNormalizedPhoneNumberException("Phone number is not normalized ("
@@ -108,7 +109,11 @@ public class NumberVerificationUtils {
     }
 
     public static Pair<VerifyAccountResponse, MasterKey> verifyNumber(
-            String sessionId, String verificationCode, String pin, PinHelper pinHelper, Verifier verifier
+            String sessionId,
+            String verificationCode,
+            String pin,
+            PinHelper pinHelper,
+            Verifier verifier
     ) throws IOException, PinLockedException, IncorrectPinException {
         verificationCode = verificationCode.replace("-", "");
         try {
@@ -138,7 +143,8 @@ public class NumberVerificationUtils {
     }
 
     private static RegistrationSessionMetadataResponse validateSession(
-            final RegistrationApi registrationApi, final String sessionId
+            final RegistrationApi registrationApi,
+            final String sessionId
     ) throws IOException {
         if (sessionId == null || sessionId.isEmpty()) {
             throw new NoSuchSessionException();
@@ -153,7 +159,8 @@ public class NumberVerificationUtils {
     }
 
     private static RegistrationSessionMetadataResponse getValidSession(
-            final RegistrationApi registrationApi, final String sessionId
+            final RegistrationApi registrationApi,
+            final String sessionId
     ) throws IOException {
         try {
             return validateSession(registrationApi, sessionId);
@@ -164,17 +171,17 @@ public class NumberVerificationUtils {
     }
 
     private static RegistrationSessionMetadataResponse submitCaptcha(
-            RegistrationApi registrationApi, String sessionId, String captcha
+            RegistrationApi registrationApi,
+            String sessionId,
+            String captcha
     ) throws IOException, CaptchaRequiredException {
         captcha = captcha == null ? null : captcha.replace("signalcaptcha://", "");
         try {
             return Utils.handleResponseException(registrationApi.submitCaptchaToken(sessionId, captcha));
-        } catch (PushChallengeRequiredException |
-                 org.whispersystems.signalservice.api.push.exceptions.CaptchaRequiredException |
-                 TokenNotAcceptedException _e) {
+        } catch (ChallengeRequiredException | TokenNotAcceptedException _e) {
             throw new CaptchaRequiredException("Captcha not accepted");
         } catch (NonSuccessfulResponseCodeException e) {
-            if (e.getCode() == 400) {
+            if (e.code == 400) {
                 throw new CaptchaRequiredException("Captcha has invalid format");
             }
             throw e;
@@ -184,7 +191,9 @@ public class NumberVerificationUtils {
     public interface Verifier {
 
         VerifyAccountResponse verify(
-                String sessionId, String verificationCode, String registrationLock
+                String sessionId,
+                String verificationCode,
+                String registrationLock
         ) throws IOException;
     }
 }