mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-17 21:29:54 +01:00
Add handshake mode to MutableTransportKeys.
This commit is contained in:
@@ -1,9 +1,11 @@
|
|||||||
package org.briarproject.bramble.transport;
|
package org.briarproject.bramble.transport;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.crypto.SecretKey;
|
||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.bramble.api.plugin.TransportId;
|
import org.briarproject.bramble.api.plugin.TransportId;
|
||||||
import org.briarproject.bramble.api.transport.TransportKeys;
|
import org.briarproject.bramble.api.transport.TransportKeys;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import javax.annotation.concurrent.NotThreadSafe;
|
import javax.annotation.concurrent.NotThreadSafe;
|
||||||
|
|
||||||
@NotThreadSafe
|
@NotThreadSafe
|
||||||
@@ -13,6 +15,9 @@ class MutableTransportKeys {
|
|||||||
private final TransportId transportId;
|
private final TransportId transportId;
|
||||||
private final MutableIncomingKeys inPrev, inCurr, inNext;
|
private final MutableIncomingKeys inPrev, inCurr, inNext;
|
||||||
private final MutableOutgoingKeys outCurr;
|
private final MutableOutgoingKeys outCurr;
|
||||||
|
@Nullable
|
||||||
|
private final SecretKey rootKey;
|
||||||
|
private final boolean alice;
|
||||||
|
|
||||||
MutableTransportKeys(TransportKeys k) {
|
MutableTransportKeys(TransportKeys k) {
|
||||||
transportId = k.getTransportId();
|
transportId = k.getTransportId();
|
||||||
@@ -20,11 +25,24 @@ class MutableTransportKeys {
|
|||||||
inCurr = new MutableIncomingKeys(k.getCurrentIncomingKeys());
|
inCurr = new MutableIncomingKeys(k.getCurrentIncomingKeys());
|
||||||
inNext = new MutableIncomingKeys(k.getNextIncomingKeys());
|
inNext = new MutableIncomingKeys(k.getNextIncomingKeys());
|
||||||
outCurr = new MutableOutgoingKeys(k.getCurrentOutgoingKeys());
|
outCurr = new MutableOutgoingKeys(k.getCurrentOutgoingKeys());
|
||||||
|
if (k.isHandshakeMode()) {
|
||||||
|
rootKey = k.getRootKey();
|
||||||
|
alice = k.isAlice();
|
||||||
|
} else {
|
||||||
|
rootKey = null;
|
||||||
|
alice = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TransportKeys snapshot() {
|
TransportKeys snapshot() {
|
||||||
return new TransportKeys(transportId, inPrev.snapshot(),
|
if (rootKey == null) {
|
||||||
inCurr.snapshot(), inNext.snapshot(), outCurr.snapshot());
|
return new TransportKeys(transportId, inPrev.snapshot(),
|
||||||
|
inCurr.snapshot(), inNext.snapshot(), outCurr.snapshot());
|
||||||
|
} else {
|
||||||
|
return new TransportKeys(transportId, inPrev.snapshot(),
|
||||||
|
inCurr.snapshot(), inNext.snapshot(), outCurr.snapshot(),
|
||||||
|
rootKey, alice);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TransportId getTransportId() {
|
TransportId getTransportId() {
|
||||||
@@ -46,4 +64,18 @@ class MutableTransportKeys {
|
|||||||
MutableOutgoingKeys getCurrentOutgoingKeys() {
|
MutableOutgoingKeys getCurrentOutgoingKeys() {
|
||||||
return outCurr;
|
return outCurr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean isHandshakeMode() {
|
||||||
|
return rootKey != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
SecretKey getRootKey() {
|
||||||
|
if (rootKey == null) throw new UnsupportedOperationException();
|
||||||
|
return rootKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean isAlice() {
|
||||||
|
if (rootKey == null) throw new UnsupportedOperationException();
|
||||||
|
return alice;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user