From 43d91e5bd6c9208fb9b3567464d56ce2dc6fab5c Mon Sep 17 00:00:00 2001 From: Jon Chambers Date: Thu, 3 Aug 2023 17:12:40 -0400 Subject: [PATCH] Convert `VerificationCode` to a record --- .../controllers/DeviceController.java | 4 +- .../textsecuregcm/util/VerificationCode.java | 58 +------------------ .../controllers/DeviceControllerTest.java | 16 ++--- 3 files changed, 11 insertions(+), 67 deletions(-) diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/controllers/DeviceController.java b/service/src/main/java/org/whispersystems/textsecuregcm/controllers/DeviceController.java index 6ce900f39..3fa07a066 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/controllers/DeviceController.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/controllers/DeviceController.java @@ -186,7 +186,7 @@ public class DeviceController { VerificationCode verificationCode = generateVerificationCode(); StoredVerificationCode storedVerificationCode = - new StoredVerificationCode(verificationCode.getVerificationCode(), System.currentTimeMillis(), null, null); + new StoredVerificationCode(verificationCode.verificationCode(), System.currentTimeMillis(), null, null); pendingDevices.store(account.getNumber(), storedVerificationCode); @@ -281,7 +281,7 @@ public class DeviceController { VerificationCode generateVerificationCode() { SecureRandom random = new SecureRandom(); int randomInt = 100000 + random.nextInt(900000); - return new VerificationCode(randomInt); + return new VerificationCode(String.valueOf(randomInt)); } private Mac getInitializedMac() { diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/util/VerificationCode.java b/service/src/main/java/org/whispersystems/textsecuregcm/util/VerificationCode.java index 888752e19..5d502e1aa 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/util/VerificationCode.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/util/VerificationCode.java @@ -4,61 +4,5 @@ */ package org.whispersystems.textsecuregcm.util; -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.google.common.annotations.VisibleForTesting; - -public class VerificationCode { - - @JsonProperty - private String verificationCode; - @JsonIgnore - private String verificationCodeDisplay; - @JsonIgnore - private String verificationCodeSpeech; - - @VisibleForTesting VerificationCode() {} - - public VerificationCode(int verificationCode) { - this(verificationCode + ""); - } - - public VerificationCode(String verificationCode) { - this.verificationCode = verificationCode; - this.verificationCodeDisplay = this.verificationCode.substring(0, 3) + "-" + this.verificationCode.substring(3, 6); - this.verificationCodeSpeech = delimit(verificationCode + ""); - } - - public String getVerificationCode() { - return verificationCode; - } - - public String getVerificationCodeDisplay() { - return verificationCodeDisplay; - } - - public String getVerificationCodeSpeech() { - return verificationCodeSpeech; - } - - private String delimit(String code) { - String delimited = ""; - - for (int i=0;i aciSignedPreKey; final Optional pniSignedPreKey; @@ -508,7 +508,7 @@ class DeviceControllerTest { .header("Authorization", AuthHelper.getAuthHeader(AuthHelper.VALID_UUID, AuthHelper.VALID_PASSWORD)) .get(VerificationCode.class); - assertThat(deviceCode).isEqualTo(new VerificationCode(5678901)); + assertThat(deviceCode).isEqualTo(new VerificationCode("5678901")); final Optional aciSignedPreKey; final Optional pniSignedPreKey; @@ -571,7 +571,7 @@ class DeviceControllerTest { .header("Authorization", AuthHelper.getAuthHeader(AuthHelper.VALID_UUID, AuthHelper.VALID_PASSWORD)) .get(VerificationCode.class); - assertThat(deviceCode).isEqualTo(new VerificationCode(5678901)); + assertThat(deviceCode).isEqualTo(new VerificationCode("5678901")); when(account.getIdentityKey()).thenReturn(aciIdentityKey); when(account.getPhoneNumberIdentityKey()).thenReturn(pniIdentityKey); @@ -631,7 +631,7 @@ class DeviceControllerTest { .header("Authorization", AuthHelper.getAuthHeader(AuthHelper.VALID_UUID, AuthHelper.VALID_PASSWORD)) .get(VerificationCode.class); - assertThat(deviceCode).isEqualTo(new VerificationCode(5678901)); + assertThat(deviceCode).isEqualTo(new VerificationCode("5678901")); when(account.getIdentityKey()).thenReturn(aciIdentityKey); when(account.getPhoneNumberIdentityKey()).thenReturn(pniIdentityKey); @@ -701,7 +701,7 @@ class DeviceControllerTest { .header("Authorization", AuthHelper.getAuthHeader(AuthHelper.VALID_UUID, AuthHelper.VALID_PASSWORD)) .get(VerificationCode.class); - assertThat(deviceCode).isEqualTo(new VerificationCode(5678901)); + assertThat(deviceCode).isEqualTo(new VerificationCode("5678901")); Response response = resources.getJerseyTest() .target("/v1/devices/5678902")