Identity manager hooks. #209

This commit is contained in:
akwizgran
2016-01-20 12:03:15 +00:00
parent 82cf12040f
commit c4692a7007
16 changed files with 258 additions and 53 deletions

View File

@@ -6,6 +6,12 @@ import java.util.Collection;
public interface IdentityManager {
/** Registers a hook to be called whenever a local pseudonym is added. */
void registerIdentityAddedHook(IdentityAddedHook hook);
/** Registers a hook to be called whenever a local pseudonym is removed. */
void registerIdentityRemovedHook(IdentityRemovedHook hook);
/** Stores a local pseudonym. */
void addLocalAuthor(LocalAuthor a) throws DbException;
@@ -17,4 +23,12 @@ public interface IdentityManager {
/** Removes a local pseudonym and all associated state. */
void removeLocalAuthor(AuthorId a) throws DbException;
interface IdentityAddedHook {
void identityAdded(AuthorId a);
}
interface IdentityRemovedHook {
void identityRemoved(AuthorId a);
}
}

View File

@@ -3,14 +3,36 @@ package org.briarproject.api.identity;
/** A pseudonym for the local user. */
public class LocalAuthor extends Author {
public enum Status {
ADDING(0), ACTIVE(1), REMOVING(2);
private final int value;
Status(int value) {
this.value = value;
}
public int getValue() {
return value;
}
public static Status fromValue(int value) {
for (Status s : values()) if (s.value == value) return s;
throw new IllegalArgumentException();
}
}
private final byte[] privateKey;
private final long created;
private final Status status;
public LocalAuthor(AuthorId id, String name, byte[] publicKey,
byte[] privateKey, long created) {
byte[] privateKey, long created, Status status) {
super(id, name, publicKey);
this.privateKey = privateKey;
this.created = created;
this.status = status;
}
/** Returns the private key used to generate the pseudonym's signatures. */
@@ -18,7 +40,16 @@ public class LocalAuthor extends Author {
return privateKey;
}
/**
* Returns the time the pseudonym was created, in milliseconds since the
* Unix epoch.
*/
public long getTimeCreated() {
return created;
}
/** Returns the status of the pseudonym. */
public Status getStatus() {
return status;
}
}