From ff9e2ad83f1c8e8c2fb8fb1fe40da08460c5e39e Mon Sep 17 00:00:00 2001 From: Eliot Jones Date: Sun, 23 Jun 2019 13:27:32 +0100 Subject: [PATCH] handle hex registry and ordering. decrypt hex tokens #34 cid fonts may contain a registry, ordering and supplement to identify the font. we were checking for string registry and ordering tokens but failing on hex tokens. for encrypted documents we now decrypt hex data. --- src/UglyToad.PdfPig/Encryption/EncryptionHandler.cs | 10 ++++++++++ .../Fonts/Parser/Parts/CidFontFactory.cs | 12 +++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/UglyToad.PdfPig/Encryption/EncryptionHandler.cs b/src/UglyToad.PdfPig/Encryption/EncryptionHandler.cs index da39699e..ee49ab46 100644 --- a/src/UglyToad.PdfPig/Encryption/EncryptionHandler.cs +++ b/src/UglyToad.PdfPig/Encryption/EncryptionHandler.cs @@ -358,6 +358,16 @@ break; } + case HexToken hexToken: + { + var data = hexToken.Bytes.ToArray(); + + var decrypted = DecryptData(data, reference); + + token = new HexToken(Hex.GetString(decrypted).ToCharArray()); + + break; + } case DictionaryToken dictionary: { // PDFBOX-2936: avoid orphan /CF dictionaries found in US govt "I-" files diff --git a/src/UglyToad.PdfPig/Fonts/Parser/Parts/CidFontFactory.cs b/src/UglyToad.PdfPig/Fonts/Parser/Parts/CidFontFactory.cs index ed377446..1dd138a3 100644 --- a/src/UglyToad.PdfPig/Fonts/Parser/Parts/CidFontFactory.cs +++ b/src/UglyToad.PdfPig/Fonts/Parser/Parts/CidFontFactory.cs @@ -322,7 +322,17 @@ if (token is IndirectReferenceToken obj) { - return DirectObjectFinder.Get(obj, pdfScanner).Data; + if (DirectObjectFinder.TryGet(obj, pdfScanner, out StringToken stringToken)) + { + return stringToken.Data; + } + + if (DirectObjectFinder.TryGet(obj, pdfScanner, out HexToken hexToken)) + { + return hexToken.Data; + } + + throw new PdfDocumentFormatException($"Could not get key for name: {keyName} in {dictionary}."); } return string.Empty;