Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add --show-encryption #31

Merged
merged 6 commits into from
Apr 13, 2023
Merged

Add --show-encryption #31

merged 6 commits into from
Apr 13, 2023

Conversation

Sparticuz
Copy link
Owner

Fixes #30

Copy link

@azymnis azymnis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! Added some comments to this

src/info.ts Outdated
Comment on lines 11 to 16
/**
* Gets the encryption info for a PDF
* @param payload The settings for info
* @returns The output of QPDF
*/
export const info = async (payload: InfoSettings): Promise<Buffer> => {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a start we could show whether the file is encrypted or not

Suggested change
/**
* Gets the encryption info for a PDF
* @param payload The settings for info
* @returns The output of QPDF
*/
export const info = async (payload: InfoSettings): Promise<Buffer> => {
export interface InfoOutput {
isEncrypted: boolean;
}
/**
* Gets the encryption info for a PDF
* @param payload The settings for info
* @returns The output of QPDF
*/
export const info = async (payload: InfoSettings): Promise<InfoOutput> => {

src/info.ts Outdated
// Input file path
callArguments.push(payload.input);

return execute(callArguments);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think here it would be enough to extract the : params.

I have not tested the following snippet but it might do the trick:

Suggested change
return execute(callArguments);
const outputParams = _.keyBy(
(await execute(callArguments))
.toString('utf8')
.split('\n')
.map(line => line.split(':').map(k => k.trim()).splice(0, 2)),
p => p[0]
);
const isEncrypted = outputParams['Has user password'] === 'yes' || outputParams['Has owner password'] === 'yes';
return { isEncrypted };

@Sparticuz
Copy link
Owner Author

For now, I just left it as the string that qpdf returns. For an unencrypted file, the result will be 'File is not encrypted'.

(await info(filePath)) === "File is not encrypted" should give you a boolean

@azymnis
Copy link

azymnis commented Apr 13, 2023

Awesome that works great, thank you

@Sparticuz Sparticuz merged commit 8aa95c0 into master Apr 13, 2023
@Sparticuz Sparticuz deleted the feature/show-encryption branch April 13, 2023 21:55
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Show encryption info
2 participants