seanjmullan commented on code in PR #504:
URL:
https://github.com/apache/santuario-xml-security-java/pull/504#discussion_r2503670536
##########
src/main/java/org/apache/xml/security/utils/XMLUtils.java:
##########
@@ -1068,4 +1122,90 @@ public static byte[] getBytes(BigInteger big, int
bitlen) {
return resizedBytes;
}
+
+ /**
+ * Aggregates formatting options for base64Binary values.
+ */
+ static class Base64FormattingOptions {
+ private static final String BASE64_IGNORE_LINE_BREAKS_PROP =
"org.apache.xml.security.base64.ignoreLineBreaks";
+ private static final String BASE64_LINE_SEPARATOR_PROP =
"org.apache.xml.security.base64.lineSeparator";
+ private static final String BASE64_LINE_LENGTH_PROP =
"org.apache.xml.security.base64.lineLength";
+
+ private boolean ignoreLineBreaks = false;
+ private Base64LineSeparator lineSeparator = Base64LineSeparator.CRLF;
+ private int lineLength = 76;
+
+ /**
+ * Creates new formatting options by reading system properties.
+ */
+ public Base64FormattingOptions() {
Review Comment:
The constructors and methods of this class should be package-private since
the class is package-private.
##########
src/test/java/org/apache/xml/security/utils/XMLUtilsTest.java:
##########
@@ -0,0 +1,270 @@
+package org.apache.xml.security.utils;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.nio.charset.StandardCharsets;
+import java.util.*;
+import java.util.stream.Collectors;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.*;
+import static org.junit.jupiter.api.Assertions.*;
+
Review Comment:
Add a comment describing what this test does.
##########
src/test/java/org/apache/xml/security/utils/XMLUtilsTest.java:
##########
Review Comment:
Missing Apache license header.
##########
src/main/java/org/apache/xml/security/utils/XMLUtils.java:
##########
@@ -1068,4 +1122,90 @@ public static byte[] getBytes(BigInteger big, int
bitlen) {
return resizedBytes;
}
+
+ /**
+ * Aggregates formatting options for base64Binary values.
+ */
+ static class Base64FormattingOptions {
+ private static final String BASE64_IGNORE_LINE_BREAKS_PROP =
"org.apache.xml.security.base64.ignoreLineBreaks";
+ private static final String BASE64_LINE_SEPARATOR_PROP =
"org.apache.xml.security.base64.lineSeparator";
+ private static final String BASE64_LINE_LENGTH_PROP =
"org.apache.xml.security.base64.lineLength";
+
+ private boolean ignoreLineBreaks = false;
+ private Base64LineSeparator lineSeparator = Base64LineSeparator.CRLF;
+ private int lineLength = 76;
+
+ /**
+ * Creates new formatting options by reading system properties.
+ */
+ public Base64FormattingOptions() {
+ String ignoreLineBreaksProp =
System.getProperty(BASE64_IGNORE_LINE_BREAKS_PROP);
+ ignoreLineBreaks = Boolean.parseBoolean(ignoreLineBreaksProp);
+ if (XMLUtils.ignoreLineBreaks && ignoreLineBreaksProp != null &&
!ignoreLineBreaks) {
+ LOG.log(Level.WARNING, "{0} property takes precedence over
{1}, line breaks will be ignored",
+ IGNORE_LINE_BREAKS_PROP,
BASE64_IGNORE_LINE_BREAKS_PROP);
+ }
+
+ String lineSeparatorProp =
System.getProperty(BASE64_LINE_SEPARATOR_PROP);
+ if (lineSeparatorProp != null) {
+ try {
+ lineSeparator =
Base64LineSeparator.valueOf(lineSeparatorProp.toUpperCase());
+ if (XMLUtils.ignoreLineBreaks || ignoreLineBreaks) {
+ LOG.log(Level.WARNING, "Property {0} has no effect
since line breaks are ignored",
+ BASE64_LINE_SEPARATOR_PROP);
+ }
+ } catch (IllegalArgumentException e) {
+ LOG.log(Level.WARNING, "Illegal value of {0} property is
ignored: {1}",
+ BASE64_LINE_SEPARATOR_PROP, lineSeparatorProp);
+ }
+ }
+
+ String lineLengthProp =
System.getProperty(BASE64_LINE_LENGTH_PROP);
+ if (lineLengthProp != null) {
+ try {
+ int lineLength = Integer.parseInt(lineLengthProp);
+ if (lineLength >= 4) {
+ this.lineLength = lineLength;
+ if (XMLUtils.ignoreLineBreaks || ignoreLineBreaks) {
+ LOG.log(Level.WARNING, "Property {0} has no effect
since line breaks are ignored",
+ BASE64_LINE_LENGTH_PROP);
+ }
+ } else {
+ LOG.log(Level.WARNING, "Illegal value of {0} property
is ignored: {1}",
+ BASE64_LINE_LENGTH_PROP, lineLengthProp);
+ }
+ } catch (NumberFormatException e) {
+ LOG.log(Level.WARNING, "Illegal value of {0} property is
ignored: {1}",
+ BASE64_LINE_LENGTH_PROP, lineLengthProp);
+ }
+ }
+ }
+
+ public boolean isIgnoreLineBreaks() {
+ return ignoreLineBreaks;
+ }
+
+ public Base64LineSeparator getLineSeparator() {
+ return lineSeparator;
+ }
+
+ public int getLineLength() {
+ return lineLength;
+ }
+ }
+
+ enum Base64LineSeparator {
+ CRLF(new byte[]{'\r', '\n'}),
+ LF(new byte[]{'\n'});
+
+ private byte[] bytes;
+
+ Base64LineSeparator(byte[] bytes) {
+ this.bytes = bytes;
+ }
+
+ public byte[] getBytes() {
Review Comment:
Change to package-private.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]