@@ -215,6 +215,7 @@ def __init__(
215
215
216
216
self ._encryption : Optional [Encryption ] = None
217
217
self ._encrypt_entry : Optional [DictionaryObject ] = None
218
+ self ._ID : Union [ArrayObject , None ] = None
218
219
219
220
def __enter__ (self ) -> "PdfWriter" :
220
221
"""Store that writer is initialized by 'with'."""
@@ -1235,7 +1236,7 @@ def generate_file_identifiers(self) -> None:
1235
1236
The only point of this is ensuring uniqueness. Reproducibility is not
1236
1237
required; see 14.4 "File Identifiers".
1237
1238
"""
1238
- if hasattr ( self , "_ID" ) and self ._ID and len ( self . _ID ) == 2 :
1239
+ if self ._ID :
1239
1240
id1 = self ._ID [0 ]
1240
1241
else :
1241
1242
id1 = self ._compute_document_identifier_from_content ()
@@ -1324,6 +1325,7 @@ def encrypt(
1324
1325
if not use_128bit :
1325
1326
alg = EncryptAlgorithm .RC4_40
1326
1327
self .generate_file_identifiers ()
1328
+ assert self ._ID
1327
1329
self ._encryption = Encryption .make (alg , permissions_flag , self ._ID [0 ])
1328
1330
# in case call `encrypt` again
1329
1331
entry = self ._encryption .write_entry (user_password , owner_password )
@@ -1425,7 +1427,7 @@ def _write_trailer(self, stream: StreamType, xref_location: int) -> None:
1425
1427
NameObject (TK .INFO ): self ._info ,
1426
1428
}
1427
1429
)
1428
- if hasattr ( self , " _ID" ) :
1430
+ if self . _ID :
1429
1431
trailer [NameObject (TK .ID )] = self ._ID
1430
1432
if self ._encrypt_entry :
1431
1433
trailer [NameObject (TK .ENCRYPT )] = self ._encrypt_entry .indirect_reference
0 commit comments