mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 19:29:06 +01:00
Use MailboxId instead of String for type-safety
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
package org.briarproject.bramble.api.mailbox;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonValue;
|
||||
|
||||
import org.briarproject.bramble.api.UniqueId;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import javax.annotation.concurrent.ThreadSafe;
|
||||
|
||||
import static org.briarproject.bramble.util.StringUtils.fromHexString;
|
||||
import static org.briarproject.bramble.util.StringUtils.toHexString;
|
||||
|
||||
@ThreadSafe
|
||||
@NotNullByDefault
|
||||
public class MailboxId extends UniqueId {
|
||||
|
||||
public MailboxId(byte[] id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link MailboxId} from the given string.
|
||||
*
|
||||
* @throws IllegalArgumentException if token is not valid.
|
||||
*/
|
||||
public static MailboxId fromString(String token) {
|
||||
if (token.length() != 64) throw new IllegalArgumentException();
|
||||
return new MailboxId(fromHexString(token));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the string representation expected by the mailbox API.
|
||||
* Also used for serialization.
|
||||
*/
|
||||
@Override
|
||||
@JsonValue
|
||||
public String toString() {
|
||||
return toHexString(getBytes()).toLowerCase(Locale.US);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return o instanceof MailboxId && super.equals(o);
|
||||
}
|
||||
}
|
||||
@@ -8,10 +8,11 @@ import javax.annotation.concurrent.Immutable;
|
||||
@NotNullByDefault
|
||||
public class MailboxProperties {
|
||||
|
||||
private final String onionAddress, authToken;
|
||||
private final String onionAddress;
|
||||
private final MailboxId authToken;
|
||||
private final boolean owner;
|
||||
|
||||
public MailboxProperties(String onionAddress, String authToken,
|
||||
public MailboxProperties(String onionAddress, MailboxId authToken,
|
||||
boolean owner) {
|
||||
this.onionAddress = onionAddress;
|
||||
this.authToken = authToken;
|
||||
@@ -22,7 +23,7 @@ public class MailboxProperties {
|
||||
return onionAddress;
|
||||
}
|
||||
|
||||
public String getAuthToken() {
|
||||
public MailboxId getAuthToken() {
|
||||
return authToken;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user