Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ public String getString()
throw new ASN1ParsingException("Internal error encoding BitString: " + e.getMessage(), e);
}

StringBuffer buf = new StringBuffer(1 + string.length * 2);
StringBuilder buf = new StringBuilder(1 + string.length * 2);
buf.append('#');

for (int i = 0; i != string.length; i++)
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/bouncycastle/asn1/ASN1Sequence.java
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ public String toString()
return "[]";
}

StringBuffer sb = new StringBuffer();
StringBuilder sb = new StringBuilder();
sb.append('[');
for (int i = 0;;)
{
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/bouncycastle/asn1/ASN1Set.java
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ public String toString()
return "[]";
}

StringBuffer sb = new StringBuffer();
StringBuilder sb = new StringBuilder();
sb.append('[');
for (int i = 0;;)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ private static String unescape(String elt)

boolean escaped = false;
boolean quoted = false;
StringBuffer buf = new StringBuffer(elt.length());
StringBuilder buf = new StringBuilder(elt.length());
int start = 0;

// if it's an escaped hash string and not an actual encoding in string form
Expand Down Expand Up @@ -367,7 +367,7 @@ public static void appendTypeAndValue(

public static String valueToString(ASN1Encodable value)
{
StringBuffer vBuf = new StringBuffer();
StringBuilder vBuf = new StringBuilder();

if (value instanceof ASN1String && !(value instanceof ASN1UniversalString))
{
Expand Down Expand Up @@ -507,12 +507,12 @@ private static ASN1Primitive decodeObject(String oValue)
public static String stripInternalSpaces(
String str)
{
if (str.indexOf(" ") < 0)
if (!str.contains(" "))
{
return str;
}

StringBuffer res = new StringBuffer();
StringBuilder res = new StringBuilder();

char c1 = str.charAt(0);
res.append(c1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public ASN1Primitive toASN1Primitive()

public String toString()
{
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
String sep = Strings.lineSeparator();

buf.append("CRLDistPoint:");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,12 @@ public ASN1Primitive toASN1Primitive()

public String toString()
{
StringBuffer p = new StringBuffer();
for (int i = 0; i < policyInformation.length; i++)
{
if (p.length() != 0)
{
StringBuilder p = new StringBuilder();
for (PolicyInformation information : policyInformation) {
if (p.length() != 0) {
p.append(", ");
}
p.append(policyInformation[i]);
p.append(information);
}

return "CertificatePolicies: [" + p + "]";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ public ASN1Encodable getName()

public String toString()
{
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();

buf.append(tag);
buf.append(": ");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public ASN1Primitive toASN1Primitive()

public String toString()
{
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
String sep = Strings.lineSeparator();

buf.append("GeneralNames:");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1825,7 +1825,7 @@ private static String extractHostFromURL(String url)
// remove ':' after protocol, e.g. https:
String sub = url.substring(url.indexOf(':') + 1);
// extract host from Common Internet Scheme Syntax, e.g. https://
if (sub.indexOf("//") != -1)
if (sub.contains("//"))
{
sub = sub.substring(sub.indexOf("//") + 2);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public void setV(BigInteger v)

public String toString()
{
StringBuffer result = new StringBuffer();
StringBuilder result = new StringBuilder();

result.append("u1: " + u1.toString());
result.append("\nu2: " + u2.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class HTMLFilter implements Filter

public String doFilter(String input)
{
StringBuffer buf = new StringBuffer(input);
StringBuilder buf = new StringBuilder(input);
int i = 0;
while (i < buf.length())
{
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/bouncycastle/math/ec/ECPoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ public String toString()
return "INF";
}

StringBuffer sb = new StringBuffer();
StringBuilder sb = new StringBuilder();
sb.append('(');
sb.append(getRawXCoord());
sb.append(',');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ private static void printGLVTypeBParameters(X9ECParameters x9, BigInteger lambda

private static void printProperty(String name, Object value)
{
StringBuffer sb = new StringBuffer(" ");
StringBuilder sb = new StringBuilder(" ");
sb.append(name);
while (sb.length() < 20)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1253,7 +1253,7 @@ public String toString()
d = length - 1;
}

StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
for (int i = 0; i < numRows; i++)
{
buf.append(i + ": ");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ public int hashCode()
*/
public String toString()
{
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
for (int i = 0; i < length; i++)
{
if ((i != 0) && ((i & 0x1f) == 0))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ public int hashCode()
*/
public String toString()
{
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
for (int i = 0; i < vector.length; i++)
{
for (int j = 0; j < field.getDegree(); j++)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.bouncycastle.pqc.legacy.math.ntru.polynomial;

import java.math.BigDecimal;
import java.math.RoundingMode;

/**
* A polynomial with {@link BigDecimal} coefficients.
Expand Down Expand Up @@ -214,7 +215,7 @@ public BigIntPolynomial round()
BigIntPolynomial p = new BigIntPolynomial(N);
for (int i = 0; i < N; i++)
{
p.coeffs[i] = coeffs[i].setScale(0, BigDecimal.ROUND_HALF_EVEN).toBigInteger();
p.coeffs[i] = coeffs[i].setScale(0, RoundingMode.HALF_EVEN).toBigInteger();
}
return p;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -284,14 +285,14 @@ public BigDecimalPolynomial div(BigDecimal divisor, int decimalPlaces)
BigInteger max = maxCoeffAbs();
int coeffLength = (int)(max.bitLength() * LOG_10_2) + 1;
// factor = 1/divisor
BigDecimal factor = Constants.BIGDEC_ONE.divide(divisor, coeffLength + decimalPlaces + 1, BigDecimal.ROUND_HALF_EVEN);
BigDecimal factor = Constants.BIGDEC_ONE.divide(divisor, coeffLength + decimalPlaces + 1, RoundingMode.HALF_EVEN);

// multiply each coefficient by factor
BigDecimalPolynomial p = new BigDecimalPolynomial(coeffs.length);
for (int i = 0; i < coeffs.length; i++)
// multiply, then truncate after decimalPlaces so subsequent operations aren't slowed down
{
p.coeffs[i] = new BigDecimal(coeffs[i]).multiply(factor).setScale(decimalPlaces, BigDecimal.ROUND_HALF_EVEN);
p.coeffs[i] = new BigDecimal(coeffs[i]).multiply(factor).setScale(decimalPlaces, RoundingMode.HALF_EVEN);
}

return p;
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/bouncycastle/util/Fingerprint.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public byte[] getFingerprint()

public String toString()
{
StringBuffer sb = new StringBuffer();
StringBuilder sb = new StringBuilder();
for (int i = 0; i != fingerprint.length; i++)
{
if (i > 0)
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/org/bouncycastle/util/test/SimpleTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,9 @@ public Exception testException(String failMessage, String exceptionClass, TestEx
{
if (failMessage != null)
{
isTrue(e.getMessage(), e.getMessage().indexOf(failMessage) >= 0);
isTrue(e.getMessage(), e.getMessage().contains(failMessage));
}
isTrue(e.getMessage(),e.getClass().getName().indexOf(exceptionClass) >= 0);
isTrue(e.getMessage(), e.getClass().getName().contains(exceptionClass));
return e;
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ private void testReset(String test,
cipher1.init(true, params);

byte[] plaintext = new byte[cipher1.getBlockSize()];
byte[] ciphertext = new byte[(cipher1.getAlgorithmName().indexOf("PGPCFBwithIV")) > -1 ? 2 * cipher1.getBlockSize() + 2
byte[] ciphertext = new byte[cipher1.getAlgorithmName().contains("PGPCFBwithIV") ? 2 * cipher1.getBlockSize() + 2
: cipher1.getBlockSize()];

// Establish baseline answer
Expand Down Expand Up @@ -191,7 +191,7 @@ private static void crypt(BlockCipher cipher1, boolean encrypt, byte[] plaintext
throws InvalidCipherTextException
{
cipher1.processBlock(plaintext, 0, output, 0);
if ((cipher1.getAlgorithmName().indexOf("PGPCFBwithIV") > -1) && !encrypt)
if ((cipher1.getAlgorithmName().contains("PGPCFBwithIV")) && !encrypt)
{
// Process past IV in first block
cipher1.processBlock(plaintext, cipher1.getBlockSize(), output, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ private void runAllVectors(StreamCipher hc, String fileName, PeekableLineReader

private String dellChar(String s, char c)
{
StringBuffer b = new StringBuffer();
StringBuilder b = new StringBuilder();

for (int i = 0; i != s.length(); i++)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void testInputTooShort()
}
catch (IllegalStateException ilarex)
{
isTrue("message", contains(ilarex.getMessage(), "input must be exactly 32 bytes"));
isTrue("message", ilarex.getMessage().contains("input must be exactly 32 bytes"));
}
}

Expand All @@ -59,7 +59,7 @@ public void testInputTooLong()
}
catch (IllegalArgumentException ilarex)
{
isTrue("long message", contains(ilarex.getMessage(), "total input cannot be more than 32 bytes"));
isTrue("long message", ilarex.getMessage().contains("total input cannot be more than 32 bytes"));
}
}

Expand All @@ -80,7 +80,7 @@ public void testOutput()
}
catch (IllegalArgumentException ilarex)
{
isTrue("message 1", contains(ilarex.getMessage(), "output too short to receive digest"));
isTrue("message 1", ilarex.getMessage().contains("output too short to receive digest"));
}

//
Expand All @@ -97,7 +97,7 @@ public void testOutput()
}
catch (IllegalArgumentException ilarex)
{
isTrue("message 2", contains(ilarex.getMessage(), "output too short to receive digest"));
isTrue("message 2", ilarex.getMessage().contains("output too short to receive digest"));
}


Expand Down Expand Up @@ -163,11 +163,6 @@ void testMonty()
}
}

private boolean contains(String message, String sub)
{
return message.indexOf(sub) >= 0;
}

public void performTest()
throws Exception
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void testInputTooShort()
}
catch (IllegalStateException ilarex)
{
isTrue("message", contains(ilarex.getMessage(), "input must be exactly 64 bytes"));
isTrue("message", ilarex.getMessage().contains("input must be exactly 64 bytes"));
}
}

Expand All @@ -58,7 +58,7 @@ public void testInputTooLong()
}
catch (IllegalArgumentException ilarex)
{
isTrue("message", contains(ilarex.getMessage(), "total input cannot be more than 64 bytes"));
isTrue("message", ilarex.getMessage().contains("total input cannot be more than 64 bytes"));
}
}

Expand All @@ -78,7 +78,7 @@ public void testOutput()
}
catch (IllegalArgumentException ilarex)
{
isTrue("message", contains(ilarex.getMessage(), "output too short to receive digest"));
isTrue("message", ilarex.getMessage().contains("output too short to receive digest"));
}

//
Expand All @@ -95,7 +95,7 @@ public void testOutput()
}
catch (IllegalArgumentException ilarex)
{
isTrue("message", contains(ilarex.getMessage(), "output too short to receive digest"));
isTrue("message", ilarex.getMessage().contains("output too short to receive digest"));
}

//
Expand Down Expand Up @@ -169,11 +169,6 @@ void testMonty()
}
}

private boolean contains(String message, String sub)
{
return message.indexOf(sub) >= 0;
}

public void performTest()
throws Exception
{
Expand Down
6 changes: 3 additions & 3 deletions core/src/test/java/org/bouncycastle/crypto/test/LEATest.java
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ else if (line.startsWith("IV:"))
}
else if (line.startsWith("Test:"))
{
if (comment.indexOf("ECB") >= 0)
if (comment.contains("ECB"))
{
LEAEngine engine = new LEAEngine();
if (line.endsWith("Encrypt"))
Expand Down Expand Up @@ -216,11 +216,11 @@ else if (line.endsWith("Decrypt"))
}

}
else if (comment.indexOf("CTR") >= 0 || comment.indexOf("CBC") >= 0)
else if (comment.contains("CTR") || comment.contains("CBC"))
{
BlockCipher engine;

if (comment.indexOf("CBC") >= 0)
if (comment.contains("CBC"))
{
engine = CBCBlockCipher.newInstance(new LEAEngine());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ private void randMult(String label, X9ECParameters spec) throws Exception

double avgRate = randMult(random, g, n);
String coordName = COORD_NAMES[coord];
StringBuffer sb = new StringBuffer();
StringBuilder sb = new StringBuilder();
sb.append(" ");
sb.append(defaultCoord ? '*' : ' ');
sb.append(coordName);
Expand Down
Loading