Skip to content

Commit a0d50c1

Browse files
committed
Make curve names case-inspecific
1 parent c7f8d1e commit a0d50c1

File tree

2 files changed

+41
-4
lines changed

2 files changed

+41
-4
lines changed

src/net/i2p/crypto/eddsa/spec/EdDSANamedCurveTable.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
package net.i2p.crypto.eddsa.spec;
1313

1414
import java.util.Hashtable;
15+
import java.util.Locale;
1516

1617
import net.i2p.crypto.eddsa.Utils;
1718
import net.i2p.crypto.eddsa.math.Curve;
@@ -48,15 +49,15 @@ public class EdDSANamedCurveTable {
4849
private static final Hashtable<String, EdDSANamedCurveSpec> curves = new Hashtable<String, EdDSANamedCurveSpec>();
4950

5051
public static void defineCurve(String name, EdDSANamedCurveSpec curve) {
51-
curves.put(name, curve);
52+
curves.put(name.toLowerCase(Locale.ENGLISH), curve);
5253
}
5354

5455
static void defineCurveAlias(String name, String alias) {
55-
EdDSANamedCurveSpec curve = curves.get(name);
56+
EdDSANamedCurveSpec curve = curves.get(name.toLowerCase(Locale.ENGLISH));
5657
if (curve == null) {
5758
throw new IllegalStateException();
5859
}
59-
curves.put(alias, curve);
60+
curves.put(alias.toLowerCase(Locale.ENGLISH), curve);
6061
}
6162

6263
static {
@@ -67,6 +68,6 @@ static void defineCurveAlias(String name, String alias) {
6768
}
6869

6970
public static EdDSANamedCurveSpec getByName(String name) {
70-
return curves.get(name);
71+
return curves.get(name.toLowerCase(Locale.ENGLISH));
7172
}
7273
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* EdDSA-Java by str4d
3+
*
4+
* To the extent possible under law, the person who associated CC0 with
5+
* EdDSA-Java has waived all copyright and related or neighboring rights
6+
* to EdDSA-Java.
7+
*
8+
* You should have received a copy of the CC0 legalcode along with this
9+
* work. If not, see <https://creativecommons.org/publicdomain/zero/1.0/>.
10+
*
11+
*/
12+
package net.i2p.crypto.eddsa.spec;
13+
14+
import static org.hamcrest.Matchers.*;
15+
import static org.junit.Assert.*;
16+
17+
import org.junit.Test;
18+
19+
/**
20+
* @author str4d
21+
*
22+
*/
23+
public class EdDSANamedCurveTableTest {
24+
/**
25+
* Ensure curve names are case-inspecific
26+
*/
27+
@Test
28+
public void curveNamesAreCaseInspecific() {
29+
EdDSANamedCurveSpec mixed = EdDSANamedCurveTable.getByName("Ed25519");
30+
EdDSANamedCurveSpec lower = EdDSANamedCurveTable.getByName("ed25519");
31+
EdDSANamedCurveSpec upper = EdDSANamedCurveTable.getByName("ED25519");
32+
33+
assertThat(lower, is(equalTo(mixed)));
34+
assertThat(upper, is(equalTo(mixed)));
35+
}
36+
}

0 commit comments

Comments
 (0)