Skip to content

Commit 93adc1a

Browse files
committed
0.6.11
1 parent b046771 commit 93adc1a

File tree

7 files changed

+30
-27
lines changed

7 files changed

+30
-27
lines changed

Changes

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
{{$NEXT}}
2-
- Support /EncryptMetadata entry in encryption
3-
dictionary
2+
3+
0.6.11 2025-04-25T08:06:09+12:00
4+
- Add support for encrypt EncryptMetadata setting
5+
- Handle reading indirect object generation numbers up to 5 digits,
6+
as per cross-reference trailer syntax.
47

58
0.6.10 2025-04-14T10:19:45+12:00
69
- Don't encrypt /Contents hex-string entry of signature

META6.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,5 +72,5 @@
7272
],
7373
"test-depends": [
7474
],
75-
"version": "0.6.10"
75+
"version": "0.6.11"
7676
}

coverage/PDF.rakucov

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
* #| this class represents the top level node in a PDF or FDF document,
22
#| the trailer dictionary
3-
* unit class PDF:ver<0.6.10>;
3+
* unit class PDF:ver<0.6.11>;
44

55
use PDF::COS::Dict;
66
also is PDF::COS::Dict;
@@ -73,10 +73,7 @@
7373
self;
7474
}
7575

76-
* method encrypt(PDF:D $doc: Str :$owner-pass!, Str :$user-pass = '', :$EncryptMetadata = True, |c ) {
77-
78-
* die '.encrypt(:!EncryptMetadata, ...) is not yet supported'
79-
unless $EncryptMetadata;
76+
* method encrypt(PDF:D $doc: Str :$owner-pass!, Str :$user-pass = '', Bool :$EncryptMetadata = True, |c ) {
8077

8178
* with $.reader {
8279
* with .crypt {
@@ -88,7 +85,7 @@
8885

8986
* $doc<Encrypt>:delete;
9087
* $!flush = True;
91-
* $!crypt = PDF::COS.required('PDF::IO::Crypt::PDF').new: :$doc, :$owner-pass, :$user-pass, |c;
88+
* $!crypt = PDF::COS.required('PDF::IO::Crypt::PDF').new: :$doc, :$owner-pass, :$user-pass, :$EncryptMetadata, |c;
9289
}
9390

9491
* method !is-indexed {

coverage/PDF/IO/Crypt.rakucov

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@
4848
* method !generate(:$doc!,
4949
Str :$owner-pass!,
5050
Str :$user-pass = '',
51-
* UInt :R($!revision) = self.type eq 'AESV2' ?? 4 !! 3,
52-
x UInt :V($version) = self.type eq 'AESV2' ?? 4 !! 2,
5351
Bool :$!EncryptMetadata = True,
52+
* UInt :R($!revision) = self.type eq 'AESV2' || !$!EncryptMetadata ?? 4 !! 3,
53+
x UInt :V($version) = self.type eq 'AESV2' ?? 4 !! 2,
5454
* UInt :$Length = $version > 1 ?? 128 !! 40,
5555
* Int :P($permissions) = -64, #| permissions mask
5656
--> PDF::COS::Type::Encrypt
@@ -93,8 +93,14 @@ x UInt :V($version) = self.type eq 'AESV2' ?? 4 !! 2,
9393
}
9494

9595
* %dict<Length> = $Length unless $version == 1;
96-
* %dict<EncryptMetadata> = False
97-
if $!revision >= 4 && ! $!EncryptMetadata;
96+
* unless $!EncryptMetadata {
97+
* if $!revision >= 4 {
98+
* %dict<EncryptMetadata> = False
99+
}
100+
else {
101+
* warn "ignoring :!EncryptMetadata for encryption revision < 4";
102+
}
103+
}
98104

99105
✱ my $enc = $doc.Encrypt = %dict;
100106

coverage/PDF/IO/Crypt/AST.rakucov

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
x method crypt {...}
44
x method EncryptMetadata {...}
55

6-
my subset CatalogDictLike of Hash where (.<Type> ~~ Pair) && (.<Type><name> ~~ 'Catalog');
6+
my subset MetadataDictLike of Hash where (.<Type> ~~ Pair) && (.<Type><name> ~~ 'Metadata');
77

88
my subset EncryptDictLike of Hash where (.<Filter>:exists) && (.<U>:exists) && (.<O>:exists) && (.<P>:exists);
99

@@ -28,14 +28,6 @@ x method EncryptMetadata {...}
2828
* $.crypt-ast($_, |c) for $ast.values
2929
}
3030

31-
* multi method crypt-ast('dict', CatalogDictLike $ast, |c) {
32-
* for $ast.pairs.sort {
33-
* $.crypt-ast(.value, |c)
34-
unless .key eq 'Encrypt'
35-
x || (.key eq 'Metadata' && ! $.EncryptMetadata);
36-
}
37-
}
38-
3931
* multi method crypt-ast('dict', EncryptDictLike $ast, |c) {
4032
# skip encryption of the Encrypt dictionary
4133
}
@@ -55,9 +47,14 @@ x $.crypt-ast(.value, |c)
5547
}
5648

5749
* multi method crypt-ast('stream', Hash $ast, |c) {
50+
✱ my $dict = $ast<dict>;
51+
52+
* return
53+
if ! $.EncryptMetadata && $dict ~~ MetadataDictLike;
54+
5855
* $.crypt-ast($_, |c)
5956
for $ast.pairs;
60-
* $ast<dict><Length> = .codes
57+
* $dict<Length> = .codes
6158
with $ast<encoded>;
6259
}
6360

coverage/PDF/IO/Crypt/PDF.rakucov

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@
1111

1212
has PDF::IO::Crypt $!stm-f; #| stream filter (/StmF)
1313
has PDF::IO::Crypt $!str-f; #| string filter (/StrF)
14-
has Bool $.EncryptMetadata is built;
1514

1615
* submethod TWEAK(:$doc!, Str :$owner-pass, |c) {
1716
* $owner-pass
1817
?? self!generate( :$doc, :$owner-pass, |c)
1918
!! self!load( :$doc, |c);
20-
* $!EncryptMetadata = $doc<EncryptMetadata> // True;
2119
}
2220

23-
x method type { ($!stm-f.type, $!str-f.type).unique }
21+
* method EncryptMetadata { do with $!stm-f { .EncryptMetadata } // Bool }
22+
23+
* method type { ($!stm-f.type, $!str-f.type).unique }
2424

2525
#| generate encryption
2626
* submethod !generate( Hash :$doc!, Bool :$aes, UInt :$V = $aes ?? 4 !! 2, |c ) {

lib/PDF.rakumod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#| this class represents the top level node in a PDF or FDF document,
22
#| the trailer dictionary
3-
unit class PDF:ver<0.6.10>;
3+
unit class PDF:ver<0.6.11>;
44

55
use PDF::COS::Dict;
66
also is PDF::COS::Dict;

0 commit comments

Comments
 (0)