Refactor the password
handling so that it's stored in the PdfManager
s, instead of in the XRef
We're already passing in a, currently unused, `PdfManager` instance when initializing the `XRef`. To avoid having to pass a single `password` parameter around, we could thus simply get the `password` through the `PdfManager` instance instead.
This commit is contained in:
parent
27513cd23b
commit
14b8523314
@ -370,22 +370,20 @@ var PDFDocument = (function PDFDocumentClosure() {
|
|||||||
var EMPTY_FINGERPRINT = '\x00\x00\x00\x00\x00\x00\x00' +
|
var EMPTY_FINGERPRINT = '\x00\x00\x00\x00\x00\x00\x00' +
|
||||||
'\x00\x00\x00\x00\x00\x00\x00\x00\x00';
|
'\x00\x00\x00\x00\x00\x00\x00\x00\x00';
|
||||||
|
|
||||||
function PDFDocument(pdfManager, arg, password) {
|
function PDFDocument(pdfManager, arg) {
|
||||||
|
var stream;
|
||||||
if (isStream(arg)) {
|
if (isStream(arg)) {
|
||||||
init.call(this, pdfManager, arg, password);
|
stream = arg;
|
||||||
} else if (isArrayBuffer(arg)) {
|
} else if (isArrayBuffer(arg)) {
|
||||||
init.call(this, pdfManager, new Stream(arg), password);
|
stream = new Stream(arg);
|
||||||
} else {
|
} else {
|
||||||
error('PDFDocument: Unknown argument type');
|
error('PDFDocument: Unknown argument type');
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
function init(pdfManager, stream, password) {
|
|
||||||
assert(stream.length > 0, 'stream must have data');
|
assert(stream.length > 0, 'stream must have data');
|
||||||
|
|
||||||
this.pdfManager = pdfManager;
|
this.pdfManager = pdfManager;
|
||||||
this.stream = stream;
|
this.stream = stream;
|
||||||
var xref = new XRef(this.stream, password, pdfManager);
|
this.xref = new XRef(stream, pdfManager);
|
||||||
this.xref = xref;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function find(stream, needle, limit, backwards) {
|
function find(stream, needle, limit, backwards) {
|
||||||
|
@ -758,13 +758,13 @@ var Catalog = (function CatalogClosure() {
|
|||||||
})();
|
})();
|
||||||
|
|
||||||
var XRef = (function XRefClosure() {
|
var XRef = (function XRefClosure() {
|
||||||
function XRef(stream, password) {
|
function XRef(stream, pdfManager) {
|
||||||
this.stream = stream;
|
this.stream = stream;
|
||||||
|
this.pdfManager = pdfManager;
|
||||||
this.entries = [];
|
this.entries = [];
|
||||||
this.xrefstms = Object.create(null);
|
this.xrefstms = Object.create(null);
|
||||||
// prepare the XRef cache
|
// prepare the XRef cache
|
||||||
this.cache = [];
|
this.cache = [];
|
||||||
this.password = password;
|
|
||||||
this.stats = {
|
this.stats = {
|
||||||
streamTypes: [],
|
streamTypes: [],
|
||||||
fontTypes: []
|
fontTypes: []
|
||||||
@ -789,7 +789,7 @@ var XRef = (function XRefClosure() {
|
|||||||
trailerDict.assignXref(this);
|
trailerDict.assignXref(this);
|
||||||
this.trailer = trailerDict;
|
this.trailer = trailerDict;
|
||||||
var encrypt = trailerDict.get('Encrypt');
|
var encrypt = trailerDict.get('Encrypt');
|
||||||
if (encrypt) {
|
if (isDict(encrypt)) {
|
||||||
var ids = trailerDict.get('ID');
|
var ids = trailerDict.get('ID');
|
||||||
var fileId = (ids && ids.length) ? ids[0] : '';
|
var fileId = (ids && ids.length) ? ids[0] : '';
|
||||||
// The 'Encrypt' dictionary itself should not be encrypted, and by
|
// The 'Encrypt' dictionary itself should not be encrypted, and by
|
||||||
@ -798,7 +798,7 @@ var XRef = (function XRefClosure() {
|
|||||||
// objects (fixes issue7665.pdf).
|
// objects (fixes issue7665.pdf).
|
||||||
encrypt.suppressEncryption = true;
|
encrypt.suppressEncryption = true;
|
||||||
this.encrypt = new CipherTransformFactory(encrypt, fileId,
|
this.encrypt = new CipherTransformFactory(encrypt, fileId,
|
||||||
this.password);
|
this.pdfManager.password);
|
||||||
}
|
}
|
||||||
|
|
||||||
// get the root dictionary (catalog) object
|
// get the root dictionary (catalog) object
|
||||||
|
@ -52,6 +52,10 @@ var BasePdfManager = (function BasePdfManagerClosure() {
|
|||||||
return this._docId;
|
return this._docId;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
get password() {
|
||||||
|
return this._password;
|
||||||
|
},
|
||||||
|
|
||||||
get docBaseUrl() {
|
get docBaseUrl() {
|
||||||
var docBaseUrl = null;
|
var docBaseUrl = null;
|
||||||
if (this._docBaseUrl) {
|
if (this._docBaseUrl) {
|
||||||
@ -106,7 +110,7 @@ var BasePdfManager = (function BasePdfManagerClosure() {
|
|||||||
},
|
},
|
||||||
|
|
||||||
updatePassword: function BasePdfManager_updatePassword(password) {
|
updatePassword: function BasePdfManager_updatePassword(password) {
|
||||||
this.pdfDocument.xref.password = this.password = password;
|
this._password = password;
|
||||||
},
|
},
|
||||||
|
|
||||||
terminate: function BasePdfManager_terminate() {
|
terminate: function BasePdfManager_terminate() {
|
||||||
@ -121,10 +125,11 @@ var LocalPdfManager = (function LocalPdfManagerClosure() {
|
|||||||
function LocalPdfManager(docId, data, password, evaluatorOptions,
|
function LocalPdfManager(docId, data, password, evaluatorOptions,
|
||||||
docBaseUrl) {
|
docBaseUrl) {
|
||||||
this._docId = docId;
|
this._docId = docId;
|
||||||
|
this._password = password;
|
||||||
this._docBaseUrl = docBaseUrl;
|
this._docBaseUrl = docBaseUrl;
|
||||||
this.evaluatorOptions = evaluatorOptions;
|
this.evaluatorOptions = evaluatorOptions;
|
||||||
var stream = new Stream(data);
|
var stream = new Stream(data);
|
||||||
this.pdfDocument = new PDFDocument(this, stream, password);
|
this.pdfDocument = new PDFDocument(this, stream);
|
||||||
this._loadedStreamCapability = createPromiseCapability();
|
this._loadedStreamCapability = createPromiseCapability();
|
||||||
this._loadedStreamCapability.resolve(stream);
|
this._loadedStreamCapability.resolve(stream);
|
||||||
}
|
}
|
||||||
@ -171,6 +176,7 @@ var NetworkPdfManager = (function NetworkPdfManagerClosure() {
|
|||||||
function NetworkPdfManager(docId, pdfNetworkStream, args, evaluatorOptions,
|
function NetworkPdfManager(docId, pdfNetworkStream, args, evaluatorOptions,
|
||||||
docBaseUrl) {
|
docBaseUrl) {
|
||||||
this._docId = docId;
|
this._docId = docId;
|
||||||
|
this._password = args.password;
|
||||||
this._docBaseUrl = docBaseUrl;
|
this._docBaseUrl = docBaseUrl;
|
||||||
this.msgHandler = args.msgHandler;
|
this.msgHandler = args.msgHandler;
|
||||||
this.evaluatorOptions = evaluatorOptions;
|
this.evaluatorOptions = evaluatorOptions;
|
||||||
@ -183,8 +189,7 @@ var NetworkPdfManager = (function NetworkPdfManagerClosure() {
|
|||||||
rangeChunkSize: args.rangeChunkSize
|
rangeChunkSize: args.rangeChunkSize
|
||||||
};
|
};
|
||||||
this.streamManager = new ChunkedStreamManager(pdfNetworkStream, params);
|
this.streamManager = new ChunkedStreamManager(pdfNetworkStream, params);
|
||||||
this.pdfDocument = new PDFDocument(this, this.streamManager.getStream(),
|
this.pdfDocument = new PDFDocument(this, this.streamManager.getStream());
|
||||||
args.password);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Util.inherit(NetworkPdfManager, BasePdfManager, {
|
Util.inherit(NetworkPdfManager, BasePdfManager, {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user