Convert VerificationCode to a record

This commit is contained in:
Jon Chambers
2023-08-03 17:12:40 -04:00
committed by Jon Chambers
parent 5c4c729703
commit 43d91e5bd6
3 changed files with 11 additions and 67 deletions

View File

@@ -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() {

View File

@@ -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) {
}