Re: [PR] Added properties for base64 formatting [santuario -xml-security-java]

kuzjka (via GitHub) <[email protected]> Wed, 05 Nov 2025 15:15:29 -0000
Newsgroups gmane.text.xml.security.devel
Message-ID <PR_kwDOD7oF986jGHuo-dcd7294c-5a73-4661-8686-6f94dc29f337@gitbox.apache.org>
kuzjka commented on code in PR #504:
URL: https://github.com/apache/santuario-xml-security-java/pull/504#discussion_r2495007194


##########
src/main/java/org/apache/xml/security/utils/XMLUtils.java:
##########
@@ -1068,4 +1147,52 @@ public static byte[] getBytes(BigInteger big, int bitlen) {
 
         return resizedBytes;
     }
+
+    /**
+     * Aggregates formatting options for base64Binary values.
+     */
+    static class Base64FormattingOptions {
+        private boolean ignoreLineBreaks = false;
+        private Base64LineSeparator lineSeparator = Base64LineSeparator.CRLF;
+        private int lineLength = 76;
+
+        public boolean isIgnoreLineBreaks() {
+            return ignoreLineBreaks;
+        }
+
+        public void setIgnoreLineBreaks(boolean ignoreLineBreaks) {

Review Comment:
   Since we would like to retain meaningful log messages for invalid property values, I couldn't find a better way than to move all properties reading together with validation logic to the constructor of `Base64FormattingOptions`.
   
   Added warnings in case a property is set, but ignored.
   Added handling of `NumberFormatException` as suggested in the comment below.
   
   Example log:
   ```
   testIgnoreLineBreaksTakesPrecedence:
   ... org.apache.xml.security.ignoreLineBreaks property takes precedence over org.apache.xml.security.base64.ignoreLineBreaks, line breaks will be ignored
   ... Property org.apache.xml.security.base64.lineSeparator has no effect since line breaks are ignored
   ... Property org.apache.xml.security.base64.lineLength has no effect since line breaks are ignored
   
   testIllegalPropertiesAreIgnored:
   ... Illegal value of org.apache.xml.security.base64.lineSeparator property is ignored: illegal
   ... Illegal value of org.apache.xml.security.base64.lineLength property is ignored: illegal
   ```



-- 
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]