mirror of
https://github.com/UglyToad/PdfPig.git
synced 2026-03-10 00:23:29 +08:00
fix bug where hex tokens for document identifier lost bytes due to encoding
This commit is contained in:
@@ -2,7 +2,6 @@
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using CrossReference;
|
||||
using Util.JetBrains.Annotations;
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -39,9 +39,9 @@
|
||||
public IndirectReference? Info { get; }
|
||||
|
||||
/// <summary>
|
||||
/// A list containing two-byte strings which act as file identifiers.
|
||||
/// A list containing two-byte string tokens which act as file identifiers.
|
||||
/// </summary>
|
||||
public IReadOnlyList<string> Identifier { get; }
|
||||
public IReadOnlyList<IDataToken<string>> Identifier { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The document's encryption dictionary.
|
||||
@@ -77,17 +77,17 @@
|
||||
|
||||
if (dictionary.TryGet(NameToken.Id, out ArrayToken arr))
|
||||
{
|
||||
var ids = new List<string>(arr.Data.Count);
|
||||
var ids = new List<IDataToken<string>>(arr.Data.Count);
|
||||
|
||||
foreach (var token in arr.Data)
|
||||
{
|
||||
if (token is StringToken str)
|
||||
{
|
||||
ids.Add(str.Data);
|
||||
ids.Add(str);
|
||||
}
|
||||
else if (token is HexToken hex)
|
||||
{
|
||||
ids.Add(hex.Data);
|
||||
ids.Add(hex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@
|
||||
}
|
||||
else
|
||||
{
|
||||
Identifier = EmptyArray<string>.Instance;
|
||||
Identifier = EmptyArray<IDataToken<string>>.Instance;
|
||||
}
|
||||
|
||||
if (dictionary.TryGet(NameToken.Encrypt, out var encryptionToken))
|
||||
|
||||
@@ -42,9 +42,27 @@
|
||||
{
|
||||
this.encryptionDictionary = encryptionDictionary;
|
||||
|
||||
var documentIdBytes = trailerDictionary.Identifier != null && trailerDictionary.Identifier.Count == 2 ?
|
||||
OtherEncodings.StringAsLatin1Bytes(trailerDictionary.Identifier[0])
|
||||
: EmptyArray<byte>.Instance;
|
||||
byte[] documentIdBytes;
|
||||
|
||||
if (trailerDictionary.Identifier != null && trailerDictionary.Identifier.Count == 2)
|
||||
{
|
||||
var token = trailerDictionary.Identifier[0];
|
||||
|
||||
switch (token)
|
||||
{
|
||||
case HexToken hex:
|
||||
documentIdBytes = hex.Bytes.ToArray();
|
||||
break;
|
||||
default:
|
||||
documentIdBytes = OtherEncodings.StringAsLatin1Bytes(token.Data);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
documentIdBytes = EmptyArray<byte>.Instance;
|
||||
}
|
||||
|
||||
password = password ?? string.Empty;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user