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

Function createR6Setup

src/security/standard-handler.test.ts:119–170  ·  view source on GitHub ↗

* Create a complete R6 (AES-256) encryption setup for testing.

(
  userPassword: string,
  ownerPassword: string,
  permissions: Permissions = DEFAULT_PERMISSIONS,
)

Source from the content-addressed store, hash-verified

117 * Create a complete R6 (AES-256) encryption setup for testing.
118 */
119function createR6Setup(
120 userPassword: string,
121 ownerPassword: string,
122 permissions: Permissions = DEFAULT_PERMISSIONS,
123) {
124 const userPwd = new TextEncoder().encode(userPassword);
125 const ownerPwd = new TextEncoder().encode(ownerPassword);
126 const fileId = new Uint8Array(32);
127
128 for (let i = 0; i < 32; i++) {
129 fileId[i] = i;
130 }
131
132 const permissionsRaw = encodePermissions(permissions);
133
134 // Generate a random 256-bit file key
135 const fileKey = new Uint8Array(32);
136
137 for (let i = 0; i < 32; i++) {
138 fileKey[i] = (i * 17) % 256;
139 }
140
141 const revision = 6;
142
143 // Generate encryption dictionary entries
144 const { u: userHash, ue: userEncryptionKey } = generateUserEntries(userPwd, fileKey, revision);
145 const { o: ownerHash, oe: ownerEncryptionKey } = generateOwnerEntries(
146 ownerPwd,
147 fileKey,
148 userHash,
149 revision,
150 );
151 const permsValue = generatePermsEntry(fileKey, permissionsRaw, true);
152
153 const encryptDict: EncryptionDict = {
154 filter: "Standard",
155 version: 5,
156 revision: 6,
157 keyLengthBits: 256,
158 ownerHash,
159 userHash,
160 permissions,
161 permissionsRaw,
162 encryptMetadata: true,
163 ownerEncryptionKey,
164 userEncryptionKey,
165 permsValue,
166 algorithm: "AES-256",
167 };
168
169 return { encryptDict, fileId, fileKey, userPwd, ownerPwd };
170}
171
172describe("StandardSecurityHandler", () => {
173 describe("R3 (RC4-128)", () => {

Callers 1

Calls 5

encodePermissionsFunction · 0.90
generateUserEntriesFunction · 0.90
generateOwnerEntriesFunction · 0.90
generatePermsEntryFunction · 0.90
encodeMethod · 0.65

Tested by

no test coverage detected