Merge branch 'crypto-api-code-cleanup' into 'master'

Minor code cleanups for crypto API

See merge request briar/briar!1076
This commit is contained in:
Torsten Grote
2019-04-06 14:20:26 +00:00
7 changed files with 39 additions and 5 deletions

View File

@@ -1,11 +1,25 @@
package org.briarproject.bramble.api.contact; package org.briarproject.bramble.api.contact;
import org.briarproject.bramble.api.UniqueId; import org.briarproject.bramble.api.UniqueId;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import javax.annotation.concurrent.ThreadSafe;
/**
* Type-safe wrapper for a byte array that uniquely identifies a
* {@link PendingContact}.
*/
@ThreadSafe
@NotNullByDefault
public class PendingContactId extends UniqueId { public class PendingContactId extends UniqueId {
public PendingContactId(byte[] id) { public PendingContactId(byte[] id) {
super(id); super(id);
} }
@Override
public boolean equals(Object o) {
return o instanceof PendingContactId && super.equals(o);
}
} }

View File

@@ -2,7 +2,7 @@ package org.briarproject.bramble.api.crypto;
/** /**
* Crypto operations for the key agreement protocol - see * Crypto operations for the key agreement protocol - see
* https://code.briarproject.org/akwizgran/briar-spec/blob/master/protocols/BQP.md * https://code.briarproject.org/briar/briar-spec/blob/master/protocols/BQP.md
*/ */
public interface KeyAgreementCrypto { public interface KeyAgreementCrypto {

View File

@@ -5,7 +5,7 @@ import org.briarproject.bramble.api.transport.TransportKeys;
/** /**
* Crypto operations for the transport security protocol - see * Crypto operations for the transport security protocol - see
* https://code.briarproject.org/akwizgran/briar-spec/blob/master/protocols/BTP.md * https://code.briarproject.org/briar/briar-spec/blob/master/protocols/BTP.md
*/ */
public interface TransportCrypto { public interface TransportCrypto {

View File

@@ -1,6 +1,9 @@
package org.briarproject.bramble.api.transport; package org.briarproject.bramble.api.transport;
import org.briarproject.bramble.api.crypto.SecretKey; import org.briarproject.bramble.api.crypto.SecretKey;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import javax.annotation.concurrent.Immutable;
import static org.briarproject.bramble.api.transport.TransportConstants.REORDERING_WINDOW_SIZE; import static org.briarproject.bramble.api.transport.TransportConstants.REORDERING_WINDOW_SIZE;
@@ -8,6 +11,8 @@ import static org.briarproject.bramble.api.transport.TransportConstants.REORDERI
* Contains transport keys for receiving streams from a given contact over a * Contains transport keys for receiving streams from a given contact over a
* given transport in a given rotation period. * given transport in a given rotation period.
*/ */
@Immutable
@NotNullByDefault
public class IncomingKeys { public class IncomingKeys {
private final SecretKey tagKey, headerKey; private final SecretKey tagKey, headerKey;

View File

@@ -1,11 +1,16 @@
package org.briarproject.bramble.api.transport; package org.briarproject.bramble.api.transport;
import org.briarproject.bramble.api.crypto.SecretKey; import org.briarproject.bramble.api.crypto.SecretKey;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import javax.annotation.concurrent.Immutable;
/** /**
* Contains transport keys for sending streams to a given contact over a given * Contains transport keys for sending streams to a given contact over a given
* transport in a given rotation period. * transport in a given rotation period.
*/ */
@Immutable
@NotNullByDefault
public class OutgoingKeys { public class OutgoingKeys {
private final SecretKey tagKey, headerKey; private final SecretKey tagKey, headerKey;

View File

@@ -2,8 +2,13 @@ package org.briarproject.bramble.api.transport;
import org.briarproject.bramble.api.contact.ContactId; import org.briarproject.bramble.api.contact.ContactId;
import org.briarproject.bramble.api.crypto.SecretKey; import org.briarproject.bramble.api.crypto.SecretKey;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import org.briarproject.bramble.api.plugin.TransportId; import org.briarproject.bramble.api.plugin.TransportId;
import javax.annotation.concurrent.Immutable;
@Immutable
@NotNullByDefault
public class StreamContext { public class StreamContext {
private final ContactId contactId; private final ContactId contactId;

View File

@@ -1,10 +1,15 @@
package org.briarproject.bramble.api.transport; package org.briarproject.bramble.api.transport;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import org.briarproject.bramble.api.plugin.TransportId; import org.briarproject.bramble.api.plugin.TransportId;
import javax.annotation.concurrent.Immutable;
/** /**
* Keys for communicating with a given contact over a given transport. * Keys for communicating with a given contact over a given transport.
*/ */
@Immutable
@NotNullByDefault
public class TransportKeys { public class TransportKeys {
private final TransportId transportId; private final TransportId transportId;
@@ -13,11 +18,11 @@ public class TransportKeys {
public TransportKeys(TransportId transportId, IncomingKeys inPrev, public TransportKeys(TransportId transportId, IncomingKeys inPrev,
IncomingKeys inCurr, IncomingKeys inNext, OutgoingKeys outCurr) { IncomingKeys inCurr, IncomingKeys inNext, OutgoingKeys outCurr) {
if (inPrev.getRotationPeriod() != inCurr.getRotationPeriod() - 1) if (inPrev.getRotationPeriod() != outCurr.getRotationPeriod() - 1)
throw new IllegalArgumentException(); throw new IllegalArgumentException();
if (inNext.getRotationPeriod() != inCurr.getRotationPeriod() + 1) if (inCurr.getRotationPeriod() != outCurr.getRotationPeriod())
throw new IllegalArgumentException(); throw new IllegalArgumentException();
if (outCurr.getRotationPeriod() != inCurr.getRotationPeriod()) if (inNext.getRotationPeriod() != outCurr.getRotationPeriod() + 1)
throw new IllegalArgumentException(); throw new IllegalArgumentException();
this.transportId = transportId; this.transportId = transportId;
this.inPrev = inPrev; this.inPrev = inPrev;