bvahdat commented on code in PR #28749:
URL: https://github.com/apache/camel/pull/28749#discussion_r4430985776


##########
components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/entity/EntityParser.java:
##########
@@ -637,10 +647,33 @@ public static MultipartSignedEntity 
parseMultipartSignedEntityBody(
             parseException.initCause(e);
             throw parseException;
         } finally {
+            inbuffer.stopRawCapture();
             inbuffer.setCharsetDecoder(previousDecoder);
         }
     }
 
+    /**
+     * Removes the boundary delimiter line a body-part parser consumed last, 
and the line break preceding it, from the
+     * raw bytes of the part - both belong to the boundary (RFC 2046, 5.1.1). 
Returns the bytes unchanged when the last
+     * line read is not that delimiter.
+     */
+    static byte[] stripBoundaryDelimiter(byte[] raw, int lastLineRawLength, 
String boundary) {
+        if (raw == null || lastLineRawLength <= 0 || lastLineRawLength > 
raw.length) {
+            return raw;
+        }
+        int end = raw.length - lastLineRawLength;
+        String lastLine = new String(raw, end, lastLineRawLength, 
StandardCharsets.US_ASCII);
+        if (!lastLine.startsWith("--" + boundary)) {
+            return raw;
+        }
+        if (end >= 2 && raw[end - 2] == CR && raw[end - 1] == LF) {
+            end -= 2;
+        } else if (end >= 1 && raw[end - 1] == LF) {
+            end -= 1;

Review Comment:
   Thanks. With 838b5b6 the strip helper is gone: `parseBodyPartText` now 
removes exactly the line break the line before the delimiter had and tells the 
buffer to leave the same bytes plus the delimiter line out of the capture, so 
verified bytes and parsed text end at the same byte by construction. A bare CR 
cannot occur there: `readLine` splits on LF only, so a delimiter line begins 
after an LF; a CR directly before `--boundary` is content of the previous line 
on both sides.
   
   _Claude Code on behalf of @bvahdat._



##########
components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/entity/MultipartSignedEntity.java:
##########
@@ -41,6 +44,40 @@ protected MultipartSignedEntity(ContentType contentType, 
String contentTransferE
         this.isMainBody = isMainBody;
     }
 
+    /**
+     * The first body part exactly as received - its MIME headers and its body 
in the transfer encoding the sender used
+     * - which is what the signature was created over (RFC 1847, 2.1) and what 
the MIC is computed over (RFC 4130, 7.1).
+     * Set by the parser; null for an entity built locally.
+     */
+    public byte[] getSignedDataRaw() {
+        return signedDataRaw;

Review Comment:
   Done in 838b5b6: `getSignedDataRaw()` returns a copy. 
`getSignedDataContent()` keeps handing out the held array to the two internal 
callers (signature check, MIC) and its javadoc now says so.
   
   _Claude Code on behalf of @bvahdat._



##########
components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/entity/MultipartSignedEntity.java:
##########
@@ -41,6 +44,40 @@ protected MultipartSignedEntity(ContentType contentType, 
String contentTransferE
         this.isMainBody = isMainBody;
     }
 
+    /**
+     * The first body part exactly as received - its MIME headers and its body 
in the transfer encoding the sender used
+     * - which is what the signature was created over (RFC 1847, 2.1) and what 
the MIC is computed over (RFC 4130, 7.1).
+     * Set by the parser; null for an entity built locally.
+     */
+    public byte[] getSignedDataRaw() {
+        return signedDataRaw;
+    }
+
+    public void setSignedDataRaw(byte[] signedDataRaw) {

Review Comment:
   Done in 838b5b6: `setSignedDataRaw` is package-private.
   
   _Claude Code on behalf of @bvahdat._



##########
components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/io/AS2SessionInputBuffer.java:
##########
@@ -233,12 +239,50 @@ public boolean isLastLineReadEnrichedByCarriageReturn() {
         return lastLineReadEnrichedByCarriageReturn;
     }
 
+    /**
+     * Starts keeping the raw bytes every following {@link 
#readLine(CharArrayBuffer, InputStream)} consumes - line
+     * terminators included, no charset decoding - until {@link 
#stopRawCapture()}.
+     */
+    public void startRawCapture() {
+        this.rawCapture = new ByteArrayBuffer(this.buffer.length);

Review Comment:
   Captures now nest (838b5b6): one buffer, a mark per open capture, every stop 
ends the innermost one and returns its bytes while the outer goes on. Covered 
by `rawCapturesNest` in `AS2SessionInputBufferTest`.
   
   _Claude Code on behalf of @bvahdat._



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

Reply via email to