- safetyNumber = safetyNumber.replaceAll(" ", "");
- if (safetyNumber.length() == 66) {
- byte[] fingerprintBytes;
- try {
- fingerprintBytes = Hex.toByteArray(safetyNumber.toLowerCase(Locale.ROOT));
- } catch (Exception e) {
- throw new UserErrorException(
- "Failed to parse the fingerprint, make sure the fingerprint is a correctly encoded hex string without additional characters.");
- }
- boolean res = m.trustIdentityVerified(recipient, fingerprintBytes);
- if (!res) {
- throw new UserErrorException(
- "Failed to set the trust for the fingerprint of this number, make sure the number and the fingerprint are correct.");
- }
- } else if (safetyNumber.length() == 60) {
- boolean res = m.trustIdentityVerifiedSafetyNumber(recipient, safetyNumber);
- if (!res) {
- throw new UserErrorException(
- "Failed to set the trust for the safety number of this phone number, make sure the phone number and the safety number are correct.");
- }
- } else {
- final byte[] scannableSafetyNumber;
- try {
- scannableSafetyNumber = Base64.getDecoder().decode(safetyNumber);
- } catch (IllegalArgumentException e) {
- throw new UserErrorException(
- "Safety number has invalid format, either specify the old hex fingerprint or the new safety number");
- }
- boolean res = m.trustIdentityVerifiedSafetyNumber(recipient, scannableSafetyNumber);
+ final IdentityVerificationCode verificationCode;
+ try {
+ verificationCode = IdentityVerificationCode.parse(safetyNumber);
+ } catch (Exception e) {
+ throw new UserErrorException(
+ "Safety number has invalid format, either specify the old hex fingerprint or the new safety number");
+ }
+
+ try {
+ final var res = m.trustIdentityVerified(recipient, verificationCode);