Skip to content

Commit 38e559d

Browse files
committed
Merge pull request #5 from pmarches/master
Added maven support and small test cleanup
2 parents 1a38980 + 8253fbe commit 38e559d

File tree

4 files changed

+76
-25
lines changed

4 files changed

+76
-25
lines changed

pom.xml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>net.i2p.crypto</groupId>
5+
<artifactId>eddsa</artifactId>
6+
<version>0.0.1-SNAPSHOT</version>
7+
<name>ed25519-java</name>
8+
<description>Implementation of EdDSA in Java</description>
9+
<build>
10+
<sourceDirectory>src</sourceDirectory>
11+
<testSourceDirectory>test</testSourceDirectory>
12+
<testResources>
13+
<testResource>
14+
<directory>test</directory>
15+
<excludes>
16+
<exclude>**/*.java</exclude>
17+
</excludes>
18+
</testResource>
19+
</testResources>
20+
<plugins>
21+
<plugin>
22+
<groupId>org.apache.maven.plugins</groupId>
23+
<artifactId>maven-compiler-plugin</artifactId>
24+
<configuration>
25+
<source>1.6</source>
26+
<target>1.6</target>
27+
<encoding>${project.build.sourceEncoding}</encoding>
28+
</configuration>
29+
<version>3.1</version>
30+
</plugin>
31+
<plugin>
32+
<groupId>org.apache.maven.plugins</groupId>
33+
<artifactId>maven-surefire-plugin</artifactId>
34+
<version>2.17</version>
35+
<configuration>
36+
<skipTests>true</skipTests>
37+
</configuration>
38+
</plugin>
39+
</plugins>
40+
</build>
41+
<dependencies>
42+
<dependency>
43+
<groupId>org.hamcrest</groupId>
44+
<artifactId>hamcrest-all</artifactId>
45+
<version>1.3</version>
46+
<scope>test</scope>
47+
</dependency>
48+
<dependency>
49+
<groupId>junit</groupId>
50+
<artifactId>junit</artifactId>
51+
<version>4.11</version>
52+
<type>maven-plugin</type>
53+
<scope>test</scope>
54+
</dependency>
55+
</dependencies>
56+
</project>

src/net/i2p/crypto/eddsa/Utils.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,22 @@ public static byte[] hexToBytes(String s) {
6363
}
6464
return data;
6565
}
66+
67+
/**
68+
* Converts bytes to a hex string.
69+
* @param raw the byte[] to be converted.
70+
* @return the hex representation as a string.
71+
*/
72+
public static String bytesToHex(byte[] raw) {
73+
if ( raw == null ) {
74+
return null;
75+
}
76+
final StringBuilder hex = new StringBuilder(2 * raw.length);
77+
for (final byte b : raw) {
78+
hex.append(Character.forDigit((b & 0xF0) >> 4, 16))
79+
.append(Character.forDigit((b & 0x0F), 16));
80+
}
81+
return hex.toString();
82+
}
83+
6684
}

src/net/i2p/crypto/eddsa/math/ed25519/Ed25519FieldElement.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package net.i2p.crypto.eddsa.math.ed25519;
22

3-
import net.i2p.crypto.eddsa.TestUtils;
43
import net.i2p.crypto.eddsa.Utils;
54
import net.i2p.crypto.eddsa.math.Field;
65
import net.i2p.crypto.eddsa.math.FieldElement;
@@ -956,13 +955,11 @@ public boolean equals(Object obj) {
956955
if (!(obj instanceof Ed25519FieldElement))
957956
return false;
958957
Ed25519FieldElement fe = (Ed25519FieldElement) obj;
959-
// XXX why does direct byte[] comparison fail?
960-
// TODO should this be constant time?
961-
return TestUtils.getHex(toByteArray()).equals(TestUtils.getHex(fe.toByteArray()));
958+
return 1==Utils.equal(toByteArray(), fe.toByteArray());
962959
}
963960

964961
@Override
965962
public String toString() {
966-
return "[Ed25519FieldElement val="+TestUtils.getHex(toByteArray())+"]";
963+
return "[Ed25519FieldElement val="+Utils.bytesToHex(toByteArray())+"]";
967964
}
968965
}

test/net/i2p/crypto/eddsa/TestUtils.java

Lines changed: 0 additions & 20 deletions
This file was deleted.

0 commit comments

Comments
 (0)