Convert `VerificationCode` to a record
This commit is contained in:
parent
5c4c729703
commit
43d91e5bd6
|
@ -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() {
|
||||
|
|
|
@ -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<code.length();i++) {
|
||||
delimited += code.charAt(i);
|
||||
|
||||
if (i != code.length() - 1)
|
||||
delimited += ',';
|
||||
}
|
||||
|
||||
return delimited;
|
||||
}
|
||||
|
||||
@VisibleForTesting public boolean equals(Object o) {
|
||||
return o instanceof VerificationCode && verificationCode.equals(((VerificationCode) o).verificationCode);
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return Integer.parseInt(verificationCode);
|
||||
}
|
||||
public record VerificationCode(String verificationCode) {
|
||||
}
|
||||
|
|
|
@ -82,7 +82,7 @@ class DeviceControllerTest {
|
|||
|
||||
@Override
|
||||
protected VerificationCode generateVerificationCode() {
|
||||
return new VerificationCode(5678901);
|
||||
return new VerificationCode("5678901");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -195,7 +195,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"));
|
||||
|
||||
DeviceResponse response = resources.getJerseyTest()
|
||||
.target("/v1/devices/5678901")
|
||||
|
@ -275,7 +275,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 Response response = resources.getJerseyTest()
|
||||
.target("/v1/devices/5678901")
|
||||
|
@ -321,7 +321,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<ECSignedPreKey> aciSignedPreKey;
|
||||
final Optional<ECSignedPreKey> 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<ECSignedPreKey> aciSignedPreKey;
|
||||
final Optional<ECSignedPreKey> 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")
|
||||
|
|
Loading…
Reference in New Issue