Update prettier styling

This commit is contained in:
Ephraim Atta-Duncan
2023-04-04 22:10:30 +00:00
parent 84b57d715c
commit 964e749039
34 changed files with 258 additions and 93 deletions

View File

@ -40,7 +40,10 @@ const extractSignature = (pdf, signatureCount = 1) => {
const byteRangePos = getSubstringIndex(pdf, "/ByteRange [", signatureCount);
if (byteRangePos === -1) {
throw new _SignPdfError.default("Failed to locate ByteRange.", _SignPdfError.default.TYPE_PARSE);
throw new _SignPdfError.default(
"Failed to locate ByteRange.",
_SignPdfError.default.TYPE_PARSE
);
}
const byteRangeEnd = pdf.indexOf("]", byteRangePos);
@ -56,7 +59,10 @@ const extractSignature = (pdf, signatureCount = 1) => {
const matches = /\/ByteRange \[(\d+) +(\d+) +(\d+) +(\d+) *\]/.exec(byteRange);
if (matches === null) {
throw new _SignPdfError.default("Failed to parse the ByteRange.", _SignPdfError.default.TYPE_PARSE);
throw new _SignPdfError.default(
"Failed to parse the ByteRange.",
_SignPdfError.default.TYPE_PARSE
);
}
const ByteRange = matches.slice(1).map(Number);

View File

@ -87,7 +87,10 @@ class PDFObject {
let string = `D:${pad(object.getUTCFullYear(), 4)}${pad(object.getUTCMonth() + 1, 2)}${pad(
object.getUTCDate(),
2
)}${pad(object.getUTCHours(), 2)}${pad(object.getUTCMinutes(), 2)}${pad(object.getUTCSeconds(), 2)}Z`; // Encrypt the string when necessary
)}${pad(object.getUTCHours(), 2)}${pad(object.getUTCMinutes(), 2)}${pad(
object.getUTCSeconds(),
2
)}Z`; // Encrypt the string when necessary
if (encryptFn) {
string = encryptFn(Buffer.from(string, "ascii")).toString("binary"); // Escape characters as required by the spec

View File

@ -21,7 +21,10 @@ const getIndexFromRef = (refTable, ref) => {
index = parseInt(index);
if (!refTable.offsets.has(index)) {
throw new _SignPdfError.default(`Failed to locate object "${ref}".`, _SignPdfError.default.TYPE_PARSE);
throw new _SignPdfError.default(
`Failed to locate object "${ref}".`,
_SignPdfError.default.TYPE_PARSE
);
}
return index;

View File

@ -21,9 +21,13 @@ var _readPdf = _interopRequireDefault(require("./readPdf"));
var _getPageRef = _interopRequireDefault(require("./getPageRef"));
var _createBufferRootWithAcroform = _interopRequireDefault(require("./createBufferRootWithAcroform"));
var _createBufferRootWithAcroform = _interopRequireDefault(
require("./createBufferRootWithAcroform")
);
var _createBufferPageWithAnnotation = _interopRequireDefault(require("./createBufferPageWithAnnotation"));
var _createBufferPageWithAnnotation = _interopRequireDefault(
require("./createBufferPageWithAnnotation")
);
var _createBufferTrailer = _interopRequireDefault(require("./createBufferTrailer"));

View File

@ -3,7 +3,11 @@
Object.defineProperty(exports, "__esModule", {
value: true,
});
exports.getXref = exports.getLastTrailerPosition = exports.getFullXrefTable = exports.default = void 0;
exports.getXref =
exports.getLastTrailerPosition =
exports.getFullXrefTable =
exports.default =
void 0;
var _SignPdfError = _interopRequireDefault(require("../../SignPdfError"));
@ -16,7 +20,9 @@ function _interopRequireDefault(obj) {
const getLastTrailerPosition = (pdf) => {
const trailerStart = pdf.lastIndexOf(Buffer.from("trailer", "utf8"));
const trailer = pdf.slice(trailerStart, pdf.length - 6);
const xRefPosition = trailer.slice(trailer.lastIndexOf(Buffer.from("startxref", "utf8")) + 10).toString();
const xRefPosition = trailer
.slice(trailer.lastIndexOf(Buffer.from("startxref", "utf8")) + 10)
.toString();
return parseInt(xRefPosition);
};
@ -63,13 +69,19 @@ const getXref = (pdf, position) => {
let size = refTable.toString().split("/Size")[1];
if (!size) {
throw new _SignPdfError.default("Size not found in xref table.", _SignPdfError.default.TYPE_PARSE);
throw new _SignPdfError.default(
"Size not found in xref table.",
_SignPdfError.default.TYPE_PARSE
);
}
size = /^\s*(\d+)/.exec(size);
if (size === null) {
throw new _SignPdfError.default("Failed to parse size of xref table.", _SignPdfError.default.TYPE_PARSE);
throw new _SignPdfError.default(
"Failed to parse size of xref table.",
_SignPdfError.default.TYPE_PARSE
);
}
size = parseInt(size[1]);

View File

@ -26,7 +26,10 @@ const xrefToRefMap = (xrefString) => {
}
if (expectedLines <= 0) {
throw new _SignPdfError.default("Too many lines in xref table.", _SignPdfError.default.TYPE_PARSE);
throw new _SignPdfError.default(
"Too many lines in xref table.",
_SignPdfError.default.TYPE_PARSE
);
}
expectedLines -= 1;

View File

@ -102,9 +102,16 @@ class SignPdf {
let actualByteRange = `/ByteRange [${byteRange.join(" ")}]`;
actualByteRange += " ".repeat(byteRangePlaceholder.length - actualByteRange.length); // Replace the /ByteRange placeholder with the actual ByteRange
pdf = Buffer.concat([pdf.slice(0, byteRangePos), Buffer.from(actualByteRange), pdf.slice(byteRangeEnd)]); // Remove the placeholder signature
pdf = Buffer.concat([
pdf.slice(0, byteRangePos),
Buffer.from(actualByteRange),
pdf.slice(byteRangeEnd),
]); // Remove the placeholder signature
pdf = Buffer.concat([pdf.slice(0, byteRange[1]), pdf.slice(byteRange[2], byteRange[2] + byteRange[3])]); // Convert Buffer P12 to a forge implementation.
pdf = Buffer.concat([
pdf.slice(0, byteRange[1]),
pdf.slice(byteRange[2], byteRange[2] + byteRange[3]),
]); // Convert Buffer P12 to a forge implementation.
const forgeCert = _nodeForge.default.util.createBuffer(p12Buffer.toString("binary"));
@ -190,11 +197,15 @@ class SignPdf {
this.lastSignature = signature; // Pad the signature with zeroes so the it is the same length as the placeholder
signature += Buffer.from(String.fromCharCode(0).repeat(placeholderLength / 2 - raw.length)).toString(
"hex"
); // Place it in the document.
signature += Buffer.from(
String.fromCharCode(0).repeat(placeholderLength / 2 - raw.length)
).toString("hex"); // Place it in the document.
pdf = Buffer.concat([pdf.slice(0, byteRange[1]), Buffer.from(`<${signature}>`), pdf.slice(byteRange[1])]); // Magic. Done.
pdf = Buffer.concat([
pdf.slice(0, byteRange[1]),
Buffer.from(`<${signature}>`),
pdf.slice(byteRange[1]),
]); // Magic. Done.
return pdf;
}