@adnsistemas/pdf-lib 1.18.0 → 2.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +71 -36
- package/cjs/api/PDFDocument.d.ts +44 -11
- package/cjs/api/PDFDocument.d.ts.map +1 -1
- package/cjs/api/PDFDocument.js +599 -609
- package/cjs/api/PDFDocument.js.map +1 -1
- package/cjs/api/PDFDocumentOptions.d.ts +4 -2
- package/cjs/api/PDFDocumentOptions.d.ts.map +1 -1
- package/cjs/api/PDFEmbeddedFile.d.ts +9 -4
- package/cjs/api/PDFEmbeddedFile.d.ts.map +1 -1
- package/cjs/api/PDFEmbeddedFile.js +54 -59
- package/cjs/api/PDFEmbeddedFile.js.map +1 -1
- package/cjs/api/PDFEmbeddedPage.d.ts +3 -3
- package/cjs/api/PDFEmbeddedPage.d.ts.map +1 -1
- package/cjs/api/PDFEmbeddedPage.js +35 -46
- package/cjs/api/PDFEmbeddedPage.js.map +1 -1
- package/cjs/api/PDFFont.d.ts +4 -4
- package/cjs/api/PDFFont.d.ts.map +1 -1
- package/cjs/api/PDFFont.js +47 -57
- package/cjs/api/PDFFont.js.map +1 -1
- package/cjs/api/PDFImage.d.ts +4 -4
- package/cjs/api/PDFImage.d.ts.map +1 -1
- package/cjs/api/PDFImage.js +50 -62
- package/cjs/api/PDFImage.js.map +1 -1
- package/cjs/api/PDFJavaScript.d.ts +4 -4
- package/cjs/api/PDFJavaScript.d.ts.map +1 -1
- package/cjs/api/PDFJavaScript.js +38 -50
- package/cjs/api/PDFJavaScript.js.map +1 -1
- package/cjs/api/PDFPage.d.ts +33 -9
- package/cjs/api/PDFPage.d.ts.map +1 -1
- package/cjs/api/PDFPage.js +478 -431
- package/cjs/api/PDFPage.js.map +1 -1
- package/cjs/api/PDFPageOptions.d.ts +35 -12
- package/cjs/api/PDFPageOptions.d.ts.map +1 -1
- package/cjs/api/PDFPageOptions.js.map +1 -1
- package/cjs/api/PDFSvg.d.ts +7 -0
- package/cjs/api/PDFSvg.d.ts.map +1 -0
- package/cjs/api/PDFSvg.js +10 -0
- package/cjs/api/PDFSvg.js.map +1 -0
- package/cjs/api/colors.d.ts +6 -2
- package/cjs/api/colors.d.ts.map +1 -1
- package/cjs/api/colors.js +51 -43
- package/cjs/api/colors.js.map +1 -1
- package/cjs/api/errors.js +73 -130
- package/cjs/api/errors.js.map +1 -1
- package/cjs/api/form/PDFButton.d.ts +8 -8
- package/cjs/api/form/PDFButton.d.ts.map +1 -1
- package/cjs/api/form/PDFButton.js +68 -72
- package/cjs/api/form/PDFButton.js.map +1 -1
- package/cjs/api/form/PDFCheckBox.d.ts +5 -5
- package/cjs/api/form/PDFCheckBox.d.ts.map +1 -1
- package/cjs/api/form/PDFCheckBox.js +64 -69
- package/cjs/api/form/PDFCheckBox.js.map +1 -1
- package/cjs/api/form/PDFDropdown.d.ts +6 -6
- package/cjs/api/form/PDFDropdown.d.ts.map +1 -1
- package/cjs/api/form/PDFDropdown.js +126 -132
- package/cjs/api/form/PDFDropdown.js.map +1 -1
- package/cjs/api/form/PDFField.d.ts +7 -7
- package/cjs/api/form/PDFField.d.ts.map +1 -1
- package/cjs/api/form/PDFField.js +118 -123
- package/cjs/api/form/PDFField.js.map +1 -1
- package/cjs/api/form/PDFForm.d.ts +11 -11
- package/cjs/api/form/PDFForm.d.ts.map +1 -1
- package/cjs/api/form/PDFForm.js +226 -221
- package/cjs/api/form/PDFForm.js.map +1 -1
- package/cjs/api/form/PDFOptionList.d.ts +6 -6
- package/cjs/api/form/PDFOptionList.d.ts.map +1 -1
- package/cjs/api/form/PDFOptionList.js +115 -121
- package/cjs/api/form/PDFOptionList.js.map +1 -1
- package/cjs/api/form/PDFRadioGroup.d.ts +5 -5
- package/cjs/api/form/PDFRadioGroup.d.ts.map +1 -1
- package/cjs/api/form/PDFRadioGroup.js +98 -101
- package/cjs/api/form/PDFRadioGroup.js.map +1 -1
- package/cjs/api/form/PDFSignature.d.ts +3 -3
- package/cjs/api/form/PDFSignature.d.ts.map +1 -1
- package/cjs/api/form/PDFSignature.js +25 -28
- package/cjs/api/form/PDFSignature.js.map +1 -1
- package/cjs/api/form/PDFTextField.d.ts +8 -8
- package/cjs/api/form/PDFTextField.d.ts.map +1 -1
- package/cjs/api/form/PDFTextField.js +136 -141
- package/cjs/api/form/PDFTextField.js.map +1 -1
- package/cjs/api/form/appearances.d.ts +21 -21
- package/cjs/api/form/appearances.d.ts.map +1 -1
- package/cjs/api/form/appearances.js +257 -219
- package/cjs/api/form/appearances.js.map +1 -1
- package/cjs/api/form/index.d.ts +10 -10
- package/cjs/api/form/index.d.ts.map +1 -1
- package/cjs/api/form/index.js +11 -10
- package/cjs/api/form/index.js.map +1 -1
- package/cjs/api/image/index.d.ts +1 -1
- package/cjs/api/image/index.d.ts.map +1 -1
- package/cjs/api/image/index.js +1 -1
- package/cjs/api/image/index.js.map +1 -1
- package/cjs/api/index.d.ts +22 -21
- package/cjs/api/index.d.ts.map +1 -1
- package/cjs/api/index.js +30 -27
- package/cjs/api/index.js.map +1 -1
- package/cjs/api/objects.d.ts +1 -1
- package/cjs/api/objects.d.ts.map +1 -1
- package/cjs/api/objects.js +7 -10
- package/cjs/api/objects.js.map +1 -1
- package/cjs/api/operations.d.ts +27 -13
- package/cjs/api/operations.d.ts.map +1 -1
- package/cjs/api/operations.js +373 -363
- package/cjs/api/operations.js.map +1 -1
- package/cjs/api/operators.d.ts +6 -1
- package/cjs/api/operators.d.ts.map +1 -1
- package/cjs/api/operators.js +169 -183
- package/cjs/api/operators.js.map +1 -1
- package/cjs/api/rotations.d.ts +2 -2
- package/cjs/api/rotations.d.ts.map +1 -1
- package/cjs/api/rotations.js +30 -30
- package/cjs/api/rotations.js.map +1 -1
- package/cjs/api/snapshot/DefaultDocumentSnapshot.d.ts +1 -1
- package/cjs/api/snapshot/DefaultDocumentSnapshot.d.ts.map +1 -1
- package/cjs/api/snapshot/DefaultDocumentSnapshot.js +13 -14
- package/cjs/api/snapshot/DefaultDocumentSnapshot.js.map +1 -1
- package/cjs/api/snapshot/DocumentSnapshot.d.ts +1 -1
- package/cjs/api/snapshot/DocumentSnapshot.d.ts.map +1 -1
- package/cjs/api/snapshot/IncrementalDocumentSnapshot.d.ts +1 -1
- package/cjs/api/snapshot/IncrementalDocumentSnapshot.d.ts.map +1 -1
- package/cjs/api/snapshot/IncrementalDocumentSnapshot.js +17 -22
- package/cjs/api/snapshot/IncrementalDocumentSnapshot.js.map +1 -1
- package/cjs/api/snapshot/index.js +1 -1
- package/cjs/api/svg.d.ts +76 -0
- package/cjs/api/svg.d.ts.map +1 -0
- package/cjs/api/svg.js +749 -0
- package/cjs/api/svg.js.map +1 -0
- package/cjs/api/svgPath.d.ts +1 -1
- package/cjs/api/svgPath.d.ts.map +1 -1
- package/cjs/api/svgPath.js +115 -118
- package/cjs/api/svgPath.js.map +1 -1
- package/cjs/api/text/index.d.ts +2 -2
- package/cjs/api/text/index.d.ts.map +1 -1
- package/cjs/api/text/index.js +1 -1
- package/cjs/api/text/index.js.map +1 -1
- package/cjs/api/text/layout.d.ts +3 -3
- package/cjs/api/text/layout.d.ts.map +1 -1
- package/cjs/api/text/layout.js +87 -88
- package/cjs/api/text/layout.js.map +1 -1
- package/cjs/core/PDFContext.d.ts +39 -19
- package/cjs/core/PDFContext.d.ts.map +1 -1
- package/cjs/core/PDFContext.js +131 -103
- package/cjs/core/PDFContext.js.map +1 -1
- package/cjs/core/PDFObjectCopier.d.ts +2 -2
- package/cjs/core/PDFObjectCopier.d.ts.map +1 -1
- package/cjs/core/PDFObjectCopier.js +58 -62
- package/cjs/core/PDFObjectCopier.js.map +1 -1
- package/cjs/core/acroform/PDFAcroButton.d.ts +7 -7
- package/cjs/core/acroform/PDFAcroButton.d.ts.map +1 -1
- package/cjs/core/acroform/PDFAcroButton.js +42 -47
- package/cjs/core/acroform/PDFAcroButton.js.map +1 -1
- package/cjs/core/acroform/PDFAcroCheckBox.d.ts +5 -5
- package/cjs/core/acroform/PDFAcroCheckBox.d.ts.map +1 -1
- package/cjs/core/acroform/PDFAcroCheckBox.js +28 -35
- package/cjs/core/acroform/PDFAcroCheckBox.js.map +1 -1
- package/cjs/core/acroform/PDFAcroChoice.d.ts +4 -4
- package/cjs/core/acroform/PDFAcroChoice.d.ts.map +1 -1
- package/cjs/core/acroform/PDFAcroChoice.js +47 -60
- package/cjs/core/acroform/PDFAcroChoice.js.map +1 -1
- package/cjs/core/acroform/PDFAcroComboBox.d.ts +4 -4
- package/cjs/core/acroform/PDFAcroComboBox.d.ts.map +1 -1
- package/cjs/core/acroform/PDFAcroComboBox.js +15 -22
- package/cjs/core/acroform/PDFAcroComboBox.js.map +1 -1
- package/cjs/core/acroform/PDFAcroField.d.ts +8 -8
- package/cjs/core/acroform/PDFAcroField.d.ts.map +1 -1
- package/cjs/core/acroform/PDFAcroField.js +80 -81
- package/cjs/core/acroform/PDFAcroField.js.map +1 -1
- package/cjs/core/acroform/PDFAcroForm.d.ts +5 -5
- package/cjs/core/acroform/PDFAcroForm.d.ts.map +1 -1
- package/cjs/core/acroform/PDFAcroForm.js +46 -47
- package/cjs/core/acroform/PDFAcroForm.js.map +1 -1
- package/cjs/core/acroform/PDFAcroListBox.d.ts +4 -4
- package/cjs/core/acroform/PDFAcroListBox.d.ts.map +1 -1
- package/cjs/core/acroform/PDFAcroListBox.js +13 -20
- package/cjs/core/acroform/PDFAcroListBox.js.map +1 -1
- package/cjs/core/acroform/PDFAcroNonTerminal.d.ts +4 -4
- package/cjs/core/acroform/PDFAcroNonTerminal.d.ts.map +1 -1
- package/cjs/core/acroform/PDFAcroNonTerminal.js +18 -25
- package/cjs/core/acroform/PDFAcroNonTerminal.js.map +1 -1
- package/cjs/core/acroform/PDFAcroPushButton.d.ts +4 -4
- package/cjs/core/acroform/PDFAcroPushButton.d.ts.map +1 -1
- package/cjs/core/acroform/PDFAcroPushButton.js +15 -22
- package/cjs/core/acroform/PDFAcroPushButton.js.map +1 -1
- package/cjs/core/acroform/PDFAcroRadioButton.d.ts +5 -5
- package/cjs/core/acroform/PDFAcroRadioButton.d.ts.map +1 -1
- package/cjs/core/acroform/PDFAcroRadioButton.js +33 -40
- package/cjs/core/acroform/PDFAcroRadioButton.js.map +1 -1
- package/cjs/core/acroform/PDFAcroSignature.d.ts +3 -3
- package/cjs/core/acroform/PDFAcroSignature.d.ts.map +1 -1
- package/cjs/core/acroform/PDFAcroSignature.js +5 -12
- package/cjs/core/acroform/PDFAcroSignature.js.map +1 -1
- package/cjs/core/acroform/PDFAcroTerminal.d.ts +5 -5
- package/cjs/core/acroform/PDFAcroTerminal.d.ts.map +1 -1
- package/cjs/core/acroform/PDFAcroTerminal.js +28 -35
- package/cjs/core/acroform/PDFAcroTerminal.js.map +1 -1
- package/cjs/core/acroform/PDFAcroText.d.ts +7 -7
- package/cjs/core/acroform/PDFAcroText.d.ts.map +1 -1
- package/cjs/core/acroform/PDFAcroText.js +40 -45
- package/cjs/core/acroform/PDFAcroText.js.map +1 -1
- package/cjs/core/acroform/flags.js +1 -1
- package/cjs/core/acroform/flags.js.map +1 -1
- package/cjs/core/acroform/index.d.ts +15 -15
- package/cjs/core/acroform/index.d.ts.map +1 -1
- package/cjs/core/acroform/index.js +15 -14
- package/cjs/core/acroform/index.js.map +1 -1
- package/cjs/core/acroform/utils.d.ts +5 -5
- package/cjs/core/acroform/utils.d.ts.map +1 -1
- package/cjs/core/acroform/utils.js +48 -48
- package/cjs/core/acroform/utils.js.map +1 -1
- package/cjs/core/annotation/AppearanceCharacteristics.d.ts +5 -5
- package/cjs/core/annotation/AppearanceCharacteristics.d.ts.map +1 -1
- package/cjs/core/annotation/AppearanceCharacteristics.js +61 -64
- package/cjs/core/annotation/AppearanceCharacteristics.js.map +1 -1
- package/cjs/core/annotation/BorderStyle.d.ts +2 -2
- package/cjs/core/annotation/BorderStyle.d.ts.map +1 -1
- package/cjs/core/annotation/BorderStyle.js +15 -16
- package/cjs/core/annotation/BorderStyle.js.map +1 -1
- package/cjs/core/annotation/PDFAnnotation.d.ts +6 -6
- package/cjs/core/annotation/PDFAnnotation.d.ts.map +1 -1
- package/cjs/core/annotation/PDFAnnotation.js +76 -77
- package/cjs/core/annotation/PDFAnnotation.js.map +1 -1
- package/cjs/core/annotation/PDFWidgetAnnotation.d.ts +9 -9
- package/cjs/core/annotation/PDFWidgetAnnotation.d.ts.map +1 -1
- package/cjs/core/annotation/PDFWidgetAnnotation.js +60 -67
- package/cjs/core/annotation/PDFWidgetAnnotation.js.map +1 -1
- package/cjs/core/annotation/flags.js +1 -1
- package/cjs/core/annotation/flags.js.map +1 -1
- package/cjs/core/annotation/index.d.ts +4 -4
- package/cjs/core/annotation/index.d.ts.map +1 -1
- package/cjs/core/annotation/index.js +5 -4
- package/cjs/core/annotation/index.js.map +1 -1
- package/cjs/core/crypto.d.ts +96 -0
- package/cjs/core/crypto.d.ts.map +1 -0
- package/cjs/core/crypto.js +1623 -0
- package/cjs/core/crypto.js.map +1 -0
- package/cjs/core/document/PDFCrossRefSection.d.ts +1 -1
- package/cjs/core/document/PDFCrossRefSection.d.ts.map +1 -1
- package/cjs/core/document/PDFCrossRefSection.js +62 -65
- package/cjs/core/document/PDFCrossRefSection.js.map +1 -1
- package/cjs/core/document/PDFHeader.d.ts +1 -0
- package/cjs/core/document/PDFHeader.d.ts.map +1 -1
- package/cjs/core/document/PDFHeader.js +21 -21
- package/cjs/core/document/PDFHeader.js.map +1 -1
- package/cjs/core/document/PDFTrailer.js +16 -19
- package/cjs/core/document/PDFTrailer.js.map +1 -1
- package/cjs/core/document/PDFTrailerDict.d.ts +1 -1
- package/cjs/core/document/PDFTrailerDict.d.ts.map +1 -1
- package/cjs/core/document/PDFTrailerDict.js +14 -15
- package/cjs/core/document/PDFTrailerDict.js.map +1 -1
- package/cjs/core/embedders/CMap.d.ts +2 -2
- package/cjs/core/embedders/CMap.d.ts.map +1 -1
- package/cjs/core/embedders/CMap.js +41 -28
- package/cjs/core/embedders/CMap.js.map +1 -1
- package/cjs/core/embedders/CustomFontEmbedder.d.ts +5 -5
- package/cjs/core/embedders/CustomFontEmbedder.d.ts.map +1 -1
- package/cjs/core/embedders/CustomFontEmbedder.js +133 -178
- package/cjs/core/embedders/CustomFontEmbedder.js.map +1 -1
- package/cjs/core/embedders/CustomFontSubsetEmbedder.d.ts +3 -3
- package/cjs/core/embedders/CustomFontSubsetEmbedder.d.ts.map +1 -1
- package/cjs/core/embedders/CustomFontSubsetEmbedder.js +38 -49
- package/cjs/core/embedders/CustomFontSubsetEmbedder.js.map +1 -1
- package/cjs/core/embedders/FileEmbedder.d.ts +3 -2
- package/cjs/core/embedders/FileEmbedder.d.ts.map +1 -1
- package/cjs/core/embedders/FileEmbedder.js +44 -48
- package/cjs/core/embedders/FileEmbedder.js.map +1 -1
- package/cjs/core/embedders/FontFlags.d.ts +1 -1
- package/cjs/core/embedders/FontFlags.d.ts.map +1 -1
- package/cjs/core/embedders/FontFlags.js +7 -6
- package/cjs/core/embedders/FontFlags.js.map +1 -1
- package/cjs/core/embedders/JavaScriptEmbedder.d.ts +2 -2
- package/cjs/core/embedders/JavaScriptEmbedder.d.ts.map +1 -1
- package/cjs/core/embedders/JavaScriptEmbedder.js +22 -27
- package/cjs/core/embedders/JavaScriptEmbedder.js.map +1 -1
- package/cjs/core/embedders/JpegEmbedder.d.ts +2 -2
- package/cjs/core/embedders/JpegEmbedder.d.ts.map +1 -1
- package/cjs/core/embedders/JpegEmbedder.js +66 -73
- package/cjs/core/embedders/JpegEmbedder.js.map +1 -1
- package/cjs/core/embedders/PDFPageEmbedder.d.ts +4 -4
- package/cjs/core/embedders/PDFPageEmbedder.d.ts.map +1 -1
- package/cjs/core/embedders/PDFPageEmbedder.js +64 -65
- package/cjs/core/embedders/PDFPageEmbedder.js.map +1 -1
- package/cjs/core/embedders/PngEmbedder.d.ts +2 -2
- package/cjs/core/embedders/PngEmbedder.d.ts.map +1 -1
- package/cjs/core/embedders/PngEmbedder.js +33 -41
- package/cjs/core/embedders/PngEmbedder.js.map +1 -1
- package/cjs/core/embedders/StandardFontEmbedder.d.ts +4 -4
- package/cjs/core/embedders/StandardFontEmbedder.d.ts.map +1 -1
- package/cjs/core/embedders/StandardFontEmbedder.js +53 -51
- package/cjs/core/embedders/StandardFontEmbedder.js.map +1 -1
- package/cjs/core/errors.d.ts +1 -1
- package/cjs/core/errors.d.ts.map +1 -1
- package/cjs/core/errors.js +147 -260
- package/cjs/core/errors.js.map +1 -1
- package/cjs/core/index.d.ts +48 -47
- package/cjs/core/index.d.ts.map +1 -1
- package/cjs/core/index.js +47 -44
- package/cjs/core/index.js.map +1 -1
- package/cjs/core/interactive/ViewerPreferences.d.ts +8 -8
- package/cjs/core/interactive/ViewerPreferences.d.ts.map +1 -1
- package/cjs/core/interactive/ViewerPreferences.js +135 -138
- package/cjs/core/interactive/ViewerPreferences.js.map +1 -1
- package/cjs/core/objects/PDFArray.d.ts +12 -12
- package/cjs/core/objects/PDFArray.d.ts.map +1 -1
- package/cjs/core/objects/PDFArray.js +72 -81
- package/cjs/core/objects/PDFArray.js.map +1 -1
- package/cjs/core/objects/PDFBool.d.ts +1 -1
- package/cjs/core/objects/PDFBool.d.ts.map +1 -1
- package/cjs/core/objects/PDFBool.js +22 -26
- package/cjs/core/objects/PDFBool.js.map +1 -1
- package/cjs/core/objects/PDFDict.d.ts +13 -12
- package/cjs/core/objects/PDFDict.d.ts.map +1 -1
- package/cjs/core/objects/PDFDict.js +76 -88
- package/cjs/core/objects/PDFDict.js.map +1 -1
- package/cjs/core/objects/PDFHexString.d.ts +2 -1
- package/cjs/core/objects/PDFHexString.d.ts.map +1 -1
- package/cjs/core/objects/PDFHexString.js +50 -52
- package/cjs/core/objects/PDFHexString.js.map +1 -1
- package/cjs/core/objects/PDFInvalidObject.d.ts +1 -1
- package/cjs/core/objects/PDFInvalidObject.d.ts.map +1 -1
- package/cjs/core/objects/PDFInvalidObject.js +19 -22
- package/cjs/core/objects/PDFInvalidObject.js.map +1 -1
- package/cjs/core/objects/PDFName.d.ts +1 -1
- package/cjs/core/objects/PDFName.d.ts.map +1 -1
- package/cjs/core/objects/PDFName.js +84 -92
- package/cjs/core/objects/PDFName.js.map +1 -1
- package/cjs/core/objects/PDFNull.d.ts +1 -1
- package/cjs/core/objects/PDFNull.d.ts.map +1 -1
- package/cjs/core/objects/PDFNull.js +15 -20
- package/cjs/core/objects/PDFNull.js.map +1 -1
- package/cjs/core/objects/PDFNumber.d.ts +1 -1
- package/cjs/core/objects/PDFNumber.d.ts.map +1 -1
- package/cjs/core/objects/PDFNumber.js +23 -26
- package/cjs/core/objects/PDFNumber.js.map +1 -1
- package/cjs/core/objects/PDFObject.d.ts +1 -1
- package/cjs/core/objects/PDFObject.d.ts.map +1 -1
- package/cjs/core/objects/PDFObject.js +13 -16
- package/cjs/core/objects/PDFObject.js.map +1 -1
- package/cjs/core/objects/PDFRawStream.d.ts +8 -5
- package/cjs/core/objects/PDFRawStream.d.ts.map +1 -1
- package/cjs/core/objects/PDFRawStream.js +24 -25
- package/cjs/core/objects/PDFRawStream.js.map +1 -1
- package/cjs/core/objects/PDFRef.d.ts +1 -1
- package/cjs/core/objects/PDFRef.d.ts.map +1 -1
- package/cjs/core/objects/PDFRef.js +31 -36
- package/cjs/core/objects/PDFRef.js.map +1 -1
- package/cjs/core/objects/PDFStream.d.ts +4 -3
- package/cjs/core/objects/PDFStream.d.ts.map +1 -1
- package/cjs/core/objects/PDFStream.js +35 -35
- package/cjs/core/objects/PDFStream.js.map +1 -1
- package/cjs/core/objects/PDFString.d.ts +1 -1
- package/cjs/core/objects/PDFString.d.ts.map +1 -1
- package/cjs/core/objects/PDFString.js +55 -58
- package/cjs/core/objects/PDFString.js.map +1 -1
- package/cjs/core/operators/PDFOperator.d.ts +9 -9
- package/cjs/core/operators/PDFOperator.d.ts.map +1 -1
- package/cjs/core/operators/PDFOperator.js +29 -32
- package/cjs/core/operators/PDFOperator.js.map +1 -1
- package/cjs/core/parser/BaseParser.d.ts +1 -1
- package/cjs/core/parser/BaseParser.d.ts.map +1 -1
- package/cjs/core/parser/BaseParser.js +40 -42
- package/cjs/core/parser/BaseParser.js.map +1 -1
- package/cjs/core/parser/ByteStream.d.ts +1 -1
- package/cjs/core/parser/ByteStream.d.ts.map +1 -1
- package/cjs/core/parser/ByteStream.js +30 -33
- package/cjs/core/parser/ByteStream.js.map +1 -1
- package/cjs/core/parser/PDFObjectParser.d.ts +23 -21
- package/cjs/core/parser/PDFObjectParser.d.ts.map +1 -1
- package/cjs/core/parser/PDFObjectParser.js +96 -88
- package/cjs/core/parser/PDFObjectParser.js.map +1 -1
- package/cjs/core/parser/PDFObjectStreamParser.d.ts +3 -3
- package/cjs/core/parser/PDFObjectStreamParser.d.ts.map +1 -1
- package/cjs/core/parser/PDFObjectStreamParser.js +42 -60
- package/cjs/core/parser/PDFObjectStreamParser.js.map +1 -1
- package/cjs/core/parser/PDFParser.d.ts +6 -4
- package/cjs/core/parser/PDFParser.d.ts.map +1 -1
- package/cjs/core/parser/PDFParser.js +169 -217
- package/cjs/core/parser/PDFParser.js.map +1 -1
- package/cjs/core/parser/PDFXRefStreamParser.d.ts +2 -2
- package/cjs/core/parser/PDFXRefStreamParser.d.ts.map +1 -1
- package/cjs/core/parser/PDFXRefStreamParser.js +38 -41
- package/cjs/core/parser/PDFXRefStreamParser.js.map +1 -1
- package/cjs/core/security/PDFSecurity.d.ts +75 -0
- package/cjs/core/security/PDFSecurity.d.ts.map +1 -0
- package/cjs/core/security/PDFSecurity.js +406 -0
- package/cjs/core/security/PDFSecurity.js.map +1 -0
- package/cjs/core/streams/Ascii85Stream.d.ts +2 -2
- package/cjs/core/streams/Ascii85Stream.d.ts.map +1 -1
- package/cjs/core/streams/Ascii85Stream.js +21 -26
- package/cjs/core/streams/Ascii85Stream.js.map +1 -1
- package/cjs/core/streams/AsciiHexStream.d.ts +2 -2
- package/cjs/core/streams/AsciiHexStream.d.ts.map +1 -1
- package/cjs/core/streams/AsciiHexStream.js +19 -22
- package/cjs/core/streams/AsciiHexStream.js.map +1 -1
- package/cjs/core/streams/DecodeStream.d.ts +1 -1
- package/cjs/core/streams/DecodeStream.d.ts.map +1 -1
- package/cjs/core/streams/DecodeStream.js +54 -61
- package/cjs/core/streams/DecodeStream.js.map +1 -1
- package/cjs/core/streams/DecryptStream.d.ts +13 -0
- package/cjs/core/streams/DecryptStream.d.ts.map +1 -0
- package/cjs/core/streams/DecryptStream.js +39 -0
- package/cjs/core/streams/DecryptStream.js.map +1 -0
- package/cjs/core/streams/FlateStream.d.ts +2 -2
- package/cjs/core/streams/FlateStream.d.ts.map +1 -1
- package/cjs/core/streams/FlateStream.js +82 -84
- package/cjs/core/streams/FlateStream.js.map +1 -1
- package/cjs/core/streams/LZWStream.d.ts +3 -3
- package/cjs/core/streams/LZWStream.d.ts.map +1 -1
- package/cjs/core/streams/LZWStream.js +42 -45
- package/cjs/core/streams/LZWStream.js.map +1 -1
- package/cjs/core/streams/RunLengthStream.d.ts +2 -2
- package/cjs/core/streams/RunLengthStream.d.ts.map +1 -1
- package/cjs/core/streams/RunLengthStream.js +16 -19
- package/cjs/core/streams/RunLengthStream.js.map +1 -1
- package/cjs/core/streams/Stream.js +45 -56
- package/cjs/core/streams/Stream.js.map +1 -1
- package/cjs/core/streams/decode.d.ts +3 -3
- package/cjs/core/streams/decode.d.ts.map +1 -1
- package/cjs/core/streams/decode.js +25 -22
- package/cjs/core/streams/decode.js.map +1 -1
- package/cjs/core/structures/PDFCatalog.d.ts +5 -5
- package/cjs/core/structures/PDFCatalog.d.ts.map +1 -1
- package/cjs/core/structures/PDFCatalog.js +40 -47
- package/cjs/core/structures/PDFCatalog.js.map +1 -1
- package/cjs/core/structures/PDFContentStream.d.ts +4 -4
- package/cjs/core/structures/PDFContentStream.d.ts.map +1 -1
- package/cjs/core/structures/PDFContentStream.js +31 -43
- package/cjs/core/structures/PDFContentStream.js.map +1 -1
- package/cjs/core/structures/PDFCrossRefStream.d.ts +6 -6
- package/cjs/core/structures/PDFCrossRefStream.d.ts.map +1 -1
- package/cjs/core/structures/PDFCrossRefStream.js +92 -100
- package/cjs/core/structures/PDFCrossRefStream.js.map +1 -1
- package/cjs/core/structures/PDFFlateStream.d.ts +5 -4
- package/cjs/core/structures/PDFFlateStream.d.ts.map +1 -1
- package/cjs/core/structures/PDFFlateStream.js +24 -24
- package/cjs/core/structures/PDFFlateStream.js.map +1 -1
- package/cjs/core/structures/PDFObjectStream.d.ts +5 -5
- package/cjs/core/structures/PDFObjectStream.d.ts.map +1 -1
- package/cjs/core/structures/PDFObjectStream.js +49 -56
- package/cjs/core/structures/PDFObjectStream.js.map +1 -1
- package/cjs/core/structures/PDFPageLeaf.d.ts +9 -9
- package/cjs/core/structures/PDFPageLeaf.d.ts.map +1 -1
- package/cjs/core/structures/PDFPageLeaf.js +126 -133
- package/cjs/core/structures/PDFPageLeaf.js.map +1 -1
- package/cjs/core/structures/PDFPageTree.d.ts +8 -8
- package/cjs/core/structures/PDFPageTree.d.ts.map +1 -1
- package/cjs/core/structures/PDFPageTree.js +67 -75
- package/cjs/core/structures/PDFPageTree.js.map +1 -1
- package/cjs/core/syntax/Delimiters.js +2 -2
- package/cjs/core/syntax/Delimiters.js.map +1 -1
- package/cjs/core/syntax/Irregular.js +5 -5
- package/cjs/core/syntax/Irregular.js.map +1 -1
- package/cjs/core/syntax/Keywords.d.ts +1 -1
- package/cjs/core/syntax/Keywords.d.ts.map +1 -1
- package/cjs/core/syntax/Keywords.js +14 -14
- package/cjs/core/syntax/Keywords.js.map +1 -1
- package/cjs/core/syntax/Numeric.js +3 -3
- package/cjs/core/syntax/Numeric.js.map +1 -1
- package/cjs/core/syntax/Whitespace.js +2 -2
- package/cjs/core/syntax/Whitespace.js.map +1 -1
- package/cjs/core/writers/PDFStreamWriter.d.ts +7 -7
- package/cjs/core/writers/PDFStreamWriter.d.ts.map +1 -1
- package/cjs/core/writers/PDFStreamWriter.js +102 -126
- package/cjs/core/writers/PDFStreamWriter.js.map +1 -1
- package/cjs/core/writers/PDFWriter.d.ts +15 -10
- package/cjs/core/writers/PDFWriter.d.ts.map +1 -1
- package/cjs/core/writers/PDFWriter.js +116 -142
- package/cjs/core/writers/PDFWriter.js.map +1 -1
- package/cjs/index.d.ts +4 -4
- package/cjs/index.d.ts.map +1 -1
- package/cjs/index.js +5 -5
- package/cjs/index.js.map +1 -1
- package/cjs/types/index.d.ts +25 -1
- package/cjs/types/index.d.ts.map +1 -1
- package/cjs/types/matrix.d.ts +8 -1
- package/cjs/types/matrix.d.ts.map +1 -1
- package/cjs/utils/Cache.js +10 -11
- package/cjs/utils/Cache.js.map +1 -1
- package/cjs/utils/arrays.d.ts +3 -1
- package/cjs/utils/arrays.d.ts.map +1 -1
- package/cjs/utils/arrays.js +97 -64
- package/cjs/utils/arrays.js.map +1 -1
- package/cjs/utils/async.d.ts.map +1 -1
- package/cjs/utils/async.js +4 -5
- package/cjs/utils/async.js.map +1 -1
- package/cjs/utils/base64.d.ts.map +1 -1
- package/cjs/utils/base64.js +29 -26
- package/cjs/utils/base64.js.map +1 -1
- package/cjs/utils/elements/Arc.d.ts +23 -0
- package/cjs/utils/elements/Arc.d.ts.map +1 -0
- package/cjs/utils/elements/Arc.js +78 -0
- package/cjs/utils/elements/Arc.js.map +1 -0
- package/cjs/utils/elements/Circle.d.ts +15 -0
- package/cjs/utils/elements/Circle.d.ts.map +1 -0
- package/cjs/utils/elements/Circle.js +41 -0
- package/cjs/utils/elements/Circle.js.map +1 -0
- package/cjs/utils/elements/Ellipse.d.ts +21 -0
- package/cjs/utils/elements/Ellipse.d.ts.map +1 -0
- package/cjs/utils/elements/Ellipse.js +91 -0
- package/cjs/utils/elements/Ellipse.js.map +1 -0
- package/cjs/utils/elements/GraphElement.d.ts +7 -0
- package/cjs/utils/elements/GraphElement.d.ts.map +1 -0
- package/cjs/utils/elements/GraphElement.js +11 -0
- package/cjs/utils/elements/GraphElement.js.map +1 -0
- package/cjs/utils/elements/Line.d.ts +24 -0
- package/cjs/utils/elements/Line.d.ts.map +1 -0
- package/cjs/utils/elements/Line.js +72 -0
- package/cjs/utils/elements/Line.js.map +1 -0
- package/cjs/utils/elements/Plot.d.ts +12 -0
- package/cjs/utils/elements/Plot.d.ts.map +1 -0
- package/cjs/utils/elements/Plot.js +46 -0
- package/cjs/utils/elements/Plot.js.map +1 -0
- package/cjs/utils/elements/Point.d.ts +19 -0
- package/cjs/utils/elements/Point.d.ts.map +1 -0
- package/cjs/utils/elements/Point.js +32 -0
- package/cjs/utils/elements/Point.js.map +1 -0
- package/cjs/utils/elements/Rectangle.d.ts +22 -0
- package/cjs/utils/elements/Rectangle.d.ts.map +1 -0
- package/cjs/utils/elements/Rectangle.js +58 -0
- package/cjs/utils/elements/Rectangle.js.map +1 -0
- package/cjs/utils/elements/Segment.d.ts +20 -0
- package/cjs/utils/elements/Segment.d.ts.map +1 -0
- package/cjs/utils/elements/Segment.js +80 -0
- package/cjs/utils/elements/Segment.js.map +1 -0
- package/cjs/utils/elements/index.d.ts +10 -0
- package/cjs/utils/elements/index.d.ts.map +1 -0
- package/cjs/utils/elements/index.js +25 -0
- package/cjs/utils/elements/index.js.map +1 -0
- package/cjs/utils/errors.js +2 -1
- package/cjs/utils/errors.js.map +1 -1
- package/cjs/utils/index.d.ts +11 -11
- package/cjs/utils/index.d.ts.map +1 -1
- package/cjs/utils/index.js +3 -2
- package/cjs/utils/index.js.map +1 -1
- package/cjs/utils/intersections.d.ts +10 -0
- package/cjs/utils/intersections.d.ts.map +1 -0
- package/cjs/utils/intersections.js +253 -0
- package/cjs/utils/intersections.js.map +1 -0
- package/cjs/utils/maths.d.ts +46 -0
- package/cjs/utils/maths.d.ts.map +1 -0
- package/cjs/utils/maths.js +89 -0
- package/cjs/utils/maths.js.map +1 -0
- package/cjs/utils/numbers.js +12 -9
- package/cjs/utils/numbers.js.map +1 -1
- package/cjs/utils/objects.js +8 -7
- package/cjs/utils/objects.js.map +1 -1
- package/cjs/utils/pdfDocEncoding.js +52 -51
- package/cjs/utils/pdfDocEncoding.js.map +1 -1
- package/cjs/utils/png.js +22 -23
- package/cjs/utils/png.js.map +1 -1
- package/cjs/utils/rng.js +7 -8
- package/cjs/utils/rng.js.map +1 -1
- package/cjs/utils/strings.d.ts +1 -0
- package/cjs/utils/strings.d.ts.map +1 -1
- package/cjs/utils/strings.js +88 -70
- package/cjs/utils/strings.js.map +1 -1
- package/cjs/utils/unicode.js +51 -64
- package/cjs/utils/unicode.js.map +1 -1
- package/cjs/utils/validators.d.ts +2 -2
- package/cjs/utils/validators.d.ts.map +1 -1
- package/cjs/utils/validators.js +84 -67
- package/cjs/utils/validators.js.map +1 -1
- package/dist/pdf-lib.esm.js +16231 -31855
- package/dist/pdf-lib.esm.js.map +1 -1
- package/dist/pdf-lib.esm.min.js +16 -13
- package/dist/pdf-lib.esm.min.js.map +1 -1
- package/dist/pdf-lib.js +16370 -32042
- package/dist/pdf-lib.js.map +1 -1
- package/dist/pdf-lib.min.js +16 -13
- package/dist/pdf-lib.min.js.map +1 -1
- package/es/api/Embeddable.js +1 -0
- package/es/api/PDFDocument.d.ts +44 -11
- package/es/api/PDFDocument.d.ts.map +1 -1
- package/es/api/PDFDocument.js +580 -591
- package/es/api/PDFDocument.js.map +1 -1
- package/es/api/PDFDocumentOptions.d.ts +4 -2
- package/es/api/PDFDocumentOptions.d.ts.map +1 -1
- package/es/api/PDFEmbeddedFile.d.ts +9 -4
- package/es/api/PDFEmbeddedFile.d.ts.map +1 -1
- package/es/api/PDFEmbeddedFile.js +54 -60
- package/es/api/PDFEmbeddedFile.js.map +1 -1
- package/es/api/PDFEmbeddedPage.d.ts +3 -3
- package/es/api/PDFEmbeddedPage.d.ts.map +1 -1
- package/es/api/PDFEmbeddedPage.js +31 -43
- package/es/api/PDFEmbeddedPage.js.map +1 -1
- package/es/api/PDFFont.d.ts +4 -4
- package/es/api/PDFFont.d.ts.map +1 -1
- package/es/api/PDFFont.js +38 -49
- package/es/api/PDFFont.js.map +1 -1
- package/es/api/PDFImage.d.ts +4 -4
- package/es/api/PDFImage.d.ts.map +1 -1
- package/es/api/PDFImage.js +44 -57
- package/es/api/PDFImage.js.map +1 -1
- package/es/api/PDFJavaScript.d.ts +4 -4
- package/es/api/PDFJavaScript.d.ts.map +1 -1
- package/es/api/PDFJavaScript.js +38 -51
- package/es/api/PDFJavaScript.js.map +1 -1
- package/es/api/PDFPage.d.ts +33 -9
- package/es/api/PDFPage.d.ts.map +1 -1
- package/es/api/PDFPage.js +311 -266
- package/es/api/PDFPage.js.map +1 -1
- package/es/api/PDFPageOptions.d.ts +35 -12
- package/es/api/PDFPageOptions.d.ts.map +1 -1
- package/es/api/PDFPageOptions.js.map +1 -1
- package/es/api/PDFSvg.d.ts +7 -0
- package/es/api/PDFSvg.d.ts.map +1 -0
- package/es/api/PDFSvg.js +7 -0
- package/es/api/PDFSvg.js.map +1 -0
- package/es/api/colors.d.ts +6 -2
- package/es/api/colors.d.ts.map +1 -1
- package/es/api/colors.js +33 -34
- package/es/api/colors.js.map +1 -1
- package/es/api/errors.js +73 -144
- package/es/api/errors.js.map +1 -1
- package/es/api/form/PDFButton.d.ts +8 -8
- package/es/api/form/PDFButton.d.ts.map +1 -1
- package/es/api/form/PDFButton.js +56 -62
- package/es/api/form/PDFButton.js.map +1 -1
- package/es/api/form/PDFCheckBox.d.ts +5 -5
- package/es/api/form/PDFCheckBox.d.ts.map +1 -1
- package/es/api/form/PDFCheckBox.js +55 -62
- package/es/api/form/PDFCheckBox.js.map +1 -1
- package/es/api/form/PDFDropdown.d.ts +6 -6
- package/es/api/form/PDFDropdown.d.ts.map +1 -1
- package/es/api/form/PDFDropdown.js +110 -118
- package/es/api/form/PDFDropdown.js.map +1 -1
- package/es/api/form/PDFField.d.ts +7 -7
- package/es/api/form/PDFField.d.ts.map +1 -1
- package/es/api/form/PDFField.js +98 -106
- package/es/api/form/PDFField.js.map +1 -1
- package/es/api/form/PDFForm.d.ts +11 -11
- package/es/api/form/PDFForm.d.ts.map +1 -1
- package/es/api/form/PDFForm.js +203 -200
- package/es/api/form/PDFForm.js.map +1 -1
- package/es/api/form/PDFOptionList.d.ts +6 -6
- package/es/api/form/PDFOptionList.d.ts.map +1 -1
- package/es/api/form/PDFOptionList.js +98 -106
- package/es/api/form/PDFOptionList.js.map +1 -1
- package/es/api/form/PDFRadioGroup.d.ts +5 -5
- package/es/api/form/PDFRadioGroup.d.ts.map +1 -1
- package/es/api/form/PDFRadioGroup.js +86 -91
- package/es/api/form/PDFRadioGroup.js.map +1 -1
- package/es/api/form/PDFSignature.d.ts +3 -3
- package/es/api/form/PDFSignature.d.ts.map +1 -1
- package/es/api/form/PDFSignature.js +23 -28
- package/es/api/form/PDFSignature.js.map +1 -1
- package/es/api/form/PDFTextField.d.ts +8 -8
- package/es/api/form/PDFTextField.d.ts.map +1 -1
- package/es/api/form/PDFTextField.js +121 -128
- package/es/api/form/PDFTextField.js.map +1 -1
- package/es/api/form/appearances.d.ts +21 -21
- package/es/api/form/appearances.d.ts.map +1 -1
- package/es/api/form/appearances.js +245 -214
- package/es/api/form/appearances.js.map +1 -1
- package/es/api/form/index.d.ts +10 -10
- package/es/api/form/index.d.ts.map +1 -1
- package/es/api/form/index.js +10 -10
- package/es/api/form/index.js.map +1 -1
- package/es/api/image/index.d.ts +1 -1
- package/es/api/image/index.d.ts.map +1 -1
- package/es/api/image/index.js +1 -1
- package/es/api/image/index.js.map +1 -1
- package/es/api/index.d.ts +22 -21
- package/es/api/index.d.ts.map +1 -1
- package/es/api/index.js +21 -20
- package/es/api/index.js.map +1 -1
- package/es/api/objects.d.ts +1 -1
- package/es/api/objects.d.ts.map +1 -1
- package/es/api/objects.js +4 -10
- package/es/api/objects.js.map +1 -1
- package/es/api/operations.d.ts +27 -13
- package/es/api/operations.d.ts.map +1 -1
- package/es/api/operations.js +266 -272
- package/es/api/operations.js.map +1 -1
- package/es/api/operators.d.ts +6 -1
- package/es/api/operators.d.ts.map +1 -1
- package/es/api/operators.js +114 -182
- package/es/api/operators.js.map +1 -1
- package/es/api/rotations.d.ts +2 -2
- package/es/api/rotations.d.ts.map +1 -1
- package/es/api/rotations.js +19 -28
- package/es/api/rotations.js.map +1 -1
- package/es/api/sizes.js +1 -1
- package/es/api/sizes.js.map +1 -1
- package/es/api/snapshot/DefaultDocumentSnapshot.d.ts +1 -1
- package/es/api/snapshot/DefaultDocumentSnapshot.d.ts.map +1 -1
- package/es/api/snapshot/DefaultDocumentSnapshot.js +14 -16
- package/es/api/snapshot/DefaultDocumentSnapshot.js.map +1 -1
- package/es/api/snapshot/DocumentSnapshot.d.ts +1 -1
- package/es/api/snapshot/DocumentSnapshot.d.ts.map +1 -1
- package/es/api/snapshot/DocumentSnapshot.js +1 -0
- package/es/api/snapshot/IncrementalDocumentSnapshot.d.ts +1 -1
- package/es/api/snapshot/IncrementalDocumentSnapshot.d.ts.map +1 -1
- package/es/api/snapshot/IncrementalDocumentSnapshot.js +17 -23
- package/es/api/snapshot/IncrementalDocumentSnapshot.js.map +1 -1
- package/es/api/snapshot/index.js +3 -3
- package/es/api/svg.d.ts +76 -0
- package/es/api/svg.d.ts.map +1 -0
- package/es/api/svg.js +742 -0
- package/es/api/svg.js.map +1 -0
- package/es/api/svgPath.d.ts +1 -1
- package/es/api/svgPath.d.ts.map +1 -1
- package/es/api/svgPath.js +104 -108
- package/es/api/svgPath.js.map +1 -1
- package/es/api/text/index.d.ts +2 -2
- package/es/api/text/index.d.ts.map +1 -1
- package/es/api/text/index.js +2 -2
- package/es/api/text/index.js.map +1 -1
- package/es/api/text/layout.d.ts +3 -3
- package/es/api/text/layout.d.ts.map +1 -1
- package/es/api/text/layout.js +84 -88
- package/es/api/text/layout.js.map +1 -1
- package/es/core/PDFContext.d.ts +39 -19
- package/es/core/PDFContext.d.ts.map +1 -1
- package/es/core/PDFContext.js +128 -101
- package/es/core/PDFContext.js.map +1 -1
- package/es/core/PDFObjectCopier.d.ts +2 -2
- package/es/core/PDFObjectCopier.d.ts.map +1 -1
- package/es/core/PDFObjectCopier.js +57 -61
- package/es/core/PDFObjectCopier.js.map +1 -1
- package/es/core/acroform/PDFAcroButton.d.ts +7 -7
- package/es/core/acroform/PDFAcroButton.d.ts.map +1 -1
- package/es/core/acroform/PDFAcroButton.js +41 -47
- package/es/core/acroform/PDFAcroButton.js.map +1 -1
- package/es/core/acroform/PDFAcroCheckBox.d.ts +5 -5
- package/es/core/acroform/PDFAcroCheckBox.d.ts.map +1 -1
- package/es/core/acroform/PDFAcroCheckBox.js +27 -35
- package/es/core/acroform/PDFAcroCheckBox.js.map +1 -1
- package/es/core/acroform/PDFAcroChoice.d.ts +4 -4
- package/es/core/acroform/PDFAcroChoice.d.ts.map +1 -1
- package/es/core/acroform/PDFAcroChoice.js +46 -60
- package/es/core/acroform/PDFAcroChoice.js.map +1 -1
- package/es/core/acroform/PDFAcroComboBox.d.ts +4 -4
- package/es/core/acroform/PDFAcroComboBox.d.ts.map +1 -1
- package/es/core/acroform/PDFAcroComboBox.js +14 -22
- package/es/core/acroform/PDFAcroComboBox.js.map +1 -1
- package/es/core/acroform/PDFAcroField.d.ts +8 -8
- package/es/core/acroform/PDFAcroField.d.ts.map +1 -1
- package/es/core/acroform/PDFAcroField.js +79 -80
- package/es/core/acroform/PDFAcroField.js.map +1 -1
- package/es/core/acroform/PDFAcroForm.d.ts +5 -5
- package/es/core/acroform/PDFAcroForm.d.ts.map +1 -1
- package/es/core/acroform/PDFAcroForm.js +43 -44
- package/es/core/acroform/PDFAcroForm.js.map +1 -1
- package/es/core/acroform/PDFAcroListBox.d.ts +4 -4
- package/es/core/acroform/PDFAcroListBox.d.ts.map +1 -1
- package/es/core/acroform/PDFAcroListBox.js +12 -20
- package/es/core/acroform/PDFAcroListBox.js.map +1 -1
- package/es/core/acroform/PDFAcroNonTerminal.d.ts +4 -4
- package/es/core/acroform/PDFAcroNonTerminal.d.ts.map +1 -1
- package/es/core/acroform/PDFAcroNonTerminal.js +17 -25
- package/es/core/acroform/PDFAcroNonTerminal.js.map +1 -1
- package/es/core/acroform/PDFAcroPushButton.d.ts +4 -4
- package/es/core/acroform/PDFAcroPushButton.d.ts.map +1 -1
- package/es/core/acroform/PDFAcroPushButton.js +14 -22
- package/es/core/acroform/PDFAcroPushButton.js.map +1 -1
- package/es/core/acroform/PDFAcroRadioButton.d.ts +5 -5
- package/es/core/acroform/PDFAcroRadioButton.d.ts.map +1 -1
- package/es/core/acroform/PDFAcroRadioButton.js +32 -40
- package/es/core/acroform/PDFAcroRadioButton.js.map +1 -1
- package/es/core/acroform/PDFAcroSignature.d.ts +3 -3
- package/es/core/acroform/PDFAcroSignature.d.ts.map +1 -1
- package/es/core/acroform/PDFAcroSignature.js +4 -12
- package/es/core/acroform/PDFAcroSignature.js.map +1 -1
- package/es/core/acroform/PDFAcroTerminal.d.ts +5 -5
- package/es/core/acroform/PDFAcroTerminal.d.ts.map +1 -1
- package/es/core/acroform/PDFAcroTerminal.js +27 -35
- package/es/core/acroform/PDFAcroTerminal.js.map +1 -1
- package/es/core/acroform/PDFAcroText.d.ts +7 -7
- package/es/core/acroform/PDFAcroText.d.ts.map +1 -1
- package/es/core/acroform/PDFAcroText.js +39 -45
- package/es/core/acroform/PDFAcroText.js.map +1 -1
- package/es/core/acroform/flags.js +1 -1
- package/es/core/acroform/flags.js.map +1 -1
- package/es/core/acroform/index.d.ts +15 -15
- package/es/core/acroform/index.d.ts.map +1 -1
- package/es/core/acroform/index.js +15 -15
- package/es/core/acroform/index.js.map +1 -1
- package/es/core/acroform/utils.d.ts +5 -5
- package/es/core/acroform/utils.d.ts.map +1 -1
- package/es/core/acroform/utils.js +44 -46
- package/es/core/acroform/utils.js.map +1 -1
- package/es/core/annotation/AppearanceCharacteristics.d.ts +5 -5
- package/es/core/annotation/AppearanceCharacteristics.d.ts.map +1 -1
- package/es/core/annotation/AppearanceCharacteristics.js +60 -63
- package/es/core/annotation/AppearanceCharacteristics.js.map +1 -1
- package/es/core/annotation/BorderStyle.d.ts +2 -2
- package/es/core/annotation/BorderStyle.d.ts.map +1 -1
- package/es/core/annotation/BorderStyle.js +14 -15
- package/es/core/annotation/BorderStyle.js.map +1 -1
- package/es/core/annotation/PDFAnnotation.d.ts +6 -6
- package/es/core/annotation/PDFAnnotation.d.ts.map +1 -1
- package/es/core/annotation/PDFAnnotation.js +75 -76
- package/es/core/annotation/PDFAnnotation.js.map +1 -1
- package/es/core/annotation/PDFWidgetAnnotation.d.ts +9 -9
- package/es/core/annotation/PDFWidgetAnnotation.d.ts.map +1 -1
- package/es/core/annotation/PDFWidgetAnnotation.js +59 -67
- package/es/core/annotation/PDFWidgetAnnotation.js.map +1 -1
- package/es/core/annotation/flags.js +1 -1
- package/es/core/annotation/flags.js.map +1 -1
- package/es/core/annotation/index.d.ts +4 -4
- package/es/core/annotation/index.d.ts.map +1 -1
- package/es/core/annotation/index.js +4 -4
- package/es/core/annotation/index.js.map +1 -1
- package/es/core/crypto.d.ts +96 -0
- package/es/core/crypto.d.ts.map +1 -0
- package/es/core/crypto.js +1609 -0
- package/es/core/crypto.js.map +1 -0
- package/es/core/document/PDFCrossRefSection.d.ts +1 -1
- package/es/core/document/PDFCrossRefSection.d.ts.map +1 -1
- package/es/core/document/PDFCrossRefSection.js +55 -58
- package/es/core/document/PDFCrossRefSection.js.map +1 -1
- package/es/core/document/PDFHeader.d.ts +1 -0
- package/es/core/document/PDFHeader.d.ts.map +1 -1
- package/es/core/document/PDFHeader.js +18 -18
- package/es/core/document/PDFHeader.js.map +1 -1
- package/es/core/document/PDFTrailer.js +14 -17
- package/es/core/document/PDFTrailer.js.map +1 -1
- package/es/core/document/PDFTrailerDict.d.ts +1 -1
- package/es/core/document/PDFTrailerDict.d.ts.map +1 -1
- package/es/core/document/PDFTrailerDict.js +13 -14
- package/es/core/document/PDFTrailerDict.js.map +1 -1
- package/es/core/embedders/CMap.d.ts +2 -2
- package/es/core/embedders/CMap.d.ts.map +1 -1
- package/es/core/embedders/CMap.js +38 -26
- package/es/core/embedders/CMap.js.map +1 -1
- package/es/core/embedders/CustomFontEmbedder.d.ts +5 -5
- package/es/core/embedders/CustomFontEmbedder.d.ts.map +1 -1
- package/es/core/embedders/CustomFontEmbedder.js +132 -177
- package/es/core/embedders/CustomFontEmbedder.js.map +1 -1
- package/es/core/embedders/CustomFontSubsetEmbedder.d.ts +3 -3
- package/es/core/embedders/CustomFontSubsetEmbedder.d.ts.map +1 -1
- package/es/core/embedders/CustomFontSubsetEmbedder.js +37 -48
- package/es/core/embedders/CustomFontSubsetEmbedder.js.map +1 -1
- package/es/core/embedders/FileEmbedder.d.ts +3 -2
- package/es/core/embedders/FileEmbedder.d.ts.map +1 -1
- package/es/core/embedders/FileEmbedder.js +44 -48
- package/es/core/embedders/FileEmbedder.js.map +1 -1
- package/es/core/embedders/FontFlags.d.ts +1 -1
- package/es/core/embedders/FontFlags.d.ts.map +1 -1
- package/es/core/embedders/FontFlags.js +6 -6
- package/es/core/embedders/FontFlags.js.map +1 -1
- package/es/core/embedders/JavaScriptEmbedder.d.ts +2 -2
- package/es/core/embedders/JavaScriptEmbedder.d.ts.map +1 -1
- package/es/core/embedders/JavaScriptEmbedder.js +22 -27
- package/es/core/embedders/JavaScriptEmbedder.js.map +1 -1
- package/es/core/embedders/JpegEmbedder.d.ts +2 -2
- package/es/core/embedders/JpegEmbedder.d.ts.map +1 -1
- package/es/core/embedders/JpegEmbedder.js +66 -73
- package/es/core/embedders/JpegEmbedder.js.map +1 -1
- package/es/core/embedders/PDFPageEmbedder.d.ts +4 -4
- package/es/core/embedders/PDFPageEmbedder.d.ts.map +1 -1
- package/es/core/embedders/PDFPageEmbedder.js +63 -64
- package/es/core/embedders/PDFPageEmbedder.js.map +1 -1
- package/es/core/embedders/PngEmbedder.d.ts +2 -2
- package/es/core/embedders/PngEmbedder.d.ts.map +1 -1
- package/es/core/embedders/PngEmbedder.js +33 -41
- package/es/core/embedders/PngEmbedder.js.map +1 -1
- package/es/core/embedders/StandardFontEmbedder.d.ts +4 -4
- package/es/core/embedders/StandardFontEmbedder.d.ts.map +1 -1
- package/es/core/embedders/StandardFontEmbedder.js +50 -48
- package/es/core/embedders/StandardFontEmbedder.js.map +1 -1
- package/es/core/errors.d.ts +1 -1
- package/es/core/errors.d.ts.map +1 -1
- package/es/core/errors.js +175 -316
- package/es/core/errors.js.map +1 -1
- package/es/core/index.d.ts +48 -47
- package/es/core/index.d.ts.map +1 -1
- package/es/core/index.js +48 -47
- package/es/core/index.js.map +1 -1
- package/es/core/interactive/ViewerPreferences.d.ts +8 -8
- package/es/core/interactive/ViewerPreferences.d.ts.map +1 -1
- package/es/core/interactive/ViewerPreferences.js +127 -130
- package/es/core/interactive/ViewerPreferences.js.map +1 -1
- package/es/core/objects/PDFArray.d.ts +12 -12
- package/es/core/objects/PDFArray.d.ts.map +1 -1
- package/es/core/objects/PDFArray.js +71 -81
- package/es/core/objects/PDFArray.js.map +1 -1
- package/es/core/objects/PDFBool.d.ts +1 -1
- package/es/core/objects/PDFBool.d.ts.map +1 -1
- package/es/core/objects/PDFBool.js +21 -26
- package/es/core/objects/PDFBool.js.map +1 -1
- package/es/core/objects/PDFDict.d.ts +13 -12
- package/es/core/objects/PDFDict.d.ts.map +1 -1
- package/es/core/objects/PDFDict.js +75 -88
- package/es/core/objects/PDFDict.js.map +1 -1
- package/es/core/objects/PDFHexString.d.ts +2 -1
- package/es/core/objects/PDFHexString.d.ts.map +1 -1
- package/es/core/objects/PDFHexString.js +45 -48
- package/es/core/objects/PDFHexString.js.map +1 -1
- package/es/core/objects/PDFInvalidObject.d.ts +1 -1
- package/es/core/objects/PDFInvalidObject.d.ts.map +1 -1
- package/es/core/objects/PDFInvalidObject.js +18 -22
- package/es/core/objects/PDFInvalidObject.js.map +1 -1
- package/es/core/objects/PDFName.d.ts +1 -1
- package/es/core/objects/PDFName.d.ts.map +1 -1
- package/es/core/objects/PDFName.js +83 -92
- package/es/core/objects/PDFName.js.map +1 -1
- package/es/core/objects/PDFNull.d.ts +1 -1
- package/es/core/objects/PDFNull.d.ts.map +1 -1
- package/es/core/objects/PDFNull.js +14 -20
- package/es/core/objects/PDFNull.js.map +1 -1
- package/es/core/objects/PDFNumber.d.ts +1 -1
- package/es/core/objects/PDFNumber.d.ts.map +1 -1
- package/es/core/objects/PDFNumber.js +22 -26
- package/es/core/objects/PDFNumber.js.map +1 -1
- package/es/core/objects/PDFObject.d.ts +1 -1
- package/es/core/objects/PDFObject.d.ts.map +1 -1
- package/es/core/objects/PDFObject.js +13 -16
- package/es/core/objects/PDFObject.js.map +1 -1
- package/es/core/objects/PDFRawStream.d.ts +8 -5
- package/es/core/objects/PDFRawStream.d.ts.map +1 -1
- package/es/core/objects/PDFRawStream.js +22 -24
- package/es/core/objects/PDFRawStream.js.map +1 -1
- package/es/core/objects/PDFRef.d.ts +1 -1
- package/es/core/objects/PDFRef.d.ts.map +1 -1
- package/es/core/objects/PDFRef.js +30 -36
- package/es/core/objects/PDFRef.js.map +1 -1
- package/es/core/objects/PDFStream.d.ts +4 -3
- package/es/core/objects/PDFStream.d.ts.map +1 -1
- package/es/core/objects/PDFStream.js +34 -35
- package/es/core/objects/PDFStream.js.map +1 -1
- package/es/core/objects/PDFString.d.ts +1 -1
- package/es/core/objects/PDFString.d.ts.map +1 -1
- package/es/core/objects/PDFString.js +50 -54
- package/es/core/objects/PDFString.js.map +1 -1
- package/es/core/operators/PDFOperator.d.ts +9 -9
- package/es/core/operators/PDFOperator.d.ts.map +1 -1
- package/es/core/operators/PDFOperator.js +26 -29
- package/es/core/operators/PDFOperator.js.map +1 -1
- package/es/core/parser/BaseParser.d.ts +1 -1
- package/es/core/parser/BaseParser.d.ts.map +1 -1
- package/es/core/parser/BaseParser.js +36 -38
- package/es/core/parser/BaseParser.js.map +1 -1
- package/es/core/parser/ByteStream.d.ts +1 -1
- package/es/core/parser/ByteStream.d.ts.map +1 -1
- package/es/core/parser/ByteStream.js +29 -32
- package/es/core/parser/ByteStream.js.map +1 -1
- package/es/core/parser/PDFObjectParser.d.ts +23 -21
- package/es/core/parser/PDFObjectParser.d.ts.map +1 -1
- package/es/core/parser/PDFObjectParser.js +92 -85
- package/es/core/parser/PDFObjectParser.js.map +1 -1
- package/es/core/parser/PDFObjectStreamParser.d.ts +3 -3
- package/es/core/parser/PDFObjectStreamParser.d.ts.map +1 -1
- package/es/core/parser/PDFObjectStreamParser.js +42 -60
- package/es/core/parser/PDFObjectStreamParser.js.map +1 -1
- package/es/core/parser/PDFParser.d.ts +6 -4
- package/es/core/parser/PDFParser.d.ts.map +1 -1
- package/es/core/parser/PDFParser.js +169 -217
- package/es/core/parser/PDFParser.js.map +1 -1
- package/es/core/parser/PDFXRefStreamParser.d.ts +2 -2
- package/es/core/parser/PDFXRefStreamParser.d.ts.map +1 -1
- package/es/core/parser/PDFXRefStreamParser.js +37 -40
- package/es/core/parser/PDFXRefStreamParser.js.map +1 -1
- package/es/core/security/PDFSecurity.d.ts +75 -0
- package/es/core/security/PDFSecurity.d.ts.map +1 -0
- package/es/core/security/PDFSecurity.js +403 -0
- package/es/core/security/PDFSecurity.js.map +1 -0
- package/es/core/streams/Ascii85Stream.d.ts +2 -2
- package/es/core/streams/Ascii85Stream.d.ts.map +1 -1
- package/es/core/streams/Ascii85Stream.js +20 -26
- package/es/core/streams/Ascii85Stream.js.map +1 -1
- package/es/core/streams/AsciiHexStream.d.ts +2 -2
- package/es/core/streams/AsciiHexStream.d.ts.map +1 -1
- package/es/core/streams/AsciiHexStream.js +18 -22
- package/es/core/streams/AsciiHexStream.js.map +1 -1
- package/es/core/streams/DecodeStream.d.ts +1 -1
- package/es/core/streams/DecodeStream.d.ts.map +1 -1
- package/es/core/streams/DecodeStream.js +53 -60
- package/es/core/streams/DecodeStream.js.map +1 -1
- package/es/core/streams/DecryptStream.d.ts +13 -0
- package/es/core/streams/DecryptStream.d.ts.map +1 -0
- package/es/core/streams/DecryptStream.js +36 -0
- package/es/core/streams/DecryptStream.js.map +1 -0
- package/es/core/streams/FlateStream.d.ts +2 -2
- package/es/core/streams/FlateStream.d.ts.map +1 -1
- package/es/core/streams/FlateStream.js +81 -84
- package/es/core/streams/FlateStream.js.map +1 -1
- package/es/core/streams/LZWStream.d.ts +3 -3
- package/es/core/streams/LZWStream.d.ts.map +1 -1
- package/es/core/streams/LZWStream.js +41 -45
- package/es/core/streams/LZWStream.js.map +1 -1
- package/es/core/streams/RunLengthStream.d.ts +2 -2
- package/es/core/streams/RunLengthStream.d.ts.map +1 -1
- package/es/core/streams/RunLengthStream.js +15 -19
- package/es/core/streams/RunLengthStream.js.map +1 -1
- package/es/core/streams/Stream.js +45 -56
- package/es/core/streams/Stream.js.map +1 -1
- package/es/core/streams/decode.d.ts +3 -3
- package/es/core/streams/decode.d.ts.map +1 -1
- package/es/core/streams/decode.js +23 -21
- package/es/core/streams/decode.js.map +1 -1
- package/es/core/structures/PDFCatalog.d.ts +5 -5
- package/es/core/structures/PDFCatalog.d.ts.map +1 -1
- package/es/core/structures/PDFCatalog.js +39 -47
- package/es/core/structures/PDFCatalog.js.map +1 -1
- package/es/core/structures/PDFContentStream.d.ts +4 -4
- package/es/core/structures/PDFContentStream.d.ts.map +1 -1
- package/es/core/structures/PDFContentStream.js +30 -43
- package/es/core/structures/PDFContentStream.js.map +1 -1
- package/es/core/structures/PDFCrossRefStream.d.ts +6 -6
- package/es/core/structures/PDFCrossRefStream.d.ts.map +1 -1
- package/es/core/structures/PDFCrossRefStream.js +91 -100
- package/es/core/structures/PDFCrossRefStream.js.map +1 -1
- package/es/core/structures/PDFFlateStream.d.ts +5 -4
- package/es/core/structures/PDFFlateStream.d.ts.map +1 -1
- package/es/core/structures/PDFFlateStream.js +22 -23
- package/es/core/structures/PDFFlateStream.js.map +1 -1
- package/es/core/structures/PDFObjectStream.d.ts +5 -5
- package/es/core/structures/PDFObjectStream.d.ts.map +1 -1
- package/es/core/structures/PDFObjectStream.js +46 -54
- package/es/core/structures/PDFObjectStream.js.map +1 -1
- package/es/core/structures/PDFPageLeaf.d.ts +9 -9
- package/es/core/structures/PDFPageLeaf.d.ts.map +1 -1
- package/es/core/structures/PDFPageLeaf.js +125 -133
- package/es/core/structures/PDFPageLeaf.js.map +1 -1
- package/es/core/structures/PDFPageTree.d.ts +8 -8
- package/es/core/structures/PDFPageTree.d.ts.map +1 -1
- package/es/core/structures/PDFPageTree.js +66 -75
- package/es/core/structures/PDFPageTree.js.map +1 -1
- package/es/core/syntax/Delimiters.js +2 -2
- package/es/core/syntax/Delimiters.js.map +1 -1
- package/es/core/syntax/Irregular.js +5 -5
- package/es/core/syntax/Irregular.js.map +1 -1
- package/es/core/syntax/Keywords.d.ts +1 -1
- package/es/core/syntax/Keywords.d.ts.map +1 -1
- package/es/core/syntax/Keywords.js +14 -15
- package/es/core/syntax/Keywords.js.map +1 -1
- package/es/core/syntax/Numeric.js +5 -5
- package/es/core/syntax/Numeric.js.map +1 -1
- package/es/core/syntax/Whitespace.js +2 -2
- package/es/core/syntax/Whitespace.js.map +1 -1
- package/es/core/writers/PDFStreamWriter.d.ts +7 -7
- package/es/core/writers/PDFStreamWriter.d.ts.map +1 -1
- package/es/core/writers/PDFStreamWriter.js +102 -126
- package/es/core/writers/PDFStreamWriter.js.map +1 -1
- package/es/core/writers/PDFWriter.d.ts +15 -10
- package/es/core/writers/PDFWriter.d.ts.map +1 -1
- package/es/core/writers/PDFWriter.js +116 -142
- package/es/core/writers/PDFWriter.js.map +1 -1
- package/es/index.d.ts +4 -4
- package/es/index.d.ts.map +1 -1
- package/es/index.js +4 -4
- package/es/index.js.map +1 -1
- package/es/package.json +3 -0
- package/es/types/fontkit.js +1 -0
- package/es/types/index.d.ts +25 -1
- package/es/types/index.d.ts.map +1 -1
- package/es/types/index.js +1 -0
- package/es/types/matrix.d.ts +8 -1
- package/es/types/matrix.d.ts.map +1 -1
- package/es/types/matrix.js +1 -1
- package/es/types/matrix.js.map +1 -1
- package/es/utils/Cache.js +10 -11
- package/es/utils/Cache.js.map +1 -1
- package/es/utils/arrays.d.ts +3 -1
- package/es/utils/arrays.d.ts.map +1 -1
- package/es/utils/arrays.js +78 -60
- package/es/utils/arrays.js.map +1 -1
- package/es/utils/async.d.ts.map +1 -1
- package/es/utils/async.js +3 -5
- package/es/utils/async.js.map +1 -1
- package/es/utils/base64.d.ts.map +1 -1
- package/es/utils/base64.js +24 -24
- package/es/utils/base64.js.map +1 -1
- package/es/utils/elements/Arc.d.ts +23 -0
- package/es/utils/elements/Arc.d.ts.map +1 -0
- package/es/utils/elements/Arc.js +74 -0
- package/es/utils/elements/Arc.js.map +1 -0
- package/es/utils/elements/Circle.d.ts +15 -0
- package/es/utils/elements/Circle.d.ts.map +1 -0
- package/es/utils/elements/Circle.js +37 -0
- package/es/utils/elements/Circle.js.map +1 -0
- package/es/utils/elements/Ellipse.d.ts +21 -0
- package/es/utils/elements/Ellipse.d.ts.map +1 -0
- package/es/utils/elements/Ellipse.js +87 -0
- package/es/utils/elements/Ellipse.js.map +1 -0
- package/es/utils/elements/GraphElement.d.ts +7 -0
- package/es/utils/elements/GraphElement.d.ts.map +1 -0
- package/es/utils/elements/GraphElement.js +8 -0
- package/es/utils/elements/GraphElement.js.map +1 -0
- package/es/utils/elements/Line.d.ts +24 -0
- package/es/utils/elements/Line.d.ts.map +1 -0
- package/es/utils/elements/Line.js +68 -0
- package/es/utils/elements/Line.js.map +1 -0
- package/es/utils/elements/Plot.d.ts +12 -0
- package/es/utils/elements/Plot.d.ts.map +1 -0
- package/es/utils/elements/Plot.js +42 -0
- package/es/utils/elements/Plot.js.map +1 -0
- package/es/utils/elements/Point.d.ts +19 -0
- package/es/utils/elements/Point.d.ts.map +1 -0
- package/es/utils/elements/Point.js +28 -0
- package/es/utils/elements/Point.js.map +1 -0
- package/es/utils/elements/Rectangle.d.ts +22 -0
- package/es/utils/elements/Rectangle.d.ts.map +1 -0
- package/es/utils/elements/Rectangle.js +54 -0
- package/es/utils/elements/Rectangle.js.map +1 -0
- package/es/utils/elements/Segment.d.ts +20 -0
- package/es/utils/elements/Segment.d.ts.map +1 -0
- package/es/utils/elements/Segment.js +76 -0
- package/es/utils/elements/Segment.js.map +1 -0
- package/es/utils/elements/index.d.ts +10 -0
- package/es/utils/elements/index.d.ts.map +1 -0
- package/es/utils/elements/index.js +10 -0
- package/es/utils/elements/index.js.map +1 -0
- package/es/utils/errors.js +1 -1
- package/es/utils/errors.js.map +1 -1
- package/es/utils/index.d.ts +11 -11
- package/es/utils/index.d.ts.map +1 -1
- package/es/utils/index.js +11 -11
- package/es/utils/index.js.map +1 -1
- package/es/utils/intersections.d.ts +10 -0
- package/es/utils/intersections.d.ts.map +1 -0
- package/es/utils/intersections.js +243 -0
- package/es/utils/intersections.js.map +1 -0
- package/es/utils/maths.d.ts +46 -0
- package/es/utils/maths.d.ts.map +1 -0
- package/es/utils/maths.js +69 -0
- package/es/utils/maths.js.map +1 -0
- package/es/utils/numbers.js +9 -9
- package/es/utils/numbers.js.map +1 -1
- package/es/utils/objects.js +4 -6
- package/es/utils/objects.js.map +1 -1
- package/es/utils/pdfDocEncoding.js +7 -7
- package/es/utils/pdfDocEncoding.js.map +1 -1
- package/es/utils/png.js +20 -22
- package/es/utils/png.js.map +1 -1
- package/es/utils/rng.js +7 -9
- package/es/utils/rng.js.map +1 -1
- package/es/utils/strings.d.ts +1 -0
- package/es/utils/strings.d.ts.map +1 -1
- package/es/utils/strings.js +66 -68
- package/es/utils/strings.js.map +1 -1
- package/es/utils/unicode.js +42 -63
- package/es/utils/unicode.js.map +1 -1
- package/es/utils/validators.d.ts +2 -2
- package/es/utils/validators.d.ts.map +1 -1
- package/es/utils/validators.js +38 -38
- package/es/utils/validators.js.map +1 -1
- package/package.json +70 -39
- package/src/api/PDFDocument.ts +248 -22
- package/src/api/PDFDocumentOptions.ts +4 -2
- package/src/api/PDFEmbeddedFile.ts +12 -4
- package/src/api/PDFEmbeddedPage.ts +4 -4
- package/src/api/PDFFont.ts +4 -4
- package/src/api/PDFImage.ts +4 -4
- package/src/api/PDFJavaScript.ts +4 -4
- package/src/api/PDFPage.ts +93 -20
- package/src/api/PDFPageOptions.ts +34 -12
- package/src/api/PDFSvg.ts +10 -0
- package/src/api/colors.ts +27 -19
- package/src/api/form/PDFButton.ts +11 -11
- package/src/api/form/PDFCheckBox.ts +8 -8
- package/src/api/form/PDFDropdown.ts +9 -9
- package/src/api/form/PDFField.ts +7 -7
- package/src/api/form/PDFForm.ts +56 -46
- package/src/api/form/PDFOptionList.ts +9 -9
- package/src/api/form/PDFRadioGroup.ts +8 -8
- package/src/api/form/PDFSignature.ts +4 -4
- package/src/api/form/PDFTextField.ts +15 -15
- package/src/api/form/appearances.ts +41 -49
- package/src/api/form/index.ts +10 -10
- package/src/api/image/index.ts +1 -1
- package/src/api/index.ts +1 -0
- package/src/api/objects.ts +1 -1
- package/src/api/operations.ts +198 -142
- package/src/api/operators.ts +10 -3
- package/src/api/rotations.ts +7 -9
- package/src/api/svg.ts +1074 -0
- package/src/api/svgPath.ts +2 -4
- package/src/api/text/index.ts +2 -2
- package/src/api/text/layout.ts +5 -5
- package/src/core/PDFContext.ts +94 -19
- package/src/core/PDFObjectCopier.ts +8 -8
- package/src/core/acroform/PDFAcroButton.ts +8 -8
- package/src/core/acroform/PDFAcroCheckBox.ts +6 -6
- package/src/core/acroform/PDFAcroChoice.ts +7 -10
- package/src/core/acroform/PDFAcroComboBox.ts +5 -5
- package/src/core/acroform/PDFAcroField.ts +12 -12
- package/src/core/acroform/PDFAcroForm.ts +8 -11
- package/src/core/acroform/PDFAcroListBox.ts +4 -4
- package/src/core/acroform/PDFAcroNonTerminal.ts +5 -5
- package/src/core/acroform/PDFAcroPushButton.ts +5 -5
- package/src/core/acroform/PDFAcroRadioButton.ts +7 -7
- package/src/core/acroform/PDFAcroSignature.ts +3 -3
- package/src/core/acroform/PDFAcroTerminal.ts +6 -6
- package/src/core/acroform/PDFAcroText.ts +8 -8
- package/src/core/acroform/index.ts +15 -15
- package/src/core/acroform/utils.ts +20 -20
- package/src/core/annotation/AppearanceCharacteristics.ts +6 -6
- package/src/core/annotation/BorderStyle.ts +3 -3
- package/src/core/annotation/PDFAnnotation.ts +6 -6
- package/src/core/annotation/PDFWidgetAnnotation.ts +9 -9
- package/src/core/annotation/index.ts +4 -4
- package/src/core/crypto.ts +1997 -0
- package/src/core/document/PDFCrossRefSection.ts +4 -4
- package/src/core/document/PDFHeader.ts +6 -2
- package/src/core/document/PDFTrailer.ts +2 -2
- package/src/core/document/PDFTrailerDict.ts +2 -2
- package/src/core/embedders/CMap.ts +3 -3
- package/src/core/embedders/CustomFontEmbedder.ts +9 -9
- package/src/core/embedders/CustomFontSubsetEmbedder.ts +10 -4
- package/src/core/embedders/FileEmbedder.ts +8 -4
- package/src/core/embedders/FontFlags.ts +1 -1
- package/src/core/embedders/JavaScriptEmbedder.ts +3 -3
- package/src/core/embedders/JpegEmbedder.ts +2 -2
- package/src/core/embedders/PDFPageEmbedder.ts +24 -22
- package/src/core/embedders/PngEmbedder.ts +3 -3
- package/src/core/embedders/StandardFontEmbedder.ts +10 -5
- package/src/core/errors.ts +15 -13
- package/src/core/index.ts +52 -47
- package/src/core/interactive/ViewerPreferences.ts +7 -7
- package/src/core/objects/PDFArray.ts +22 -22
- package/src/core/objects/PDFBool.ts +3 -3
- package/src/core/objects/PDFDict.ts +14 -12
- package/src/core/objects/PDFHexString.ts +8 -4
- package/src/core/objects/PDFInvalidObject.ts +1 -1
- package/src/core/objects/PDFName.ts +6 -6
- package/src/core/objects/PDFNull.ts +2 -2
- package/src/core/objects/PDFNumber.ts +3 -3
- package/src/core/objects/PDFObject.ts +2 -2
- package/src/core/objects/PDFRawStream.ts +24 -10
- package/src/core/objects/PDFRef.ts +4 -4
- package/src/core/objects/PDFStream.ts +14 -7
- package/src/core/objects/PDFString.ts +4 -4
- package/src/core/operators/PDFOperator.ts +10 -10
- package/src/core/parser/BaseParser.ts +6 -6
- package/src/core/parser/ByteStream.ts +4 -4
- package/src/core/parser/PDFObjectParser.ts +78 -41
- package/src/core/parser/PDFObjectStreamParser.ts +9 -9
- package/src/core/parser/PDFParser.ts +43 -23
- package/src/core/parser/PDFXRefStreamParser.ts +9 -9
- package/src/core/security/PDFSecurity.ts +685 -0
- package/src/core/streams/Ascii85Stream.ts +2 -2
- package/src/core/streams/AsciiHexStream.ts +2 -2
- package/src/core/streams/DecodeStream.ts +2 -2
- package/src/core/streams/DecryptStream.ts +56 -0
- package/src/core/streams/FlateStream.ts +3 -2
- package/src/core/streams/LZWStream.ts +3 -3
- package/src/core/streams/RunLengthStream.ts +2 -2
- package/src/core/streams/decode.ts +23 -18
- package/src/core/structures/PDFCatalog.ts +6 -6
- package/src/core/structures/PDFContentStream.ts +5 -5
- package/src/core/structures/PDFCrossRefStream.ts +6 -6
- package/src/core/structures/PDFFlateStream.ts +10 -6
- package/src/core/structures/PDFObjectStream.ts +8 -8
- package/src/core/structures/PDFPageLeaf.ts +9 -9
- package/src/core/structures/PDFPageTree.ts +8 -8
- package/src/core/syntax/Delimiters.ts +1 -1
- package/src/core/syntax/Irregular.ts +3 -3
- package/src/core/syntax/Keywords.ts +1 -1
- package/src/core/syntax/Numeric.ts +1 -1
- package/src/core/syntax/Whitespace.ts +1 -1
- package/src/core/writers/PDFStreamWriter.ts +12 -1
- package/src/core/writers/PDFWriter.ts +22 -13
- package/src/index.ts +4 -4
- package/src/types/index.ts +38 -1
- package/src/utils/arrays.ts +33 -2
- package/src/utils/base64.ts +2 -1
- package/src/utils/elements/Arc.ts +107 -0
- package/src/utils/elements/Circle.ts +55 -0
- package/src/utils/elements/Ellipse.ts +135 -0
- package/src/utils/elements/GraphElement.ts +14 -0
- package/src/utils/elements/Line.ts +85 -0
- package/src/utils/elements/Plot.ts +50 -0
- package/src/utils/elements/Point.ts +37 -0
- package/src/utils/elements/Rectangle.ts +65 -0
- package/src/utils/elements/Segment.ts +92 -0
- package/src/utils/elements/index.ts +9 -0
- package/src/utils/index.ts +11 -11
- package/src/utils/intersections.ts +280 -0
- package/src/utils/maths.ts +108 -0
- package/src/utils/pdfDocEncoding.ts +1 -1
- package/src/utils/png.ts +1 -1
- package/src/utils/strings.ts +11 -1
- package/src/utils/unicode.ts +1 -1
- package/src/utils/validators.ts +1 -1
- package/ts3.4/cjs/api/PDFDocument.d.ts +52 -13
- package/ts3.4/cjs/api/PDFDocumentOptions.d.ts +4 -2
- package/ts3.4/cjs/api/PDFEmbeddedFile.d.ts +9 -4
- package/ts3.4/cjs/api/PDFEmbeddedPage.d.ts +3 -3
- package/ts3.4/cjs/api/PDFFont.d.ts +4 -4
- package/ts3.4/cjs/api/PDFImage.d.ts +4 -4
- package/ts3.4/cjs/api/PDFJavaScript.d.ts +4 -4
- package/ts3.4/cjs/api/PDFPage.d.ts +36 -9
- package/ts3.4/cjs/api/PDFPageOptions.d.ts +35 -12
- package/ts3.4/cjs/api/PDFSvg.d.ts +7 -0
- package/ts3.4/cjs/api/colors.d.ts +6 -2
- package/ts3.4/cjs/api/form/PDFButton.d.ts +8 -8
- package/ts3.4/cjs/api/form/PDFCheckBox.d.ts +5 -5
- package/ts3.4/cjs/api/form/PDFDropdown.d.ts +6 -6
- package/ts3.4/cjs/api/form/PDFField.d.ts +7 -7
- package/ts3.4/cjs/api/form/PDFForm.d.ts +11 -11
- package/ts3.4/cjs/api/form/PDFOptionList.d.ts +6 -6
- package/ts3.4/cjs/api/form/PDFRadioGroup.d.ts +5 -5
- package/ts3.4/cjs/api/form/PDFSignature.d.ts +3 -3
- package/ts3.4/cjs/api/form/PDFTextField.d.ts +8 -8
- package/ts3.4/cjs/api/form/appearances.d.ts +21 -21
- package/ts3.4/cjs/api/form/index.d.ts +10 -10
- package/ts3.4/cjs/api/image/index.d.ts +1 -1
- package/ts3.4/cjs/api/index.d.ts +22 -21
- package/ts3.4/cjs/api/objects.d.ts +1 -1
- package/ts3.4/cjs/api/operations.d.ts +27 -13
- package/ts3.4/cjs/api/operators.d.ts +6 -1
- package/ts3.4/cjs/api/rotations.d.ts +2 -2
- package/ts3.4/cjs/api/sizes.d.ts +200 -50
- package/ts3.4/cjs/api/snapshot/DefaultDocumentSnapshot.d.ts +1 -1
- package/ts3.4/cjs/api/snapshot/DocumentSnapshot.d.ts +1 -1
- package/ts3.4/cjs/api/snapshot/IncrementalDocumentSnapshot.d.ts +1 -1
- package/ts3.4/cjs/api/svg.d.ts +76 -0
- package/ts3.4/cjs/api/svgPath.d.ts +1 -1
- package/ts3.4/cjs/api/text/index.d.ts +2 -2
- package/ts3.4/cjs/api/text/layout.d.ts +3 -3
- package/ts3.4/cjs/core/PDFContext.d.ts +43 -20
- package/ts3.4/cjs/core/PDFObjectCopier.d.ts +2 -2
- package/ts3.4/cjs/core/acroform/PDFAcroButton.d.ts +7 -7
- package/ts3.4/cjs/core/acroform/PDFAcroCheckBox.d.ts +5 -5
- package/ts3.4/cjs/core/acroform/PDFAcroChoice.d.ts +4 -4
- package/ts3.4/cjs/core/acroform/PDFAcroComboBox.d.ts +4 -4
- package/ts3.4/cjs/core/acroform/PDFAcroField.d.ts +8 -8
- package/ts3.4/cjs/core/acroform/PDFAcroForm.d.ts +13 -7
- package/ts3.4/cjs/core/acroform/PDFAcroListBox.d.ts +4 -4
- package/ts3.4/cjs/core/acroform/PDFAcroNonTerminal.d.ts +4 -4
- package/ts3.4/cjs/core/acroform/PDFAcroPushButton.d.ts +4 -4
- package/ts3.4/cjs/core/acroform/PDFAcroRadioButton.d.ts +5 -5
- package/ts3.4/cjs/core/acroform/PDFAcroSignature.d.ts +3 -3
- package/ts3.4/cjs/core/acroform/PDFAcroTerminal.d.ts +5 -5
- package/ts3.4/cjs/core/acroform/PDFAcroText.d.ts +7 -7
- package/ts3.4/cjs/core/acroform/index.d.ts +15 -15
- package/ts3.4/cjs/core/acroform/utils.d.ts +8 -5
- package/ts3.4/cjs/core/annotation/AppearanceCharacteristics.d.ts +5 -5
- package/ts3.4/cjs/core/annotation/BorderStyle.d.ts +2 -2
- package/ts3.4/cjs/core/annotation/PDFAnnotation.d.ts +6 -6
- package/ts3.4/cjs/core/annotation/PDFWidgetAnnotation.d.ts +9 -9
- package/ts3.4/cjs/core/annotation/index.d.ts +4 -4
- package/ts3.4/cjs/core/crypto.d.ts +96 -0
- package/ts3.4/cjs/core/document/PDFCrossRefSection.d.ts +1 -1
- package/ts3.4/cjs/core/document/PDFHeader.d.ts +1 -0
- package/ts3.4/cjs/core/document/PDFTrailerDict.d.ts +1 -1
- package/ts3.4/cjs/core/embedders/CMap.d.ts +2 -2
- package/ts3.4/cjs/core/embedders/CustomFontEmbedder.d.ts +5 -5
- package/ts3.4/cjs/core/embedders/CustomFontSubsetEmbedder.d.ts +3 -3
- package/ts3.4/cjs/core/embedders/FileEmbedder.d.ts +3 -2
- package/ts3.4/cjs/core/embedders/FontFlags.d.ts +1 -1
- package/ts3.4/cjs/core/embedders/JavaScriptEmbedder.d.ts +2 -2
- package/ts3.4/cjs/core/embedders/JpegEmbedder.d.ts +2 -2
- package/ts3.4/cjs/core/embedders/PDFPageEmbedder.d.ts +4 -4
- package/ts3.4/cjs/core/embedders/PngEmbedder.d.ts +2 -2
- package/ts3.4/cjs/core/embedders/StandardFontEmbedder.d.ts +4 -4
- package/ts3.4/cjs/core/errors.d.ts +1 -1
- package/ts3.4/cjs/core/index.d.ts +48 -47
- package/ts3.4/cjs/core/interactive/ViewerPreferences.d.ts +8 -8
- package/ts3.4/cjs/core/objects/PDFArray.d.ts +12 -12
- package/ts3.4/cjs/core/objects/PDFBool.d.ts +1 -1
- package/ts3.4/cjs/core/objects/PDFDict.d.ts +17 -13
- package/ts3.4/cjs/core/objects/PDFHexString.d.ts +2 -1
- package/ts3.4/cjs/core/objects/PDFInvalidObject.d.ts +1 -1
- package/ts3.4/cjs/core/objects/PDFName.d.ts +1 -1
- package/ts3.4/cjs/core/objects/PDFNull.d.ts +1 -1
- package/ts3.4/cjs/core/objects/PDFNumber.d.ts +1 -1
- package/ts3.4/cjs/core/objects/PDFObject.d.ts +1 -1
- package/ts3.4/cjs/core/objects/PDFRawStream.d.ts +8 -5
- package/ts3.4/cjs/core/objects/PDFRef.d.ts +1 -1
- package/ts3.4/cjs/core/objects/PDFStream.d.ts +4 -3
- package/ts3.4/cjs/core/objects/PDFString.d.ts +1 -1
- package/ts3.4/cjs/core/operators/PDFOperator.d.ts +9 -9
- package/ts3.4/cjs/core/parser/BaseParser.d.ts +1 -1
- package/ts3.4/cjs/core/parser/ByteStream.d.ts +1 -1
- package/ts3.4/cjs/core/parser/PDFObjectParser.d.ts +23 -21
- package/ts3.4/cjs/core/parser/PDFObjectStreamParser.d.ts +3 -3
- package/ts3.4/cjs/core/parser/PDFParser.d.ts +6 -4
- package/ts3.4/cjs/core/parser/PDFXRefStreamParser.d.ts +2 -2
- package/ts3.4/cjs/core/security/PDFSecurity.d.ts +75 -0
- package/ts3.4/cjs/core/streams/Ascii85Stream.d.ts +2 -2
- package/ts3.4/cjs/core/streams/AsciiHexStream.d.ts +2 -2
- package/ts3.4/cjs/core/streams/DecodeStream.d.ts +1 -1
- package/ts3.4/cjs/core/streams/DecryptStream.d.ts +13 -0
- package/ts3.4/cjs/core/streams/FlateStream.d.ts +2 -2
- package/ts3.4/cjs/core/streams/LZWStream.d.ts +3 -3
- package/ts3.4/cjs/core/streams/RunLengthStream.d.ts +2 -2
- package/ts3.4/cjs/core/streams/decode.d.ts +3 -3
- package/ts3.4/cjs/core/structures/PDFCatalog.d.ts +5 -5
- package/ts3.4/cjs/core/structures/PDFContentStream.d.ts +4 -4
- package/ts3.4/cjs/core/structures/PDFCrossRefStream.d.ts +10 -6
- package/ts3.4/cjs/core/structures/PDFFlateStream.d.ts +5 -4
- package/ts3.4/cjs/core/structures/PDFObjectStream.d.ts +8 -5
- package/ts3.4/cjs/core/structures/PDFPageLeaf.d.ts +9 -9
- package/ts3.4/cjs/core/structures/PDFPageTree.d.ts +8 -8
- package/ts3.4/cjs/core/syntax/Keywords.d.ts +1 -1
- package/ts3.4/cjs/core/writers/PDFStreamWriter.d.ts +11 -8
- package/ts3.4/cjs/core/writers/PDFWriter.d.ts +19 -11
- package/ts3.4/cjs/index.d.ts +4 -4
- package/ts3.4/cjs/types/index.d.ts +25 -1
- package/ts3.4/cjs/types/matrix.d.ts +8 -1
- package/ts3.4/cjs/utils/arrays.d.ts +3 -1
- package/ts3.4/cjs/utils/elements/Arc.d.ts +23 -0
- package/ts3.4/cjs/utils/elements/Circle.d.ts +15 -0
- package/ts3.4/cjs/utils/elements/Ellipse.d.ts +21 -0
- package/ts3.4/cjs/utils/elements/GraphElement.d.ts +7 -0
- package/ts3.4/cjs/utils/elements/Line.d.ts +24 -0
- package/ts3.4/cjs/utils/elements/Plot.d.ts +12 -0
- package/ts3.4/cjs/utils/elements/Point.d.ts +19 -0
- package/ts3.4/cjs/utils/elements/Rectangle.d.ts +22 -0
- package/ts3.4/cjs/utils/elements/Segment.d.ts +20 -0
- package/ts3.4/cjs/utils/elements/index.d.ts +10 -0
- package/ts3.4/cjs/utils/index.d.ts +11 -11
- package/ts3.4/cjs/utils/intersections.d.ts +10 -0
- package/ts3.4/cjs/utils/maths.d.ts +46 -0
- package/ts3.4/cjs/utils/strings.d.ts +5 -1
- package/ts3.4/cjs/utils/validators.d.ts +5 -2
- package/ts3.4/es/api/PDFDocument.d.ts +52 -13
- package/ts3.4/es/api/PDFDocumentOptions.d.ts +4 -2
- package/ts3.4/es/api/PDFEmbeddedFile.d.ts +9 -4
- package/ts3.4/es/api/PDFEmbeddedPage.d.ts +3 -3
- package/ts3.4/es/api/PDFFont.d.ts +4 -4
- package/ts3.4/es/api/PDFImage.d.ts +4 -4
- package/ts3.4/es/api/PDFJavaScript.d.ts +4 -4
- package/ts3.4/es/api/PDFPage.d.ts +36 -9
- package/ts3.4/es/api/PDFPageOptions.d.ts +35 -12
- package/ts3.4/es/api/PDFSvg.d.ts +7 -0
- package/ts3.4/es/api/colors.d.ts +6 -2
- package/ts3.4/es/api/form/PDFButton.d.ts +8 -8
- package/ts3.4/es/api/form/PDFCheckBox.d.ts +5 -5
- package/ts3.4/es/api/form/PDFDropdown.d.ts +6 -6
- package/ts3.4/es/api/form/PDFField.d.ts +7 -7
- package/ts3.4/es/api/form/PDFForm.d.ts +11 -11
- package/ts3.4/es/api/form/PDFOptionList.d.ts +6 -6
- package/ts3.4/es/api/form/PDFRadioGroup.d.ts +5 -5
- package/ts3.4/es/api/form/PDFSignature.d.ts +3 -3
- package/ts3.4/es/api/form/PDFTextField.d.ts +8 -8
- package/ts3.4/es/api/form/appearances.d.ts +21 -21
- package/ts3.4/es/api/form/index.d.ts +10 -10
- package/ts3.4/es/api/image/index.d.ts +1 -1
- package/ts3.4/es/api/index.d.ts +22 -21
- package/ts3.4/es/api/objects.d.ts +1 -1
- package/ts3.4/es/api/operations.d.ts +27 -13
- package/ts3.4/es/api/operators.d.ts +6 -1
- package/ts3.4/es/api/rotations.d.ts +2 -2
- package/ts3.4/es/api/sizes.d.ts +200 -50
- package/ts3.4/es/api/snapshot/DefaultDocumentSnapshot.d.ts +1 -1
- package/ts3.4/es/api/snapshot/DocumentSnapshot.d.ts +1 -1
- package/ts3.4/es/api/snapshot/IncrementalDocumentSnapshot.d.ts +1 -1
- package/ts3.4/es/api/svg.d.ts +76 -0
- package/ts3.4/es/api/svgPath.d.ts +1 -1
- package/ts3.4/es/api/text/index.d.ts +2 -2
- package/ts3.4/es/api/text/layout.d.ts +3 -3
- package/ts3.4/es/core/PDFContext.d.ts +43 -20
- package/ts3.4/es/core/PDFObjectCopier.d.ts +2 -2
- package/ts3.4/es/core/acroform/PDFAcroButton.d.ts +7 -7
- package/ts3.4/es/core/acroform/PDFAcroCheckBox.d.ts +5 -5
- package/ts3.4/es/core/acroform/PDFAcroChoice.d.ts +4 -4
- package/ts3.4/es/core/acroform/PDFAcroComboBox.d.ts +4 -4
- package/ts3.4/es/core/acroform/PDFAcroField.d.ts +8 -8
- package/ts3.4/es/core/acroform/PDFAcroForm.d.ts +13 -7
- package/ts3.4/es/core/acroform/PDFAcroListBox.d.ts +4 -4
- package/ts3.4/es/core/acroform/PDFAcroNonTerminal.d.ts +4 -4
- package/ts3.4/es/core/acroform/PDFAcroPushButton.d.ts +4 -4
- package/ts3.4/es/core/acroform/PDFAcroRadioButton.d.ts +5 -5
- package/ts3.4/es/core/acroform/PDFAcroSignature.d.ts +3 -3
- package/ts3.4/es/core/acroform/PDFAcroTerminal.d.ts +5 -5
- package/ts3.4/es/core/acroform/PDFAcroText.d.ts +7 -7
- package/ts3.4/es/core/acroform/index.d.ts +15 -15
- package/ts3.4/es/core/acroform/utils.d.ts +8 -5
- package/ts3.4/es/core/annotation/AppearanceCharacteristics.d.ts +5 -5
- package/ts3.4/es/core/annotation/BorderStyle.d.ts +2 -2
- package/ts3.4/es/core/annotation/PDFAnnotation.d.ts +6 -6
- package/ts3.4/es/core/annotation/PDFWidgetAnnotation.d.ts +9 -9
- package/ts3.4/es/core/annotation/index.d.ts +4 -4
- package/ts3.4/es/core/crypto.d.ts +96 -0
- package/ts3.4/es/core/document/PDFCrossRefSection.d.ts +1 -1
- package/ts3.4/es/core/document/PDFHeader.d.ts +1 -0
- package/ts3.4/es/core/document/PDFTrailerDict.d.ts +1 -1
- package/ts3.4/es/core/embedders/CMap.d.ts +2 -2
- package/ts3.4/es/core/embedders/CustomFontEmbedder.d.ts +5 -5
- package/ts3.4/es/core/embedders/CustomFontSubsetEmbedder.d.ts +3 -3
- package/ts3.4/es/core/embedders/FileEmbedder.d.ts +3 -2
- package/ts3.4/es/core/embedders/FontFlags.d.ts +1 -1
- package/ts3.4/es/core/embedders/JavaScriptEmbedder.d.ts +2 -2
- package/ts3.4/es/core/embedders/JpegEmbedder.d.ts +2 -2
- package/ts3.4/es/core/embedders/PDFPageEmbedder.d.ts +4 -4
- package/ts3.4/es/core/embedders/PngEmbedder.d.ts +2 -2
- package/ts3.4/es/core/embedders/StandardFontEmbedder.d.ts +4 -4
- package/ts3.4/es/core/errors.d.ts +1 -1
- package/ts3.4/es/core/index.d.ts +48 -47
- package/ts3.4/es/core/interactive/ViewerPreferences.d.ts +8 -8
- package/ts3.4/es/core/objects/PDFArray.d.ts +12 -12
- package/ts3.4/es/core/objects/PDFBool.d.ts +1 -1
- package/ts3.4/es/core/objects/PDFDict.d.ts +17 -13
- package/ts3.4/es/core/objects/PDFHexString.d.ts +2 -1
- package/ts3.4/es/core/objects/PDFInvalidObject.d.ts +1 -1
- package/ts3.4/es/core/objects/PDFName.d.ts +1 -1
- package/ts3.4/es/core/objects/PDFNull.d.ts +1 -1
- package/ts3.4/es/core/objects/PDFNumber.d.ts +1 -1
- package/ts3.4/es/core/objects/PDFObject.d.ts +1 -1
- package/ts3.4/es/core/objects/PDFRawStream.d.ts +8 -5
- package/ts3.4/es/core/objects/PDFRef.d.ts +1 -1
- package/ts3.4/es/core/objects/PDFStream.d.ts +4 -3
- package/ts3.4/es/core/objects/PDFString.d.ts +1 -1
- package/ts3.4/es/core/operators/PDFOperator.d.ts +9 -9
- package/ts3.4/es/core/parser/BaseParser.d.ts +1 -1
- package/ts3.4/es/core/parser/ByteStream.d.ts +1 -1
- package/ts3.4/es/core/parser/PDFObjectParser.d.ts +23 -21
- package/ts3.4/es/core/parser/PDFObjectStreamParser.d.ts +3 -3
- package/ts3.4/es/core/parser/PDFParser.d.ts +6 -4
- package/ts3.4/es/core/parser/PDFXRefStreamParser.d.ts +2 -2
- package/ts3.4/es/core/security/PDFSecurity.d.ts +75 -0
- package/ts3.4/es/core/streams/Ascii85Stream.d.ts +2 -2
- package/ts3.4/es/core/streams/AsciiHexStream.d.ts +2 -2
- package/ts3.4/es/core/streams/DecodeStream.d.ts +1 -1
- package/ts3.4/es/core/streams/DecryptStream.d.ts +13 -0
- package/ts3.4/es/core/streams/FlateStream.d.ts +2 -2
- package/ts3.4/es/core/streams/LZWStream.d.ts +3 -3
- package/ts3.4/es/core/streams/RunLengthStream.d.ts +2 -2
- package/ts3.4/es/core/streams/decode.d.ts +3 -3
- package/ts3.4/es/core/structures/PDFCatalog.d.ts +5 -5
- package/ts3.4/es/core/structures/PDFContentStream.d.ts +4 -4
- package/ts3.4/es/core/structures/PDFCrossRefStream.d.ts +10 -6
- package/ts3.4/es/core/structures/PDFFlateStream.d.ts +5 -4
- package/ts3.4/es/core/structures/PDFObjectStream.d.ts +8 -5
- package/ts3.4/es/core/structures/PDFPageLeaf.d.ts +9 -9
- package/ts3.4/es/core/structures/PDFPageTree.d.ts +8 -8
- package/ts3.4/es/core/syntax/Keywords.d.ts +1 -1
- package/ts3.4/es/core/writers/PDFStreamWriter.d.ts +11 -8
- package/ts3.4/es/core/writers/PDFWriter.d.ts +19 -11
- package/ts3.4/es/index.d.ts +4 -4
- package/ts3.4/es/types/index.d.ts +25 -1
- package/ts3.4/es/types/matrix.d.ts +8 -1
- package/ts3.4/es/utils/arrays.d.ts +3 -1
- package/ts3.4/es/utils/elements/Arc.d.ts +23 -0
- package/ts3.4/es/utils/elements/Circle.d.ts +15 -0
- package/ts3.4/es/utils/elements/Ellipse.d.ts +21 -0
- package/ts3.4/es/utils/elements/GraphElement.d.ts +7 -0
- package/ts3.4/es/utils/elements/Line.d.ts +24 -0
- package/ts3.4/es/utils/elements/Plot.d.ts +12 -0
- package/ts3.4/es/utils/elements/Point.d.ts +19 -0
- package/ts3.4/es/utils/elements/Rectangle.d.ts +22 -0
- package/ts3.4/es/utils/elements/Segment.d.ts +20 -0
- package/ts3.4/es/utils/elements/index.d.ts +10 -0
- package/ts3.4/es/utils/index.d.ts +11 -11
- package/ts3.4/es/utils/intersections.d.ts +10 -0
- package/ts3.4/es/utils/maths.d.ts +46 -0
- package/ts3.4/es/utils/strings.d.ts +5 -1
- package/ts3.4/es/utils/validators.d.ts +5 -2
- package/yarn.lock +0 -4446
|
@@ -0,0 +1,1609 @@
|
|
|
1
|
+
/* Copyright 2012 Mozilla Foundation
|
|
2
|
+
*
|
|
3
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License.
|
|
5
|
+
* You may obtain a copy of the License at
|
|
6
|
+
*
|
|
7
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
*
|
|
9
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
* See the License for the specific language governing permissions and
|
|
13
|
+
* limitations under the License.
|
|
14
|
+
*/
|
|
15
|
+
/* tslint:disable */
|
|
16
|
+
import { arrayAsString, isArrayEqual } from '../utils/arrays.js';
|
|
17
|
+
import { stringAsByteArray } from '../utils/strings.js';
|
|
18
|
+
import PDFDict from './objects/PDFDict.js';
|
|
19
|
+
import PDFName from './objects/PDFName.js';
|
|
20
|
+
import DecryptStream from './streams/DecryptStream.js';
|
|
21
|
+
class ARCFourCipher {
|
|
22
|
+
constructor(key) {
|
|
23
|
+
this.a = 0;
|
|
24
|
+
this.b = 0;
|
|
25
|
+
const s = new Uint8Array(256);
|
|
26
|
+
const keyLength = key.length;
|
|
27
|
+
for (let i = 0; i < 256; ++i) {
|
|
28
|
+
s[i] = i;
|
|
29
|
+
}
|
|
30
|
+
for (let i = 0, j = 0; i < 256; ++i) {
|
|
31
|
+
const tmp = s[i];
|
|
32
|
+
j = (j + tmp + key[i % keyLength]) & 0xff;
|
|
33
|
+
s[i] = s[j];
|
|
34
|
+
s[j] = tmp;
|
|
35
|
+
}
|
|
36
|
+
this.s = s;
|
|
37
|
+
}
|
|
38
|
+
encryptBlock(data) {
|
|
39
|
+
let a = this.a, b = this.b;
|
|
40
|
+
const s = this.s;
|
|
41
|
+
const n = data.length;
|
|
42
|
+
const output = new Uint8Array(n);
|
|
43
|
+
for (let i = 0; i < n; ++i) {
|
|
44
|
+
a = (a + 1) & 0xff;
|
|
45
|
+
const tmp = s[a];
|
|
46
|
+
b = (b + tmp) & 0xff;
|
|
47
|
+
const tmp2 = s[b];
|
|
48
|
+
s[a] = tmp2;
|
|
49
|
+
s[b] = tmp;
|
|
50
|
+
output[i] = data[i] ^ s[(tmp + tmp2) & 0xff];
|
|
51
|
+
}
|
|
52
|
+
this.a = a;
|
|
53
|
+
this.b = b;
|
|
54
|
+
return output;
|
|
55
|
+
}
|
|
56
|
+
decryptBlock(data) {
|
|
57
|
+
return this.encryptBlock(data);
|
|
58
|
+
}
|
|
59
|
+
encrypt(data) {
|
|
60
|
+
return this.encryptBlock(data);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
const calculateMD5 = (function calculateMD5Closure() {
|
|
64
|
+
const r = new Uint8Array([
|
|
65
|
+
7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 5, 9, 14, 20, 5,
|
|
66
|
+
9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11,
|
|
67
|
+
16, 23, 4, 11, 16, 23, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10,
|
|
68
|
+
15, 21,
|
|
69
|
+
]);
|
|
70
|
+
const k = new Int32Array([
|
|
71
|
+
-680876936, -389564586, 606105819, -1044525330, -176418897, 1200080426,
|
|
72
|
+
-1473231341, -45705983, 1770035416, -1958414417, -42063, -1990404162,
|
|
73
|
+
1804603682, -40341101, -1502002290, 1236535329, -165796510, -1069501632,
|
|
74
|
+
643717713, -373897302, -701558691, 38016083, -660478335, -405537848,
|
|
75
|
+
568446438, -1019803690, -187363961, 1163531501, -1444681467, -51403784,
|
|
76
|
+
1735328473, -1926607734, -378558, -2022574463, 1839030562, -35309556,
|
|
77
|
+
-1530992060, 1272893353, -155497632, -1094730640, 681279174, -358537222,
|
|
78
|
+
-722521979, 76029189, -640364487, -421815835, 530742520, -995338651,
|
|
79
|
+
-198630844, 1126891415, -1416354905, -57434055, 1700485571, -1894986606,
|
|
80
|
+
-1051523, -2054922799, 1873313359, -30611744, -1560198380, 1309151649,
|
|
81
|
+
-145523070, -1120210379, 718787259, -343485551,
|
|
82
|
+
]);
|
|
83
|
+
function hash(data, offset, length) {
|
|
84
|
+
let h0 = 1732584193, h1 = -271733879, h2 = -1732584194, h3 = 271733878;
|
|
85
|
+
// pre-processing
|
|
86
|
+
const paddedLength = (length + 72) & ~63; // data + 9 extra bytes
|
|
87
|
+
const padded = new Uint8Array(paddedLength);
|
|
88
|
+
let i, j;
|
|
89
|
+
for (i = 0; i < length; ++i) {
|
|
90
|
+
padded[i] = data[offset++];
|
|
91
|
+
}
|
|
92
|
+
padded[i++] = 0x80;
|
|
93
|
+
const n = paddedLength - 8;
|
|
94
|
+
while (i < n) {
|
|
95
|
+
padded[i++] = 0;
|
|
96
|
+
}
|
|
97
|
+
padded[i++] = (length << 3) & 0xff;
|
|
98
|
+
padded[i++] = (length >> 5) & 0xff;
|
|
99
|
+
padded[i++] = (length >> 13) & 0xff;
|
|
100
|
+
padded[i++] = (length >> 21) & 0xff;
|
|
101
|
+
padded[i++] = (length >>> 29) & 0xff;
|
|
102
|
+
padded[i++] = 0;
|
|
103
|
+
padded[i++] = 0;
|
|
104
|
+
padded[i++] = 0;
|
|
105
|
+
const w = new Int32Array(16);
|
|
106
|
+
for (i = 0; i < paddedLength;) {
|
|
107
|
+
for (j = 0; j < 16; ++j, i += 4) {
|
|
108
|
+
w[j] =
|
|
109
|
+
padded[i] |
|
|
110
|
+
(padded[i + 1] << 8) |
|
|
111
|
+
(padded[i + 2] << 16) |
|
|
112
|
+
(padded[i + 3] << 24);
|
|
113
|
+
}
|
|
114
|
+
let a = h0, b = h1, c = h2, d = h3, f, g;
|
|
115
|
+
for (j = 0; j < 64; ++j) {
|
|
116
|
+
if (j < 16) {
|
|
117
|
+
f = (b & c) | (~b & d);
|
|
118
|
+
g = j;
|
|
119
|
+
}
|
|
120
|
+
else if (j < 32) {
|
|
121
|
+
f = (d & b) | (~d & c);
|
|
122
|
+
g = (5 * j + 1) & 15;
|
|
123
|
+
}
|
|
124
|
+
else if (j < 48) {
|
|
125
|
+
f = b ^ c ^ d;
|
|
126
|
+
g = (3 * j + 5) & 15;
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
f = c ^ (b | ~d);
|
|
130
|
+
g = (7 * j) & 15;
|
|
131
|
+
}
|
|
132
|
+
const tmp = d, rotateArg = (a + f + k[j] + w[g]) | 0, rotate = r[j];
|
|
133
|
+
d = c;
|
|
134
|
+
c = b;
|
|
135
|
+
b = (b + ((rotateArg << rotate) | (rotateArg >>> (32 - rotate)))) | 0;
|
|
136
|
+
a = tmp;
|
|
137
|
+
}
|
|
138
|
+
h0 = (h0 + a) | 0;
|
|
139
|
+
h1 = (h1 + b) | 0;
|
|
140
|
+
h2 = (h2 + c) | 0;
|
|
141
|
+
h3 = (h3 + d) | 0;
|
|
142
|
+
}
|
|
143
|
+
// prettier-ignore
|
|
144
|
+
return new Uint8Array([
|
|
145
|
+
h0 & 0xFF, (h0 >> 8) & 0xFF, (h0 >> 16) & 0xFF, (h0 >>> 24) & 0xFF,
|
|
146
|
+
h1 & 0xFF, (h1 >> 8) & 0xFF, (h1 >> 16) & 0xFF, (h1 >>> 24) & 0xFF,
|
|
147
|
+
h2 & 0xFF, (h2 >> 8) & 0xFF, (h2 >> 16) & 0xFF, (h2 >>> 24) & 0xFF,
|
|
148
|
+
h3 & 0xFF, (h3 >> 8) & 0xFF, (h3 >> 16) & 0xFF, (h3 >>> 24) & 0xFF
|
|
149
|
+
]);
|
|
150
|
+
}
|
|
151
|
+
return hash;
|
|
152
|
+
})();
|
|
153
|
+
class Word64 {
|
|
154
|
+
constructor(highInteger, lowInteger) {
|
|
155
|
+
this.high = highInteger | 0;
|
|
156
|
+
this.low = lowInteger | 0;
|
|
157
|
+
}
|
|
158
|
+
and(word) {
|
|
159
|
+
this.high &= word.high;
|
|
160
|
+
this.low &= word.low;
|
|
161
|
+
}
|
|
162
|
+
xor(word) {
|
|
163
|
+
this.high ^= word.high;
|
|
164
|
+
this.low ^= word.low;
|
|
165
|
+
}
|
|
166
|
+
or(word) {
|
|
167
|
+
this.high |= word.high;
|
|
168
|
+
this.low |= word.low;
|
|
169
|
+
}
|
|
170
|
+
shiftRight(places) {
|
|
171
|
+
if (places >= 32) {
|
|
172
|
+
this.low = (this.high >>> (places - 32)) | 0;
|
|
173
|
+
this.high = 0;
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
this.low = (this.low >>> places) | (this.high << (32 - places));
|
|
177
|
+
this.high = (this.high >>> places) | 0;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
shiftLeft(places) {
|
|
181
|
+
if (places >= 32) {
|
|
182
|
+
this.high = this.low << (places - 32);
|
|
183
|
+
this.low = 0;
|
|
184
|
+
}
|
|
185
|
+
else {
|
|
186
|
+
this.high = (this.high << places) | (this.low >>> (32 - places));
|
|
187
|
+
this.low <<= places;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
rotateRight(places) {
|
|
191
|
+
let low, high;
|
|
192
|
+
if (places & 32) {
|
|
193
|
+
high = this.low;
|
|
194
|
+
low = this.high;
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
low = this.low;
|
|
198
|
+
high = this.high;
|
|
199
|
+
}
|
|
200
|
+
places &= 31;
|
|
201
|
+
this.low = (low >>> places) | (high << (32 - places));
|
|
202
|
+
this.high = (high >>> places) | (low << (32 - places));
|
|
203
|
+
}
|
|
204
|
+
not() {
|
|
205
|
+
this.high = ~this.high;
|
|
206
|
+
this.low = ~this.low;
|
|
207
|
+
}
|
|
208
|
+
add(word) {
|
|
209
|
+
const lowAdd = (this.low >>> 0) + (word.low >>> 0);
|
|
210
|
+
let highAdd = (this.high >>> 0) + (word.high >>> 0);
|
|
211
|
+
if (lowAdd > 0xffffffff) {
|
|
212
|
+
highAdd += 1;
|
|
213
|
+
}
|
|
214
|
+
this.low = lowAdd | 0;
|
|
215
|
+
this.high = highAdd | 0;
|
|
216
|
+
}
|
|
217
|
+
copyTo(bytes, offset) {
|
|
218
|
+
bytes[offset] = (this.high >>> 24) & 0xff;
|
|
219
|
+
bytes[offset + 1] = (this.high >> 16) & 0xff;
|
|
220
|
+
bytes[offset + 2] = (this.high >> 8) & 0xff;
|
|
221
|
+
bytes[offset + 3] = this.high & 0xff;
|
|
222
|
+
bytes[offset + 4] = (this.low >>> 24) & 0xff;
|
|
223
|
+
bytes[offset + 5] = (this.low >> 16) & 0xff;
|
|
224
|
+
bytes[offset + 6] = (this.low >> 8) & 0xff;
|
|
225
|
+
bytes[offset + 7] = this.low & 0xff;
|
|
226
|
+
}
|
|
227
|
+
assign(word) {
|
|
228
|
+
this.high = word.high;
|
|
229
|
+
this.low = word.low;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
const calculateSHA256 = (function calculateSHA256Closure() {
|
|
233
|
+
function rotr(x, n) {
|
|
234
|
+
return (x >>> n) | (x << (32 - n));
|
|
235
|
+
}
|
|
236
|
+
function ch(x, y, z) {
|
|
237
|
+
return (x & y) ^ (~x & z);
|
|
238
|
+
}
|
|
239
|
+
function maj(x, y, z) {
|
|
240
|
+
return (x & y) ^ (x & z) ^ (y & z);
|
|
241
|
+
}
|
|
242
|
+
function sigma(x) {
|
|
243
|
+
return rotr(x, 2) ^ rotr(x, 13) ^ rotr(x, 22);
|
|
244
|
+
}
|
|
245
|
+
function sigmaPrime(x) {
|
|
246
|
+
return rotr(x, 6) ^ rotr(x, 11) ^ rotr(x, 25);
|
|
247
|
+
}
|
|
248
|
+
function littleSigma(x) {
|
|
249
|
+
return rotr(x, 7) ^ rotr(x, 18) ^ (x >>> 3);
|
|
250
|
+
}
|
|
251
|
+
function littleSigmaPrime(x) {
|
|
252
|
+
return rotr(x, 17) ^ rotr(x, 19) ^ (x >>> 10);
|
|
253
|
+
}
|
|
254
|
+
const k = [
|
|
255
|
+
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1,
|
|
256
|
+
0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
|
|
257
|
+
0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, 0xe49b69c1, 0xefbe4786,
|
|
258
|
+
0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
|
|
259
|
+
0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147,
|
|
260
|
+
0x06ca6351, 0x14292967, 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
|
|
261
|
+
0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, 0xa2bfe8a1, 0xa81a664b,
|
|
262
|
+
0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
|
|
263
|
+
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a,
|
|
264
|
+
0x5b9cca4f, 0x682e6ff3, 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
|
|
265
|
+
0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2,
|
|
266
|
+
];
|
|
267
|
+
function hash(data, offset, length) {
|
|
268
|
+
// initial hash values
|
|
269
|
+
let h0 = 0x6a09e667, h1 = 0xbb67ae85, h2 = 0x3c6ef372, h3 = 0xa54ff53a, h4 = 0x510e527f, h5 = 0x9b05688c, h6 = 0x1f83d9ab, h7 = 0x5be0cd19;
|
|
270
|
+
// pre-processing
|
|
271
|
+
const paddedLength = Math.ceil((length + 9) / 64) * 64;
|
|
272
|
+
const padded = new Uint8Array(paddedLength);
|
|
273
|
+
let i, j;
|
|
274
|
+
for (i = 0; i < length; ++i) {
|
|
275
|
+
padded[i] = data[offset++];
|
|
276
|
+
}
|
|
277
|
+
padded[i++] = 0x80;
|
|
278
|
+
const n = paddedLength - 8;
|
|
279
|
+
while (i < n) {
|
|
280
|
+
padded[i++] = 0;
|
|
281
|
+
}
|
|
282
|
+
padded[i++] = 0;
|
|
283
|
+
padded[i++] = 0;
|
|
284
|
+
padded[i++] = 0;
|
|
285
|
+
padded[i++] = (length >>> 29) & 0xff;
|
|
286
|
+
padded[i++] = (length >> 21) & 0xff;
|
|
287
|
+
padded[i++] = (length >> 13) & 0xff;
|
|
288
|
+
padded[i++] = (length >> 5) & 0xff;
|
|
289
|
+
padded[i++] = (length << 3) & 0xff;
|
|
290
|
+
const w = new Uint32Array(64);
|
|
291
|
+
// for each 512 bit block
|
|
292
|
+
for (i = 0; i < paddedLength;) {
|
|
293
|
+
for (j = 0; j < 16; ++j) {
|
|
294
|
+
w[j] =
|
|
295
|
+
(padded[i] << 24) |
|
|
296
|
+
(padded[i + 1] << 16) |
|
|
297
|
+
(padded[i + 2] << 8) |
|
|
298
|
+
padded[i + 3];
|
|
299
|
+
i += 4;
|
|
300
|
+
}
|
|
301
|
+
for (j = 16; j < 64; ++j) {
|
|
302
|
+
w[j] =
|
|
303
|
+
(littleSigmaPrime(w[j - 2]) +
|
|
304
|
+
w[j - 7] +
|
|
305
|
+
littleSigma(w[j - 15]) +
|
|
306
|
+
w[j - 16]) |
|
|
307
|
+
0;
|
|
308
|
+
}
|
|
309
|
+
let a = h0, b = h1, c = h2, d = h3, e = h4, f = h5, g = h6, h = h7, t1, t2;
|
|
310
|
+
for (j = 0; j < 64; ++j) {
|
|
311
|
+
t1 = h + sigmaPrime(e) + ch(e, f, g) + k[j] + w[j];
|
|
312
|
+
t2 = sigma(a) + maj(a, b, c);
|
|
313
|
+
h = g;
|
|
314
|
+
g = f;
|
|
315
|
+
f = e;
|
|
316
|
+
e = (d + t1) | 0;
|
|
317
|
+
d = c;
|
|
318
|
+
c = b;
|
|
319
|
+
b = a;
|
|
320
|
+
a = (t1 + t2) | 0;
|
|
321
|
+
}
|
|
322
|
+
h0 = (h0 + a) | 0;
|
|
323
|
+
h1 = (h1 + b) | 0;
|
|
324
|
+
h2 = (h2 + c) | 0;
|
|
325
|
+
h3 = (h3 + d) | 0;
|
|
326
|
+
h4 = (h4 + e) | 0;
|
|
327
|
+
h5 = (h5 + f) | 0;
|
|
328
|
+
h6 = (h6 + g) | 0;
|
|
329
|
+
h7 = (h7 + h) | 0;
|
|
330
|
+
}
|
|
331
|
+
// prettier-ignore
|
|
332
|
+
return new Uint8Array([
|
|
333
|
+
(h0 >> 24) & 0xFF, (h0 >> 16) & 0xFF, (h0 >> 8) & 0xFF, (h0) & 0xFF,
|
|
334
|
+
(h1 >> 24) & 0xFF, (h1 >> 16) & 0xFF, (h1 >> 8) & 0xFF, (h1) & 0xFF,
|
|
335
|
+
(h2 >> 24) & 0xFF, (h2 >> 16) & 0xFF, (h2 >> 8) & 0xFF, (h2) & 0xFF,
|
|
336
|
+
(h3 >> 24) & 0xFF, (h3 >> 16) & 0xFF, (h3 >> 8) & 0xFF, (h3) & 0xFF,
|
|
337
|
+
(h4 >> 24) & 0xFF, (h4 >> 16) & 0xFF, (h4 >> 8) & 0xFF, (h4) & 0xFF,
|
|
338
|
+
(h5 >> 24) & 0xFF, (h5 >> 16) & 0xFF, (h5 >> 8) & 0xFF, (h5) & 0xFF,
|
|
339
|
+
(h6 >> 24) & 0xFF, (h6 >> 16) & 0xFF, (h6 >> 8) & 0xFF, (h6) & 0xFF,
|
|
340
|
+
(h7 >> 24) & 0xFF, (h7 >> 16) & 0xFF, (h7 >> 8) & 0xFF, (h7) & 0xFF
|
|
341
|
+
]);
|
|
342
|
+
}
|
|
343
|
+
return hash;
|
|
344
|
+
})();
|
|
345
|
+
const calculateSHA512 = (function calculateSHA512Closure() {
|
|
346
|
+
function ch(result, x, y, z, tmp) {
|
|
347
|
+
result.assign(x);
|
|
348
|
+
result.and(y);
|
|
349
|
+
tmp.assign(x);
|
|
350
|
+
tmp.not();
|
|
351
|
+
tmp.and(z);
|
|
352
|
+
result.xor(tmp);
|
|
353
|
+
}
|
|
354
|
+
function maj(result, x, y, z, tmp) {
|
|
355
|
+
result.assign(x);
|
|
356
|
+
result.and(y);
|
|
357
|
+
tmp.assign(x);
|
|
358
|
+
tmp.and(z);
|
|
359
|
+
result.xor(tmp);
|
|
360
|
+
tmp.assign(y);
|
|
361
|
+
tmp.and(z);
|
|
362
|
+
result.xor(tmp);
|
|
363
|
+
}
|
|
364
|
+
function sigma(result, x, tmp) {
|
|
365
|
+
result.assign(x);
|
|
366
|
+
result.rotateRight(28);
|
|
367
|
+
tmp.assign(x);
|
|
368
|
+
tmp.rotateRight(34);
|
|
369
|
+
result.xor(tmp);
|
|
370
|
+
tmp.assign(x);
|
|
371
|
+
tmp.rotateRight(39);
|
|
372
|
+
result.xor(tmp);
|
|
373
|
+
}
|
|
374
|
+
function sigmaPrime(result, x, tmp) {
|
|
375
|
+
result.assign(x);
|
|
376
|
+
result.rotateRight(14);
|
|
377
|
+
tmp.assign(x);
|
|
378
|
+
tmp.rotateRight(18);
|
|
379
|
+
result.xor(tmp);
|
|
380
|
+
tmp.assign(x);
|
|
381
|
+
tmp.rotateRight(41);
|
|
382
|
+
result.xor(tmp);
|
|
383
|
+
}
|
|
384
|
+
function littleSigma(result, x, tmp) {
|
|
385
|
+
result.assign(x);
|
|
386
|
+
result.rotateRight(1);
|
|
387
|
+
tmp.assign(x);
|
|
388
|
+
tmp.rotateRight(8);
|
|
389
|
+
result.xor(tmp);
|
|
390
|
+
tmp.assign(x);
|
|
391
|
+
tmp.shiftRight(7);
|
|
392
|
+
result.xor(tmp);
|
|
393
|
+
}
|
|
394
|
+
function littleSigmaPrime(result, x, tmp) {
|
|
395
|
+
result.assign(x);
|
|
396
|
+
result.rotateRight(19);
|
|
397
|
+
tmp.assign(x);
|
|
398
|
+
tmp.rotateRight(61);
|
|
399
|
+
result.xor(tmp);
|
|
400
|
+
tmp.assign(x);
|
|
401
|
+
tmp.shiftRight(6);
|
|
402
|
+
result.xor(tmp);
|
|
403
|
+
}
|
|
404
|
+
// prettier-ignore
|
|
405
|
+
const k = [
|
|
406
|
+
new Word64(0x428a2f98, 0xd728ae22), new Word64(0x71374491, 0x23ef65cd),
|
|
407
|
+
new Word64(0xb5c0fbcf, 0xec4d3b2f), new Word64(0xe9b5dba5, 0x8189dbbc),
|
|
408
|
+
new Word64(0x3956c25b, 0xf348b538), new Word64(0x59f111f1, 0xb605d019),
|
|
409
|
+
new Word64(0x923f82a4, 0xaf194f9b), new Word64(0xab1c5ed5, 0xda6d8118),
|
|
410
|
+
new Word64(0xd807aa98, 0xa3030242), new Word64(0x12835b01, 0x45706fbe),
|
|
411
|
+
new Word64(0x243185be, 0x4ee4b28c), new Word64(0x550c7dc3, 0xd5ffb4e2),
|
|
412
|
+
new Word64(0x72be5d74, 0xf27b896f), new Word64(0x80deb1fe, 0x3b1696b1),
|
|
413
|
+
new Word64(0x9bdc06a7, 0x25c71235), new Word64(0xc19bf174, 0xcf692694),
|
|
414
|
+
new Word64(0xe49b69c1, 0x9ef14ad2), new Word64(0xefbe4786, 0x384f25e3),
|
|
415
|
+
new Word64(0x0fc19dc6, 0x8b8cd5b5), new Word64(0x240ca1cc, 0x77ac9c65),
|
|
416
|
+
new Word64(0x2de92c6f, 0x592b0275), new Word64(0x4a7484aa, 0x6ea6e483),
|
|
417
|
+
new Word64(0x5cb0a9dc, 0xbd41fbd4), new Word64(0x76f988da, 0x831153b5),
|
|
418
|
+
new Word64(0x983e5152, 0xee66dfab), new Word64(0xa831c66d, 0x2db43210),
|
|
419
|
+
new Word64(0xb00327c8, 0x98fb213f), new Word64(0xbf597fc7, 0xbeef0ee4),
|
|
420
|
+
new Word64(0xc6e00bf3, 0x3da88fc2), new Word64(0xd5a79147, 0x930aa725),
|
|
421
|
+
new Word64(0x06ca6351, 0xe003826f), new Word64(0x14292967, 0x0a0e6e70),
|
|
422
|
+
new Word64(0x27b70a85, 0x46d22ffc), new Word64(0x2e1b2138, 0x5c26c926),
|
|
423
|
+
new Word64(0x4d2c6dfc, 0x5ac42aed), new Word64(0x53380d13, 0x9d95b3df),
|
|
424
|
+
new Word64(0x650a7354, 0x8baf63de), new Word64(0x766a0abb, 0x3c77b2a8),
|
|
425
|
+
new Word64(0x81c2c92e, 0x47edaee6), new Word64(0x92722c85, 0x1482353b),
|
|
426
|
+
new Word64(0xa2bfe8a1, 0x4cf10364), new Word64(0xa81a664b, 0xbc423001),
|
|
427
|
+
new Word64(0xc24b8b70, 0xd0f89791), new Word64(0xc76c51a3, 0x0654be30),
|
|
428
|
+
new Word64(0xd192e819, 0xd6ef5218), new Word64(0xd6990624, 0x5565a910),
|
|
429
|
+
new Word64(0xf40e3585, 0x5771202a), new Word64(0x106aa070, 0x32bbd1b8),
|
|
430
|
+
new Word64(0x19a4c116, 0xb8d2d0c8), new Word64(0x1e376c08, 0x5141ab53),
|
|
431
|
+
new Word64(0x2748774c, 0xdf8eeb99), new Word64(0x34b0bcb5, 0xe19b48a8),
|
|
432
|
+
new Word64(0x391c0cb3, 0xc5c95a63), new Word64(0x4ed8aa4a, 0xe3418acb),
|
|
433
|
+
new Word64(0x5b9cca4f, 0x7763e373), new Word64(0x682e6ff3, 0xd6b2b8a3),
|
|
434
|
+
new Word64(0x748f82ee, 0x5defb2fc), new Word64(0x78a5636f, 0x43172f60),
|
|
435
|
+
new Word64(0x84c87814, 0xa1f0ab72), new Word64(0x8cc70208, 0x1a6439ec),
|
|
436
|
+
new Word64(0x90befffa, 0x23631e28), new Word64(0xa4506ceb, 0xde82bde9),
|
|
437
|
+
new Word64(0xbef9a3f7, 0xb2c67915), new Word64(0xc67178f2, 0xe372532b),
|
|
438
|
+
new Word64(0xca273ece, 0xea26619c), new Word64(0xd186b8c7, 0x21c0c207),
|
|
439
|
+
new Word64(0xeada7dd6, 0xcde0eb1e), new Word64(0xf57d4f7f, 0xee6ed178),
|
|
440
|
+
new Word64(0x06f067aa, 0x72176fba), new Word64(0x0a637dc5, 0xa2c898a6),
|
|
441
|
+
new Word64(0x113f9804, 0xbef90dae), new Word64(0x1b710b35, 0x131c471b),
|
|
442
|
+
new Word64(0x28db77f5, 0x23047d84), new Word64(0x32caab7b, 0x40c72493),
|
|
443
|
+
new Word64(0x3c9ebe0a, 0x15c9bebc), new Word64(0x431d67c4, 0x9c100d4c),
|
|
444
|
+
new Word64(0x4cc5d4be, 0xcb3e42b6), new Word64(0x597f299c, 0xfc657e2a),
|
|
445
|
+
new Word64(0x5fcb6fab, 0x3ad6faec), new Word64(0x6c44198c, 0x4a475817)
|
|
446
|
+
];
|
|
447
|
+
function hash(data, offset, length, mode384 = false) {
|
|
448
|
+
// initial hash values
|
|
449
|
+
let h0, h1, h2, h3, h4, h5, h6, h7;
|
|
450
|
+
if (!mode384) {
|
|
451
|
+
h0 = new Word64(0x6a09e667, 0xf3bcc908);
|
|
452
|
+
h1 = new Word64(0xbb67ae85, 0x84caa73b);
|
|
453
|
+
h2 = new Word64(0x3c6ef372, 0xfe94f82b);
|
|
454
|
+
h3 = new Word64(0xa54ff53a, 0x5f1d36f1);
|
|
455
|
+
h4 = new Word64(0x510e527f, 0xade682d1);
|
|
456
|
+
h5 = new Word64(0x9b05688c, 0x2b3e6c1f);
|
|
457
|
+
h6 = new Word64(0x1f83d9ab, 0xfb41bd6b);
|
|
458
|
+
h7 = new Word64(0x5be0cd19, 0x137e2179);
|
|
459
|
+
}
|
|
460
|
+
else {
|
|
461
|
+
// SHA384 is exactly the same
|
|
462
|
+
// except with different starting values and a trimmed result
|
|
463
|
+
h0 = new Word64(0xcbbb9d5d, 0xc1059ed8);
|
|
464
|
+
h1 = new Word64(0x629a292a, 0x367cd507);
|
|
465
|
+
h2 = new Word64(0x9159015a, 0x3070dd17);
|
|
466
|
+
h3 = new Word64(0x152fecd8, 0xf70e5939);
|
|
467
|
+
h4 = new Word64(0x67332667, 0xffc00b31);
|
|
468
|
+
h5 = new Word64(0x8eb44a87, 0x68581511);
|
|
469
|
+
h6 = new Word64(0xdb0c2e0d, 0x64f98fa7);
|
|
470
|
+
h7 = new Word64(0x47b5481d, 0xbefa4fa4);
|
|
471
|
+
}
|
|
472
|
+
// pre-processing
|
|
473
|
+
const paddedLength = Math.ceil((length + 17) / 128) * 128;
|
|
474
|
+
const padded = new Uint8Array(paddedLength);
|
|
475
|
+
let i, j;
|
|
476
|
+
for (i = 0; i < length; ++i) {
|
|
477
|
+
padded[i] = data[offset++];
|
|
478
|
+
}
|
|
479
|
+
padded[i++] = 0x80;
|
|
480
|
+
const n = paddedLength - 16;
|
|
481
|
+
while (i < n) {
|
|
482
|
+
padded[i++] = 0;
|
|
483
|
+
}
|
|
484
|
+
padded[i++] = 0;
|
|
485
|
+
padded[i++] = 0;
|
|
486
|
+
padded[i++] = 0;
|
|
487
|
+
padded[i++] = 0;
|
|
488
|
+
padded[i++] = 0;
|
|
489
|
+
padded[i++] = 0;
|
|
490
|
+
padded[i++] = 0;
|
|
491
|
+
padded[i++] = 0;
|
|
492
|
+
padded[i++] = 0;
|
|
493
|
+
padded[i++] = 0;
|
|
494
|
+
padded[i++] = 0;
|
|
495
|
+
padded[i++] = (length >>> 29) & 0xff;
|
|
496
|
+
padded[i++] = (length >> 21) & 0xff;
|
|
497
|
+
padded[i++] = (length >> 13) & 0xff;
|
|
498
|
+
padded[i++] = (length >> 5) & 0xff;
|
|
499
|
+
padded[i++] = (length << 3) & 0xff;
|
|
500
|
+
const w = new Array(80);
|
|
501
|
+
for (i = 0; i < 80; i++) {
|
|
502
|
+
w[i] = new Word64(0, 0);
|
|
503
|
+
}
|
|
504
|
+
let a = new Word64(0, 0), b = new Word64(0, 0), c = new Word64(0, 0);
|
|
505
|
+
let d = new Word64(0, 0), e = new Word64(0, 0), f = new Word64(0, 0);
|
|
506
|
+
let g = new Word64(0, 0), h = new Word64(0, 0);
|
|
507
|
+
const t1 = new Word64(0, 0), t2 = new Word64(0, 0);
|
|
508
|
+
const tmp1 = new Word64(0, 0), tmp2 = new Word64(0, 0);
|
|
509
|
+
let tmp3;
|
|
510
|
+
// for each 1024 bit block
|
|
511
|
+
for (i = 0; i < paddedLength;) {
|
|
512
|
+
for (j = 0; j < 16; ++j) {
|
|
513
|
+
w[j].high =
|
|
514
|
+
(padded[i] << 24) |
|
|
515
|
+
(padded[i + 1] << 16) |
|
|
516
|
+
(padded[i + 2] << 8) |
|
|
517
|
+
padded[i + 3];
|
|
518
|
+
w[j].low =
|
|
519
|
+
(padded[i + 4] << 24) |
|
|
520
|
+
(padded[i + 5] << 16) |
|
|
521
|
+
(padded[i + 6] << 8) |
|
|
522
|
+
padded[i + 7];
|
|
523
|
+
i += 8;
|
|
524
|
+
}
|
|
525
|
+
for (j = 16; j < 80; ++j) {
|
|
526
|
+
tmp3 = w[j];
|
|
527
|
+
littleSigmaPrime(tmp3, w[j - 2], tmp2);
|
|
528
|
+
tmp3.add(w[j - 7]);
|
|
529
|
+
littleSigma(tmp1, w[j - 15], tmp2);
|
|
530
|
+
tmp3.add(tmp1);
|
|
531
|
+
tmp3.add(w[j - 16]);
|
|
532
|
+
}
|
|
533
|
+
a.assign(h0);
|
|
534
|
+
b.assign(h1);
|
|
535
|
+
c.assign(h2);
|
|
536
|
+
d.assign(h3);
|
|
537
|
+
e.assign(h4);
|
|
538
|
+
f.assign(h5);
|
|
539
|
+
g.assign(h6);
|
|
540
|
+
h.assign(h7);
|
|
541
|
+
for (j = 0; j < 80; ++j) {
|
|
542
|
+
t1.assign(h);
|
|
543
|
+
sigmaPrime(tmp1, e, tmp2);
|
|
544
|
+
t1.add(tmp1);
|
|
545
|
+
ch(tmp1, e, f, g, tmp2);
|
|
546
|
+
t1.add(tmp1);
|
|
547
|
+
t1.add(k[j]);
|
|
548
|
+
t1.add(w[j]);
|
|
549
|
+
sigma(t2, a, tmp2);
|
|
550
|
+
maj(tmp1, a, b, c, tmp2);
|
|
551
|
+
t2.add(tmp1);
|
|
552
|
+
tmp3 = h;
|
|
553
|
+
h = g;
|
|
554
|
+
g = f;
|
|
555
|
+
f = e;
|
|
556
|
+
d.add(t1);
|
|
557
|
+
e = d;
|
|
558
|
+
d = c;
|
|
559
|
+
c = b;
|
|
560
|
+
b = a;
|
|
561
|
+
tmp3.assign(t1);
|
|
562
|
+
tmp3.add(t2);
|
|
563
|
+
a = tmp3;
|
|
564
|
+
}
|
|
565
|
+
h0.add(a);
|
|
566
|
+
h1.add(b);
|
|
567
|
+
h2.add(c);
|
|
568
|
+
h3.add(d);
|
|
569
|
+
h4.add(e);
|
|
570
|
+
h5.add(f);
|
|
571
|
+
h6.add(g);
|
|
572
|
+
h7.add(h);
|
|
573
|
+
}
|
|
574
|
+
let result;
|
|
575
|
+
if (!mode384) {
|
|
576
|
+
result = new Uint8Array(64);
|
|
577
|
+
h0.copyTo(result, 0);
|
|
578
|
+
h1.copyTo(result, 8);
|
|
579
|
+
h2.copyTo(result, 16);
|
|
580
|
+
h3.copyTo(result, 24);
|
|
581
|
+
h4.copyTo(result, 32);
|
|
582
|
+
h5.copyTo(result, 40);
|
|
583
|
+
h6.copyTo(result, 48);
|
|
584
|
+
h7.copyTo(result, 56);
|
|
585
|
+
}
|
|
586
|
+
else {
|
|
587
|
+
result = new Uint8Array(48);
|
|
588
|
+
h0.copyTo(result, 0);
|
|
589
|
+
h1.copyTo(result, 8);
|
|
590
|
+
h2.copyTo(result, 16);
|
|
591
|
+
h3.copyTo(result, 24);
|
|
592
|
+
h4.copyTo(result, 32);
|
|
593
|
+
h5.copyTo(result, 40);
|
|
594
|
+
}
|
|
595
|
+
return result;
|
|
596
|
+
}
|
|
597
|
+
return hash;
|
|
598
|
+
})();
|
|
599
|
+
function calculateSHA384(data, offset, length) {
|
|
600
|
+
return calculateSHA512(data, offset, length, /* mode384 = */ true);
|
|
601
|
+
}
|
|
602
|
+
class NullCipher {
|
|
603
|
+
decryptBlock(data) {
|
|
604
|
+
return data;
|
|
605
|
+
}
|
|
606
|
+
encrypt(data) {
|
|
607
|
+
return data;
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
class AESBaseCipher {
|
|
611
|
+
constructor() {
|
|
612
|
+
if (this.constructor === AESBaseCipher) {
|
|
613
|
+
throw new Error('Cannot initialize AESBaseCipher.');
|
|
614
|
+
}
|
|
615
|
+
this._s = new Uint8Array([
|
|
616
|
+
0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
|
|
617
|
+
0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
|
|
618
|
+
0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
|
|
619
|
+
0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
|
|
620
|
+
0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
|
|
621
|
+
0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
|
|
622
|
+
0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
|
|
623
|
+
0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
|
|
624
|
+
0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
|
|
625
|
+
0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
|
|
626
|
+
0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
|
|
627
|
+
0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
|
|
628
|
+
0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
|
|
629
|
+
0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
|
|
630
|
+
0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
|
|
631
|
+
0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
|
|
632
|
+
0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
|
|
633
|
+
0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
|
|
634
|
+
0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
|
|
635
|
+
0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
|
|
636
|
+
0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
|
|
637
|
+
0xb0, 0x54, 0xbb, 0x16,
|
|
638
|
+
]);
|
|
639
|
+
this._inv_s = new Uint8Array([
|
|
640
|
+
0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
|
|
641
|
+
0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
|
|
642
|
+
0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
|
|
643
|
+
0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
|
|
644
|
+
0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
|
|
645
|
+
0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
|
|
646
|
+
0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
|
|
647
|
+
0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
|
|
648
|
+
0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
|
|
649
|
+
0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
|
|
650
|
+
0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
|
|
651
|
+
0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
|
|
652
|
+
0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
|
|
653
|
+
0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
|
|
654
|
+
0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
|
|
655
|
+
0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
|
|
656
|
+
0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
|
|
657
|
+
0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
|
|
658
|
+
0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
|
|
659
|
+
0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
|
|
660
|
+
0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
|
|
661
|
+
0x55, 0x21, 0x0c, 0x7d,
|
|
662
|
+
]);
|
|
663
|
+
this._mix = new Uint32Array([
|
|
664
|
+
0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
|
|
665
|
+
0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
|
|
666
|
+
0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
|
|
667
|
+
0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
|
|
668
|
+
0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
|
|
669
|
+
0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
|
|
670
|
+
0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
|
|
671
|
+
0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
|
|
672
|
+
0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
|
|
673
|
+
0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
|
|
674
|
+
0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
|
|
675
|
+
0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
|
|
676
|
+
0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
|
|
677
|
+
0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
|
|
678
|
+
0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
|
|
679
|
+
0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
|
|
680
|
+
0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
|
|
681
|
+
0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
|
|
682
|
+
0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
|
|
683
|
+
0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
|
|
684
|
+
0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
|
|
685
|
+
0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
|
|
686
|
+
0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
|
|
687
|
+
0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
|
|
688
|
+
0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
|
|
689
|
+
0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
|
|
690
|
+
0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
|
|
691
|
+
0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
|
|
692
|
+
0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
|
|
693
|
+
0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
|
|
694
|
+
0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
|
|
695
|
+
0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
|
|
696
|
+
0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
|
|
697
|
+
0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
|
|
698
|
+
0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
|
|
699
|
+
0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
|
|
700
|
+
0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
|
|
701
|
+
0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
|
|
702
|
+
0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
|
|
703
|
+
0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
|
|
704
|
+
0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
|
|
705
|
+
0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
|
|
706
|
+
0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3,
|
|
707
|
+
]);
|
|
708
|
+
this._mixCol = new Uint8Array(256);
|
|
709
|
+
for (let i = 0; i < 256; i++) {
|
|
710
|
+
if (i < 128) {
|
|
711
|
+
this._mixCol[i] = i << 1;
|
|
712
|
+
}
|
|
713
|
+
else {
|
|
714
|
+
this._mixCol[i] = (i << 1) ^ 0x1b;
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
this.buffer = new Uint8Array(16);
|
|
718
|
+
this.bufferPosition = 0;
|
|
719
|
+
}
|
|
720
|
+
_expandKey(_cipherKey) {
|
|
721
|
+
throw new Error('Cannot call `_expandKey` on the base class');
|
|
722
|
+
}
|
|
723
|
+
_decrypt(input, key) {
|
|
724
|
+
let t, u, v;
|
|
725
|
+
const state = new Uint8Array(16);
|
|
726
|
+
state.set(input);
|
|
727
|
+
// AddRoundKey
|
|
728
|
+
for (let j = 0, k = this._keySize; j < 16; ++j, ++k) {
|
|
729
|
+
state[j] ^= key[k];
|
|
730
|
+
}
|
|
731
|
+
for (let i = this._cyclesOfRepetition - 1; i >= 1; --i) {
|
|
732
|
+
// InvShiftRows
|
|
733
|
+
t = state[13];
|
|
734
|
+
state[13] = state[9];
|
|
735
|
+
state[9] = state[5];
|
|
736
|
+
state[5] = state[1];
|
|
737
|
+
state[1] = t;
|
|
738
|
+
t = state[14];
|
|
739
|
+
u = state[10];
|
|
740
|
+
state[14] = state[6];
|
|
741
|
+
state[10] = state[2];
|
|
742
|
+
state[6] = t;
|
|
743
|
+
state[2] = u;
|
|
744
|
+
t = state[15];
|
|
745
|
+
u = state[11];
|
|
746
|
+
v = state[7];
|
|
747
|
+
state[15] = state[3];
|
|
748
|
+
state[11] = t;
|
|
749
|
+
state[7] = u;
|
|
750
|
+
state[3] = v;
|
|
751
|
+
// InvSubBytes
|
|
752
|
+
for (let j = 0; j < 16; ++j) {
|
|
753
|
+
state[j] = this._inv_s[state[j]];
|
|
754
|
+
}
|
|
755
|
+
// AddRoundKey
|
|
756
|
+
for (let j = 0, k = i * 16; j < 16; ++j, ++k) {
|
|
757
|
+
state[j] ^= key[k];
|
|
758
|
+
}
|
|
759
|
+
// InvMixColumns
|
|
760
|
+
for (let j = 0; j < 16; j += 4) {
|
|
761
|
+
const s0 = this._mix[state[j]];
|
|
762
|
+
const s1 = this._mix[state[j + 1]];
|
|
763
|
+
const s2 = this._mix[state[j + 2]];
|
|
764
|
+
const s3 = this._mix[state[j + 3]];
|
|
765
|
+
t =
|
|
766
|
+
s0 ^
|
|
767
|
+
(s1 >>> 8) ^
|
|
768
|
+
(s1 << 24) ^
|
|
769
|
+
(s2 >>> 16) ^
|
|
770
|
+
(s2 << 16) ^
|
|
771
|
+
(s3 >>> 24) ^
|
|
772
|
+
(s3 << 8);
|
|
773
|
+
state[j] = (t >>> 24) & 0xff;
|
|
774
|
+
state[j + 1] = (t >> 16) & 0xff;
|
|
775
|
+
state[j + 2] = (t >> 8) & 0xff;
|
|
776
|
+
state[j + 3] = t & 0xff;
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
// InvShiftRows
|
|
780
|
+
t = state[13];
|
|
781
|
+
state[13] = state[9];
|
|
782
|
+
state[9] = state[5];
|
|
783
|
+
state[5] = state[1];
|
|
784
|
+
state[1] = t;
|
|
785
|
+
t = state[14];
|
|
786
|
+
u = state[10];
|
|
787
|
+
state[14] = state[6];
|
|
788
|
+
state[10] = state[2];
|
|
789
|
+
state[6] = t;
|
|
790
|
+
state[2] = u;
|
|
791
|
+
t = state[15];
|
|
792
|
+
u = state[11];
|
|
793
|
+
v = state[7];
|
|
794
|
+
state[15] = state[3];
|
|
795
|
+
state[11] = t;
|
|
796
|
+
state[7] = u;
|
|
797
|
+
state[3] = v;
|
|
798
|
+
for (let j = 0; j < 16; ++j) {
|
|
799
|
+
// InvSubBytes
|
|
800
|
+
state[j] = this._inv_s[state[j]];
|
|
801
|
+
// AddRoundKey
|
|
802
|
+
state[j] ^= key[j];
|
|
803
|
+
}
|
|
804
|
+
return state;
|
|
805
|
+
}
|
|
806
|
+
_encrypt(input, key) {
|
|
807
|
+
const s = this._s;
|
|
808
|
+
let t, u, v;
|
|
809
|
+
const state = new Uint8Array(16);
|
|
810
|
+
state.set(input);
|
|
811
|
+
for (let j = 0; j < 16; ++j) {
|
|
812
|
+
// AddRoundKey
|
|
813
|
+
state[j] ^= key[j];
|
|
814
|
+
}
|
|
815
|
+
for (let i = 1; i < this._cyclesOfRepetition; i++) {
|
|
816
|
+
// SubBytes
|
|
817
|
+
for (let j = 0; j < 16; ++j) {
|
|
818
|
+
state[j] = s[state[j]];
|
|
819
|
+
}
|
|
820
|
+
// ShiftRows
|
|
821
|
+
v = state[1];
|
|
822
|
+
state[1] = state[5];
|
|
823
|
+
state[5] = state[9];
|
|
824
|
+
state[9] = state[13];
|
|
825
|
+
state[13] = v;
|
|
826
|
+
v = state[2];
|
|
827
|
+
u = state[6];
|
|
828
|
+
state[2] = state[10];
|
|
829
|
+
state[6] = state[14];
|
|
830
|
+
state[10] = v;
|
|
831
|
+
state[14] = u;
|
|
832
|
+
v = state[3];
|
|
833
|
+
u = state[7];
|
|
834
|
+
t = state[11];
|
|
835
|
+
state[3] = state[15];
|
|
836
|
+
state[7] = v;
|
|
837
|
+
state[11] = u;
|
|
838
|
+
state[15] = t;
|
|
839
|
+
// MixColumns
|
|
840
|
+
for (let j = 0; j < 16; j += 4) {
|
|
841
|
+
const s0 = state[j + 0];
|
|
842
|
+
const s1 = state[j + 1];
|
|
843
|
+
const s2 = state[j + 2];
|
|
844
|
+
const s3 = state[j + 3];
|
|
845
|
+
t = s0 ^ s1 ^ s2 ^ s3;
|
|
846
|
+
state[j + 0] ^= t ^ this._mixCol[s0 ^ s1];
|
|
847
|
+
state[j + 1] ^= t ^ this._mixCol[s1 ^ s2];
|
|
848
|
+
state[j + 2] ^= t ^ this._mixCol[s2 ^ s3];
|
|
849
|
+
state[j + 3] ^= t ^ this._mixCol[s3 ^ s0];
|
|
850
|
+
}
|
|
851
|
+
// AddRoundKey
|
|
852
|
+
for (let j = 0, k = i * 16; j < 16; ++j, ++k) {
|
|
853
|
+
state[j] ^= key[k];
|
|
854
|
+
}
|
|
855
|
+
}
|
|
856
|
+
// SubBytes
|
|
857
|
+
for (let j = 0; j < 16; ++j) {
|
|
858
|
+
state[j] = s[state[j]];
|
|
859
|
+
}
|
|
860
|
+
// ShiftRows
|
|
861
|
+
v = state[1];
|
|
862
|
+
state[1] = state[5];
|
|
863
|
+
state[5] = state[9];
|
|
864
|
+
state[9] = state[13];
|
|
865
|
+
state[13] = v;
|
|
866
|
+
v = state[2];
|
|
867
|
+
u = state[6];
|
|
868
|
+
state[2] = state[10];
|
|
869
|
+
state[6] = state[14];
|
|
870
|
+
state[10] = v;
|
|
871
|
+
state[14] = u;
|
|
872
|
+
v = state[3];
|
|
873
|
+
u = state[7];
|
|
874
|
+
t = state[11];
|
|
875
|
+
state[3] = state[15];
|
|
876
|
+
state[7] = v;
|
|
877
|
+
state[11] = u;
|
|
878
|
+
state[15] = t;
|
|
879
|
+
// AddRoundKey
|
|
880
|
+
for (let j = 0, k = this._keySize; j < 16; ++j, ++k) {
|
|
881
|
+
state[j] ^= key[k];
|
|
882
|
+
}
|
|
883
|
+
return state;
|
|
884
|
+
}
|
|
885
|
+
_decryptBlock2(data, finalize) {
|
|
886
|
+
const sourceLength = data.length;
|
|
887
|
+
let buffer = this.buffer, bufferLength = this.bufferPosition;
|
|
888
|
+
const result = [];
|
|
889
|
+
let iv = this.iv;
|
|
890
|
+
for (let i = 0; i < sourceLength; ++i) {
|
|
891
|
+
buffer[bufferLength] = data[i];
|
|
892
|
+
++bufferLength;
|
|
893
|
+
if (bufferLength < 16) {
|
|
894
|
+
continue;
|
|
895
|
+
}
|
|
896
|
+
// buffer is full, decrypting
|
|
897
|
+
const plain = this._decrypt(buffer, this._key);
|
|
898
|
+
// xor-ing the IV vector to get plain text
|
|
899
|
+
for (let j = 0; j < 16; ++j) {
|
|
900
|
+
plain[j] ^= iv[j];
|
|
901
|
+
}
|
|
902
|
+
iv = buffer;
|
|
903
|
+
result.push(plain);
|
|
904
|
+
buffer = new Uint8Array(16);
|
|
905
|
+
bufferLength = 0;
|
|
906
|
+
}
|
|
907
|
+
// saving incomplete buffer
|
|
908
|
+
this.buffer = buffer;
|
|
909
|
+
this.bufferLength = bufferLength;
|
|
910
|
+
this.iv = iv;
|
|
911
|
+
if (result.length === 0) {
|
|
912
|
+
return new Uint8Array(0);
|
|
913
|
+
}
|
|
914
|
+
// combining plain text blocks into one
|
|
915
|
+
let outputLength = 16 * result.length;
|
|
916
|
+
if (finalize) {
|
|
917
|
+
// undo a padding that is described in RFC 2898
|
|
918
|
+
const lastBlock = result[result.length - 1];
|
|
919
|
+
let psLen = lastBlock[15];
|
|
920
|
+
if (psLen <= 16) {
|
|
921
|
+
for (let i = 15, ii = 16 - psLen; i >= ii; --i) {
|
|
922
|
+
if (lastBlock[i] !== psLen) {
|
|
923
|
+
// Invalid padding, assume that the block has no padding.
|
|
924
|
+
psLen = 0;
|
|
925
|
+
break;
|
|
926
|
+
}
|
|
927
|
+
}
|
|
928
|
+
outputLength -= psLen;
|
|
929
|
+
result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
|
|
930
|
+
}
|
|
931
|
+
}
|
|
932
|
+
const output = new Uint8Array(outputLength);
|
|
933
|
+
for (let i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
|
|
934
|
+
output.set(result[i], j);
|
|
935
|
+
}
|
|
936
|
+
return output;
|
|
937
|
+
}
|
|
938
|
+
decryptBlock(data, finalize, iv) {
|
|
939
|
+
const sourceLength = data.length;
|
|
940
|
+
const buffer = this.buffer;
|
|
941
|
+
let bufferLength = this.bufferPosition;
|
|
942
|
+
// If an IV is not supplied, wait for IV values. They are at the start
|
|
943
|
+
// of the stream.
|
|
944
|
+
if (iv) {
|
|
945
|
+
this.iv = iv;
|
|
946
|
+
}
|
|
947
|
+
else {
|
|
948
|
+
for (let i = 0; bufferLength < 16 && i < sourceLength; ++i, ++bufferLength) {
|
|
949
|
+
buffer[bufferLength] = data[i];
|
|
950
|
+
}
|
|
951
|
+
if (bufferLength < 16) {
|
|
952
|
+
// Need more data.
|
|
953
|
+
this.bufferLength = bufferLength;
|
|
954
|
+
return new Uint8Array(0);
|
|
955
|
+
}
|
|
956
|
+
this.iv = buffer;
|
|
957
|
+
data = data.subarray(16);
|
|
958
|
+
}
|
|
959
|
+
this.buffer = new Uint8Array(16);
|
|
960
|
+
this.bufferLength = 0;
|
|
961
|
+
// starting decryption
|
|
962
|
+
this.decryptBlock = this._decryptBlock2;
|
|
963
|
+
return this.decryptBlock(data, finalize);
|
|
964
|
+
}
|
|
965
|
+
encrypt(data, iv) {
|
|
966
|
+
const sourceLength = data.length;
|
|
967
|
+
let buffer = this.buffer, bufferLength = this.bufferPosition;
|
|
968
|
+
const result = [];
|
|
969
|
+
if (!iv) {
|
|
970
|
+
iv = new Uint8Array(16);
|
|
971
|
+
}
|
|
972
|
+
for (let i = 0; i < sourceLength; ++i) {
|
|
973
|
+
buffer[bufferLength] = data[i];
|
|
974
|
+
++bufferLength;
|
|
975
|
+
if (bufferLength < 16) {
|
|
976
|
+
continue;
|
|
977
|
+
}
|
|
978
|
+
for (let j = 0; j < 16; ++j) {
|
|
979
|
+
buffer[j] ^= iv[j];
|
|
980
|
+
}
|
|
981
|
+
// buffer is full, encrypting
|
|
982
|
+
const cipher = this._encrypt(buffer, this._key);
|
|
983
|
+
iv = cipher;
|
|
984
|
+
result.push(cipher);
|
|
985
|
+
buffer = new Uint8Array(16);
|
|
986
|
+
bufferLength = 0;
|
|
987
|
+
}
|
|
988
|
+
// saving incomplete buffer
|
|
989
|
+
this.buffer = buffer;
|
|
990
|
+
this.bufferLength = bufferLength;
|
|
991
|
+
this.iv = iv;
|
|
992
|
+
if (result.length === 0) {
|
|
993
|
+
return new Uint8Array(0);
|
|
994
|
+
}
|
|
995
|
+
// combining plain text blocks into one
|
|
996
|
+
const outputLength = 16 * result.length;
|
|
997
|
+
const output = new Uint8Array(outputLength);
|
|
998
|
+
for (let i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
|
|
999
|
+
output.set(result[i], j);
|
|
1000
|
+
}
|
|
1001
|
+
return output;
|
|
1002
|
+
}
|
|
1003
|
+
}
|
|
1004
|
+
class AES128Cipher extends AESBaseCipher {
|
|
1005
|
+
constructor(key) {
|
|
1006
|
+
super();
|
|
1007
|
+
this._cyclesOfRepetition = 10;
|
|
1008
|
+
this._keySize = 160; // bits
|
|
1009
|
+
this._rcon = new Uint8Array([
|
|
1010
|
+
0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
|
|
1011
|
+
0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
|
|
1012
|
+
0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
|
|
1013
|
+
0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
|
|
1014
|
+
0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
|
|
1015
|
+
0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
|
|
1016
|
+
0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
|
|
1017
|
+
0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
|
|
1018
|
+
0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
|
|
1019
|
+
0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
|
|
1020
|
+
0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
|
|
1021
|
+
0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
|
|
1022
|
+
0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
|
|
1023
|
+
0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
|
|
1024
|
+
0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
|
|
1025
|
+
0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
|
|
1026
|
+
0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
|
|
1027
|
+
0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
|
|
1028
|
+
0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
|
|
1029
|
+
0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
|
|
1030
|
+
0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
|
|
1031
|
+
0x74, 0xe8, 0xcb, 0x8d,
|
|
1032
|
+
]);
|
|
1033
|
+
this._key = this._expandKey(key);
|
|
1034
|
+
}
|
|
1035
|
+
_expandKey(cipherKey) {
|
|
1036
|
+
const b = 176;
|
|
1037
|
+
const s = this._s;
|
|
1038
|
+
const rcon = this._rcon;
|
|
1039
|
+
const result = new Uint8Array(b);
|
|
1040
|
+
result.set(cipherKey);
|
|
1041
|
+
for (let j = 16, i = 1; j < b; ++i) {
|
|
1042
|
+
// RotWord
|
|
1043
|
+
let t1 = result[j - 3];
|
|
1044
|
+
let t2 = result[j - 2];
|
|
1045
|
+
let t3 = result[j - 1];
|
|
1046
|
+
let t4 = result[j - 4];
|
|
1047
|
+
// SubWord
|
|
1048
|
+
t1 = s[t1];
|
|
1049
|
+
t2 = s[t2];
|
|
1050
|
+
t3 = s[t3];
|
|
1051
|
+
t4 = s[t4];
|
|
1052
|
+
// Rcon
|
|
1053
|
+
t1 ^= rcon[i];
|
|
1054
|
+
for (let n = 0; n < 4; ++n) {
|
|
1055
|
+
result[j] = t1 ^= result[j - 16];
|
|
1056
|
+
j++;
|
|
1057
|
+
result[j] = t2 ^= result[j - 16];
|
|
1058
|
+
j++;
|
|
1059
|
+
result[j] = t3 ^= result[j - 16];
|
|
1060
|
+
j++;
|
|
1061
|
+
result[j] = t4 ^= result[j - 16];
|
|
1062
|
+
j++;
|
|
1063
|
+
}
|
|
1064
|
+
}
|
|
1065
|
+
return result;
|
|
1066
|
+
}
|
|
1067
|
+
}
|
|
1068
|
+
class AES256Cipher extends AESBaseCipher {
|
|
1069
|
+
constructor(key) {
|
|
1070
|
+
super();
|
|
1071
|
+
this._cyclesOfRepetition = 14;
|
|
1072
|
+
this._keySize = 224; // bits
|
|
1073
|
+
this._key = this._expandKey(key);
|
|
1074
|
+
}
|
|
1075
|
+
_expandKey(cipherKey) {
|
|
1076
|
+
const b = 240;
|
|
1077
|
+
const s = this._s;
|
|
1078
|
+
const result = new Uint8Array(b);
|
|
1079
|
+
result.set(cipherKey);
|
|
1080
|
+
let r = 1;
|
|
1081
|
+
let t1 = 0, t2 = 0, t3 = 0, t4 = 0;
|
|
1082
|
+
for (let j = 32, i = 1; j < b; ++i) {
|
|
1083
|
+
if (j % 32 === 16) {
|
|
1084
|
+
t1 = s[t1];
|
|
1085
|
+
t2 = s[t2];
|
|
1086
|
+
t3 = s[t3];
|
|
1087
|
+
t4 = s[t4];
|
|
1088
|
+
}
|
|
1089
|
+
else if (j % 32 === 0) {
|
|
1090
|
+
// RotWord
|
|
1091
|
+
t1 = result[j - 3];
|
|
1092
|
+
t2 = result[j - 2];
|
|
1093
|
+
t3 = result[j - 1];
|
|
1094
|
+
t4 = result[j - 4];
|
|
1095
|
+
// SubWord
|
|
1096
|
+
t1 = s[t1];
|
|
1097
|
+
t2 = s[t2];
|
|
1098
|
+
t3 = s[t3];
|
|
1099
|
+
t4 = s[t4];
|
|
1100
|
+
// Rcon
|
|
1101
|
+
t1 ^= r;
|
|
1102
|
+
if ((r <<= 1) >= 256) {
|
|
1103
|
+
r = (r ^ 0x1b) & 0xff;
|
|
1104
|
+
}
|
|
1105
|
+
}
|
|
1106
|
+
for (let n = 0; n < 4; ++n) {
|
|
1107
|
+
result[j] = t1 ^= result[j - 32];
|
|
1108
|
+
j++;
|
|
1109
|
+
result[j] = t2 ^= result[j - 32];
|
|
1110
|
+
j++;
|
|
1111
|
+
result[j] = t3 ^= result[j - 32];
|
|
1112
|
+
j++;
|
|
1113
|
+
result[j] = t4 ^= result[j - 32];
|
|
1114
|
+
j++;
|
|
1115
|
+
}
|
|
1116
|
+
}
|
|
1117
|
+
return result;
|
|
1118
|
+
}
|
|
1119
|
+
}
|
|
1120
|
+
class PDF17 {
|
|
1121
|
+
checkOwnerPassword(password, ownerValidationSalt, userBytes, ownerPassword) {
|
|
1122
|
+
const hashData = new Uint8Array(password.length + 56);
|
|
1123
|
+
hashData.set(password, 0);
|
|
1124
|
+
hashData.set(ownerValidationSalt, password.length);
|
|
1125
|
+
hashData.set(userBytes, password.length + ownerValidationSalt.length);
|
|
1126
|
+
const result = calculateSHA256(hashData, 0, hashData.length);
|
|
1127
|
+
return isArrayEqual(result, ownerPassword);
|
|
1128
|
+
}
|
|
1129
|
+
checkUserPassword(password, userValidationSalt, userPassword) {
|
|
1130
|
+
const hashData = new Uint8Array(password.length + 8);
|
|
1131
|
+
hashData.set(password, 0);
|
|
1132
|
+
hashData.set(userValidationSalt, password.length);
|
|
1133
|
+
const result = calculateSHA256(hashData, 0, hashData.length);
|
|
1134
|
+
return isArrayEqual(result, userPassword);
|
|
1135
|
+
}
|
|
1136
|
+
getOwnerKey(password, ownerKeySalt, userBytes, ownerEncryption) {
|
|
1137
|
+
const hashData = new Uint8Array(password.length + 56);
|
|
1138
|
+
hashData.set(password, 0);
|
|
1139
|
+
hashData.set(ownerKeySalt, password.length);
|
|
1140
|
+
hashData.set(userBytes, password.length + ownerKeySalt.length);
|
|
1141
|
+
const key = calculateSHA256(hashData, 0, hashData.length);
|
|
1142
|
+
const cipher = new AES256Cipher(key);
|
|
1143
|
+
return cipher.decryptBlock(ownerEncryption, false, new Uint8Array(16));
|
|
1144
|
+
}
|
|
1145
|
+
getUserKey(password, userKeySalt, userEncryption) {
|
|
1146
|
+
const hashData = new Uint8Array(password.length + 8);
|
|
1147
|
+
hashData.set(password, 0);
|
|
1148
|
+
hashData.set(userKeySalt, password.length);
|
|
1149
|
+
// `key` is the decryption key for the UE string.
|
|
1150
|
+
const key = calculateSHA256(hashData, 0, hashData.length);
|
|
1151
|
+
const cipher = new AES256Cipher(key);
|
|
1152
|
+
return cipher.decryptBlock(userEncryption, false, new Uint8Array(16));
|
|
1153
|
+
}
|
|
1154
|
+
}
|
|
1155
|
+
class PDF20 {
|
|
1156
|
+
calculatePDF20Hash(password, input, userBytes) {
|
|
1157
|
+
// This refers to Algorithm 2.B as defined in ISO 32000-2.
|
|
1158
|
+
let k = calculateSHA256(input, 0, input.length).subarray(0, 32);
|
|
1159
|
+
let e = new Uint8Array([0]);
|
|
1160
|
+
let i = 0;
|
|
1161
|
+
while (i < 64 || e[e.length - 1] > i - 32) {
|
|
1162
|
+
const combinedLength = password.length + k.length + userBytes.length, combinedArray = new Uint8Array(combinedLength);
|
|
1163
|
+
let writeOffset = 0;
|
|
1164
|
+
combinedArray.set(password, writeOffset);
|
|
1165
|
+
writeOffset += password.length;
|
|
1166
|
+
combinedArray.set(k, writeOffset);
|
|
1167
|
+
writeOffset += k.length;
|
|
1168
|
+
combinedArray.set(userBytes, writeOffset);
|
|
1169
|
+
const k1 = new Uint8Array(combinedLength * 64);
|
|
1170
|
+
for (let j = 0, pos = 0; j < 64; j++, pos += combinedLength) {
|
|
1171
|
+
k1.set(combinedArray, pos);
|
|
1172
|
+
}
|
|
1173
|
+
// AES128 CBC NO PADDING with first 16 bytes of k as the key
|
|
1174
|
+
// and the second 16 as the iv.
|
|
1175
|
+
const cipher = new AES128Cipher(k.subarray(0, 16));
|
|
1176
|
+
e = cipher.encrypt(k1, k.subarray(16, 32));
|
|
1177
|
+
// Now we have to take the first 16 bytes of an unsigned big endian
|
|
1178
|
+
// integer and compute the remainder modulo 3. That is a fairly large
|
|
1179
|
+
// number and JavaScript isn't going to handle that well.
|
|
1180
|
+
// The number is e0 + 256 * e1 + 256^2 * e2... and 256 % 3 === 1, hence
|
|
1181
|
+
// the powers of 256 are === 1 modulo 3 and finally the number modulo 3
|
|
1182
|
+
// is equal to the remainder modulo 3 of the sum of the e_n.
|
|
1183
|
+
const remainder = e.slice(0, 16).reduce((a, b) => a + b, 0) % 3;
|
|
1184
|
+
if (remainder === 0) {
|
|
1185
|
+
k = calculateSHA256(e, 0, e.length);
|
|
1186
|
+
}
|
|
1187
|
+
else if (remainder === 1) {
|
|
1188
|
+
k = calculateSHA384(e, 0, e.length);
|
|
1189
|
+
}
|
|
1190
|
+
else if (remainder === 2) {
|
|
1191
|
+
k = calculateSHA512(e, 0, e.length);
|
|
1192
|
+
}
|
|
1193
|
+
i++;
|
|
1194
|
+
}
|
|
1195
|
+
return k.subarray(0, 32);
|
|
1196
|
+
}
|
|
1197
|
+
hash(password, concatBytes, userBytes) {
|
|
1198
|
+
return this.calculatePDF20Hash(password, concatBytes, userBytes);
|
|
1199
|
+
}
|
|
1200
|
+
checkOwnerPassword(password, ownerValidationSalt, userBytes, ownerPassword) {
|
|
1201
|
+
const hashData = new Uint8Array(password.length + 56);
|
|
1202
|
+
hashData.set(password, 0);
|
|
1203
|
+
hashData.set(ownerValidationSalt, password.length);
|
|
1204
|
+
hashData.set(userBytes, password.length + ownerValidationSalt.length);
|
|
1205
|
+
const result = this.calculatePDF20Hash(password, hashData, userBytes);
|
|
1206
|
+
return isArrayEqual(result, ownerPassword);
|
|
1207
|
+
}
|
|
1208
|
+
checkUserPassword(password, userValidationSalt, userPassword) {
|
|
1209
|
+
const hashData = new Uint8Array(password.length + 8);
|
|
1210
|
+
hashData.set(password, 0);
|
|
1211
|
+
hashData.set(userValidationSalt, password.length);
|
|
1212
|
+
const result = this.calculatePDF20Hash(password, hashData, new Uint8Array());
|
|
1213
|
+
return isArrayEqual(result, userPassword);
|
|
1214
|
+
}
|
|
1215
|
+
getOwnerKey(password, ownerKeySalt, userBytes, ownerEncryption) {
|
|
1216
|
+
const hashData = new Uint8Array(password.length + 56);
|
|
1217
|
+
hashData.set(password, 0);
|
|
1218
|
+
hashData.set(ownerKeySalt, password.length);
|
|
1219
|
+
hashData.set(userBytes, password.length + ownerKeySalt.length);
|
|
1220
|
+
const key = this.calculatePDF20Hash(password, hashData, userBytes);
|
|
1221
|
+
const cipher = new AES256Cipher(key);
|
|
1222
|
+
return cipher.decryptBlock(ownerEncryption, false, new Uint8Array(16));
|
|
1223
|
+
}
|
|
1224
|
+
getUserKey(password, userKeySalt, userEncryption) {
|
|
1225
|
+
const hashData = new Uint8Array(password.length + 8);
|
|
1226
|
+
hashData.set(password, 0);
|
|
1227
|
+
hashData.set(userKeySalt, password.length);
|
|
1228
|
+
// `key` is the decryption key for the UE string.
|
|
1229
|
+
const key = this.calculatePDF20Hash(password, hashData, new Uint8Array());
|
|
1230
|
+
const cipher = new AES256Cipher(key);
|
|
1231
|
+
return cipher.decryptBlock(userEncryption, false, new Uint8Array(16));
|
|
1232
|
+
}
|
|
1233
|
+
}
|
|
1234
|
+
class CipherTransform {
|
|
1235
|
+
constructor(stringCipherConstructor, streamCipherConstructor) {
|
|
1236
|
+
this.StringCipherConstructor = stringCipherConstructor;
|
|
1237
|
+
this.StreamCipherConstructor = streamCipherConstructor;
|
|
1238
|
+
}
|
|
1239
|
+
createStream(stream, length) {
|
|
1240
|
+
const cipher = this.StreamCipherConstructor();
|
|
1241
|
+
return new DecryptStream(stream, function cipherTransformDecryptStream(data, finalize) {
|
|
1242
|
+
return cipher.decryptBlock(data, finalize);
|
|
1243
|
+
}, length);
|
|
1244
|
+
}
|
|
1245
|
+
decryptString(s) {
|
|
1246
|
+
const cipher = this.StringCipherConstructor();
|
|
1247
|
+
let data = stringAsByteArray(s);
|
|
1248
|
+
data = cipher.decryptBlock(data, true);
|
|
1249
|
+
return arrayAsString(data);
|
|
1250
|
+
}
|
|
1251
|
+
decryptBytes(d) {
|
|
1252
|
+
const cipher = this.StringCipherConstructor();
|
|
1253
|
+
return cipher.decryptBlock(d, true);
|
|
1254
|
+
}
|
|
1255
|
+
encryptString(s) {
|
|
1256
|
+
const cipher = this.StringCipherConstructor();
|
|
1257
|
+
if (cipher instanceof AESBaseCipher) {
|
|
1258
|
+
// Append some chars equal to "16 - (M mod 16)"
|
|
1259
|
+
// where M is the string length (see section 7.6.2 in PDF specification)
|
|
1260
|
+
// to have a final string where the length is a multiple of 16.
|
|
1261
|
+
// Special note:
|
|
1262
|
+
// "Note that the pad is present when M is evenly divisible by 16;
|
|
1263
|
+
// it contains 16 bytes of 0x10."
|
|
1264
|
+
const strLen = s.length;
|
|
1265
|
+
const pad = 16 - (strLen % 16);
|
|
1266
|
+
s += String.fromCharCode(pad).repeat(pad);
|
|
1267
|
+
// Generate an initialization vector
|
|
1268
|
+
const iv = new Uint8Array(16);
|
|
1269
|
+
if (typeof crypto !== 'undefined') {
|
|
1270
|
+
crypto.getRandomValues(iv);
|
|
1271
|
+
}
|
|
1272
|
+
else {
|
|
1273
|
+
for (let i = 0; i < 16; i++) {
|
|
1274
|
+
iv[i] = Math.floor(256 * Math.random());
|
|
1275
|
+
}
|
|
1276
|
+
}
|
|
1277
|
+
let data = stringAsByteArray(s);
|
|
1278
|
+
data = cipher.encrypt(data, iv);
|
|
1279
|
+
const buf = new Uint8Array(16 + data.length);
|
|
1280
|
+
buf.set(iv);
|
|
1281
|
+
buf.set(data, 16);
|
|
1282
|
+
return arrayAsString(buf);
|
|
1283
|
+
}
|
|
1284
|
+
let data = stringAsByteArray(s);
|
|
1285
|
+
data = cipher.encrypt(data);
|
|
1286
|
+
return arrayAsString(data);
|
|
1287
|
+
}
|
|
1288
|
+
}
|
|
1289
|
+
// eslint-disable-next-line no-shadow
|
|
1290
|
+
class CipherTransformFactory {
|
|
1291
|
+
constructor(dict, fileIdBytes, password) {
|
|
1292
|
+
var _a, _b;
|
|
1293
|
+
this.defaultPasswordBytes = new Uint8Array([
|
|
1294
|
+
0x28, 0xbf, 0x4e, 0x5e, 0x4e, 0x75, 0x8a, 0x41, 0x64, 0x00, 0x4e, 0x56,
|
|
1295
|
+
0xff, 0xfa, 0x01, 0x08, 0x2e, 0x2e, 0x00, 0xb6, 0xd0, 0x68, 0x3e, 0x80,
|
|
1296
|
+
0x2f, 0x0c, 0xa9, 0xfe, 0x64, 0x53, 0x69, 0x7a,
|
|
1297
|
+
]);
|
|
1298
|
+
this.identityName = PDFName.of('Identity');
|
|
1299
|
+
const filter = dict.get(PDFName.of('Filter'));
|
|
1300
|
+
if (filter.asString() !== '/Standard') {
|
|
1301
|
+
throw new Error('unknown encryption method');
|
|
1302
|
+
}
|
|
1303
|
+
this.filterName = filter.asString();
|
|
1304
|
+
this.dict = dict;
|
|
1305
|
+
const algorithm = dict.get(PDFName.of('V')).asNumber();
|
|
1306
|
+
if (!Number.isInteger(algorithm) ||
|
|
1307
|
+
(algorithm !== 1 && algorithm !== 2 && algorithm !== 4 && algorithm !== 5)) {
|
|
1308
|
+
throw new Error('unsupported encryption algorithm');
|
|
1309
|
+
}
|
|
1310
|
+
this.algorithm = algorithm;
|
|
1311
|
+
let keyLength = (_a = dict.get(PDFName.of('Length'))) === null || _a === void 0 ? void 0 : _a.asNumber();
|
|
1312
|
+
if (!keyLength) {
|
|
1313
|
+
// Spec asks to rely on encryption dictionary's Length entry, however
|
|
1314
|
+
// some PDFs don't have it. Trying to recover.
|
|
1315
|
+
if (algorithm <= 3) {
|
|
1316
|
+
// For 1 and 2 it's fixed to 40-bit, for 3 40-bit is a minimal value.
|
|
1317
|
+
keyLength = 40;
|
|
1318
|
+
}
|
|
1319
|
+
else {
|
|
1320
|
+
// Trying to find default handler -- it usually has Length.
|
|
1321
|
+
const cfDict = dict.get(PDFName.of('CF'));
|
|
1322
|
+
const streamCryptoName = dict.get(PDFName.of('StmF'));
|
|
1323
|
+
if (cfDict instanceof PDFDict && streamCryptoName instanceof PDFName) {
|
|
1324
|
+
cfDict.suppressEncryption = true;
|
|
1325
|
+
const handlerDict = cfDict.get(PDFName.of(streamCryptoName.asString()));
|
|
1326
|
+
let keyLen = null;
|
|
1327
|
+
if (handlerDict) {
|
|
1328
|
+
keyLen = handlerDict.get(PDFName.of('Length'));
|
|
1329
|
+
}
|
|
1330
|
+
keyLength = (keyLen && keyLen.asNumber()) || 128;
|
|
1331
|
+
if (keyLength < 40) {
|
|
1332
|
+
// Sometimes it's incorrect value of bits, generators specify
|
|
1333
|
+
// bytes.
|
|
1334
|
+
keyLength <<= 3;
|
|
1335
|
+
}
|
|
1336
|
+
}
|
|
1337
|
+
}
|
|
1338
|
+
}
|
|
1339
|
+
if (keyLength === undefined ||
|
|
1340
|
+
!Number.isInteger(keyLength) ||
|
|
1341
|
+
keyLength < 40 ||
|
|
1342
|
+
keyLength % 8 !== 0) {
|
|
1343
|
+
throw new Error(`invalid key length: ${keyLength}`);
|
|
1344
|
+
}
|
|
1345
|
+
const oPdfStr = dict.get(PDFName.of('O')).asBytes();
|
|
1346
|
+
const uPdfStr = dict.get(PDFName.of('U')).asBytes();
|
|
1347
|
+
// prepare keys
|
|
1348
|
+
const ownerPassword = oPdfStr.subarray(0, 32);
|
|
1349
|
+
const userPassword = uPdfStr.subarray(0, 32);
|
|
1350
|
+
const flags = dict.get(PDFName.of('P')).asNumber();
|
|
1351
|
+
const revision = dict.get(PDFName.of('R')).asNumber();
|
|
1352
|
+
// meaningful when V is 4 or 5
|
|
1353
|
+
const encryptMetadata = (algorithm === 4 || algorithm === 5) &&
|
|
1354
|
+
((_b = dict.get(PDFName.of('EncryptMetadata'))) === null || _b === void 0 ? void 0 : _b.asBoolean()) !==
|
|
1355
|
+
false;
|
|
1356
|
+
this.encryptMetadata = encryptMetadata;
|
|
1357
|
+
let passwordBytes;
|
|
1358
|
+
if (password) {
|
|
1359
|
+
if (revision === 6) {
|
|
1360
|
+
try {
|
|
1361
|
+
password = unescape(encodeURIComponent(password));
|
|
1362
|
+
}
|
|
1363
|
+
catch (ex) {
|
|
1364
|
+
console.warn('CipherTransformFactory: ' +
|
|
1365
|
+
'Unable to convert UTF8 encoded password.');
|
|
1366
|
+
}
|
|
1367
|
+
}
|
|
1368
|
+
passwordBytes = stringAsByteArray(password);
|
|
1369
|
+
}
|
|
1370
|
+
let encryptionKey;
|
|
1371
|
+
if (algorithm !== 5) {
|
|
1372
|
+
encryptionKey = this.prepareKeyData(fileIdBytes, passwordBytes, ownerPassword, userPassword, flags, revision, keyLength, encryptMetadata);
|
|
1373
|
+
}
|
|
1374
|
+
else {
|
|
1375
|
+
const ownerValidationSalt = oPdfStr.subarray(32, 40);
|
|
1376
|
+
const ownerKeySalt = oPdfStr.subarray(40, 48);
|
|
1377
|
+
const uBytes = uPdfStr.subarray(0, 48);
|
|
1378
|
+
const userValidationSalt = uPdfStr.subarray(32, 40);
|
|
1379
|
+
const userKeySalt = uPdfStr.subarray(40, 48);
|
|
1380
|
+
const ownerEncryption = dict.get(PDFName.of('OE')).asBytes();
|
|
1381
|
+
const userEncryption = dict.get(PDFName.of('UE')).asBytes();
|
|
1382
|
+
const perms = dict.get(PDFName.of('Perms')).asBytes();
|
|
1383
|
+
encryptionKey = this.createEncryptionKey20(revision, passwordBytes, ownerPassword, ownerValidationSalt, ownerKeySalt, uBytes, userPassword, userValidationSalt, userKeySalt, ownerEncryption, userEncryption, perms);
|
|
1384
|
+
}
|
|
1385
|
+
if (!encryptionKey && !password) {
|
|
1386
|
+
throw new Error('NEEDS PASSWORD');
|
|
1387
|
+
}
|
|
1388
|
+
else if (!encryptionKey && password) {
|
|
1389
|
+
// Attempting use the password as an owner password
|
|
1390
|
+
const decodedPassword = this.decodeUserPassword(passwordBytes, ownerPassword, revision, keyLength);
|
|
1391
|
+
encryptionKey = this.prepareKeyData(fileIdBytes, decodedPassword, ownerPassword, userPassword, flags, revision, keyLength, encryptMetadata);
|
|
1392
|
+
}
|
|
1393
|
+
if (!encryptionKey) {
|
|
1394
|
+
throw new Error('Password incorrect');
|
|
1395
|
+
}
|
|
1396
|
+
this.encryptionKey = encryptionKey;
|
|
1397
|
+
if (algorithm >= 4) {
|
|
1398
|
+
const cf = dict.get(PDFName.of('CF'));
|
|
1399
|
+
if (cf instanceof PDFDict) {
|
|
1400
|
+
// The 'CF' dictionary itself should not be encrypted, and by setting
|
|
1401
|
+
// `suppressEncryption` we can prevent an infinite loop inside of
|
|
1402
|
+
// `XRef_fetchUncompressed` if the dictionary contains indirect
|
|
1403
|
+
// objects (fixes issue7665.pdf).
|
|
1404
|
+
cf.suppressEncryption = true;
|
|
1405
|
+
}
|
|
1406
|
+
this.cf = cf;
|
|
1407
|
+
this.stmf =
|
|
1408
|
+
dict.get(PDFName.of('StmF')) || this.identityName;
|
|
1409
|
+
this.strf =
|
|
1410
|
+
dict.get(PDFName.of('StrF')) || this.identityName;
|
|
1411
|
+
this.eff = dict.get(PDFName.of('EFF')) || this.stmf;
|
|
1412
|
+
}
|
|
1413
|
+
}
|
|
1414
|
+
createCipherTransform(num, gen) {
|
|
1415
|
+
if (this.algorithm === 4 || this.algorithm === 5) {
|
|
1416
|
+
return new CipherTransform(this.buildCipherConstructor(this.cf, this.strf, num, gen, this.encryptionKey), this.buildCipherConstructor(this.cf, this.stmf, num, gen, this.encryptionKey));
|
|
1417
|
+
}
|
|
1418
|
+
// algorithms 1 and 2
|
|
1419
|
+
const key = this.buildObjectKey(num, gen, this.encryptionKey,
|
|
1420
|
+
/* isAes = */ false);
|
|
1421
|
+
const cipherConstructor = function buildCipherCipherConstructor() {
|
|
1422
|
+
return new ARCFourCipher(key);
|
|
1423
|
+
};
|
|
1424
|
+
return new CipherTransform(cipherConstructor, cipherConstructor);
|
|
1425
|
+
}
|
|
1426
|
+
createEncryptionKey20(revision, password, ownerPassword, ownerValidationSalt, ownerKeySalt, uBytes, userPassword, userValidationSalt, userKeySalt, ownerEncryption, userEncryption, _perms) {
|
|
1427
|
+
if (password) {
|
|
1428
|
+
const passwordLength = Math.min(127, password.length);
|
|
1429
|
+
password = password.subarray(0, passwordLength);
|
|
1430
|
+
}
|
|
1431
|
+
else {
|
|
1432
|
+
password = new Uint8Array();
|
|
1433
|
+
}
|
|
1434
|
+
let pdfAlgorithm;
|
|
1435
|
+
if (revision === 6) {
|
|
1436
|
+
pdfAlgorithm = new PDF20();
|
|
1437
|
+
}
|
|
1438
|
+
else {
|
|
1439
|
+
pdfAlgorithm = new PDF17();
|
|
1440
|
+
}
|
|
1441
|
+
if (pdfAlgorithm.checkUserPassword(password, userValidationSalt, userPassword)) {
|
|
1442
|
+
return pdfAlgorithm.getUserKey(password, userKeySalt, userEncryption);
|
|
1443
|
+
}
|
|
1444
|
+
else if (password.length &&
|
|
1445
|
+
pdfAlgorithm.checkOwnerPassword(password, ownerValidationSalt, uBytes, ownerPassword)) {
|
|
1446
|
+
return pdfAlgorithm.getOwnerKey(password, ownerKeySalt, uBytes, ownerEncryption);
|
|
1447
|
+
}
|
|
1448
|
+
return null;
|
|
1449
|
+
}
|
|
1450
|
+
prepareKeyData(fileId, password, ownerPassword, userPassword, flags, revision, keyLength, encryptMetadata) {
|
|
1451
|
+
const hashDataSize = 40 + ownerPassword.length + fileId.length;
|
|
1452
|
+
const hashData = new Uint8Array(hashDataSize);
|
|
1453
|
+
let i = 0, j, n;
|
|
1454
|
+
if (password) {
|
|
1455
|
+
n = Math.min(32, password.length);
|
|
1456
|
+
for (; i < n; ++i) {
|
|
1457
|
+
hashData[i] = password[i];
|
|
1458
|
+
}
|
|
1459
|
+
}
|
|
1460
|
+
j = 0;
|
|
1461
|
+
while (i < 32) {
|
|
1462
|
+
hashData[i++] = this.defaultPasswordBytes[j++];
|
|
1463
|
+
}
|
|
1464
|
+
// as now the padded password in the hashData[0..i]
|
|
1465
|
+
for (j = 0, n = ownerPassword.length; j < n; ++j) {
|
|
1466
|
+
hashData[i++] = ownerPassword[j];
|
|
1467
|
+
}
|
|
1468
|
+
hashData[i++] = flags & 0xff;
|
|
1469
|
+
hashData[i++] = (flags >> 8) & 0xff;
|
|
1470
|
+
hashData[i++] = (flags >> 16) & 0xff;
|
|
1471
|
+
hashData[i++] = (flags >>> 24) & 0xff;
|
|
1472
|
+
for (j = 0, n = fileId.length; j < n; ++j) {
|
|
1473
|
+
hashData[i++] = fileId[j];
|
|
1474
|
+
}
|
|
1475
|
+
if (revision >= 4 && !encryptMetadata) {
|
|
1476
|
+
hashData[i++] = 0xff;
|
|
1477
|
+
hashData[i++] = 0xff;
|
|
1478
|
+
hashData[i++] = 0xff;
|
|
1479
|
+
hashData[i++] = 0xff;
|
|
1480
|
+
}
|
|
1481
|
+
let hash = calculateMD5(hashData, 0, i);
|
|
1482
|
+
const keyLengthInBytes = keyLength >> 3;
|
|
1483
|
+
if (revision >= 3) {
|
|
1484
|
+
for (j = 0; j < 50; ++j) {
|
|
1485
|
+
hash = calculateMD5(hash, 0, keyLengthInBytes);
|
|
1486
|
+
}
|
|
1487
|
+
}
|
|
1488
|
+
const encryptionKey = hash.subarray(0, keyLengthInBytes);
|
|
1489
|
+
let cipher, checkData;
|
|
1490
|
+
if (revision >= 3) {
|
|
1491
|
+
for (i = 0; i < 32; ++i) {
|
|
1492
|
+
hashData[i] = this.defaultPasswordBytes[i];
|
|
1493
|
+
}
|
|
1494
|
+
for (j = 0, n = fileId.length; j < n; ++j) {
|
|
1495
|
+
hashData[i++] = fileId[j];
|
|
1496
|
+
}
|
|
1497
|
+
cipher = new ARCFourCipher(encryptionKey);
|
|
1498
|
+
checkData = cipher.encryptBlock(calculateMD5(hashData, 0, i));
|
|
1499
|
+
n = encryptionKey.length;
|
|
1500
|
+
const derivedKey = new Uint8Array(n);
|
|
1501
|
+
for (j = 1; j <= 19; ++j) {
|
|
1502
|
+
for (let k = 0; k < n; ++k) {
|
|
1503
|
+
derivedKey[k] = encryptionKey[k] ^ j;
|
|
1504
|
+
}
|
|
1505
|
+
cipher = new ARCFourCipher(derivedKey);
|
|
1506
|
+
checkData = cipher.encryptBlock(checkData);
|
|
1507
|
+
}
|
|
1508
|
+
for (j = 0, n = checkData.length; j < n; ++j) {
|
|
1509
|
+
if (userPassword[j] !== checkData[j]) {
|
|
1510
|
+
return null;
|
|
1511
|
+
}
|
|
1512
|
+
}
|
|
1513
|
+
}
|
|
1514
|
+
else {
|
|
1515
|
+
cipher = new ARCFourCipher(encryptionKey);
|
|
1516
|
+
checkData = cipher.encryptBlock(this.defaultPasswordBytes);
|
|
1517
|
+
for (j = 0, n = checkData.length; j < n; ++j) {
|
|
1518
|
+
if (userPassword[j] !== checkData[j]) {
|
|
1519
|
+
return null;
|
|
1520
|
+
}
|
|
1521
|
+
}
|
|
1522
|
+
}
|
|
1523
|
+
return encryptionKey;
|
|
1524
|
+
}
|
|
1525
|
+
decodeUserPassword(password, ownerPassword, revision, keyLength) {
|
|
1526
|
+
const hashData = new Uint8Array(32);
|
|
1527
|
+
let i = 0;
|
|
1528
|
+
const n = Math.min(32, password.length);
|
|
1529
|
+
for (; i < n; ++i) {
|
|
1530
|
+
hashData[i] = password[i];
|
|
1531
|
+
}
|
|
1532
|
+
let j = 0;
|
|
1533
|
+
while (i < 32) {
|
|
1534
|
+
hashData[i++] = this.defaultPasswordBytes[j++];
|
|
1535
|
+
}
|
|
1536
|
+
let hash = calculateMD5(hashData, 0, i);
|
|
1537
|
+
const keyLengthInBytes = keyLength >> 3;
|
|
1538
|
+
if (revision >= 3) {
|
|
1539
|
+
for (j = 0; j < 50; ++j) {
|
|
1540
|
+
hash = calculateMD5(hash, 0, hash.length);
|
|
1541
|
+
}
|
|
1542
|
+
}
|
|
1543
|
+
let cipher, userPassword;
|
|
1544
|
+
if (revision >= 3) {
|
|
1545
|
+
userPassword = ownerPassword;
|
|
1546
|
+
const derivedKey = new Uint8Array(keyLengthInBytes);
|
|
1547
|
+
for (j = 19; j >= 0; j--) {
|
|
1548
|
+
for (let k = 0; k < keyLengthInBytes; ++k) {
|
|
1549
|
+
derivedKey[k] = hash[k] ^ j;
|
|
1550
|
+
}
|
|
1551
|
+
cipher = new ARCFourCipher(derivedKey);
|
|
1552
|
+
userPassword = cipher.encryptBlock(userPassword);
|
|
1553
|
+
}
|
|
1554
|
+
}
|
|
1555
|
+
else {
|
|
1556
|
+
cipher = new ARCFourCipher(hash.subarray(0, keyLengthInBytes));
|
|
1557
|
+
userPassword = cipher.encryptBlock(ownerPassword);
|
|
1558
|
+
}
|
|
1559
|
+
return userPassword;
|
|
1560
|
+
}
|
|
1561
|
+
buildObjectKey(num, gen, encryptionKey, isAes = false) {
|
|
1562
|
+
const key = new Uint8Array(encryptionKey.length + 9);
|
|
1563
|
+
const n = encryptionKey.length;
|
|
1564
|
+
let i;
|
|
1565
|
+
for (i = 0; i < n; ++i) {
|
|
1566
|
+
key[i] = encryptionKey[i];
|
|
1567
|
+
}
|
|
1568
|
+
key[i++] = num & 0xff;
|
|
1569
|
+
key[i++] = (num >> 8) & 0xff;
|
|
1570
|
+
key[i++] = (num >> 16) & 0xff;
|
|
1571
|
+
key[i++] = gen & 0xff;
|
|
1572
|
+
key[i++] = (gen >> 8) & 0xff;
|
|
1573
|
+
if (isAes) {
|
|
1574
|
+
key[i++] = 0x73;
|
|
1575
|
+
key[i++] = 0x41;
|
|
1576
|
+
key[i++] = 0x6c;
|
|
1577
|
+
key[i++] = 0x54;
|
|
1578
|
+
}
|
|
1579
|
+
const hash = calculateMD5(key, 0, i);
|
|
1580
|
+
return hash.subarray(0, Math.min(encryptionKey.length + 5, 16));
|
|
1581
|
+
}
|
|
1582
|
+
buildCipherConstructor(cf, name, num, gen, key) {
|
|
1583
|
+
if (!(name instanceof PDFName)) {
|
|
1584
|
+
throw new Error('Invalid crypt filter name.');
|
|
1585
|
+
}
|
|
1586
|
+
const cryptFilter = cf.get(PDFName.of(name.asString().replace('/', '')));
|
|
1587
|
+
let cfm;
|
|
1588
|
+
if (cryptFilter !== null && cryptFilter !== undefined) {
|
|
1589
|
+
cfm = cryptFilter.get(PDFName.of('CFM'));
|
|
1590
|
+
}
|
|
1591
|
+
if (!cfm || cfm.asString() === '/None') {
|
|
1592
|
+
return function cipherTransformFactoryBuildCipherConstructorNone() {
|
|
1593
|
+
return new NullCipher();
|
|
1594
|
+
};
|
|
1595
|
+
}
|
|
1596
|
+
if (cfm.asString() === '/V2') {
|
|
1597
|
+
return () => new ARCFourCipher(this.buildObjectKey(num, gen, key, /* isAes = */ false));
|
|
1598
|
+
}
|
|
1599
|
+
if (cfm.asString() === '/AESV2') {
|
|
1600
|
+
return () => new AES128Cipher(this.buildObjectKey(num, gen, key, /* isAes = */ true));
|
|
1601
|
+
}
|
|
1602
|
+
if (cfm.asString() === '/AESV3') {
|
|
1603
|
+
return () => new AES256Cipher(key);
|
|
1604
|
+
}
|
|
1605
|
+
throw new Error('Unknown crypto method');
|
|
1606
|
+
}
|
|
1607
|
+
}
|
|
1608
|
+
export { AES128Cipher, AES256Cipher, ARCFourCipher, calculateMD5, calculateSHA256, calculateSHA384, calculateSHA512, CipherTransformFactory, CipherTransform, PDF17, PDF20, };
|
|
1609
|
+
//# sourceMappingURL=crypto.js.map
|