[briar-core] Add a getRealHandshakeLink() method to BriarTestUtils

Also allow testOutput from briar-core to be used in briar-headless
This commit is contained in:
Torsten Grote
2019-05-14 14:58:11 -03:00
parent 69e57bee61
commit dc6971734a
2 changed files with 28 additions and 0 deletions

View File

@@ -30,3 +30,15 @@ dependencies {
signature 'org.codehaus.mojo.signature:java16:1.1@signature'
}
// needed to make test output available to briar-headless
configurations {
testOutput.extendsFrom(testCompile)
}
task jarTest(type: Jar, dependsOn: testClasses) {
from sourceSets.test.output
classifier = 'test'
}
artifacts {
testOutput jarTest
}

View File

@@ -1,13 +1,19 @@
package org.briarproject.briar.test;
import org.briarproject.bramble.api.crypto.CryptoComponent;
import org.briarproject.bramble.api.crypto.KeyPair;
import org.briarproject.bramble.api.db.DbException;
import org.briarproject.bramble.api.identity.Author;
import org.briarproject.bramble.api.identity.AuthorFactory;
import org.briarproject.bramble.api.identity.LocalAuthor;
import org.briarproject.bramble.api.sync.GroupId;
import org.briarproject.bramble.util.Base32;
import org.briarproject.briar.api.client.MessageTracker;
import org.briarproject.briar.api.client.MessageTracker.GroupCount;
import static java.lang.System.arraycopy;
import static org.briarproject.bramble.api.contact.HandshakeLinkConstants.FORMAT_VERSION;
import static org.briarproject.bramble.api.contact.HandshakeLinkConstants.RAW_LINK_BYTES;
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_AUTHOR_NAME_LENGTH;
import static org.briarproject.bramble.util.StringUtils.getRandomString;
import static org.junit.Assert.assertEquals;
@@ -40,4 +46,14 @@ public class BriarTestUtils {
return authorFactory.createLocalAuthor(name);
}
public static String getRealHandshakeLink(CryptoComponent cryptoComponent) {
KeyPair keyPair = cryptoComponent.generateAgreementKeyPair();
byte[] linkBytes = new byte[RAW_LINK_BYTES];
byte[] version = new byte[] {FORMAT_VERSION};
byte[] publicKey = keyPair.getPublic().getEncoded();
arraycopy(version,0, linkBytes, 0, 1);
arraycopy(publicKey,0, linkBytes, 1, RAW_LINK_BYTES - 1);
return ("briar://" + Base32.encode(linkBytes)).toLowerCase();
}
}