@awacloud/pdf 0.0.0-stage → 1.0.0
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/CHANGELOG.md +609 -0
- package/LICENSE +661 -0
- package/NOTICE +77 -0
- package/README.md +363 -2
- package/dist/build/index.js +21 -0
- package/dist/build/pdf-full-rw.js +10972 -0
- package/dist/build/pdf-full-rw.meta.json +105 -0
- package/dist/build/pdf-full-rw.min.js +53 -0
- package/dist/build/pdf-full.js +6078 -0
- package/dist/build/pdf-full.meta.json +90 -0
- package/dist/build/pdf-full.min.js +32 -0
- package/dist/build/pdf-large-rw.js +10367 -0
- package/dist/build/pdf-large-rw.meta.json +99 -0
- package/dist/build/pdf-large-rw.min.js +53 -0
- package/dist/build/pdf-large.js +5473 -0
- package/dist/build/pdf-large.meta.json +84 -0
- package/dist/build/pdf-large.min.js +32 -0
- package/dist/build/pdf-legacy-rw.js +12402 -0
- package/dist/build/pdf-legacy-rw.meta.json +110 -0
- package/dist/build/pdf-legacy-rw.min.js +53 -0
- package/dist/build/pdf-legacy.js +7508 -0
- package/dist/build/pdf-legacy.meta.json +95 -0
- package/dist/build/pdf-legacy.min.js +32 -0
- package/dist/build/pdf-rw.js +7578 -0
- package/dist/build/pdf-rw.meta.json +77 -0
- package/dist/build/pdf-rw.min.js +53 -0
- package/dist/build/pdf.js +2684 -0
- package/dist/build/pdf.meta.json +62 -0
- package/dist/build/pdf.min.js +32 -0
- package/dist/standalone/pdf-full-rw.js +16798 -0
- package/dist/standalone/pdf-full-rw.meta.json +78 -0
- package/dist/standalone/pdf-full-rw.min.js +56 -0
- package/dist/standalone/pdf-full.js +11904 -0
- package/dist/standalone/pdf-full.meta.json +63 -0
- package/dist/standalone/pdf-full.min.js +35 -0
- package/dist/standalone/pdf-large-rw.js +16193 -0
- package/dist/standalone/pdf-large-rw.meta.json +72 -0
- package/dist/standalone/pdf-large-rw.min.js +56 -0
- package/dist/standalone/pdf-large.js +11299 -0
- package/dist/standalone/pdf-large.meta.json +57 -0
- package/dist/standalone/pdf-large.min.js +35 -0
- package/dist/standalone/pdf-legacy-rw.js +18228 -0
- package/dist/standalone/pdf-legacy-rw.meta.json +83 -0
- package/dist/standalone/pdf-legacy-rw.min.js +56 -0
- package/dist/standalone/pdf-legacy.js +13334 -0
- package/dist/standalone/pdf-legacy.meta.json +68 -0
- package/dist/standalone/pdf-legacy.min.js +35 -0
- package/dist/standalone/pdf-rw.js +13404 -0
- package/dist/standalone/pdf-rw.meta.json +50 -0
- package/dist/standalone/pdf-rw.min.js +56 -0
- package/dist/standalone/pdf.js +8510 -0
- package/dist/standalone/pdf.meta.json +35 -0
- package/dist/standalone/pdf.min.js +35 -0
- package/docs/README.md +53 -0
- package/docs/api/README.md +38 -0
- package/docs/api/_shared/README.md +91 -0
- package/docs/api/action/README.md +29 -0
- package/docs/api/action/action.md +81 -0
- package/docs/api/action/goTo.md +66 -0
- package/docs/api/action/launch.md +58 -0
- package/docs/api/action/named.md +55 -0
- package/docs/api/action/uri.md +54 -0
- package/docs/api/annot/README.md +53 -0
- package/docs/api/annot/annot.md +114 -0
- package/docs/api/annot/fileAttach.md +53 -0
- package/docs/api/annot/freeText.md +68 -0
- package/docs/api/annot/ink.md +69 -0
- package/docs/api/annot/link.md +74 -0
- package/docs/api/annot/markup.md +83 -0
- package/docs/api/annot/popup.md +52 -0
- package/docs/api/annot/projection.md +56 -0
- package/docs/api/annot/redact.md +67 -0
- package/docs/api/annot/square.md +87 -0
- package/docs/api/annot/stamp.md +54 -0
- package/docs/api/annot/text.md +69 -0
- package/docs/api/annot/widget.md +69 -0
- package/docs/api/associatedFiles/README.md +9 -0
- package/docs/api/associatedFiles/associatedFiles.md +78 -0
- package/docs/api/bundles/README.md +68 -0
- package/docs/api/bundles/dist-matrix.md +165 -0
- package/docs/api/bundles/pdf-full.md +148 -0
- package/docs/api/bundles/pdf-large.md +144 -0
- package/docs/api/bundles/pdf-legacy.md +169 -0
- package/docs/api/content/README.md +29 -0
- package/docs/api/content/color.md +99 -0
- package/docs/api/content/graphics.md +114 -0
- package/docs/api/content/images.md +124 -0
- package/docs/api/content/ops.md +100 -0
- package/docs/api/content/stream.md +107 -0
- package/docs/api/content/text.md +98 -0
- package/docs/api/crypto/README.md +29 -0
- package/docs/api/crypto/aesGcm.md +72 -0
- package/docs/api/crypto/permissions.md +79 -0
- package/docs/api/crypto/security.md +98 -0
- package/docs/api/crypto/standardV4.md +104 -0
- package/docs/api/crypto/standardV5.md +84 -0
- package/docs/api/crypto/standardV6.md +93 -0
- package/docs/api/destination/README.md +9 -0
- package/docs/api/destination/destination.md +79 -0
- package/docs/api/document/README.md +29 -0
- package/docs/api/document/builder.md +281 -0
- package/docs/api/document/catalog.md +98 -0
- package/docs/api/document/document.md +187 -0
- package/docs/api/document/encryptedWriter.md +149 -0
- package/docs/api/document/incrementalWriter.md +148 -0
- package/docs/api/document/page.md +99 -0
- package/docs/api/document/pages.md +82 -0
- package/docs/api/document/resources.md +102 -0
- package/docs/api/document/writer.md +157 -0
- package/docs/api/document/xrefStreamWriter.md +122 -0
- package/docs/api/embedded/README.md +13 -0
- package/docs/api/embedded/collection.md +80 -0
- package/docs/api/embedded/embeddedFile.md +86 -0
- package/docs/api/embedded/fileSpec.md +87 -0
- package/docs/api/errors.md +110 -0
- package/docs/api/extra/3d-richmedia.md +76 -0
- package/docs/api/extra/README.md +99 -0
- package/docs/api/extra/annot-extended.md +71 -0
- package/docs/api/extra/associated-files.md +70 -0
- package/docs/api/extra/ccitt-fax-decoder.md +74 -0
- package/docs/api/extra/color-spaces-extended.md +72 -0
- package/docs/api/extra/content-ops-extended.md +82 -0
- package/docs/api/extra/document-parts.md +69 -0
- package/docs/api/extra/embedded-files-portfolio.md +87 -0
- package/docs/api/extra/font-cid-typed.md +77 -0
- package/docs/api/extra/font-color-tagging.md +76 -0
- package/docs/api/extra/form-actions-extended.md +75 -0
- package/docs/api/extra/info-dict-deprecated.md +72 -0
- package/docs/api/extra/jbig2-read.md +80 -0
- package/docs/api/extra/legacy-deprecated-annots.md +89 -0
- package/docs/api/extra/legacy-deprecated-filters.md +78 -0
- package/docs/api/extra/legacy-rc4-read.md +74 -0
- package/docs/api/extra/legacy-xfa-read.md +65 -0
- package/docs/api/extra/linearization-write.md +71 -0
- package/docs/api/extra/misc.md +93 -0
- package/docs/api/extra/optional-content-extended.md +83 -0
- package/docs/api/extra/pdf-a-output-intent.md +65 -0
- package/docs/api/extra/pdf-sandbox.md +76 -0
- package/docs/api/extra/pdf-ua-tagged.md +63 -0
- package/docs/api/extra/pdf-x-prepress.md +65 -0
- package/docs/api/extra/redaction-iso32005.md +65 -0
- package/docs/api/extra/shading-typed.md +73 -0
- package/docs/api/extra/sig-aes-gcm.md +69 -0
- package/docs/api/extra/sig-pades.md +103 -0
- package/docs/api/extra/tagged-pdf-typed.md +78 -0
- package/docs/api/extra/transparency-typed.md +74 -0
- package/docs/api/extra/well-tagged-pdf.md +61 -0
- package/docs/api/extra/xmp-extended.md +65 -0
- package/docs/api/font/README.md +25 -0
- package/docs/api/font/embed.md +157 -0
- package/docs/api/font/encoding.md +95 -0
- package/docs/api/font/font.md +97 -0
- package/docs/api/font/type3.md +89 -0
- package/docs/api/form/README.md +35 -0
- package/docs/api/form/acroform.md +88 -0
- package/docs/api/form/appearance.md +87 -0
- package/docs/api/form/button.md +97 -0
- package/docs/api/form/choice.md +96 -0
- package/docs/api/form/fieldTree.md +93 -0
- package/docs/api/form/signature.md +90 -0
- package/docs/api/form/text.md +88 -0
- package/docs/api/linearization/README.md +11 -0
- package/docs/api/linearization/linearization.md +81 -0
- package/docs/api/main.md +116 -0
- package/docs/api/metadata/README.md +10 -0
- package/docs/api/metadata/info.md +70 -0
- package/docs/api/metadata/xmp.md +62 -0
- package/docs/api/ocg/README.md +23 -0
- package/docs/api/ocg/config.md +95 -0
- package/docs/api/ocg/ocg.md +77 -0
- package/docs/api/outline/README.md +11 -0
- package/docs/api/outline/outline.md +107 -0
- package/docs/api/pdf.md +152 -0
- package/docs/api/prepress/README.md +10 -0
- package/docs/api/prepress/outputIntent.md +79 -0
- package/docs/api/prepress/pageBoundary.md +75 -0
- package/docs/api/sig/README.md +32 -0
- package/docs/api/sig/byteRange.md +120 -0
- package/docs/api/sig/certChain.md +84 -0
- package/docs/api/sig/dss.md +111 -0
- package/docs/api/sig/oids.md +76 -0
- package/docs/api/sig/sha1.md +72 -0
- package/docs/api/sig/sign.md +317 -0
- package/docs/api/sig/signature.md +178 -0
- package/docs/api/sig/timestamp.md +84 -0
- package/docs/api/syntax/README.md +29 -0
- package/docs/api/syntax/crossRefStream.md +115 -0
- package/docs/api/syntax/filters/README.md +50 -0
- package/docs/api/syntax/filters/ascii85.md +76 -0
- package/docs/api/syntax/filters/asciiHex.md +73 -0
- package/docs/api/syntax/filters/dispatch.md +125 -0
- package/docs/api/syntax/filters/flate.md +134 -0
- package/docs/api/syntax/filters/runLength.md +78 -0
- package/docs/api/syntax/objStream.md +88 -0
- package/docs/api/syntax/parser-obj.md +97 -0
- package/docs/api/syntax/parser.md +151 -0
- package/docs/api/syntax/serializer.md +109 -0
- package/docs/api/syntax/tokenizer.md +104 -0
- package/docs/api/syntax/trailer.md +85 -0
- package/docs/api/syntax/xref.md +139 -0
- package/docs/api/tagged/README.md +25 -0
- package/docs/api/tagged/classMap.md +67 -0
- package/docs/api/tagged/markedContent.md +62 -0
- package/docs/api/tagged/parentTree.md +67 -0
- package/docs/api/tagged/roleMap.md +67 -0
- package/docs/api/tagged/structElement.md +76 -0
- package/docs/api/tagged/structTree.md +75 -0
- package/docs/guide/coverage.md +113 -0
- package/docs/guide/crypto.md +121 -0
- package/docs/guide/extending.md +76 -0
- package/docs/guide/getting-started.md +75 -0
- package/docs/guide/legacy-1.7.md +42 -0
- package/docs/guide/pades-integration.md +579 -0
- package/docs/guide/read-pdf.md +89 -0
- package/package.json +97 -4
- package/src/_shared/index.js +179 -0
- package/src/action/action.js +119 -0
- package/src/action/goTo.js +89 -0
- package/src/action/launch.js +61 -0
- package/src/action/named.js +54 -0
- package/src/action/uri.js +51 -0
- package/src/annot/annot.js +212 -0
- package/src/annot/fileAttach.js +55 -0
- package/src/annot/freeText.js +82 -0
- package/src/annot/ink.js +77 -0
- package/src/annot/link.js +77 -0
- package/src/annot/markup.js +91 -0
- package/src/annot/popup.js +53 -0
- package/src/annot/projection.js +52 -0
- package/src/annot/redact.js +87 -0
- package/src/annot/square.js +132 -0
- package/src/annot/stamp.js +48 -0
- package/src/annot/text.js +54 -0
- package/src/annot/widget.js +61 -0
- package/src/associatedFiles/associatedFiles.js +86 -0
- package/src/bundles/pdf-full.js +91 -0
- package/src/bundles/pdf-large.js +81 -0
- package/src/bundles/pdf-legacy.js +107 -0
- package/src/content/color.js +114 -0
- package/src/content/graphics.js +192 -0
- package/src/content/images.js +160 -0
- package/src/content/ops.js +137 -0
- package/src/content/stream.js +154 -0
- package/src/content/text.js +125 -0
- package/src/crypto/aesGcm.js +123 -0
- package/src/crypto/permissions.js +112 -0
- package/src/crypto/security.js +327 -0
- package/src/crypto/standardV4.js +443 -0
- package/src/crypto/standardV5.js +306 -0
- package/src/crypto/standardV6.js +334 -0
- package/src/destination/destination.js +183 -0
- package/src/document/builder.js +618 -0
- package/src/document/catalog.js +100 -0
- package/src/document/document.js +472 -0
- package/src/document/encryptedWriter.js +554 -0
- package/src/document/incrementalWriter.js +514 -0
- package/src/document/page.js +131 -0
- package/src/document/pages.js +103 -0
- package/src/document/resources.js +146 -0
- package/src/document/writer.js +211 -0
- package/src/document/xrefStreamWriter.js +353 -0
- package/src/embedded/collection.js +102 -0
- package/src/embedded/embeddedFile.js +99 -0
- package/src/embedded/fileSpec.js +137 -0
- package/src/errors.js +78 -0
- package/src/extra/3d-richmedia.js +171 -0
- package/src/extra/annot-extended.js +200 -0
- package/src/extra/associated-files.js +131 -0
- package/src/extra/ccitt-fax-decoder.js +776 -0
- package/src/extra/color-spaces-extended.js +196 -0
- package/src/extra/content-ops-extended.js +153 -0
- package/src/extra/document-parts.js +149 -0
- package/src/extra/embedded-files-portfolio.js +234 -0
- package/src/extra/font-cid-typed.js +185 -0
- package/src/extra/font-color-tagging.js +144 -0
- package/src/extra/form-actions-extended.js +196 -0
- package/src/extra/info-dict-deprecated.js +137 -0
- package/src/extra/jbig2-read.js +169 -0
- package/src/extra/legacy-deprecated-annots.js +198 -0
- package/src/extra/legacy-deprecated-filters.js +167 -0
- package/src/extra/legacy-rc4-read.js +235 -0
- package/src/extra/legacy-xfa-read.js +104 -0
- package/src/extra/linearization-write.js +97 -0
- package/src/extra/misc.js +217 -0
- package/src/extra/optional-content-extended.js +142 -0
- package/src/extra/pdf-a-output-intent.js +112 -0
- package/src/extra/pdf-sandbox.js +88 -0
- package/src/extra/pdf-ua-tagged.js +116 -0
- package/src/extra/pdf-x-prepress.js +114 -0
- package/src/extra/redaction-iso32005.js +136 -0
- package/src/extra/shading-typed.js +222 -0
- package/src/extra/sig-aes-gcm.js +135 -0
- package/src/extra/sig-pades.js +242 -0
- package/src/extra/tagged-pdf-typed.js +203 -0
- package/src/extra/transparency-typed.js +135 -0
- package/src/extra/well-tagged-pdf.js +138 -0
- package/src/extra/xmp-extended.js +190 -0
- package/src/font/embed.js +480 -0
- package/src/font/encoding.js +92 -0
- package/src/font/font.js +101 -0
- package/src/font/type3.js +75 -0
- package/src/form/acroform.js +94 -0
- package/src/form/appearance.js +90 -0
- package/src/form/button.js +105 -0
- package/src/form/choice.js +152 -0
- package/src/form/fieldTree.js +120 -0
- package/src/form/signature.js +100 -0
- package/src/form/text.js +101 -0
- package/src/linearization/linearization.js +107 -0
- package/src/main.js +411 -0
- package/src/metadata/info.js +87 -0
- package/src/metadata/xmp.js +62 -0
- package/src/ocg/config.js +156 -0
- package/src/ocg/ocg.js +124 -0
- package/src/outline/outline.js +157 -0
- package/src/pdf.js +133 -0
- package/src/prepress/outputIntent.js +118 -0
- package/src/prepress/pageBoundary.js +108 -0
- package/src/sig/byteRange.js +306 -0
- package/src/sig/certChain.js +247 -0
- package/src/sig/dss.js +317 -0
- package/src/sig/oids.js +157 -0
- package/src/sig/sha1.js +142 -0
- package/src/sig/sign.js +1899 -0
- package/src/sig/signature.js +1441 -0
- package/src/sig/timestamp.js +236 -0
- package/src/syntax/crossRefStream.js +133 -0
- package/src/syntax/filters/ascii85.js +122 -0
- package/src/syntax/filters/asciiHex.js +83 -0
- package/src/syntax/filters/dispatch.js +176 -0
- package/src/syntax/filters/flate.js +316 -0
- package/src/syntax/filters/runLength.js +96 -0
- package/src/syntax/objStream.js +99 -0
- package/src/syntax/parser-obj.js +52 -0
- package/src/syntax/parser.js +321 -0
- package/src/syntax/serializer.js +221 -0
- package/src/syntax/tokenizer.js +290 -0
- package/src/syntax/trailer.js +76 -0
- package/src/syntax/xref.js +341 -0
- package/src/tagged/classMap.js +81 -0
- package/src/tagged/markedContent.js +123 -0
- package/src/tagged/parentTree.js +126 -0
- package/src/tagged/roleMap.js +107 -0
- package/src/tagged/structElement.js +138 -0
- package/src/tagged/structTree.js +94 -0
package/src/sig/oids.js
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
// Copyright (c) 2026 AwaCloud SAS
|
|
2
|
+
// Author: Matthieu Bouilloux
|
|
3
|
+
// SPDX-License-Identifier: AGPL-3.0-only
|
|
4
|
+
// Dual-licensed; see the NOTICE file for licensing and any additional terms.
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @fileoverview Shared OID dispatch tables for the `pdf/sig/*` family.
|
|
8
|
+
*
|
|
9
|
+
* Thin adapter over `@awacloud/fw/crypto/utils/asn1-oid.js` — the canonical
|
|
10
|
+
* OID database (~150 entries covering PKCS, X.509, CMS, JOSE, PAdES,
|
|
11
|
+
* ECC, AES). This module **does not** duplicate the data ; it filters
|
|
12
|
+
* and normalises a subset for the dispatch semantics expected by the
|
|
13
|
+
* PDF signature code path :
|
|
14
|
+
*
|
|
15
|
+
* - `DIGEST_OIDS` — OID → fw hash module name
|
|
16
|
+
* (`'sha256'`, `'sha384'`, `'sha512'`, `'sha1'`).
|
|
17
|
+
* - `SIG_DISPATCH_OIDS` — OID → fw verifier name
|
|
18
|
+
* (`'rsa'`, `'rsa-pss'`, `'ecc'`, `'ed25519'`).
|
|
19
|
+
* - `KEY_ALG_OIDS` — SPKI algorithm OID → short algorithm name
|
|
20
|
+
* (`'rsa'`, `'ecc'`, `'ed25519'`, `'ed448'`).
|
|
21
|
+
* - `SIG_ALG_OIDS_VERBOSE` — cert `sigAlgorithm` verbose name
|
|
22
|
+
* (e.g. `'sha256WithRSAEncryption'`,
|
|
23
|
+
* `'ecdsa-with-SHA256'`, `'rsassa-pss'`).
|
|
24
|
+
* - `OID_TST_INFO`/`OID_AA_TIMESTAMP` — RFC 3161 constants.
|
|
25
|
+
* - `shortOid()` — DN attribute OID → `'CN'`/`'O'`/… short form,
|
|
26
|
+
* delegated to `asn1Oid.lookup(oid).shortName`.
|
|
27
|
+
*
|
|
28
|
+
* Adding/renaming an OID happens in fw's `asn1Oid` database ; this
|
|
29
|
+
* module just decides how to surface the entry to PDF callers.
|
|
30
|
+
*
|
|
31
|
+
* Factory-only strict — no top-level binding besides this descriptor.
|
|
32
|
+
*
|
|
33
|
+
* @module pdf/sig/oids
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
import { asn1Oid } from '@awacloud/fw/crypto/utils/asn1-oid.js';
|
|
37
|
+
|
|
38
|
+
export const pdfSigOids = {
|
|
39
|
+
name: 'pdfSigOids',
|
|
40
|
+
dependencies: ['asn1Oid'],
|
|
41
|
+
deps: [asn1Oid],
|
|
42
|
+
factory(asn1Oid) {
|
|
43
|
+
// ── Dispatch tables built from fw's database ─────────────────
|
|
44
|
+
//
|
|
45
|
+
// We rebuild static `Object.freeze`-d tables for two reasons :
|
|
46
|
+
// 1. Existing consumers (signature.js, timestamp.js,
|
|
47
|
+
// certChain.js, sign.js) destructure the tables and look
|
|
48
|
+
// up by OID directly — keeping the table shape avoids
|
|
49
|
+
// cascading refactors.
|
|
50
|
+
// 2. The dispatch semantics (e.g. mapping multiple
|
|
51
|
+
// `*WithRSAEncryption` OIDs to a single `'rsa'` verifier
|
|
52
|
+
// name) are PDF-domain decisions that don't belong in fw.
|
|
53
|
+
|
|
54
|
+
// DIGEST_OIDS — fw hash module names. fw stores `hashAlg` as
|
|
55
|
+
// `'sha-256'` (RFC 5280 form) and digest-category entries as
|
|
56
|
+
// `name: 'sha256'`. We surface the fw module name (no dash).
|
|
57
|
+
const DIGEST_OID_LIST = [
|
|
58
|
+
'2.16.840.1.101.3.4.2.1', // sha256
|
|
59
|
+
'2.16.840.1.101.3.4.2.2', // sha384
|
|
60
|
+
'2.16.840.1.101.3.4.2.3', // sha512
|
|
61
|
+
'1.3.14.3.2.26' // sha1
|
|
62
|
+
];
|
|
63
|
+
const _digest = {};
|
|
64
|
+
for (const oid of DIGEST_OID_LIST) {
|
|
65
|
+
const e = asn1Oid.lookup(oid);
|
|
66
|
+
if (e) _digest[oid] = e.name; // 'sha256', 'sha384', 'sha512', 'sha1'
|
|
67
|
+
}
|
|
68
|
+
const DIGEST_OIDS = Object.freeze(_digest);
|
|
69
|
+
|
|
70
|
+
// SIG_DISPATCH_OIDS — verifier name. PDF maps:
|
|
71
|
+
// PKCS#1 v1.5 family → 'rsa'
|
|
72
|
+
// RSASSA-PSS → 'rsa-pss'
|
|
73
|
+
// id-ecPublicKey + ECDSA-W → 'ecc'
|
|
74
|
+
// id-Ed25519 → 'ed25519'
|
|
75
|
+
const SIG_DISPATCH_OID_LIST = [
|
|
76
|
+
['1.2.840.113549.1.1.1', 'rsa'], // rsaEncryption (PKCS#1 v1.5)
|
|
77
|
+
['1.2.840.113549.1.1.11', 'rsa'], // sha256WithRSAEncryption
|
|
78
|
+
['1.2.840.113549.1.1.12', 'rsa'], // sha384WithRSAEncryption
|
|
79
|
+
['1.2.840.113549.1.1.13', 'rsa'], // sha512WithRSAEncryption
|
|
80
|
+
['1.2.840.113549.1.1.10', 'rsa-pss'], // id-RSASSA-PSS
|
|
81
|
+
['1.2.840.10045.2.1', 'ecc'], // id-ecPublicKey
|
|
82
|
+
['1.2.840.10045.4.3.2', 'ecc'], // ecdsa-with-SHA256
|
|
83
|
+
['1.2.840.10045.4.3.3', 'ecc'], // ecdsa-with-SHA384
|
|
84
|
+
['1.2.840.10045.4.3.4', 'ecc'], // ecdsa-with-SHA512
|
|
85
|
+
['1.3.101.112', 'ed25519'] // id-Ed25519
|
|
86
|
+
];
|
|
87
|
+
const _sig = {};
|
|
88
|
+
for (const [oid, dispatch] of SIG_DISPATCH_OID_LIST) {
|
|
89
|
+
if (asn1Oid.lookup(oid)) _sig[oid] = dispatch;
|
|
90
|
+
}
|
|
91
|
+
const SIG_DISPATCH_OIDS = Object.freeze(_sig);
|
|
92
|
+
|
|
93
|
+
// KEY_ALG_OIDS — SPKI base algo (no hash suffix).
|
|
94
|
+
const KEY_ALG_OID_LIST = [
|
|
95
|
+
['1.2.840.113549.1.1.1', 'rsa'],
|
|
96
|
+
['1.2.840.10045.2.1', 'ecc'],
|
|
97
|
+
['1.3.101.112', 'ed25519'],
|
|
98
|
+
['1.3.101.113', 'ed448']
|
|
99
|
+
];
|
|
100
|
+
const _key = {};
|
|
101
|
+
for (const [oid, alg] of KEY_ALG_OID_LIST) {
|
|
102
|
+
if (asn1Oid.lookup(oid)) _key[oid] = alg;
|
|
103
|
+
}
|
|
104
|
+
const KEY_ALG_OIDS = Object.freeze(_key);
|
|
105
|
+
|
|
106
|
+
// SIG_ALG_OIDS_VERBOSE — cert sigAlgorithm verbose name. PDF
|
|
107
|
+
// uses RFC-canonical wire-format names that differ slightly
|
|
108
|
+
// from fw's `name` field.
|
|
109
|
+
const _verbose = {
|
|
110
|
+
'1.2.840.113549.1.1.5': 'sha1WithRSAEncryption',
|
|
111
|
+
'1.2.840.113549.1.1.11': 'sha256WithRSAEncryption',
|
|
112
|
+
'1.2.840.113549.1.1.12': 'sha384WithRSAEncryption',
|
|
113
|
+
'1.2.840.113549.1.1.13': 'sha512WithRSAEncryption',
|
|
114
|
+
'1.2.840.113549.1.1.10': 'rsassa-pss',
|
|
115
|
+
'1.2.840.10045.4.3.2': 'ecdsa-with-SHA256',
|
|
116
|
+
'1.2.840.10045.4.3.3': 'ecdsa-with-SHA384',
|
|
117
|
+
'1.2.840.10045.4.3.4': 'ecdsa-with-SHA512',
|
|
118
|
+
'1.3.101.112': 'ed25519',
|
|
119
|
+
'1.3.101.113': 'ed448'
|
|
120
|
+
};
|
|
121
|
+
// Strip OIDs that fw doesn't know (paranoia : keeps fw as
|
|
122
|
+
// single source of truth for what's a valid OID).
|
|
123
|
+
for (const oid of Object.keys(_verbose)) {
|
|
124
|
+
if (!asn1Oid.lookup(oid)) delete _verbose[oid];
|
|
125
|
+
}
|
|
126
|
+
const SIG_ALG_OIDS_VERBOSE = Object.freeze(_verbose);
|
|
127
|
+
|
|
128
|
+
// RFC 3161 constants — also in fw's pkcs9 / pkcs7 categories,
|
|
129
|
+
// re-exposed here for caller ergonomics.
|
|
130
|
+
const OID_TST_INFO = '1.2.840.113549.1.9.16.1.4';
|
|
131
|
+
const OID_AA_TIMESTAMP = '1.2.840.113549.1.9.16.2.14';
|
|
132
|
+
|
|
133
|
+
// ── Helpers ──────────────────────────────────────────────────
|
|
134
|
+
|
|
135
|
+
/** DN attribute OID → short form (CN, O, OU, C, …). */
|
|
136
|
+
function shortOid(oid) {
|
|
137
|
+
const e = asn1Oid.lookup(oid);
|
|
138
|
+
if (e && e.category === 'x509-dn') return e.shortName;
|
|
139
|
+
// PKCS#9 emailAddress is also rendered as 'E' in DNs.
|
|
140
|
+
if (oid === '1.2.840.113549.1.9.1') return 'E';
|
|
141
|
+
return oid;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function lookupDigest(oid) { return DIGEST_OIDS[oid] || null; }
|
|
145
|
+
function lookupSigAlg(oid) { return SIG_DISPATCH_OIDS[oid] || null; }
|
|
146
|
+
function lookupKeyAlg(oid) { return KEY_ALG_OIDS[oid] || null; }
|
|
147
|
+
function lookupSigVerbose(oid) { return SIG_ALG_OIDS_VERBOSE[oid] || null; }
|
|
148
|
+
|
|
149
|
+
return {
|
|
150
|
+
DIGEST_OIDS, SIG_DISPATCH_OIDS,
|
|
151
|
+
KEY_ALG_OIDS, SIG_ALG_OIDS_VERBOSE,
|
|
152
|
+
OID_TST_INFO, OID_AA_TIMESTAMP,
|
|
153
|
+
lookupDigest, lookupSigAlg, lookupKeyAlg, lookupSigVerbose,
|
|
154
|
+
shortOid
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
};
|
package/src/sig/sha1.js
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
// Copyright (c) 2026 AwaCloud SAS
|
|
2
|
+
// Author: Matthieu Bouilloux
|
|
3
|
+
// SPDX-License-Identifier: AGPL-3.0-only
|
|
4
|
+
// Dual-licensed; see the NOTICE file for licensing and any additional terms.
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @fileoverview SHA-1 hash function (FIPS 180-4 §6.1) — PDF-local
|
|
8
|
+
* legacy module.
|
|
9
|
+
*
|
|
10
|
+
* **Why this lives in pdf and not fw** : SHA-1 is cryptographically
|
|
11
|
+
* broken for collision resistance. It MUST NOT be used for new
|
|
12
|
+
* signatures, MACs, or password hashing. The only reason this module
|
|
13
|
+
* exists in the workspace is **PDF legacy compatibility** — ISO
|
|
14
|
+
* 32000-2 §12.8.4.3 mandates SHA-1 of the signature value as the DSS
|
|
15
|
+
* `/VRI` dict key. Keeping the implementation in `@awacloud/pdf` instead of
|
|
16
|
+
* `@awacloud/fw` makes the legacy-only nature obvious to anyone reading
|
|
17
|
+
* fw's hash family (sha256/384/512 only).
|
|
18
|
+
*
|
|
19
|
+
* Exposes the same surface as fw's hash modules (`hash(data)` one-shot
|
|
20
|
+
* and `fn` constructor) so the dispatch idiom stays uniform.
|
|
21
|
+
*
|
|
22
|
+
* Factory descriptor — deps `['bitArray', 'utf8']`. Pattern aligned
|
|
23
|
+
* on `@awacloud/fw/crypto/hash/sha256.js`.
|
|
24
|
+
*
|
|
25
|
+
* @module pdf/sig/sha1
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
import { bitArray } from '@awacloud/fw/crypto/utils/bitArray.js';
|
|
29
|
+
import { utf8 } from '@awacloud/fw/io/codec/utf8.js';
|
|
30
|
+
|
|
31
|
+
export const pdfSha1 = {
|
|
32
|
+
name: 'pdfSha1',
|
|
33
|
+
dependencies: ['bitArray', 'utf8'],
|
|
34
|
+
deps: [bitArray, utf8],
|
|
35
|
+
factory(bitArray, utf8) {
|
|
36
|
+
|
|
37
|
+
const _INIT = [
|
|
38
|
+
0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0
|
|
39
|
+
];
|
|
40
|
+
|
|
41
|
+
// K[0..3] — round constants (FIPS 180-4 §4.2.1).
|
|
42
|
+
const _KEY = [
|
|
43
|
+
0x5a827999, 0x6ed9eba1, 0x8f1bbcdc, 0xca62c1d6
|
|
44
|
+
];
|
|
45
|
+
|
|
46
|
+
// Closure-based constructor — worker-safe (no `this.` in factory
|
|
47
|
+
// body). `fn(other?)` returns an object with `_h`/`_buffer`/
|
|
48
|
+
// `_length`/`reset`/`update`/`finalize` closing over locals.
|
|
49
|
+
function fn(other) {
|
|
50
|
+
let h, buffer, length;
|
|
51
|
+
function reset() {
|
|
52
|
+
h = _INIT.slice(0);
|
|
53
|
+
buffer = [];
|
|
54
|
+
length = 0;
|
|
55
|
+
return self;
|
|
56
|
+
}
|
|
57
|
+
function _block(w) {
|
|
58
|
+
let a = h[0], b = h[1], c = h[2], d = h[3], e = h[4];
|
|
59
|
+
const W = new Array(80);
|
|
60
|
+
for (let i = 0; i < 16; i++) W[i] = w[i] | 0;
|
|
61
|
+
for (let i = 16; i < 80; i++) {
|
|
62
|
+
const x = W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16];
|
|
63
|
+
W[i] = (x << 1) | (x >>> 31);
|
|
64
|
+
}
|
|
65
|
+
for (let i = 0; i < 80; i++) {
|
|
66
|
+
let f, kt;
|
|
67
|
+
if (i < 20) { f = (b & c) | ((~b) & d); kt = _KEY[0]; }
|
|
68
|
+
else if (i < 40) { f = b ^ c ^ d; kt = _KEY[1]; }
|
|
69
|
+
else if (i < 60) { f = (b & c) | (b & d) | (c & d); kt = _KEY[2]; }
|
|
70
|
+
else { f = b ^ c ^ d; kt = _KEY[3]; }
|
|
71
|
+
const t = (((a << 5) | (a >>> 27)) + f + e + kt + W[i]) | 0;
|
|
72
|
+
e = d;
|
|
73
|
+
d = c;
|
|
74
|
+
c = ((b << 30) | (b >>> 2)) | 0;
|
|
75
|
+
b = a;
|
|
76
|
+
a = t;
|
|
77
|
+
}
|
|
78
|
+
h[0] = (h[0] + a) | 0;
|
|
79
|
+
h[1] = (h[1] + b) | 0;
|
|
80
|
+
h[2] = (h[2] + c) | 0;
|
|
81
|
+
h[3] = (h[3] + d) | 0;
|
|
82
|
+
h[4] = (h[4] + e) | 0;
|
|
83
|
+
}
|
|
84
|
+
function update(data) {
|
|
85
|
+
if (typeof data === 'string') {
|
|
86
|
+
data = bitArray.ui8_to_ba(utf8.toBytes(data));
|
|
87
|
+
}
|
|
88
|
+
buffer = bitArray.concat(buffer, data);
|
|
89
|
+
const ol = length;
|
|
90
|
+
const nl = length = ol + bitArray.bitLength(data);
|
|
91
|
+
if (nl > 9007199254740991) {
|
|
92
|
+
console.warn('[crypto] INVALID: sha1: cannot hash more than 2^53 - 1 bits');
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
const c = new Uint32Array(buffer);
|
|
96
|
+
let j = 0;
|
|
97
|
+
for (let i = 512 + ol - ((512 + ol) & 511); i <= nl; i += 512) {
|
|
98
|
+
_block(c.subarray(16 * j, 16 * (j + 1)));
|
|
99
|
+
j += 1;
|
|
100
|
+
}
|
|
101
|
+
buffer.splice(0, 16 * j);
|
|
102
|
+
return self;
|
|
103
|
+
}
|
|
104
|
+
function finalize() {
|
|
105
|
+
buffer = bitArray.concat(buffer, [bitArray.partial(1, 1)]);
|
|
106
|
+
for (let i = buffer.length + 2; i & 15; i++) {
|
|
107
|
+
buffer.push(0);
|
|
108
|
+
}
|
|
109
|
+
buffer.push(Math.floor(length / 0x100000000));
|
|
110
|
+
buffer.push(length | 0);
|
|
111
|
+
while (buffer.length) {
|
|
112
|
+
_block(buffer.splice(0, 16));
|
|
113
|
+
}
|
|
114
|
+
const out = h;
|
|
115
|
+
reset();
|
|
116
|
+
return out;
|
|
117
|
+
}
|
|
118
|
+
const self = {
|
|
119
|
+
blockSize: 512,
|
|
120
|
+
reset, update, finalize,
|
|
121
|
+
// Expose state for clone — caller uses `fn(otherInstance)`.
|
|
122
|
+
get _h() { return h; },
|
|
123
|
+
get _buffer() { return buffer; },
|
|
124
|
+
get _length() { return length; }
|
|
125
|
+
};
|
|
126
|
+
if (other) {
|
|
127
|
+
h = other._h.slice(0);
|
|
128
|
+
buffer = other._buffer.slice(0);
|
|
129
|
+
length = other._length;
|
|
130
|
+
} else {
|
|
131
|
+
reset();
|
|
132
|
+
}
|
|
133
|
+
return self;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function hash(data) {
|
|
137
|
+
return fn().update(data).finalize();
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
return { fn, hash };
|
|
141
|
+
}
|
|
142
|
+
};
|