@libpdf/core 0.0.1-beta.4 → 0.0.1-beta.5

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/dist/index.d.mts CHANGED
@@ -8869,6 +8869,44 @@ declare function layoutText(text: string, font: FontInput, fontSize: number, max
8869
8869
  */
8870
8870
  declare function layoutJustifiedLine(words: string[], font: FontInput, fontSize: number, targetWidth: number): PositionedWord[];
8871
8871
  //#endregion
8872
+ //#region src/helpers/pem.d.ts
8873
+ /**
8874
+ * PEM encoding/decoding utilities.
8875
+ *
8876
+ * PEM (Privacy-Enhanced Mail) is a Base64 encoding format with header/footer
8877
+ * lines used for certificates, keys, and other cryptographic data.
8878
+ */
8879
+ /**
8880
+ * A single PEM block parsed from a PEM file.
8881
+ */
8882
+ interface PemBlock {
8883
+ /** The label from the BEGIN statement (e.g., "CERTIFICATE", "PRIVATE KEY") */
8884
+ label: string;
8885
+ /** The DER-encoded binary data */
8886
+ der: Uint8Array;
8887
+ }
8888
+ /**
8889
+ * Parse a PEM file into a series of DER blocks with their types.
8890
+ *
8891
+ * PEM files can contain multiple blocks (e.g., certificate chains). This function
8892
+ * extracts each block along with its label from the BEGIN statement.
8893
+ *
8894
+ * @param pem - The PEM-encoded string (may contain multiple blocks)
8895
+ * @returns Array of PEM blocks, each containing a label and DER data
8896
+ * @throws {Error} if the PEM format is invalid (mismatched labels or missing markers)
8897
+ *
8898
+ * @example
8899
+ * ```typescript
8900
+ * const blocks = parsePem(pemString);
8901
+ * // [
8902
+ * // { label: "CERTIFICATE", der: Uint8Array(...) },
8903
+ * // { label: "CERTIFICATE", der: Uint8Array(...) },
8904
+ * // { label: "PRIVATE KEY", der: Uint8Array(...) }
8905
+ * // ]
8906
+ * ```
8907
+ */
8908
+ declare function parsePem(pem: string): PemBlock[];
8909
+ //#endregion
8872
8910
  //#region src/annotations/factory.d.ts
8873
8911
  /**
8874
8912
  * Unknown annotation - fallback for unsupported types.
@@ -8892,5 +8930,5 @@ declare function isWidgetAnnotation(dict: PdfDict): boolean;
8892
8930
  */
8893
8931
  declare function isPopupAnnotation(dict: PdfDict): boolean;
8894
8932
  //#endregion
8895
- export { AnnotationFlags, type AnnotationSubtype, type AuthenticationResult, type BorderStyle, type BorderStyleType, type ButtonField, type CMYK, type CaretAnnotationOptions, type CaretSymbol, CertificateChainError, type CheckboxField, type CheckboxOptions, type CheckboxSymbol, type CircleAnnotationOptions, type Color, type CopyPagesOptions, CryptoKeySigner, type Degrees, type DestinationType, type DigestAlgorithm, type DocumentMetadata, type DrawCircleOptions, type DrawEllipseOptions, type DrawFieldOptions, type DrawImageOptions, type DrawLineOptions, type DrawPageOptions, type DrawRectangleOptions, type DrawTextOptions, type DropdownField, type DropdownOptions, type EmbedFontOptions, type EmbeddedFont, type EncryptionAlgorithmOption, type ExtractPagesOptions, type FieldOptions, type FieldType, type FieldValue, type FileAttachmentIcon, type FlattenAnnotationsOptions, type FlattenLayersResult, type FlattenOptions, type FontInput, type FormField, type FormProperties, type FreeTextAnnotationOptions, type FreeTextJustification, GoogleKmsSigner, type Grayscale, type HighlightMode, HttpTimestampAuthority, type HttpTimestampAuthorityOptions, type InkAnnotationOptions, type KeyType, KmsSignerError, type LayerInfo, type LayoutResult, type LineAnnotationOptions, type LineCap, type LineEndingStyle, type LineJoin, type LinkAction, type LinkAnnotationOptions, type LinkDestination, type ListBoxField, type ListboxOptions, type LoadOptions, type MergeOptions, P12Signer, type PAdESLevel, PDF, PDFAnnotation, PDFCaretAnnotation, PDFCircleAnnotation, PDFEmbeddedPage, PDFFileAttachmentAnnotation, PDFForm, PDFFreeTextAnnotation, PDFHighlightAnnotation, PDFImage, PDFInkAnnotation, PDFLineAnnotation, PDFLinkAnnotation, PDFMarkupAnnotation, PDFPage, PDFPolygonAnnotation, PDFPolylineAnnotation, PDFPopupAnnotation, PDFSquareAnnotation, PDFSquigglyAnnotation, PDFStampAnnotation, PDFStrikeOutAnnotation, PDFTextAnnotation, PDFTextMarkupAnnotation, PDFUnderlineAnnotation, PDFUnknownAnnotation, PathBuilder, type PathOptions, PdfArray, PdfBool, PdfDict, PdfName, PdfNull, PdfNumber, type PdfObject, PdfRef, PdfStream, PdfString, PermissionDeniedError, type PermissionOptions, type Permissions, PlaceholderError, type Point, type PolygonAnnotationOptions, type PolylineAnnotationOptions, type PopupOptions, type PositionedWord, type ProtectionOptions, type RGB, type RadioField, type RadioGroupOptions, type RadioSymbol, type Rect, type Rectangle, type RemoveAnnotationsOptions, RevocationError, type RevocationProvider, type Rotation, STANDARD_STAMPS, type SaveOptions, SecurityError, type SecurityInfo, type SetTitleOptions, type SignOptions, type SignResult, type SignWarning, type SignatureAlgorithm, SignatureError, type SignatureField, type SignatureFieldOptions, type Signer, SignerError, type SquareAnnotationOptions, type StampAnnotationOptions, type StampName, type Standard14FontName, StandardFonts, type SubFilter, TextAlignment, type TextAnnotationIcon, type TextAnnotationOptions, type TextAnnotationState, type TextAnnotationStateModel, type TextField, type TextFieldOptions, type TextLine, type TextMarkupAnnotationOptions, type TimestampAuthority, TimestampError, type TrappedStatus, black, blue, cmyk, createAnnotation, degrees, grayscale, green, isPopupAnnotation, isWidgetAnnotation, layoutJustifiedLine, layoutText, lineCapToNumber, lineJoinToNumber, measureText, rectToQuadPoints, rectsToQuadPoints, red, rgb, version, white };
8933
+ export { AnnotationFlags, type AnnotationSubtype, type AuthenticationResult, type BorderStyle, type BorderStyleType, type ButtonField, type CMYK, type CaretAnnotationOptions, type CaretSymbol, CertificateChainError, type CheckboxField, type CheckboxOptions, type CheckboxSymbol, type CircleAnnotationOptions, type Color, type CopyPagesOptions, CryptoKeySigner, type Degrees, type DestinationType, type DigestAlgorithm, type DocumentMetadata, type DrawCircleOptions, type DrawEllipseOptions, type DrawFieldOptions, type DrawImageOptions, type DrawLineOptions, type DrawPageOptions, type DrawRectangleOptions, type DrawTextOptions, type DropdownField, type DropdownOptions, type EmbedFontOptions, type EmbeddedFont, type EncryptionAlgorithmOption, type ExtractPagesOptions, type FieldOptions, type FieldType, type FieldValue, type FileAttachmentIcon, type FlattenAnnotationsOptions, type FlattenLayersResult, type FlattenOptions, type FontInput, type FormField, type FormProperties, type FreeTextAnnotationOptions, type FreeTextJustification, GoogleKmsSigner, type Grayscale, type HighlightMode, HttpTimestampAuthority, type HttpTimestampAuthorityOptions, type InkAnnotationOptions, type KeyType, KmsSignerError, type LayerInfo, type LayoutResult, type LineAnnotationOptions, type LineCap, type LineEndingStyle, type LineJoin, type LinkAction, type LinkAnnotationOptions, type LinkDestination, type ListBoxField, type ListboxOptions, type LoadOptions, type MergeOptions, P12Signer, type PAdESLevel, PDF, PDFAnnotation, PDFCaretAnnotation, PDFCircleAnnotation, PDFEmbeddedPage, PDFFileAttachmentAnnotation, PDFForm, PDFFreeTextAnnotation, PDFHighlightAnnotation, PDFImage, PDFInkAnnotation, PDFLineAnnotation, PDFLinkAnnotation, PDFMarkupAnnotation, PDFPage, PDFPolygonAnnotation, PDFPolylineAnnotation, PDFPopupAnnotation, PDFSquareAnnotation, PDFSquigglyAnnotation, PDFStampAnnotation, PDFStrikeOutAnnotation, PDFTextAnnotation, PDFTextMarkupAnnotation, PDFUnderlineAnnotation, PDFUnknownAnnotation, PathBuilder, type PathOptions, PdfArray, PdfBool, PdfDict, PdfName, PdfNull, PdfNumber, type PdfObject, PdfRef, PdfStream, PdfString, type PemBlock, PermissionDeniedError, type PermissionOptions, type Permissions, PlaceholderError, type Point, type PolygonAnnotationOptions, type PolylineAnnotationOptions, type PopupOptions, type PositionedWord, type ProtectionOptions, type RGB, type RadioField, type RadioGroupOptions, type RadioSymbol, type Rect, type Rectangle, type RemoveAnnotationsOptions, RevocationError, type RevocationProvider, type Rotation, STANDARD_STAMPS, type SaveOptions, SecurityError, type SecurityInfo, type SetTitleOptions, type SignOptions, type SignResult, type SignWarning, type SignatureAlgorithm, SignatureError, type SignatureField, type SignatureFieldOptions, type Signer, SignerError, type SquareAnnotationOptions, type StampAnnotationOptions, type StampName, type Standard14FontName, StandardFonts, type SubFilter, TextAlignment, type TextAnnotationIcon, type TextAnnotationOptions, type TextAnnotationState, type TextAnnotationStateModel, type TextField, type TextFieldOptions, type TextLine, type TextMarkupAnnotationOptions, type TimestampAuthority, TimestampError, type TrappedStatus, black, blue, cmyk, createAnnotation, degrees, grayscale, green, isPopupAnnotation, isWidgetAnnotation, layoutJustifiedLine, layoutText, lineCapToNumber, lineJoinToNumber, measureText, parsePem, rectToQuadPoints, rectsToQuadPoints, red, rgb, version, white };
8896
8934
  //# sourceMappingURL=index.d.mts.map
package/dist/index.mjs CHANGED
@@ -9,7 +9,7 @@ import * as pkijs from "pkijs";
9
9
  import { base64 } from "@scure/base";
10
10
 
11
11
  //#region package.json
12
- var version = "0.0.1-beta.4";
12
+ var version = "0.0.1-beta.5";
13
13
 
14
14
  //#endregion
15
15
  //#region src/objects/pdf-array.ts
@@ -38385,6 +38385,51 @@ var CryptoKeySigner = class {
38385
38385
  * lines used for certificates, keys, and other cryptographic data.
38386
38386
  */
38387
38387
  /**
38388
+ * Parse a PEM file into a series of DER blocks with their types.
38389
+ *
38390
+ * PEM files can contain multiple blocks (e.g., certificate chains). This function
38391
+ * extracts each block along with its label from the BEGIN statement.
38392
+ *
38393
+ * @param pem - The PEM-encoded string (may contain multiple blocks)
38394
+ * @returns Array of PEM blocks, each containing a label and DER data
38395
+ * @throws {Error} if the PEM format is invalid (mismatched labels or missing markers)
38396
+ *
38397
+ * @example
38398
+ * ```typescript
38399
+ * const blocks = parsePem(pemString);
38400
+ * // [
38401
+ * // { label: "CERTIFICATE", der: Uint8Array(...) },
38402
+ * // { label: "CERTIFICATE", der: Uint8Array(...) },
38403
+ * // { label: "PRIVATE KEY", der: Uint8Array(...) }
38404
+ * // ]
38405
+ * ```
38406
+ */
38407
+ function parsePem(pem) {
38408
+ const blocks = [];
38409
+ const blockRegex = /-----BEGIN ([A-Z0-9 ]+)-----([\s\S]*?)-----END ([A-Z0-9 ]+)-----/g;
38410
+ let match;
38411
+ while ((match = blockRegex.exec(pem)) !== null) {
38412
+ const beginLabel = match[1];
38413
+ const content = match[2];
38414
+ const endLabel = match[3];
38415
+ if (beginLabel !== endLabel) throw new Error(`PEM label mismatch: BEGIN ${beginLabel} but END ${endLabel}`);
38416
+ const b64 = content.replace(/\s/g, "");
38417
+ if (b64.length === 0) {
38418
+ blocks.push({
38419
+ label: beginLabel,
38420
+ der: new Uint8Array(0)
38421
+ });
38422
+ continue;
38423
+ }
38424
+ const der = base64.decode(b64);
38425
+ blocks.push({
38426
+ label: beginLabel,
38427
+ der
38428
+ });
38429
+ }
38430
+ return blocks;
38431
+ }
38432
+ /**
38388
38433
  * Convert DER (binary) bytes to PEM format.
38389
38434
  *
38390
38435
  * @param der - The DER-encoded binary data
@@ -40875,5 +40920,5 @@ var HttpTimestampAuthority = class {
40875
40920
  };
40876
40921
 
40877
40922
  //#endregion
40878
- export { AnnotationFlags, CertificateChainError, CryptoKeySigner, GoogleKmsSigner, HttpTimestampAuthority, KmsSignerError, P12Signer, PDF, PDFAnnotation, PDFCaretAnnotation, PDFCircleAnnotation, PDFEmbeddedPage, PDFFileAttachmentAnnotation, PDFForm, PDFFreeTextAnnotation, PDFHighlightAnnotation, PDFImage, PDFInkAnnotation, PDFLineAnnotation, PDFLinkAnnotation, PDFMarkupAnnotation, PDFPage, PDFPolygonAnnotation, PDFPolylineAnnotation, PDFPopupAnnotation, PDFSquareAnnotation, PDFSquigglyAnnotation, PDFStampAnnotation, PDFStrikeOutAnnotation, PDFTextAnnotation, PDFTextMarkupAnnotation, PDFUnderlineAnnotation, PDFUnknownAnnotation, PathBuilder, PdfArray, PdfBool, PdfDict, PdfName, PdfNull, PdfNumber, PdfRef, PdfStream, PdfString, PermissionDeniedError, PlaceholderError, RevocationError, STANDARD_STAMPS, SecurityError, SignatureError, SignerError, StandardFonts, TextAlignment, TimestampError, black, blue, cmyk, createAnnotation, degrees, grayscale, green, isPopupAnnotation, isWidgetAnnotation, layoutJustifiedLine, layoutText, lineCapToNumber, lineJoinToNumber, measureText, rectToQuadPoints, rectsToQuadPoints, red, rgb, version, white };
40923
+ export { AnnotationFlags, CertificateChainError, CryptoKeySigner, GoogleKmsSigner, HttpTimestampAuthority, KmsSignerError, P12Signer, PDF, PDFAnnotation, PDFCaretAnnotation, PDFCircleAnnotation, PDFEmbeddedPage, PDFFileAttachmentAnnotation, PDFForm, PDFFreeTextAnnotation, PDFHighlightAnnotation, PDFImage, PDFInkAnnotation, PDFLineAnnotation, PDFLinkAnnotation, PDFMarkupAnnotation, PDFPage, PDFPolygonAnnotation, PDFPolylineAnnotation, PDFPopupAnnotation, PDFSquareAnnotation, PDFSquigglyAnnotation, PDFStampAnnotation, PDFStrikeOutAnnotation, PDFTextAnnotation, PDFTextMarkupAnnotation, PDFUnderlineAnnotation, PDFUnknownAnnotation, PathBuilder, PdfArray, PdfBool, PdfDict, PdfName, PdfNull, PdfNumber, PdfRef, PdfStream, PdfString, PermissionDeniedError, PlaceholderError, RevocationError, STANDARD_STAMPS, SecurityError, SignatureError, SignerError, StandardFonts, TextAlignment, TimestampError, black, blue, cmyk, createAnnotation, degrees, grayscale, green, isPopupAnnotation, isWidgetAnnotation, layoutJustifiedLine, layoutText, lineCapToNumber, lineJoinToNumber, measureText, parsePem, rectToQuadPoints, rectsToQuadPoints, red, rgb, version, white };
40879
40924
  //# sourceMappingURL=index.mjs.map