MCPcopy Create free account
hub / github.com/LibPDF-js/core / tryUserPasswordR56

Method tryUserPasswordR56

src/security/standard-handler.ts:275–322  ·  view source on GitHub ↗

* Try user password for R5-R6 encryption.

(password: Uint8Array)

Source from the content-addressed store, hash-verified

273 * Try user password for R5-R6 encryption.
274 */
275 private tryUserPasswordR56(password: Uint8Array): AuthResult {
276 const { userHash, userEncryptionKey, revision, permsValue, permissionsRaw, encryptMetadata } =
277 this.encryptDict;
278
279 if (!userEncryptionKey) {
280 return {
281 authenticated: false,
282 permissions: this.encryptDict.permissions,
283 isOwner: false,
284 };
285 }
286
287 const result = verifyUserPasswordR56(password, userHash, userEncryptionKey, revision);
288
289 if (result.isValid && result.encryptionKey) {
290 // For R6, verify Perms entry
291 if (revision === 6 && permsValue) {
292 const permsValid = verifyPermsEntry(
293 result.encryptionKey,
294 permsValue,
295 permissionsRaw,
296 encryptMetadata,
297 );
298 if (!permsValid) {
299 return {
300 authenticated: false,
301 permissions: this.encryptDict.permissions,
302 isOwner: false,
303 };
304 }
305 }
306
307 this.setAuthenticated(result.encryptionKey, false);
308
309 return {
310 authenticated: true,
311 passwordType: "user",
312 permissions: this.encryptDict.permissions,
313 isOwner: false,
314 };
315 }
316
317 return {
318 authenticated: false,
319 permissions: this.encryptDict.permissions,
320 isOwner: false,
321 };
322 }
323
324 /**
325 * Try owner password for R5-R6 encryption.

Callers 1

tryUserPasswordMethod · 0.95

Calls 3

setAuthenticatedMethod · 0.95
verifyUserPasswordR56Function · 0.90
verifyPermsEntryFunction · 0.90

Tested by

no test coverage detected