* Get detailed security information about the document. * * @returns Security information including encryption details and permissions * * @example * ```typescript * const security = pdf.getSecurity(); * console.log(`Algorithm: ${security.algorithm}`); * console.log(`Can copy
()
| 779 | * ``` |
| 780 | */ |
| 781 | getSecurity(): SecurityInfo { |
| 782 | const handler = this.ctx.info.securityHandler; |
| 783 | |
| 784 | if (!this.isEncrypted || !handler) { |
| 785 | return { |
| 786 | isEncrypted: false, |
| 787 | permissions: DEFAULT_PERMISSIONS, |
| 788 | }; |
| 789 | } |
| 790 | |
| 791 | const encryption = handler.encryption; |
| 792 | |
| 793 | // Map internal algorithm to public API type |
| 794 | let algorithm: EncryptionAlgorithmOption | undefined; |
| 795 | |
| 796 | switch (encryption.algorithm) { |
| 797 | case "RC4": |
| 798 | algorithm = encryption.keyLengthBits <= 40 ? "RC4-40" : "RC4-128"; |
| 799 | break; |
| 800 | case "AES-128": |
| 801 | algorithm = "AES-128"; |
| 802 | break; |
| 803 | case "AES-256": |
| 804 | algorithm = "AES-256"; |
| 805 | break; |
| 806 | } |
| 807 | |
| 808 | // Determine how the document was authenticated |
| 809 | let authenticatedAs: "user" | "owner" | null = null; |
| 810 | |
| 811 | if (handler.isAuthenticated) { |
| 812 | authenticatedAs = handler.hasOwnerAccess ? "owner" : "user"; |
| 813 | } |
| 814 | |
| 815 | // For owner access, all permissions are granted regardless of flags |
| 816 | const permissions = handler.hasOwnerAccess ? DEFAULT_PERMISSIONS : handler.permissions; |
| 817 | |
| 818 | return { |
| 819 | isEncrypted: true, |
| 820 | algorithm, |
| 821 | keyLength: encryption.keyLengthBits, |
| 822 | revision: encryption.revision, |
| 823 | hasUserPassword: true, // We can't easily detect empty user password after the fact |
| 824 | hasOwnerPassword: true, |
| 825 | authenticatedAs, |
| 826 | permissions, |
| 827 | encryptMetadata: encryption.encryptMetadata, |
| 828 | }; |
| 829 | } |
| 830 | |
| 831 | /** |
| 832 | * Get the current permission flags. |
no outgoing calls
no test coverage detected