- public void handleCommand(final Namespace ns, final Manager m) throws CommandException {
- var number = ns.getString("number");
- if (ns.getBoolean("trust_all_known_keys")) {
- var res = m.trustIdentityAllKeys(number);
- if (!res) {
- throw new UserErrorException("Failed to set the trust for this number, make sure the number is correct.");
- }
- } else {
- var safetyNumber = ns.getString("verified_safety_number");
- if (safetyNumber != null) {
- 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;
- try {
- res = m.trustIdentityVerified(number, fingerprintBytes);
- } catch (InvalidNumberException e) {
- throw new UserErrorException("Failed to parse recipient: " + e.getMessage());
- }
- 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;
- try {
- res = m.trustIdentityVerifiedSafetyNumber(number, safetyNumber);
- } catch (InvalidNumberException e) {
- throw new UserErrorException("Failed to parse recipient: " + e.getMessage());
- }
- 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 {
+ public void handleCommand(
+ final Namespace ns, final Manager m, final OutputWriter outputWriter
+ ) throws CommandException {
+ var recipentString = ns.getString("recipient");
+ var recipient = CommandUtil.getSingleRecipientIdentifier(recipentString, m.getSelfNumber());
+ if (Boolean.TRUE.equals(ns.getBoolean("trust-all-known-keys"))) {
+ try {
+ final var res = m.trustIdentityAllKeys(recipient);
+ if (!res) {