Skip to content
Snippets Groups Projects
Verified Commit a35e9af1 authored by akwizgran's avatar akwizgran Committed by Daniel Lublin
Browse files

Add method for generating a unique ID, remove equals() methods.

parent ade89c14
No related branches found
No related tags found
No related merge requests found
......@@ -6,14 +6,14 @@ import javax.annotation.concurrent.ThreadSafe;
@ThreadSafe
@NotNullByDefault
public abstract class UniqueId extends Bytes {
public class UniqueId extends Bytes {
/**
* The length of a unique identifier in bytes.
*/
public static final int LENGTH = 32;
protected UniqueId(byte[] id) {
public UniqueId(byte[] id) {
super(id);
if (id.length != LENGTH) throw new IllegalArgumentException();
}
......
......@@ -3,7 +3,6 @@ package org.briarproject.bramble.api.contact;
import org.briarproject.bramble.api.UniqueId;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import javax.annotation.Nullable;
import javax.annotation.concurrent.ThreadSafe;
/**
......@@ -17,9 +16,4 @@ public class PendingContactId extends UniqueId {
public PendingContactId(byte[] id) {
super(id);
}
@Override
public boolean equals(@Nullable Object o) {
return o instanceof PendingContactId && super.equals(o);
}
}
package org.briarproject.bramble.api.crypto;
import org.briarproject.bramble.api.UniqueId;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import java.security.GeneralSecurityException;
......@@ -10,6 +11,8 @@ import javax.annotation.Nullable;
@NotNullByDefault
public interface CryptoComponent {
UniqueId generateUniqueId();
SecretKey generateSecretKey();
SecureRandom getSecureRandom();
......
......@@ -21,9 +21,4 @@ public class AuthorId extends UniqueId {
public AuthorId(byte[] id) {
super(id);
}
@Override
public boolean equals(Object o) {
return o instanceof AuthorId && super.equals(o);
}
}
......@@ -20,9 +20,4 @@ public class GroupId extends UniqueId {
public GroupId(byte[] id) {
super(id);
}
@Override
public boolean equals(Object o) {
return o instanceof GroupId && super.equals(o);
}
}
......@@ -27,9 +27,4 @@ public class MessageId extends UniqueId {
public MessageId(byte[] id) {
super(id);
}
@Override
public boolean equals(Object o) {
return o instanceof MessageId && super.equals(o);
}
}
......@@ -8,6 +8,7 @@ import org.bouncycastle.crypto.CryptoException;
import org.bouncycastle.crypto.Digest;
import org.bouncycastle.crypto.digests.Blake2bDigest;
import org.bouncycastle.crypto.digests.SHA3Digest;
import org.briarproject.bramble.api.UniqueId;
import org.briarproject.bramble.api.crypto.AgreementPrivateKey;
import org.briarproject.bramble.api.crypto.AgreementPublicKey;
import org.briarproject.bramble.api.crypto.CryptoComponent;
......@@ -41,6 +42,7 @@ import javax.inject.Inject;
import static java.lang.System.arraycopy;
import static java.util.logging.Level.INFO;
import static java.util.logging.Logger.getLogger;
import static org.briarproject.bramble.api.crypto.CryptoConstants.KEY_TYPE_AGREEMENT;
import static org.briarproject.bramble.api.crypto.CryptoConstants.KEY_TYPE_SIGNATURE;
import static org.briarproject.bramble.api.crypto.DecryptionResult.INVALID_CIPHERTEXT;
......@@ -54,7 +56,7 @@ import static org.briarproject.bramble.util.LogUtils.now;
class CryptoComponentImpl implements CryptoComponent {
private static final Logger LOG =
Logger.getLogger(CryptoComponentImpl.class.getName());
getLogger(CryptoComponentImpl.class.getName());
private static final int SIGNATURE_KEY_PAIR_BITS = 256;
private static final int STORAGE_IV_BYTES = 24; // 196 bits
......@@ -128,6 +130,13 @@ class CryptoComponentImpl implements CryptoComponent {
}
}
@Override
public UniqueId generateUniqueId() {
byte[] b = new byte[UniqueId.LENGTH];
secureRandom.nextBytes(b);
return new UniqueId(b);
}
@Override
public SecretKey generateSecretKey() {
byte[] b = new byte[SecretKey.LENGTH];
......
......@@ -16,9 +16,4 @@ public class SessionId extends UniqueId {
public SessionId(byte[] id) {
super(id);
}
@Override
public boolean equals(Object o) {
return o instanceof SessionId && super.equals(o);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment