Skip to content

Commit ab5caf6

Browse files
committed
Refactor StandardDSAEncoding
1 parent 54d7959 commit ab5caf6

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

core/src/main/java/org/bouncycastle/crypto/signers/StandardDSAEncoding.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,9 @@ public class StandardDSAEncoding
1616
{
1717
public static final StandardDSAEncoding INSTANCE = new StandardDSAEncoding();
1818

19-
public byte[] encode(BigInteger n, BigInteger r, BigInteger s) throws IOException
20-
{
21-
ASN1EncodableVector v = new ASN1EncodableVector();
22-
encodeValue(n, v, r);
23-
encodeValue(n, v, s);
24-
return new DERSequence(v).getEncoded(ASN1Encoding.DER);
25-
}
26-
2719
public BigInteger[] decode(BigInteger n, byte[] encoding) throws IOException
2820
{
29-
ASN1Sequence seq = (ASN1Sequence)ASN1Primitive.fromByteArray(encoding);
21+
ASN1Sequence seq = ASN1Sequence.getInstance(encoding);
3022
if (seq.size() == 2)
3123
{
3224
BigInteger r = decodeValue(n, seq, 0);
@@ -42,6 +34,14 @@ public BigInteger[] decode(BigInteger n, byte[] encoding) throws IOException
4234
throw new IllegalArgumentException("Malformed signature");
4335
}
4436

37+
public byte[] encode(BigInteger n, BigInteger r, BigInteger s) throws IOException
38+
{
39+
return new DERSequence(
40+
encodeValue(n, r),
41+
encodeValue(n, s)
42+
).getEncoded(ASN1Encoding.DER);
43+
}
44+
4545
protected BigInteger checkValue(BigInteger n, BigInteger x)
4646
{
4747
if (x.signum() < 0 || (null != n && x.compareTo(n) >= 0))
@@ -57,8 +57,8 @@ protected BigInteger decodeValue(BigInteger n, ASN1Sequence s, int pos)
5757
return checkValue(n, ((ASN1Integer)s.getObjectAt(pos)).getValue());
5858
}
5959

60-
protected void encodeValue(BigInteger n, ASN1EncodableVector v, BigInteger x)
60+
protected ASN1Integer encodeValue(BigInteger n, BigInteger x)
6161
{
62-
v.add(new ASN1Integer(checkValue(n, x)));
62+
return new ASN1Integer(checkValue(n, x));
6363
}
6464
}

0 commit comments

Comments
 (0)