diff --git a/src/main/java/emissary/core/IBaseDataObjectXmlCodecs.java b/src/main/java/emissary/core/IBaseDataObjectXmlCodecs.java index daf6e69518..bd4e89555c 100644 --- a/src/main/java/emissary/core/IBaseDataObjectXmlCodecs.java +++ b/src/main/java/emissary/core/IBaseDataObjectXmlCodecs.java @@ -535,11 +535,11 @@ public void encode(final List values, final Element private static Element protectedElementHash(final String name, final byte[] bytes) { final Element element = new Element(name); - if (ByteUtil.hasNonPrintableValues(bytes)) { + if (ByteUtil.containsNonIndexableBytes(bytes)) { element.setAttribute(ENCODING_ATTRIBUTE_NAME, SHA256); element.addContent(ByteUtil.sha256Bytes(bytes)); } else { - element.addContent(new String(bytes, StandardCharsets.ISO_8859_1)); + element.addContent(new String(bytes, StandardCharsets.UTF_8)); } return element; @@ -777,7 +777,7 @@ public static Element protectedElement(final String name, final String string) { public static Element protectedElementBase64(final String name, final byte[] bytes) { final Element element = new Element(name); - if (ByteUtil.hasNonPrintableValues(bytes)) { + if (ByteUtil.containsNonIndexableBytes(bytes)) { String base64String = BASE64_NEW_LINE_STRING + BASE64_ENCODER.encodeToString(bytes) + BASE64_NEW_LINE_STRING; @@ -785,7 +785,7 @@ public static Element protectedElementBase64(final String name, final byte[] byt element.setAttribute(ENCODING_ATTRIBUTE_NAME, BASE64); element.addContent(base64String); } else { - element.addContent(new String(bytes, StandardCharsets.ISO_8859_1)); + element.addContent(new String(bytes, StandardCharsets.UTF_8)); } return element; @@ -803,11 +803,11 @@ public static Element protectedElementBase64(final String name, final byte[] byt public static Element protectedElementSha256(final String name, final byte[] bytes) { final Element element = new Element(name); - if (ByteUtil.hasNonPrintableValues(bytes)) { + if (ByteUtil.containsNonIndexableBytes(bytes)) { element.setAttribute(IBaseDataObjectXmlCodecs.ENCODING_ATTRIBUTE_NAME, IBaseDataObjectXmlCodecs.SHA256); element.addContent(ByteUtil.sha256Bytes(bytes)); } else { - element.addContent(new String(bytes, StandardCharsets.ISO_8859_1)); + element.addContent(new String(bytes, StandardCharsets.UTF_8)); } return element; diff --git a/src/test/java/emissary/core/IBaseDataObjectXmlHelperTest.java b/src/test/java/emissary/core/IBaseDataObjectXmlHelperTest.java index 499bd4d920..e35a7ad60d 100644 --- a/src/test/java/emissary/core/IBaseDataObjectXmlHelperTest.java +++ b/src/test/java/emissary/core/IBaseDataObjectXmlHelperTest.java @@ -69,8 +69,8 @@ private static void setAllFieldsPrintable(final IBaseDataObject ibdo, final byte ibdo.setFilename("Filename"); ibdo.setFileType("FileType"); ibdo.setFontEncoding("FontEncoding"); - ibdo.setFooter("Footer".getBytes(StandardCharsets.ISO_8859_1)); - ibdo.setHeader("Header".getBytes(StandardCharsets.ISO_8859_1)); + ibdo.setFooter("Footer".getBytes(StandardCharsets.UTF_8)); + ibdo.setHeader("Header".getBytes(StandardCharsets.UTF_8)); ibdo.setHeaderEncoding("HeaderEncoding"); ibdo.setId("Id"); ibdo.setNumChildren(9); @@ -84,8 +84,8 @@ private static void setAllFieldsPrintable(final IBaseDataObject ibdo, final byte ibdo.putParameter("Parameter1Key", "Parameter1Value"); ibdo.putParameter("Parameter2Key", Arrays.asList("Parameter2Value1", "Parameter2Value2")); ibdo.putParameter("Parameter3Key", Arrays.asList(10L, 20L)); - ibdo.addAlternateView("AlternateView1Key", "AlternateView1Value".getBytes(StandardCharsets.ISO_8859_1)); - ibdo.addAlternateView("AlternateView11Key", "AlternateView11Value".getBytes(StandardCharsets.ISO_8859_1)); + ibdo.addAlternateView("AlternateView1Key", "AlternateView1Value".getBytes(StandardCharsets.UTF_8)); + ibdo.addAlternateView("AlternateView11Key", "AlternateView11Value".getBytes(StandardCharsets.UTF_8)); } private static void setAllFieldsNonPrintable(final IBaseDataObject ibdo, final byte[] bytes) { @@ -99,8 +99,8 @@ private static void setAllFieldsNonPrintable(final IBaseDataObject ibdo, final b ibdo.setFilename("\001Filename"); ibdo.setFileType("\001FileType"); ibdo.setFontEncoding("\001FontEncoding"); - ibdo.setFooter("\001Footer".getBytes(StandardCharsets.ISO_8859_1)); - ibdo.setHeader("\001Header".getBytes(StandardCharsets.ISO_8859_1)); + ibdo.setFooter("\001Footer".getBytes(StandardCharsets.UTF_8)); + ibdo.setHeader("\001Header".getBytes(StandardCharsets.UTF_8)); ibdo.setHeaderEncoding("\001HeaderEncoding"); ibdo.setId("\001Id"); ibdo.setNumChildren(9); @@ -114,9 +114,9 @@ private static void setAllFieldsNonPrintable(final IBaseDataObject ibdo, final b ibdo.putParameter("\020Parameter1Key", "\020Parameter1Value"); ibdo.putParameter("\020Parameter2Key", "\020Parameter2Value"); ibdo.addAlternateView("\200AlternateView1Key", - "\200AlternateView1Value".getBytes(StandardCharsets.ISO_8859_1)); + "\200AlternateView1Value".getBytes(StandardCharsets.UTF_8)); ibdo.addAlternateView("\200AlternateView11Key", - "\200AlternateView11Value".getBytes(StandardCharsets.ISO_8859_1)); + "\200AlternateView11Value".getBytes(StandardCharsets.UTF_8)); } @Test @@ -125,7 +125,7 @@ void testParentIbdoAllFieldsChanged() throws Exception { final IBaseDataObject expectedIbdo = new BaseDataObject(); final List expectedChildren = new ArrayList<>(); final List actualChildren = new ArrayList<>(); - final byte[] bytes = "Data".getBytes(StandardCharsets.ISO_8859_1); + final byte[] bytes = "Data".getBytes(StandardCharsets.UTF_8); setAllFieldsPrintable(expectedIbdo, bytes); @@ -150,7 +150,7 @@ void testBase64Conversion() throws Exception { final IBaseDataObject expectedIbdo = new BaseDataObject(); final List expectedChildren = new ArrayList<>(); final List actualChildren = new ArrayList<>(); - final byte[] bytes = "\001Data".getBytes(StandardCharsets.ISO_8859_1); + final byte[] bytes = "\001Data".getBytes(StandardCharsets.UTF_8); setAllFieldsNonPrintable(expectedIbdo, bytes); @@ -164,10 +164,10 @@ void testBase64Conversion() throws Exception { final IBaseDataObject sha256ActualIbdo = ibdoFromXmlFromIbdo(expectedIbdo, expectedChildren, initialIbdo, actualChildren, SHA256_ELEMENT_ENCODERS); - expectedIbdo.setData(ByteUtil.sha256Bytes(bytes).getBytes(StandardCharsets.ISO_8859_1)); + expectedIbdo.setData(ByteUtil.sha256Bytes(bytes).getBytes(StandardCharsets.UTF_8)); for (Entry entry : new TreeMap<>(expectedIbdo.getAlternateViews()).entrySet()) { - expectedIbdo.addAlternateView(entry.getKey(), ByteUtil.sha256Bytes(entry.getValue()).getBytes(StandardCharsets.ISO_8859_1)); + expectedIbdo.addAlternateView(entry.getKey(), ByteUtil.sha256Bytes(entry.getValue()).getBytes(StandardCharsets.UTF_8)); } final String sha256Diff = PlaceComparisonHelper.checkDifferences(expectedIbdo, sha256ActualIbdo, expectedChildren, @@ -180,7 +180,7 @@ void testBase64Conversion() throws Exception { void testLengthAttributeDefault() throws Exception { final IBaseDataObject ibdo = new BaseDataObject(); final List children = new ArrayList<>(); - final byte[] bytes = "Data".getBytes(StandardCharsets.ISO_8859_1); + final byte[] bytes = "Data".getBytes(StandardCharsets.UTF_8); setAllFieldsPrintable(ibdo, bytes); @@ -201,7 +201,7 @@ void testLengthAttributeDefault() throws Exception { void testLengthAttributeHash() throws Exception { final IBaseDataObject ibdo = new BaseDataObject(); final List children = new ArrayList<>(); - final byte[] bytes = "Data".getBytes(StandardCharsets.ISO_8859_1); + final byte[] bytes = "Data".getBytes(StandardCharsets.UTF_8); setAllFieldsNonPrintable(ibdo, bytes); diff --git a/src/test/java/emissary/test/core/junit5/RegressionTest.java b/src/test/java/emissary/test/core/junit5/RegressionTest.java index 5f6c1462bb..98f51c828b 100644 --- a/src/test/java/emissary/test/core/junit5/RegressionTest.java +++ b/src/test/java/emissary/test/core/junit5/RegressionTest.java @@ -182,7 +182,7 @@ protected void checkAnswersPreHook(final Document answers, final IBaseDataObject // touch up alternate views to match how their bytes would have encoded into the answer file for (Entry entry : new TreeMap<>(payload.getAlternateViews()).entrySet()) { Optional viewSha256 = hashBytesIfNonPrintable(entry.getValue()); - viewSha256.ifPresent(s -> payload.addAlternateView(entry.getKey(), s.getBytes(StandardCharsets.ISO_8859_1))); + viewSha256.ifPresent(s -> payload.addAlternateView(entry.getKey(), s.getBytes(StandardCharsets.UTF_8))); } // touch up primary view if necessary @@ -233,7 +233,7 @@ protected void checkAnswersPreHookLogEvents(List simplifiedL * @return a value optionally containing the generated hash */ protected Optional hashBytesIfNonPrintable(byte[] bytes) { - if (ArrayUtils.isNotEmpty(bytes) && ByteUtil.hasNonPrintableValues(bytes)) { + if (ArrayUtils.isNotEmpty(bytes) && ByteUtil.containsNonIndexableBytes(bytes)) { return Optional.ofNullable(ByteUtil.sha256Bytes(bytes)); }