Skip to content

Commit b41f239

Browse files
committed
ErrorProne noise reduction.
1 parent d87f83d commit b41f239

File tree

3 files changed

+39
-8
lines changed

3 files changed

+39
-8
lines changed

core/src/test/java/org/bouncycastle/asn1/test/DLExternalTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ private void checkRealDataExample(int encoding, DLExternal dle)
184184
isTrue("check tag", objNameTagged.hasContextTag(3));
185185
isEquals("check implicit", false, objNameTagged.isExplicit());
186186
isEquals("check tagged object: " + objNameTagged.getBaseUniversal(false, BERTags.OCTET_STRING).getClass(), DEROctetString.class.getName(), objNameTagged.getBaseUniversal(false, BERTags.OCTET_STRING).getClass().getName());
187-
isEquals("check O", "Organization", new String(((DEROctetString)objNameTagged.getBaseUniversal(false, BERTags.OCTET_STRING)).getOctets(), "8859_1"));
187+
isEquals("check O", "Organization", StringTestUtil.fromISO_8891(((DEROctetString)objNameTagged.getBaseUniversal(false, BERTags.OCTET_STRING)).getOctets()));
188188
isEquals("check fourth element in set: " + objNameElems.getObjectAt(3).getClass(), DLTaggedObject.class.getName(), objNameElems.getObjectAt(3).getClass().getName());
189189
objNameTagged = (DLTaggedObject)objNameElems.getObjectAt(3);
190190
isTrue("check tag", objNameTagged.hasContextTag(5));
@@ -194,7 +194,7 @@ private void checkRealDataExample(int encoding, DLExternal dle)
194194
isTrue("check tag", objNameTagged.hasContextTag(0));
195195
isEquals("check implicit", false, objNameTagged.isExplicit());
196196
isEquals("check tagged object: " + objNameTagged.getBaseUniversal(false, BERTags.OCTET_STRING).getClass(), DEROctetString.class.getName(), objNameTagged.getBaseUniversal(false, BERTags.OCTET_STRING).getClass().getName());
197-
isEquals("check CN", "Common Name", new String(((DEROctetString)objNameTagged.getBaseUniversal(false, BERTags.OCTET_STRING)).getOctets(), "8859_1"));
197+
isEquals("check CN", "Common Name", StringTestUtil.fromISO_8891(((DEROctetString)objNameTagged.getBaseUniversal(false, BERTags.OCTET_STRING)).getOctets()));
198198

199199
isEquals("check second element in set: " + msBindSet.getObjectAt(1).getClass(), DLTaggedObject.class.getName(), msBindSet.getObjectAt(1).getClass().getName());
200200
DLTaggedObject password = (DLTaggedObject)msBindSet.getObjectAt(1);
@@ -216,8 +216,8 @@ private ASN1EncodableVector createRealDataExample(int encoding)
216216
ASN1EncodableVector objectNameVec = new ASN1EncodableVector();
217217
objectNameVec.add(new DLTaggedObject(BERTags.APPLICATION, 0, new DERPrintableString("de")));
218218
objectNameVec.add(new DLTaggedObject(BERTags.APPLICATION, 2, new DERPrintableString("viaT")));
219-
objectNameVec.add(new DLTaggedObject(false, 3, new DEROctetString("Organization".getBytes("8859_1"))));
220-
objectNameVec.add(new DLTaggedObject(true, 5, new DLTaggedObject(false, 0, new DEROctetString("Common Name".getBytes("8859_1")))));
219+
objectNameVec.add(new DLTaggedObject(false, 3, new DEROctetString(StringTestUtil.toISO_8891("Organization"))));
220+
objectNameVec.add(new DLTaggedObject(true, 5, new DLTaggedObject(false, 0, new DEROctetString(StringTestUtil.toISO_8891("Common Name")))));
221221

222222
DLTaggedObject objectName = new DLTaggedObject(BERTags.APPLICATION, 0, new DLSequence(objectNameVec));
223223
DLTaggedObject password = new DLTaggedObject(true, 2, new DERIA5String("SomePassword"));

core/src/test/java/org/bouncycastle/asn1/test/StringTest.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package org.bouncycastle.asn1.test;
22

33
import java.io.IOException;
4-
import java.io.UnsupportedEncodingException;
54

65
import org.bouncycastle.asn1.ASN1Primitive;
76
import org.bouncycastle.asn1.ASN1String;
@@ -90,7 +89,7 @@ public void performTest()
9089

9190
try
9291
{
93-
String t61String = new String(t61Bytes, "iso-8859-1");
92+
String t61String = StringTestUtil.fromISO_8891(t61Bytes);
9493
ASN1T61String t61 = new DERT61String(Strings.fromByteArray(t61Bytes));
9594

9695
if (!t61.getString().equals(t61String))
@@ -103,8 +102,8 @@ public void performTest()
103102
fail("DERT61String.toString() result incorrect");
104103
}
105104
}
106-
catch (UnsupportedEncodingException e)
107-
{
105+
catch (IllegalStateException e)
106+
{
108107
// ignore test
109108
}
110109

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package org.bouncycastle.asn1.test;
2+
3+
import java.io.UnsupportedEncodingException;
4+
5+
import org.bouncycastle.util.Exceptions;
6+
7+
class StringTestUtil
8+
{
9+
static byte[] toISO_8891(String str)
10+
{
11+
try
12+
{
13+
return str.getBytes("iso-8859-1");
14+
}
15+
catch (UnsupportedEncodingException e)
16+
{
17+
throw Exceptions.illegalStateException(e.getMessage(), e);
18+
}
19+
}
20+
21+
static String fromISO_8891(byte[] encStr)
22+
{
23+
try
24+
{
25+
return new String(encStr, "iso-8859-1");
26+
}
27+
catch (UnsupportedEncodingException e)
28+
{
29+
throw Exceptions.illegalStateException(e.getMessage(), e);
30+
}
31+
}
32+
}

0 commit comments

Comments
 (0)