Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

permissions: calculation #473

Closed
ihipop opened this issue May 18, 2022 · 4 comments
Closed

permissions: calculation #473

ihipop opened this issue May 18, 2022 · 4 comments
Assignees
Labels

Comments

@ihipop
Copy link

ihipop commented May 18, 2022

  • Your issue is based on the latest commit
    YES
  • State your OS and OS version
    Linux

// Supplied user access permissions, see Table 22.
Permissions int16

I can only find 3 permission listed here

PermissionsAll int16 = -1 // 0xFFFF
// PermissionsPrint disables all user access permissions bits except for printing.
PermissionsPrint int16 = -1849 // 0xF8C7
// PermissionsNone disables all user access permissions bits.
PermissionsNone int16 = -3901 // 0xF0C3

But there is more permission bit listed here

https://pdfcpu.io/encrypt/perm_list.html#examples

How can I calc them myself ?

@hhrutter
Copy link
Collaborator

Hello!

Thanks for the tip! This is what you need:

Screen Shot 2022-05-18 at 10 30 32 PM

@hhrutter hhrutter changed the title Where is the Table 22 for file permissions or how Can I calc them? permissions: calculation May 18, 2022
@ihipop
Copy link
Author

ihipop commented May 19, 2022

according to this table

44 permits print and copy

according to this table

Bit\POS 12 11 10 9 8 7 6 5 4 3 2 1 0
44 0 0 0 0 0 0 0 1 0 1 1 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0

so I should define ~44 as -45 to make the pdf copy and printable ?right?

I tried, but it not works like this , -45 means copy / extract / fill exists form

and,
I think it's very counterintuitive, why don't we design the API like this?

const (
	PermissionPrint                                  = 1 << 3
	PermissionModifyDocContent                       = 1 << 4
	PermissionCopyDocText                            = 1 << 5
	PermissionModifyTextAnnotationsOrInteractiveForm = 1 << 6
	PermissionFillExistsForm                         = 1 << 9
        //..........
)

and set permission like this PermissionPrint | PermissionCopyDocText ?

@hhrutter
Copy link
Collaborator

hhrutter commented May 21, 2022

The example from the spec turns on bits 3 and 5: 1111 1111 1101 0100 = -44

When you count the bit positions you start with 1 (not with 0).

The example assumes security handler rev 2 so bits 9-12 are disregarded.
Bits 1 and 2 are not interpreted so you should be getting the same permissions with: 1111 1111 1101 0111 = -41
My guess is the same applies to bits 7 and 8.

In order to calculate specific permissions you just turn on the corresponding bits which will get you a two's complement binary integer for which you define the corresponding negative integer value in your code.

It's all explained in the screenshot above.

hhrutter added a commit that referenced this issue Dec 9, 2023
@hhrutter
Copy link
Collaborator

Please see the optimized permissions command of https://github.com/pdfcpu/pdfcpu/releases/tag/v0.6.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants