Skip to content

Commit 92888ba

Browse files
committed
PDFBOX-6026: remove windows line changes, fix digest conversion
git-svn-id: https://svn.apache.org/repos/asf/pdfbox/trunk@1926756 13f79535-47bb-0310-9956-ffa450edef68
1 parent bc074ac commit 92888ba

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

xmpbox/src/test/java/org/apache/xmpbox/parser/DeserializationTest.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
import java.io.ByteArrayOutputStream;
2929
import java.io.IOException;
3030
import java.io.InputStream;
31-
import java.nio.ByteBuffer;
31+
import java.math.BigInteger;
32+
import java.nio.charset.StandardCharsets;
3233
import java.security.MessageDigest;
3334
import java.security.NoSuchAlgorithmException;
3435
import java.util.List;
@@ -102,11 +103,11 @@ void testGetTitle() throws XmpParsingException, BadFieldValueException
102103
}
103104

104105
@Test
105-
void testAltBagSeq() throws XmpParsingException, TransformerException, NoSuchAlgorithmException
106+
void testAltBagSeq() throws XmpParsingException, TransformerException, NoSuchAlgorithmException, IOException
106107
{
107108
InputStream fis = DomXmpParser.class.getResourceAsStream("/org/apache/xmpbox/parser/AltBagSeqTest.xml");
108109
XMPMetadata metadata=xdb.parse(fis);
109-
checkTransform(metadata, "AA3B148E4F802DE4");
110+
checkTransform(metadata, "96393121650279079517435472505216876362174786845882116375023427217573081361024");
110111
}
111112

112113
@Test
@@ -327,12 +328,14 @@ void testSpaceTextValues() throws XmpParsingException
327328
}
328329

329330
private void checkTransform(XMPMetadata metadata, String expected)
330-
throws TransformerException, NoSuchAlgorithmException
331+
throws TransformerException, NoSuchAlgorithmException, IOException
331332
{
332333
ByteArrayOutputStream baos = new ByteArrayOutputStream();
333334
serializer.serialize(metadata, baos, true);
334-
byte[] digest = MessageDigest.getInstance("SHA-256").digest(baos.toByteArray());
335-
String result = String.format("%X", ByteBuffer.wrap(digest).getLong());
335+
String replaced = baos.toString(StandardCharsets.UTF_8).replace("\r\n", "\n");
336+
byte[] ba = replaced.getBytes(StandardCharsets.UTF_8);
337+
byte[] digest = MessageDigest.getInstance("SHA-256").digest(ba);
338+
String result = new BigInteger(1, digest).toString();
336339
assertEquals(expected, result);
337340
}
338341
}

0 commit comments

Comments
 (0)