Rename account to identity.

This commit is contained in:
akwizgran
2019-05-03 13:46:02 +01:00
parent 5553b7d0e4
commit 9c08073e49
17 changed files with 459 additions and 453 deletions

View File

@@ -5,9 +5,9 @@ import org.briarproject.bramble.api.contact.ContactId;
import org.briarproject.bramble.api.contact.PendingContact;
import org.briarproject.bramble.api.contact.PendingContactId;
import org.briarproject.bramble.api.crypto.SecretKey;
import org.briarproject.bramble.api.identity.Account;
import org.briarproject.bramble.api.identity.Author;
import org.briarproject.bramble.api.identity.AuthorId;
import org.briarproject.bramble.api.identity.Identity;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import org.briarproject.bramble.api.plugin.TransportId;
import org.briarproject.bramble.api.settings.Settings;
@@ -101,11 +101,6 @@ public interface DatabaseComponent {
<R, E extends Exception> R transactionWithNullableResult(boolean readOnly,
NullableDbCallable<R, E> task) throws DbException, E;
/**
* Stores an account.
*/
void addAccount(Transaction txn, Account a) throws DbException;
/**
* Stores a contact associated with the given local and remote pseudonyms,
* and returns an ID for the contact.
@@ -132,6 +127,11 @@ public interface DatabaseComponent {
HandshakeKeySetId addHandshakeKeys(Transaction txn, PendingContactId p,
HandshakeKeys k) throws DbException;
/**
* Stores an identity.
*/
void addIdentity(Transaction txn, Identity i) throws DbException;
/**
* Stores a local message.
*/
@@ -157,13 +157,6 @@ public interface DatabaseComponent {
TransportKeySetId addTransportKeys(Transaction txn, ContactId c,
TransportKeys k) throws DbException;
/**
* Returns true if the database contains an account for the given pseudonym.
* <p/>
* Read-only.
*/
boolean containsAccount(Transaction txn, AuthorId local) throws DbException;
/**
* Returns true if the database contains the given contact for the given
* local pseudonym.
@@ -180,6 +173,14 @@ public interface DatabaseComponent {
*/
boolean containsGroup(Transaction txn, GroupId g) throws DbException;
/**
* Returns true if the database contains an identity for the given
* pseudonym.
* <p/>
* Read-only.
*/
boolean containsIdentity(Transaction txn, AuthorId a) throws DbException;
/**
* Returns true if the database contains the given pending contact.
* <p/>
@@ -246,20 +247,6 @@ public interface DatabaseComponent {
Collection<Message> generateRequestedBatch(Transaction txn, ContactId c,
int maxLength, int maxLatency) throws DbException;
/**
* Returns the account for the local pseudonym with the given ID.
* <p/>
* Read-only.
*/
Account getAccount(Transaction txn, AuthorId a) throws DbException;
/**
* Returns the accounts for all local pseudonyms.
* <p/>
* Read-only.
*/
Collection<Account> getAccounts(Transaction txn) throws DbException;
/**
* Returns the contact with the given ID.
* <p/>
@@ -329,6 +316,20 @@ public interface DatabaseComponent {
Collection<HandshakeKeySet> getHandshakeKeys(Transaction txn, TransportId t)
throws DbException;
/**
* Returns the identity for the local pseudonym with the given ID.
* <p/>
* Read-only.
*/
Identity getIdentity(Transaction txn, AuthorId a) throws DbException;
/**
* Returns the identities for all local pseudonyms.
* <p/>
* Read-only.
*/
Collection<Identity> getIdentities(Transaction txn) throws DbException;
/**
* Returns the message with the given ID.
* <p/>
@@ -541,11 +542,6 @@ public interface DatabaseComponent {
void receiveRequest(Transaction txn, ContactId c, Request r)
throws DbException;
/**
* Removes an account (and all associated state) from the database.
*/
void removeAccount(Transaction txn, AuthorId a) throws DbException;
/**
* Removes a contact (and all associated state) from the database.
*/
@@ -562,6 +558,11 @@ public interface DatabaseComponent {
void removeHandshakeKeys(Transaction txn, TransportId t,
HandshakeKeySetId k) throws DbException;
/**
* Removes an identity (and all associated state) from the database.
*/
void removeIdentity(Transaction txn, AuthorId a) throws DbException;
/**
* Removes a message (and all associated state) from the database.
*/
@@ -619,7 +620,7 @@ public interface DatabaseComponent {
Collection<MessageId> dependencies) throws DbException;
/**
* Sets the handshake key pair for the account with the given ID.
* Sets the handshake key pair for the identity with the given ID.
*/
void setHandshakeKeyPair(Transaction txn, AuthorId local, byte[] publicKey,
byte[] privateKey) throws DbException;

View File

@@ -11,14 +11,14 @@ import static org.briarproject.bramble.api.crypto.CryptoConstants.MAX_AGREEMENT_
@Immutable
@NotNullByDefault
public class Account {
public class Identity {
private final LocalAuthor localAuthor;
@Nullable
private final byte[] handshakePublicKey, handshakePrivateKey;
private final long created;
public Account(LocalAuthor localAuthor,
public Identity(LocalAuthor localAuthor,
@Nullable byte[] handshakePublicKey,
@Nullable byte[] handshakePrivateKey, long created) {
if (handshakePublicKey != null) {
@@ -47,7 +47,7 @@ public class Account {
}
/**
* Returns true if the account has a handshake key pair.
* Returns true if the identity has a handshake key pair.
*/
public boolean hasHandshakeKeyPair() {
return handshakePublicKey != null && handshakePrivateKey != null;
@@ -70,7 +70,7 @@ public class Account {
}
/**
* Returns the time the account was created, in milliseconds since the
* Returns the time the identity was created, in milliseconds since the
* Unix epoch.
*/
public long getTimeCreated() {
@@ -84,12 +84,12 @@ public class Account {
@Override
public boolean equals(Object o) {
if (o instanceof Account) {
Account a = (Account) o;
return created == a.created &&
localAuthor.equals(a.localAuthor) &&
Arrays.equals(handshakePublicKey, a.handshakePublicKey) &&
Arrays.equals(handshakePrivateKey, a.handshakePrivateKey);
if (o instanceof Identity) {
Identity i = (Identity) o;
return created == i.created &&
localAuthor.equals(i.localAuthor) &&
Arrays.equals(handshakePublicKey, i.handshakePublicKey) &&
Arrays.equals(handshakePrivateKey, i.handshakePrivateKey);
}
return false;
}

View File

@@ -11,19 +11,19 @@ import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
public interface IdentityManager {
/**
* Creates an account with the given name. The account includes a handshake
* key pair.
* Creates an identity with the given name. The identity includes a
* handshake key pair.
*/
@CryptoExecutor
Account createAccount(String name);
Identity createIdentity(String name);
/**
* Registers the given account with the manager. This method should be
* Registers the given identity with the manager. This method should be
* called before {@link LifecycleManager#startServices(SecretKey)}. The
* account is stored when {@link LifecycleManager#startServices(SecretKey)}
* is called. The account must include a handshake key pair.
* identity is stored when {@link LifecycleManager#startServices(SecretKey)}
* is called. The identity must include a handshake key pair.
*/
void registerAccount(Account a);
void registerIdentity(Identity i);
/**
* Returns the cached local identity or loads it from the database.