Skip to content

Commit 643e8be

Browse files
committed
CryptoKey: assorted cleanup
1 parent 1fb091a commit 643e8be

File tree

3 files changed

+12
-21
lines changed

3 files changed

+12
-21
lines changed

src/freenet/crypt/DSAGroup.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
*/
2121
public class DSAGroup extends CryptoKey {
2222
private static final long serialVersionUID = -1;
23-
24-
protected static final int Q_BIT_LENGTH = 256;
2523

2624
private final BigInteger p, q, g;
2725

src/freenet/crypt/DSAPrivateKey.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@ public SimpleFieldSet asFieldSet() {
6767
}
6868

6969
public static DSAPrivateKey create(SimpleFieldSet fs, DSAGroup group) throws IllegalBase64Exception {
70-
BigInteger y = new BigInteger(1, Base64.decode(fs.get("x")));
71-
if(y.bitLength() > 512)
70+
BigInteger x = new BigInteger(1, Base64.decode(fs.get("x")));
71+
if (x.bitLength() > 512) {
7272
throw new IllegalBase64Exception("Probably a pubkey");
73-
return new DSAPrivateKey(y, group);
73+
}
74+
return new DSAPrivateKey(x, group);
7475
}
7576
}
76-

src/freenet/crypt/DSAPublicKey.java

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ public DSAPublicKey(DSAGroup g, BigInteger y) {
3333
if(y.signum() != 1)
3434
throw new IllegalArgumentException();
3535
this.y = y;
36-
if(g == Global.DSAgroupBigA) g = null;
37-
this.group = g;
38-
if(y.compareTo(getGroup().getP()) > 0)
39-
throw new IllegalArgumentException("y must be < p but y=" + y + " p=" + g.getP());
36+
this.group = g == Global.DSAgroupBigA ? null : g;
37+
if (y.compareTo(getGroup().getP()) > 0) {
38+
throw new IllegalArgumentException("y must be < p but y=" + y + " p=" + getGroup().getP());
39+
}
4040
}
4141

4242
/**
@@ -88,10 +88,8 @@ public String keyType() {
8888
return "DSA.p";
8989
}
9090

91-
// Nope, this is fine
9291
public final DSAGroup getGroup() {
93-
if(group == null) return Global.DSAgroupBigA;
94-
else return group;
92+
return group == null ? Global.DSAgroupBigA : group;
9593
}
9694

9795
public static CryptoKey read(InputStream i) throws IOException, CryptFormatException {
@@ -160,15 +158,10 @@ public SimpleFieldSet asFieldSet() {
160158
}
161159

162160
public static DSAPublicKey create(SimpleFieldSet set, DSAGroup group) throws FSParseException {
163-
BigInteger x;
164-
try {
165-
x = new BigInteger(1, Base64.decode(set.get("y")));
166-
} catch (IllegalBase64Exception e) {
167-
throw new FSParseException(e);
168-
}
169161
try {
170-
return new DSAPublicKey(group, x);
171-
} catch (IllegalArgumentException e) {
162+
BigInteger y = new BigInteger(1, Base64.decode(set.get("y")));
163+
return new DSAPublicKey(group, y);
164+
} catch (IllegalBase64Exception | IllegalArgumentException e) {
172165
throw new FSParseException(e);
173166
}
174167
}

0 commit comments

Comments
 (0)