all basic tests pass!
This commit is contained in:
@@ -3,6 +3,7 @@ package nodash.models;
|
||||
import java.io.IOException;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
@@ -32,13 +33,12 @@ public final class NoSession implements Serializable {
|
||||
private NoUser original;
|
||||
private NoState state;
|
||||
private final long expiry;
|
||||
private boolean newUserSession;
|
||||
|
||||
private Collection<NoByteSet> incoming;
|
||||
private NoUser current;
|
||||
private String uuid;
|
||||
|
||||
public NoSession() {
|
||||
private NoSession() {
|
||||
this.state = NoState.IDLE;
|
||||
this.expiry = System.currentTimeMillis() + NoSession.SESSION_DURATION;
|
||||
this.uuid = UUID.randomUUID().toString();
|
||||
@@ -46,18 +46,25 @@ public final class NoSession implements Serializable {
|
||||
|
||||
public NoSession(NoUser newUser) {
|
||||
this();
|
||||
if (newUser == null) {
|
||||
throw new NullPointerException("Session cannot be created with null user.");
|
||||
}
|
||||
this.state = NoState.MODIFIED;
|
||||
this.original = null;
|
||||
this.current = newUser;
|
||||
this.newUserSession = true;
|
||||
}
|
||||
|
||||
public NoSession(NoAdapter adapter, byte[] data, char[] password) throws NoUserNotValidException {
|
||||
public NoSession(byte[] data, char[] password) throws NoUserNotValidException {
|
||||
this();
|
||||
this.newUserSession = false;
|
||||
this.state = NoState.IDLE;
|
||||
try {
|
||||
this.original = NoUser.createUserFromFile(data, password);
|
||||
byte[] originalData = Arrays.copyOf(data, data.length);
|
||||
char[] originalPassword = Arrays.copyOf(password, password.length);
|
||||
this.original = NoUser.createUserFromFile(originalData, originalPassword);
|
||||
this.current = NoUser.createUserFromFile(data, password);
|
||||
NoUtil.wipeBytes(data);
|
||||
NoUtil.wipeChars(password);
|
||||
this.uuid = UUID.randomUUID().toString();
|
||||
} catch (IOException e) {
|
||||
throw new NoUserNotValidException();
|
||||
} catch (IllegalBlockSizeException e) {
|
||||
@@ -80,7 +87,7 @@ public final class NoSession implements Serializable {
|
||||
|
||||
public NoState touchState() throws NoSessionConfirmedException, NoSessionExpiredException {
|
||||
check();
|
||||
if (this.newUserSession) {
|
||||
if (this.original == null) {
|
||||
if (this.state != NoState.AWAITING_CONFIRMATION) {
|
||||
this.state = NoState.MODIFIED;
|
||||
}
|
||||
@@ -133,8 +140,6 @@ public final class NoSession implements Serializable {
|
||||
this.incoming = new ArrayList<NoByteSet>();
|
||||
List<NoAction> actions = this.current.getNoActions();
|
||||
this.incoming = null;
|
||||
this.original = null;
|
||||
this.current = null;
|
||||
/* 5.2.4: execute NoActions */
|
||||
for (NoAction action : actions) {
|
||||
/*
|
||||
@@ -181,7 +186,7 @@ public final class NoSession implements Serializable {
|
||||
}
|
||||
|
||||
public byte[] getOriginalHash() {
|
||||
if (this.original != null) {
|
||||
if (!isNewUser()) {
|
||||
return this.original.createHash();
|
||||
} else {
|
||||
return null;
|
||||
@@ -200,4 +205,8 @@ public final class NoSession implements Serializable {
|
||||
public void close() {
|
||||
this.state = NoState.CLOSED;
|
||||
}
|
||||
|
||||
public boolean isNewUser() {
|
||||
return this.original == null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -195,7 +195,21 @@ public class NoUser implements Serializable {
|
||||
}
|
||||
|
||||
public String createHashString() {
|
||||
return Base64.encodeBase64String(this.createHash());
|
||||
return Base64.encodeBase64URLSafeString(this.createHash());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object otherUser) {
|
||||
if (otherUser == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!otherUser.getClass().equals(getClass())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return this.privateKey.equals(((NoUser) otherUser).privateKey);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user