@weavecode/weave 0.1.0 → 0.1.1
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/node_modules/@weavecode/cli/dist/cli.js +4 -4
- package/node_modules/@weavecode/cli/dist/commands/chpass.js +1 -1
- package/node_modules/@weavecode/cli/dist/commands/daemon-auth.js +1 -1
- package/node_modules/@weavecode/cli/dist/commands/daemon.js +2 -2
- package/node_modules/@weavecode/cli/dist/commands/dashboard.d.ts +0 -2
- package/node_modules/@weavecode/cli/dist/commands/dashboard.js +2 -1
- package/node_modules/@weavecode/cli/dist/commands/doctor.js +1 -1
- package/node_modules/@weavecode/cli/dist/commands/init.js +1 -1
- package/node_modules/@weavecode/cli/dist/commands/msg.js +2 -2
- package/node_modules/@weavecode/cli/dist/commands/scan.js +1 -1
- package/node_modules/@weavecode/cli/dist/commands/status.js +2 -2
- package/node_modules/@weavecode/cli/dist/commands/uninstall.js +1 -1
- package/node_modules/@weavecode/cli/dist/i18n/dict/en.js +5 -3
- package/node_modules/@weavecode/cli/dist/i18n/dict/zh.d.ts +44 -1
- package/node_modules/@weavecode/cli/dist/i18n/dict/zh.js +6 -4
- package/node_modules/@weavecode/cli/dist/i18n/index.js +1 -1
- package/node_modules/@weavecode/cli/dist/i18n/t.js +1 -1
- package/node_modules/@weavecode/cli/dist/init/claudemd-gen.js +4 -4
- package/node_modules/@weavecode/cli/dist/init/executor.js +3 -3
- package/node_modules/@weavecode/cli/dist/init/git-commit.js +2 -2
- package/node_modules/@weavecode/cli/dist/init/harnesses/claude.js +7 -7
- package/node_modules/@weavecode/cli/dist/init/harnesses/codex.js +1 -1
- package/node_modules/@weavecode/cli/dist/init/helpers-gen.d.ts +4 -0
- package/node_modules/@weavecode/cli/dist/init/helpers-gen.js +1 -20
- package/node_modules/@weavecode/cli/dist/init/instruction-link.js +1 -1
- package/node_modules/@weavecode/cli/dist/init/mcp-gen.d.ts +3 -20
- package/node_modules/@weavecode/cli/dist/init/mcp-gen.js +1 -1
- package/node_modules/@weavecode/cli/dist/init/plugin-templates.js +1 -1
- package/node_modules/@weavecode/cli/dist/init/prompt.js +4 -4
- package/node_modules/@weavecode/cli/dist/init/settings-gen.d.ts +3 -30
- package/node_modules/@weavecode/cli/dist/init/settings-gen.js +1 -1
- package/node_modules/@weavecode/cli/dist/init/uninstall.js +6 -6
- package/node_modules/@weavecode/cli/dist/init/wiring.js +1 -1
- package/node_modules/@weavecode/cli/dist/parser.js +1 -1
- package/node_modules/@weavecode/cli/dist/statusline/ansi.js +1 -1
- package/node_modules/@weavecode/cli/dist/statusline/mock-input.js +1 -1
- package/node_modules/@weavecode/cli/dist/statusline/preview.js +2 -2
- package/node_modules/@weavecode/cli/package.json +5 -5
- package/node_modules/@weavecode/core/dist/harness-checks.js +1 -1
- package/node_modules/@weavecode/core/dist/harness.d.ts +45 -2
- package/node_modules/@weavecode/core/dist/harness.js +1 -1
- package/node_modules/@weavecode/core/dist/index.d.ts +1 -1
- package/node_modules/@weavecode/core/dist/index.js +1 -1
- package/node_modules/@weavecode/core/dist/platform.js +1 -1
- package/node_modules/@weavecode/core/dist/terminal.d.ts +28 -4
- package/node_modules/@weavecode/core/dist/terminal.js +1 -1
- package/node_modules/@weavecode/core/dist/types.d.ts +188 -11
- package/node_modules/@weavecode/core/dist/types.js +1 -1
- package/node_modules/@weavecode/core/dist/utils/fs.js +1 -1
- package/node_modules/@weavecode/core/dist/utils/logger.js +1 -1
- package/node_modules/@weavecode/core/package.json +1 -1
- package/node_modules/@weavecode/harness/dist/claude/assets.js +1 -1
- package/node_modules/@weavecode/harness/dist/claude/capture.d.ts +11 -1
- package/node_modules/@weavecode/harness/dist/claude/capture.js +5 -5
- package/node_modules/@weavecode/harness/dist/claude/detect.js +1 -1
- package/node_modules/@weavecode/harness/dist/claude/event-source.d.ts +1 -1
- package/node_modules/@weavecode/harness/dist/claude/event-source.js +1 -1
- package/node_modules/@weavecode/harness/dist/claude/helpers-gen.d.ts +5 -0
- package/node_modules/@weavecode/harness/dist/claude/helpers-gen.js +20 -0
- package/node_modules/@weavecode/harness/dist/claude/index.d.ts +5 -1
- package/node_modules/@weavecode/harness/dist/claude/index.js +1 -1
- package/node_modules/@weavecode/harness/dist/claude/mcp-gen.d.ts +22 -0
- package/node_modules/@weavecode/harness/dist/claude/mcp-gen.js +1 -0
- package/node_modules/@weavecode/harness/dist/claude/messaging.d.ts +11 -2
- package/node_modules/@weavecode/harness/dist/claude/messaging.js +4 -1
- package/node_modules/@weavecode/harness/dist/claude/model-aliases.d.ts +25 -0
- package/node_modules/@weavecode/harness/dist/claude/model-aliases.js +1 -0
- package/node_modules/@weavecode/harness/dist/claude/peers.js +1 -1
- package/node_modules/@weavecode/harness/dist/claude/plugins.js +4 -4
- package/node_modules/@weavecode/harness/dist/claude/prompt-inbox.js +1 -1
- package/node_modules/@weavecode/harness/dist/claude/prompt.js +3 -3
- package/node_modules/@weavecode/harness/dist/claude/questions.js +2 -1
- package/node_modules/@weavecode/harness/dist/claude/settings-gen.d.ts +32 -0
- package/node_modules/@weavecode/harness/dist/claude/settings-gen.js +1 -0
- package/node_modules/@weavecode/harness/dist/claude/transcript.d.ts +16 -0
- package/node_modules/@weavecode/harness/dist/claude/transcript.js +4 -2
- package/node_modules/@weavecode/harness/dist/codex/assets.js +1 -1
- package/node_modules/@weavecode/harness/dist/codex/detect.js +1 -1
- package/node_modules/@weavecode/harness/dist/codex/messaging.js +1 -1
- package/node_modules/@weavecode/harness/dist/codex/plugin-state.js +1 -1
- package/node_modules/@weavecode/harness/dist/codex/toml.js +9 -9
- package/node_modules/@weavecode/harness/dist/driver.d.ts +58 -1
- package/node_modules/@weavecode/harness/dist/driver.js +1 -1
- package/node_modules/@weavecode/harness/dist/index.d.ts +1 -0
- package/node_modules/@weavecode/harness/dist/index.js +1 -1
- package/node_modules/@weavecode/harness/dist/init/generated.d.ts +37 -0
- package/node_modules/@weavecode/harness/dist/init/generated.js +2 -0
- package/node_modules/@weavecode/harness/dist/init/pipeline.js +1 -1
- package/node_modules/@weavecode/harness/dist/registry-wiring.d.ts +3 -1
- package/node_modules/@weavecode/harness/dist/registry-wiring.js +1 -1
- package/node_modules/@weavecode/harness/dist/shared/install-link.js +1 -1
- package/node_modules/@weavecode/harness/package.json +2 -2
- package/node_modules/@weavecode/server/dist/daemon/ai-config.js +2 -2
- package/node_modules/@weavecode/server/dist/daemon/ai-context.js +6 -6
- package/node_modules/@weavecode/server/dist/daemon/ai-routes.js +4 -4
- package/node_modules/@weavecode/server/dist/daemon/api-log.d.ts +48 -0
- package/node_modules/@weavecode/server/dist/daemon/api-log.js +3 -0
- package/node_modules/@weavecode/server/dist/daemon/auth-routes.js +1 -1
- package/node_modules/@weavecode/server/dist/daemon/auto-start.js +6 -6
- package/node_modules/@weavecode/server/dist/daemon/capture-routes.js +1 -1
- package/node_modules/@weavecode/server/dist/daemon/claude-liveness.js +1 -1
- package/node_modules/@weavecode/server/dist/daemon/dashboard-auth.js +2 -2
- package/node_modules/@weavecode/server/dist/daemon/data-bus.js +1 -1
- package/node_modules/@weavecode/server/dist/daemon/dev-entry.js +1 -1
- package/node_modules/@weavecode/server/dist/daemon/fs-browser.js +1 -1
- package/node_modules/@weavecode/server/dist/daemon/hook-pipeline.d.ts +6 -1
- package/node_modules/@weavecode/server/dist/daemon/hook-pipeline.js +1 -1
- package/node_modules/@weavecode/server/dist/daemon/hooks-routes.js +1 -1
- package/node_modules/@weavecode/server/dist/daemon/http.js +1 -1
- package/node_modules/@weavecode/server/dist/daemon/opener.d.ts +102 -19
- package/node_modules/@weavecode/server/dist/daemon/opener.js +97 -7
- package/node_modules/@weavecode/server/dist/daemon/port.js +1 -1
- package/node_modules/@weavecode/server/dist/daemon/project-harnesses.js +2 -2
- package/node_modules/@weavecode/server/dist/daemon/project-updates-refresher.d.ts +4 -3
- package/node_modules/@weavecode/server/dist/daemon/project-updates-refresher.js +1 -1
- package/node_modules/@weavecode/server/dist/daemon/server.d.ts +8 -0
- package/node_modules/@weavecode/server/dist/daemon/server.js +6 -6
- package/node_modules/@weavecode/server/dist/daemon/session-probe.d.ts +59 -2
- package/node_modules/@weavecode/server/dist/daemon/session-probe.js +1 -1
- package/node_modules/@weavecode/server/dist/daemon/settings.d.ts +10 -0
- package/node_modules/@weavecode/server/dist/daemon/settings.js +2 -2
- package/node_modules/@weavecode/server/dist/daemon/start.js +1 -1
- package/node_modules/@weavecode/server/dist/daemon/state.js +2 -2
- package/node_modules/@weavecode/server/dist/daemon/static.js +1 -1
- package/node_modules/@weavecode/server/dist/daemon/terminal-topology-refresher.d.ts +4 -1
- package/node_modules/@weavecode/server/dist/daemon/tls.js +1 -1
- package/node_modules/@weavecode/server/dist/daemon/toolkit-routes.js +1 -1
- package/node_modules/@weavecode/server/dist/db/db.js +20 -2
- package/node_modules/@weavecode/server/dist/db/paths.d.ts +4 -0
- package/node_modules/@weavecode/server/dist/db/paths.js +1 -1
- package/node_modules/@weavecode/server/dist/hooks/answer-keys.js +1 -1
- package/node_modules/@weavecode/server/dist/hooks/bus.js +1 -1
- package/node_modules/@weavecode/server/dist/hooks/dispatcher.js +6 -6
- package/node_modules/@weavecode/server/dist/hooks/handlers/webhook.js +1 -1
- package/node_modules/@weavecode/server/dist/hooks/headless-runner.js +2 -2
- package/node_modules/@weavecode/server/dist/hooks/inbox-socket.d.ts +17 -4
- package/node_modules/@weavecode/server/dist/hooks/inbox-socket.js +2 -1
- package/node_modules/@weavecode/server/dist/hooks/inbox-worker.d.ts +20 -6
- package/node_modules/@weavecode/server/dist/hooks/inbox-worker.js +3 -3
- package/node_modules/@weavecode/server/dist/hooks/match.js +1 -1
- package/node_modules/@weavecode/server/dist/hooks/message-deliverer.d.ts +171 -13
- package/node_modules/@weavecode/server/dist/hooks/message-deliverer.js +3 -2
- package/node_modules/@weavecode/server/dist/hooks/mirror.js +4 -4
- package/node_modules/@weavecode/server/dist/hooks/plugin-installer.js +3 -3
- package/node_modules/@weavecode/server/dist/hooks/plugin-loader.js +1 -1
- package/node_modules/@weavecode/server/dist/hooks/plugin-project-state.js +1 -1
- package/node_modules/@weavecode/server/dist/hooks/prompt-flusher.js +1 -1
- package/node_modules/@weavecode/server/dist/hooks/promptbox.d.ts +13 -0
- package/node_modules/@weavecode/server/dist/hooks/promptbox.js +8 -8
- package/node_modules/@weavecode/server/dist/hooks/push-notify.js +2 -2
- package/node_modules/@weavecode/server/dist/hooks/question-tracker.d.ts +6 -4
- package/node_modules/@weavecode/server/dist/hooks/question-tracker.js +1 -1
- package/node_modules/@weavecode/server/dist/hooks/registry.js +1 -1
- package/node_modules/@weavecode/server/dist/hooks/resume-runner.js +1 -1
- package/node_modules/@weavecode/server/dist/hooks/sequence-engine.js +1 -1
- package/node_modules/@weavecode/server/dist/hooks/session-purge.d.ts +4 -0
- package/node_modules/@weavecode/server/dist/hooks/session-purge.js +1 -1
- package/node_modules/@weavecode/server/dist/hooks/session-sweeper.d.ts +5 -8
- package/node_modules/@weavecode/server/dist/hooks/session-sweeper.js +1 -1
- package/node_modules/@weavecode/server/dist/hooks/toolkit-scan.js +1 -1
- package/node_modules/@weavecode/server/dist/hooks/toolkit.d.ts +8 -0
- package/node_modules/@weavecode/server/dist/hooks/toolkit.js +5 -5
- package/node_modules/@weavecode/server/dist/hooks/watch-engine.d.ts +7 -0
- package/node_modules/@weavecode/server/dist/hooks/watch-engine.js +1 -1
- package/node_modules/@weavecode/server/dist/index.d.ts +1 -1
- package/node_modules/@weavecode/server/dist/install/apply-update.d.ts +1 -1
- package/node_modules/@weavecode/server/dist/install/apply-update.js +1 -1
- package/node_modules/@weavecode/server/dist/install/capabilities.js +1 -1
- package/node_modules/@weavecode/server/dist/install/codex-toml.js +1 -1
- package/node_modules/@weavecode/server/dist/install/file-assets.js +1 -1
- package/node_modules/@weavecode/server/dist/install/fingerprint.d.ts +5 -1
- package/node_modules/@weavecode/server/dist/install/fingerprint.js +1 -1
- package/node_modules/@weavecode/server/dist/install/git-classify.d.ts +30 -0
- package/node_modules/@weavecode/server/dist/install/git-classify.js +1 -0
- package/node_modules/@weavecode/server/dist/install/global-config.js +2 -2
- package/node_modules/@weavecode/server/dist/install/global-file-assets.js +1 -1
- package/node_modules/@weavecode/server/dist/install/init-files.d.ts +46 -0
- package/node_modules/@weavecode/server/dist/install/init-files.js +2 -0
- package/node_modules/@weavecode/server/dist/install/install-ledger.js +1 -1
- package/node_modules/@weavecode/server/dist/install/installer.js +3 -3
- package/node_modules/@weavecode/server/dist/install/library-index.js +1 -1
- package/node_modules/@weavecode/server/dist/install/mcp-rows.js +1 -1
- package/node_modules/@weavecode/server/dist/install/plugin-install.js +1 -1
- package/node_modules/@weavecode/server/dist/install/plugin-rows.js +1 -1
- package/node_modules/@weavecode/server/dist/install/plugin-templates.js +1 -1
- package/node_modules/@weavecode/server/dist/install/project-config.d.ts +0 -2
- package/node_modules/@weavecode/server/dist/install/project-config.js +2 -2
- package/node_modules/@weavecode/server/dist/install/reader.js +1 -1
- package/node_modules/@weavecode/server/dist/install/scan-cache.js +1 -1
- package/node_modules/@weavecode/server/dist/install/scanner.js +1 -1
- package/node_modules/@weavecode/server/dist/install/settings-mcp.js +2 -2
- package/node_modules/@weavecode/server/dist/install/updates.d.ts +17 -5
- package/node_modules/@weavecode/server/dist/install/updates.js +1 -1
- package/node_modules/@weavecode/server/dist/market/builtin.js +1 -1
- package/node_modules/@weavecode/server/dist/market/identity.js +1 -1
- package/node_modules/@weavecode/server/dist/market/import.js +2 -2
- package/node_modules/@weavecode/server/dist/market/refresh.js +1 -1
- package/node_modules/@weavecode/server/dist/market/resolve.js +1 -1
- package/node_modules/@weavecode/server/dist/market/updates.js +1 -1
- package/node_modules/@weavecode/server/dist/registry.js +2 -2
- package/node_modules/@weavecode/server/dist/repositories/hook-dispatches.js +5 -5
- package/node_modules/@weavecode/server/dist/repositories/hook-events.js +2 -2
- package/node_modules/@weavecode/server/dist/repositories/hook-rules.js +4 -4
- package/node_modules/@weavecode/server/dist/repositories/libraries.js +1 -1
- package/node_modules/@weavecode/server/dist/repositories/plugin-states.js +1 -1
- package/node_modules/@weavecode/server/dist/repositories/projects.d.ts +7 -0
- package/node_modules/@weavecode/server/dist/repositories/projects.js +2 -2
- package/node_modules/@weavecode/server/dist/repositories/push-subscriptions.js +2 -2
- package/node_modules/@weavecode/server/dist/repositories/session-watches.js +4 -4
- package/node_modules/@weavecode/server/dist/repositories/sessions.d.ts +17 -4
- package/node_modules/@weavecode/server/dist/repositories/sessions.js +2 -2
- package/node_modules/@weavecode/server/dist/repositories/uploads.d.ts +66 -0
- package/node_modules/@weavecode/server/dist/repositories/uploads.js +7 -0
- package/node_modules/@weavecode/server/dist/statusline/cache-sweeper.js +1 -1
- package/node_modules/@weavecode/server/dist/statusline/generator.js +81 -40
- package/node_modules/@weavecode/server/dist/statusline/manager.d.ts +2 -0
- package/node_modules/@weavecode/server/dist/statusline/manager.js +4 -4
- package/node_modules/@weavecode/server/dist/surfaces.js +1 -1
- package/node_modules/@weavecode/server/dist/watch/cache.js +1 -1
- package/node_modules/@weavecode/server/dist/watch/classifier.js +1 -1
- package/node_modules/@weavecode/server/dist/watch/plugin-mods.js +1 -1
- package/node_modules/@weavecode/server/dist/watch/sync-scheduler.d.ts +8 -4
- package/node_modules/@weavecode/server/dist/watch/sync-scheduler.js +1 -1
- package/node_modules/@weavecode/server/dist/watch/watch-service.js +1 -1
- package/node_modules/@weavecode/server/package.json +4 -4
- package/node_modules/@weavecode/server/web/dist/assets/index-D5WFh77i.css +11 -0
- package/node_modules/@weavecode/server/web/dist/assets/index-DJibaGnJ.js +585 -0
- package/node_modules/@weavecode/server/web/dist/index.html +14 -2
- package/node_modules/@weavecode/templates/dist/resources/weave-market/plugins/core-skills/weave-plugin-creator/skills/weave-plugin-creator/SKILL.md +2 -2
- package/node_modules/@weavecode/templates/package.json +2 -2
- package/node_modules/selfsigned/node_modules/@peculiar/x509/node_modules/@peculiar/asn1-cms/node_modules/asn1js/README.md +50 -32
- package/node_modules/selfsigned/node_modules/@peculiar/x509/node_modules/@peculiar/asn1-cms/node_modules/asn1js/build/index.d.ts +86 -40
- package/node_modules/selfsigned/node_modules/@peculiar/x509/node_modules/@peculiar/asn1-cms/node_modules/asn1js/build/index.es.js +860 -353
- package/node_modules/selfsigned/node_modules/@peculiar/x509/node_modules/@peculiar/asn1-cms/node_modules/asn1js/build/index.js +860 -353
- package/node_modules/selfsigned/node_modules/@peculiar/x509/node_modules/@peculiar/asn1-cms/node_modules/asn1js/package.json +20 -17
- package/node_modules/selfsigned/node_modules/@peculiar/x509/node_modules/@peculiar/asn1-csr/node_modules/asn1js/README.md +50 -32
- package/node_modules/selfsigned/node_modules/@peculiar/x509/node_modules/@peculiar/asn1-csr/node_modules/asn1js/build/index.d.ts +86 -40
- package/node_modules/selfsigned/node_modules/@peculiar/x509/node_modules/@peculiar/asn1-csr/node_modules/asn1js/build/index.es.js +860 -353
- package/node_modules/selfsigned/node_modules/@peculiar/x509/node_modules/@peculiar/asn1-csr/node_modules/asn1js/build/index.js +860 -353
- package/node_modules/selfsigned/node_modules/@peculiar/x509/node_modules/@peculiar/asn1-csr/node_modules/asn1js/package.json +20 -17
- package/node_modules/selfsigned/node_modules/@peculiar/x509/node_modules/@peculiar/asn1-ecc/node_modules/asn1js/README.md +50 -32
- package/node_modules/selfsigned/node_modules/@peculiar/x509/node_modules/@peculiar/asn1-ecc/node_modules/asn1js/build/index.d.ts +86 -40
- package/node_modules/selfsigned/node_modules/@peculiar/x509/node_modules/@peculiar/asn1-ecc/node_modules/asn1js/build/index.es.js +860 -353
- package/node_modules/selfsigned/node_modules/@peculiar/x509/node_modules/@peculiar/asn1-ecc/node_modules/asn1js/build/index.js +860 -353
- package/node_modules/selfsigned/node_modules/@peculiar/x509/node_modules/@peculiar/asn1-ecc/node_modules/asn1js/package.json +20 -17
- package/node_modules/selfsigned/node_modules/@peculiar/x509/node_modules/@peculiar/asn1-pkcs9/node_modules/asn1js/README.md +50 -32
- package/node_modules/selfsigned/node_modules/@peculiar/x509/node_modules/@peculiar/asn1-pkcs9/node_modules/asn1js/build/index.d.ts +86 -40
- package/node_modules/selfsigned/node_modules/@peculiar/x509/node_modules/@peculiar/asn1-pkcs9/node_modules/asn1js/build/index.es.js +860 -353
- package/node_modules/selfsigned/node_modules/@peculiar/x509/node_modules/@peculiar/asn1-pkcs9/node_modules/asn1js/build/index.js +860 -353
- package/node_modules/selfsigned/node_modules/@peculiar/x509/node_modules/@peculiar/asn1-pkcs9/node_modules/asn1js/package.json +20 -17
- package/node_modules/selfsigned/node_modules/@peculiar/x509/node_modules/@peculiar/asn1-rsa/node_modules/asn1js/README.md +50 -32
- package/node_modules/selfsigned/node_modules/@peculiar/x509/node_modules/@peculiar/asn1-rsa/node_modules/asn1js/build/index.d.ts +86 -40
- package/node_modules/selfsigned/node_modules/@peculiar/x509/node_modules/@peculiar/asn1-rsa/node_modules/asn1js/build/index.es.js +860 -353
- package/node_modules/selfsigned/node_modules/@peculiar/x509/node_modules/@peculiar/asn1-rsa/node_modules/asn1js/build/index.js +860 -353
- package/node_modules/selfsigned/node_modules/@peculiar/x509/node_modules/@peculiar/asn1-rsa/node_modules/asn1js/package.json +20 -17
- package/node_modules/selfsigned/node_modules/@peculiar/x509/node_modules/@peculiar/asn1-schema/node_modules/asn1js/README.md +50 -32
- package/node_modules/selfsigned/node_modules/@peculiar/x509/node_modules/@peculiar/asn1-schema/node_modules/asn1js/build/index.d.ts +86 -40
- package/node_modules/selfsigned/node_modules/@peculiar/x509/node_modules/@peculiar/asn1-schema/node_modules/asn1js/build/index.es.js +860 -353
- package/node_modules/selfsigned/node_modules/@peculiar/x509/node_modules/@peculiar/asn1-schema/node_modules/asn1js/build/index.js +860 -353
- package/node_modules/selfsigned/node_modules/@peculiar/x509/node_modules/@peculiar/asn1-schema/node_modules/asn1js/package.json +20 -17
- package/node_modules/selfsigned/node_modules/@peculiar/x509/node_modules/@peculiar/asn1-x509/node_modules/asn1js/README.md +50 -32
- package/node_modules/selfsigned/node_modules/@peculiar/x509/node_modules/@peculiar/asn1-x509/node_modules/asn1js/build/index.d.ts +86 -40
- package/node_modules/selfsigned/node_modules/@peculiar/x509/node_modules/@peculiar/asn1-x509/node_modules/asn1js/build/index.es.js +860 -353
- package/node_modules/selfsigned/node_modules/@peculiar/x509/node_modules/@peculiar/asn1-x509/node_modules/asn1js/build/index.js +860 -353
- package/node_modules/selfsigned/node_modules/@peculiar/x509/node_modules/@peculiar/asn1-x509/node_modules/asn1js/package.json +20 -17
- package/node_modules/selfsigned/node_modules/pkijs/node_modules/asn1js/README.md +50 -32
- package/node_modules/selfsigned/node_modules/pkijs/node_modules/asn1js/build/index.d.ts +86 -40
- package/node_modules/selfsigned/node_modules/pkijs/node_modules/asn1js/build/index.es.js +860 -353
- package/node_modules/selfsigned/node_modules/pkijs/node_modules/asn1js/build/index.js +860 -353
- package/node_modules/selfsigned/node_modules/pkijs/node_modules/asn1js/package.json +20 -17
- package/package.json +6 -6
- package/node_modules/@weavecode/server/web/dist/assets/index-BOzaRlQE.js +0 -560
- package/node_modules/@weavecode/server/web/dist/assets/index-ChX8G8cT.css +0 -11
|
@@ -50,7 +50,7 @@ function concat(buffers) {
|
|
|
50
50
|
const retView = new Uint8Array(outputLength);
|
|
51
51
|
for (let i = 0; i < buffers.length; i++) {
|
|
52
52
|
const buffer = buffers[i];
|
|
53
|
-
retView.set(new Uint8Array(buffer), prevLength);
|
|
53
|
+
retView.set(buffer instanceof Uint8Array ? buffer : new Uint8Array(buffer), prevLength);
|
|
54
54
|
prevLength += buffer.byteLength;
|
|
55
55
|
}
|
|
56
56
|
return retView.buffer;
|
|
@@ -72,7 +72,7 @@ function checkBufferParams(baseBlock, inputBuffer, inputOffset, inputLength) {
|
|
|
72
72
|
baseBlock.error = "Wrong parameter: inputLength less than zero";
|
|
73
73
|
return false;
|
|
74
74
|
}
|
|
75
|
-
if (
|
|
75
|
+
if (inputBuffer.byteLength - inputOffset - inputLength < 0) {
|
|
76
76
|
baseBlock.error = "End of input reached before message was fully decoded (inconsistent offset and length values)";
|
|
77
77
|
return false;
|
|
78
78
|
}
|
|
@@ -84,15 +84,15 @@ class ViewWriter {
|
|
|
84
84
|
this.items = [];
|
|
85
85
|
}
|
|
86
86
|
write(buf) {
|
|
87
|
-
this.items.push(buf);
|
|
87
|
+
this.items.push(buf instanceof ArrayBuffer ? buf : concat([buf]));
|
|
88
88
|
}
|
|
89
89
|
final() {
|
|
90
90
|
return concat(this.items);
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
|
+
const ORIGINAL_VIEW_WRITER_WRITE = ViewWriter.prototype.write;
|
|
94
|
+
const ORIGINAL_VIEW_WRITER_FINAL = ViewWriter.prototype.final;
|
|
93
95
|
|
|
94
|
-
const powers2 = [new Uint8Array([1])];
|
|
95
|
-
const digitsString = "0123456789";
|
|
96
96
|
const NAME = "name";
|
|
97
97
|
const VALUE_HEX_VIEW = "valueHexView";
|
|
98
98
|
const IS_HEX_ONLY = "isHexOnly";
|
|
@@ -148,15 +148,17 @@ function HexBlock(BaseClass) {
|
|
|
148
148
|
if (sizeOnly) {
|
|
149
149
|
return new ArrayBuffer(this.valueHexView.byteLength);
|
|
150
150
|
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
151
|
+
if (this.valueHexView.buffer instanceof ArrayBuffer &&
|
|
152
|
+
this.valueHexView.byteLength === this.valueHexView.buffer.byteLength) {
|
|
153
|
+
return this.valueHexView.buffer;
|
|
154
|
+
}
|
|
155
|
+
return pvtsutils.BufferSourceConverter.toArrayBuffer(this.valueHexView);
|
|
154
156
|
}
|
|
155
157
|
toJSON() {
|
|
156
158
|
return {
|
|
157
159
|
...super.toJSON(),
|
|
158
160
|
isHexOnly: this.isHexOnly,
|
|
159
|
-
valueHex: pvtsutils.Convert.ToHex(this.valueHexView)
|
|
161
|
+
valueHex: pvtsutils.Convert.ToHex(this.valueHexView)
|
|
160
162
|
};
|
|
161
163
|
}
|
|
162
164
|
},
|
|
@@ -174,7 +176,7 @@ class LocalBaseBlock {
|
|
|
174
176
|
set valueBeforeDecode(value) {
|
|
175
177
|
this.valueBeforeDecodeView = new Uint8Array(value);
|
|
176
178
|
}
|
|
177
|
-
constructor({ blockLength = 0, error = EMPTY_STRING, warnings = [], valueBeforeDecode = EMPTY_VIEW
|
|
179
|
+
constructor({ blockLength = 0, error = EMPTY_STRING, warnings = [], valueBeforeDecode = EMPTY_VIEW } = {}) {
|
|
178
180
|
this.blockLength = blockLength;
|
|
179
181
|
this.error = error;
|
|
180
182
|
this.warnings = warnings;
|
|
@@ -186,7 +188,7 @@ class LocalBaseBlock {
|
|
|
186
188
|
blockLength: this.blockLength,
|
|
187
189
|
error: this.error,
|
|
188
190
|
warnings: this.warnings,
|
|
189
|
-
valueBeforeDecode: pvtsutils.Convert.ToHex(this.valueBeforeDecodeView)
|
|
191
|
+
valueBeforeDecode: pvtsutils.Convert.ToHex(this.valueBeforeDecodeView)
|
|
190
192
|
};
|
|
191
193
|
}
|
|
192
194
|
}
|
|
@@ -234,7 +236,7 @@ class LocalIdentificationBlock extends HexBlock(LocalBaseBlock) {
|
|
|
234
236
|
firstOctet |= 0x80;
|
|
235
237
|
break;
|
|
236
238
|
case 4:
|
|
237
|
-
firstOctet |=
|
|
239
|
+
firstOctet |= 0xc0;
|
|
238
240
|
break;
|
|
239
241
|
default:
|
|
240
242
|
this.error = "Unknown tag class";
|
|
@@ -246,7 +248,7 @@ class LocalIdentificationBlock extends HexBlock(LocalBaseBlock) {
|
|
|
246
248
|
const retView = new Uint8Array(1);
|
|
247
249
|
if (!sizeOnly) {
|
|
248
250
|
let number = this.tagNumber;
|
|
249
|
-
number &=
|
|
251
|
+
number &= 0x1f;
|
|
250
252
|
firstOctet |= number;
|
|
251
253
|
retView[0] = firstOctet;
|
|
252
254
|
}
|
|
@@ -257,19 +259,19 @@ class LocalIdentificationBlock extends HexBlock(LocalBaseBlock) {
|
|
|
257
259
|
const encodedView = new Uint8Array(encodedBuf);
|
|
258
260
|
const size = encodedBuf.byteLength;
|
|
259
261
|
const retView = new Uint8Array(size + 1);
|
|
260
|
-
retView[0] =
|
|
262
|
+
retView[0] = firstOctet | 0x1f;
|
|
261
263
|
if (!sizeOnly) {
|
|
262
|
-
for (let i = 0; i <
|
|
264
|
+
for (let i = 0; i < size - 1; i++)
|
|
263
265
|
retView[i + 1] = encodedView[i] | 0x80;
|
|
264
266
|
retView[size] = encodedView[size - 1];
|
|
265
267
|
}
|
|
266
268
|
return retView.buffer;
|
|
267
269
|
}
|
|
268
270
|
const retView = new Uint8Array(this.valueHexView.byteLength + 1);
|
|
269
|
-
retView[0] =
|
|
271
|
+
retView[0] = firstOctet | 0x1f;
|
|
270
272
|
if (!sizeOnly) {
|
|
271
273
|
const curView = this.valueHexView;
|
|
272
|
-
for (let i = 0; i <
|
|
274
|
+
for (let i = 0; i < curView.length - 1; i++)
|
|
273
275
|
retView[i + 1] = curView[i] | 0x80;
|
|
274
276
|
retView[this.valueHexView.byteLength] = curView[curView.length - 1];
|
|
275
277
|
}
|
|
@@ -280,52 +282,55 @@ class LocalIdentificationBlock extends HexBlock(LocalBaseBlock) {
|
|
|
280
282
|
if (!checkBufferParams(this, inputView, inputOffset, inputLength)) {
|
|
281
283
|
return -1;
|
|
282
284
|
}
|
|
283
|
-
const
|
|
284
|
-
|
|
285
|
+
const fastArgs = Number.isInteger(inputOffset) && Number.isInteger(inputLength);
|
|
286
|
+
const intBuffer = fastArgs ? inputView : inputView.subarray(inputOffset, inputOffset + inputLength);
|
|
287
|
+
const baseIndex = fastArgs ? inputOffset : 0;
|
|
288
|
+
const bufferLength = fastArgs ? inputLength : intBuffer.length;
|
|
289
|
+
if (bufferLength === 0) {
|
|
285
290
|
this.error = "Zero buffer length";
|
|
286
291
|
return -1;
|
|
287
292
|
}
|
|
288
|
-
const tagClassMask = intBuffer[
|
|
293
|
+
const tagClassMask = intBuffer[baseIndex] & 0xc0;
|
|
289
294
|
switch (tagClassMask) {
|
|
290
295
|
case 0x00:
|
|
291
|
-
this.tagClass =
|
|
296
|
+
this.tagClass = 1;
|
|
292
297
|
break;
|
|
293
298
|
case 0x40:
|
|
294
|
-
this.tagClass =
|
|
299
|
+
this.tagClass = 2;
|
|
295
300
|
break;
|
|
296
301
|
case 0x80:
|
|
297
|
-
this.tagClass =
|
|
302
|
+
this.tagClass = 3;
|
|
298
303
|
break;
|
|
299
|
-
case
|
|
300
|
-
this.tagClass =
|
|
304
|
+
case 0xc0:
|
|
305
|
+
this.tagClass = 4;
|
|
301
306
|
break;
|
|
302
307
|
default:
|
|
303
308
|
this.error = "Unknown tag class";
|
|
304
309
|
return -1;
|
|
305
310
|
}
|
|
306
|
-
this.isConstructed = (intBuffer[
|
|
311
|
+
this.isConstructed = (intBuffer[baseIndex] & 0x20) === 0x20;
|
|
307
312
|
this.isHexOnly = false;
|
|
308
|
-
const tagNumberMask = intBuffer[
|
|
309
|
-
if (tagNumberMask !==
|
|
310
|
-
this.tagNumber =
|
|
313
|
+
const tagNumberMask = intBuffer[baseIndex] & 0x1f;
|
|
314
|
+
if (tagNumberMask !== 0x1f) {
|
|
315
|
+
this.tagNumber = tagNumberMask;
|
|
311
316
|
this.blockLength = 1;
|
|
312
317
|
}
|
|
313
318
|
else {
|
|
314
319
|
let count = 0;
|
|
315
320
|
while (true) {
|
|
316
321
|
const tagByteIndex = count + 1;
|
|
317
|
-
if (tagByteIndex >=
|
|
322
|
+
if (tagByteIndex >= bufferLength) {
|
|
318
323
|
this.error = "End of input reached before message was fully decoded";
|
|
319
324
|
return -1;
|
|
320
325
|
}
|
|
321
326
|
count++;
|
|
322
|
-
if ((intBuffer[tagByteIndex] & 0x80) === 0x00)
|
|
327
|
+
if ((intBuffer[baseIndex + tagByteIndex] & 0x80) === 0x00)
|
|
323
328
|
break;
|
|
324
329
|
}
|
|
325
|
-
this.blockLength =
|
|
326
|
-
const intTagNumberBuffer = this.valueHexView = new Uint8Array(count);
|
|
330
|
+
this.blockLength = count + 1;
|
|
331
|
+
const intTagNumberBuffer = (this.valueHexView = new Uint8Array(count));
|
|
327
332
|
for (let i = 0; i < count; i++)
|
|
328
|
-
intTagNumberBuffer[i] = intBuffer[i + 1] &
|
|
333
|
+
intTagNumberBuffer[i] = intBuffer[baseIndex + i + 1] & 0x7f;
|
|
329
334
|
if (this.blockLength <= 9)
|
|
330
335
|
this.tagNumber = pvutils.utilFromBase(intTagNumberBuffer, 7);
|
|
331
336
|
else {
|
|
@@ -333,8 +338,7 @@ class LocalIdentificationBlock extends HexBlock(LocalBaseBlock) {
|
|
|
333
338
|
this.warnings.push("Tag too long, represented as hex-coded");
|
|
334
339
|
}
|
|
335
340
|
}
|
|
336
|
-
if (
|
|
337
|
-
&& (this.isConstructed)) {
|
|
341
|
+
if (this.tagClass === 1 && this.isConstructed) {
|
|
338
342
|
switch (this.tagNumber) {
|
|
339
343
|
case 1:
|
|
340
344
|
case 2:
|
|
@@ -353,18 +357,20 @@ class LocalIdentificationBlock extends HexBlock(LocalBaseBlock) {
|
|
|
353
357
|
return -1;
|
|
354
358
|
}
|
|
355
359
|
}
|
|
356
|
-
return
|
|
360
|
+
return inputOffset + this.blockLength;
|
|
357
361
|
}
|
|
358
362
|
toJSON() {
|
|
359
363
|
return {
|
|
360
364
|
...super.toJSON(),
|
|
361
365
|
tagClass: this.tagClass,
|
|
362
366
|
tagNumber: this.tagNumber,
|
|
363
|
-
isConstructed: this.isConstructed
|
|
367
|
+
isConstructed: this.isConstructed
|
|
364
368
|
};
|
|
365
369
|
}
|
|
366
370
|
}
|
|
367
371
|
LocalIdentificationBlock.NAME = "identificationBlock";
|
|
372
|
+
const ORIGINAL_LOCAL_IDENTIFICATION_TO_BER = LocalIdentificationBlock.prototype.toBER;
|
|
373
|
+
const ORIGINAL_LOCAL_IDENTIFICATION_FROM_BER = LocalIdentificationBlock.prototype.fromBER;
|
|
368
374
|
|
|
369
375
|
class LocalLengthBlock extends LocalBaseBlock {
|
|
370
376
|
constructor({ lenBlock = {} } = {}) {
|
|
@@ -379,32 +385,35 @@ class LocalLengthBlock extends LocalBaseBlock {
|
|
|
379
385
|
if (!checkBufferParams(this, view, inputOffset, inputLength)) {
|
|
380
386
|
return -1;
|
|
381
387
|
}
|
|
382
|
-
const
|
|
383
|
-
|
|
388
|
+
const fastArgs = Number.isInteger(inputOffset) && Number.isInteger(inputLength);
|
|
389
|
+
const intBuffer = fastArgs ? view : view.subarray(inputOffset, inputOffset + inputLength);
|
|
390
|
+
const baseIndex = fastArgs ? inputOffset : 0;
|
|
391
|
+
const bufferLength = fastArgs ? inputLength : intBuffer.length;
|
|
392
|
+
if (bufferLength === 0) {
|
|
384
393
|
this.error = "Zero buffer length";
|
|
385
394
|
return -1;
|
|
386
395
|
}
|
|
387
|
-
if (intBuffer[
|
|
396
|
+
if (intBuffer[baseIndex] === 0xff) {
|
|
388
397
|
this.error = "Length block 0xFF is reserved by standard";
|
|
389
398
|
return -1;
|
|
390
399
|
}
|
|
391
|
-
this.isIndefiniteForm = intBuffer[
|
|
400
|
+
this.isIndefiniteForm = intBuffer[baseIndex] === 0x80;
|
|
392
401
|
if (this.isIndefiniteForm) {
|
|
393
402
|
this.blockLength = 1;
|
|
394
|
-
return
|
|
403
|
+
return inputOffset + this.blockLength;
|
|
395
404
|
}
|
|
396
|
-
this.longFormUsed = !!(intBuffer[
|
|
405
|
+
this.longFormUsed = !!(intBuffer[baseIndex] & 0x80);
|
|
397
406
|
if (this.longFormUsed === false) {
|
|
398
|
-
this.length =
|
|
407
|
+
this.length = intBuffer[baseIndex];
|
|
399
408
|
this.blockLength = 1;
|
|
400
|
-
return
|
|
409
|
+
return inputOffset + this.blockLength;
|
|
401
410
|
}
|
|
402
|
-
const count = intBuffer[
|
|
411
|
+
const count = intBuffer[baseIndex] & 0x7f;
|
|
403
412
|
if (count > 8) {
|
|
404
413
|
this.error = "Too big integer";
|
|
405
414
|
return -1;
|
|
406
415
|
}
|
|
407
|
-
if (
|
|
416
|
+
if (count + 1 > bufferLength) {
|
|
408
417
|
this.error = "End of input reached before message was fully decoded";
|
|
409
418
|
return -1;
|
|
410
419
|
}
|
|
@@ -413,10 +422,10 @@ class LocalLengthBlock extends LocalBaseBlock {
|
|
|
413
422
|
if (lengthBufferView[count - 1] === 0x00)
|
|
414
423
|
this.warnings.push("Needlessly long encoded length");
|
|
415
424
|
this.length = pvutils.utilFromBase(lengthBufferView, 8);
|
|
416
|
-
if (this.longFormUsed &&
|
|
425
|
+
if (this.longFormUsed && this.length <= 127)
|
|
417
426
|
this.warnings.push("Unnecessary usage of long length form");
|
|
418
427
|
this.blockLength = count + 1;
|
|
419
|
-
return
|
|
428
|
+
return inputOffset + this.blockLength;
|
|
420
429
|
}
|
|
421
430
|
toBER(sizeOnly = false) {
|
|
422
431
|
let retBuf;
|
|
@@ -435,7 +444,7 @@ class LocalLengthBlock extends LocalBaseBlock {
|
|
|
435
444
|
const encodedBuf = pvutils.utilToBase(this.length, 8);
|
|
436
445
|
if (encodedBuf.byteLength > 127) {
|
|
437
446
|
this.error = "Too big length";
|
|
438
|
-
return
|
|
447
|
+
return EMPTY_BUFFER;
|
|
439
448
|
}
|
|
440
449
|
retBuf = new ArrayBuffer(encodedBuf.byteLength + 1);
|
|
441
450
|
if (sizeOnly)
|
|
@@ -459,14 +468,427 @@ class LocalLengthBlock extends LocalBaseBlock {
|
|
|
459
468
|
...super.toJSON(),
|
|
460
469
|
isIndefiniteForm: this.isIndefiniteForm,
|
|
461
470
|
longFormUsed: this.longFormUsed,
|
|
462
|
-
length: this.length
|
|
471
|
+
length: this.length
|
|
463
472
|
};
|
|
464
473
|
}
|
|
465
474
|
}
|
|
466
475
|
LocalLengthBlock.NAME = "lengthBlock";
|
|
476
|
+
const ORIGINAL_LOCAL_LENGTH_TO_BER = LocalLengthBlock.prototype.toBER;
|
|
477
|
+
const ORIGINAL_LOCAL_LENGTH_FROM_BER = LocalLengthBlock.prototype.fromBER;
|
|
467
478
|
|
|
468
479
|
const typeStore = {};
|
|
469
480
|
|
|
481
|
+
var _a$y, _b, _c;
|
|
482
|
+
const originalUint8ArraySliceInfo = findMethod(Uint8Array.prototype, "slice");
|
|
483
|
+
const originalUint8ArrayConstructor = (_a$y = Object.getOwnPropertyDescriptor(Uint8Array.prototype, "constructor")) === null || _a$y === void 0 ? void 0 : _a$y.value;
|
|
484
|
+
const originalArrayIterator = (_b = Object.getOwnPropertyDescriptor(Array.prototype, Symbol.iterator)) === null || _b === void 0 ? void 0 : _b.value;
|
|
485
|
+
const intrinsicTypedArrayByteLength = (_c = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(Uint8Array.prototype), "byteLength")) === null || _c === void 0 ? void 0 : _c.get;
|
|
486
|
+
const BUILTIN_DISPATCH_PAYLOAD_THRESHOLD = 16384;
|
|
487
|
+
const BUILTIN_DISPATCH_MAX_DEPTH = 64;
|
|
488
|
+
let builtinRegistry;
|
|
489
|
+
function registerBuiltinEncoder(builtinConstructors, internals) {
|
|
490
|
+
const current = builtinRegistry;
|
|
491
|
+
const nextInternals = internals || current;
|
|
492
|
+
if (!nextInternals) {
|
|
493
|
+
builtinRegistry = undefined;
|
|
494
|
+
return;
|
|
495
|
+
}
|
|
496
|
+
builtinRegistry = { ...nextInternals, ...builtinConstructors };
|
|
497
|
+
}
|
|
498
|
+
function dataProperty(object, name) {
|
|
499
|
+
const descriptor = Object.getOwnPropertyDescriptor(object, name);
|
|
500
|
+
if (!descriptor || !("value" in descriptor))
|
|
501
|
+
return undefined;
|
|
502
|
+
return descriptor.value;
|
|
503
|
+
}
|
|
504
|
+
function intrinsicPayloadByteLength(value) {
|
|
505
|
+
if (!intrinsicTypedArrayByteLength || !value || typeof value !== "object")
|
|
506
|
+
return undefined;
|
|
507
|
+
try {
|
|
508
|
+
const byteLength = intrinsicTypedArrayByteLength.call(value);
|
|
509
|
+
return typeof byteLength === "number" ? byteLength : undefined;
|
|
510
|
+
}
|
|
511
|
+
catch {
|
|
512
|
+
return undefined;
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
function largePayloadOrChain(block, depth) {
|
|
516
|
+
if (depth > BUILTIN_DISPATCH_MAX_DEPTH || !block || typeof block !== "object")
|
|
517
|
+
return false;
|
|
518
|
+
const valueBlockDescriptor = Object.getOwnPropertyDescriptor(block, "valueBlock");
|
|
519
|
+
if (!valueBlockDescriptor || !("value" in valueBlockDescriptor))
|
|
520
|
+
return false;
|
|
521
|
+
const valueBlock = valueBlockDescriptor.value;
|
|
522
|
+
if (!valueBlock || typeof valueBlock !== "object")
|
|
523
|
+
return false;
|
|
524
|
+
const payloadDescriptor = Object.getOwnPropertyDescriptor(valueBlock, "valueHexView");
|
|
525
|
+
if (payloadDescriptor) {
|
|
526
|
+
if (!("value" in payloadDescriptor))
|
|
527
|
+
return false;
|
|
528
|
+
const byteLength = intrinsicPayloadByteLength(payloadDescriptor.value);
|
|
529
|
+
return byteLength !== undefined && byteLength >= BUILTIN_DISPATCH_PAYLOAD_THRESHOLD;
|
|
530
|
+
}
|
|
531
|
+
const valuesDescriptor = Object.getOwnPropertyDescriptor(valueBlock, "value");
|
|
532
|
+
if (!valuesDescriptor || !("value" in valuesDescriptor) || !Array.isArray(valuesDescriptor.value))
|
|
533
|
+
return false;
|
|
534
|
+
const values = valuesDescriptor.value;
|
|
535
|
+
const lengthDescriptor = Object.getOwnPropertyDescriptor(values, "length");
|
|
536
|
+
if (!lengthDescriptor || !("value" in lengthDescriptor) || lengthDescriptor.value !== 1)
|
|
537
|
+
return false;
|
|
538
|
+
const indexDescriptor = Object.getOwnPropertyDescriptor(values, "0");
|
|
539
|
+
if (!indexDescriptor || !("value" in indexDescriptor))
|
|
540
|
+
return false;
|
|
541
|
+
return largePayloadOrChain(indexDescriptor.value, depth + 1);
|
|
542
|
+
}
|
|
543
|
+
function shouldUseBuiltinEncoder(block) {
|
|
544
|
+
try {
|
|
545
|
+
return largePayloadOrChain(block, 0);
|
|
546
|
+
}
|
|
547
|
+
catch {
|
|
548
|
+
return false;
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
function sameDataMethod(current, original) {
|
|
552
|
+
return (!!current &&
|
|
553
|
+
"value" in current &&
|
|
554
|
+
current.value === original &&
|
|
555
|
+
current.writable === true &&
|
|
556
|
+
current.enumerable === false &&
|
|
557
|
+
current.configurable === true);
|
|
558
|
+
}
|
|
559
|
+
function writerMethodsStable(registry) {
|
|
560
|
+
return (sameDataMethod(Object.getOwnPropertyDescriptor(registry.ViewWriter.prototype, "write"), registry.originalWriterWrite) &&
|
|
561
|
+
sameDataMethod(Object.getOwnPropertyDescriptor(registry.ViewWriter.prototype, "final"), registry.originalWriterFinal));
|
|
562
|
+
}
|
|
563
|
+
function findMethod(prototype, name) {
|
|
564
|
+
let current = prototype;
|
|
565
|
+
while (current) {
|
|
566
|
+
const descriptor = Object.getOwnPropertyDescriptor(current, name);
|
|
567
|
+
if (descriptor) {
|
|
568
|
+
if ("value" in descriptor && typeof descriptor.value === "function") {
|
|
569
|
+
return { declaringPrototype: current, method: descriptor.value };
|
|
570
|
+
}
|
|
571
|
+
return undefined;
|
|
572
|
+
}
|
|
573
|
+
current = Object.getPrototypeOf(current);
|
|
574
|
+
}
|
|
575
|
+
return undefined;
|
|
576
|
+
}
|
|
577
|
+
function stableInheritedMethod(prototype, name, original) {
|
|
578
|
+
if (!original)
|
|
579
|
+
return false;
|
|
580
|
+
let current = prototype;
|
|
581
|
+
while (current) {
|
|
582
|
+
const descriptor = Object.getOwnPropertyDescriptor(current, name);
|
|
583
|
+
if (current === original.declaringPrototype) {
|
|
584
|
+
return !!descriptor && "value" in descriptor && descriptor.value === original.method;
|
|
585
|
+
}
|
|
586
|
+
if (descriptor)
|
|
587
|
+
return false;
|
|
588
|
+
current = Object.getPrototypeOf(current);
|
|
589
|
+
}
|
|
590
|
+
return false;
|
|
591
|
+
}
|
|
592
|
+
function prototypeMethod(object, prototype, name, expected) {
|
|
593
|
+
if (Object.prototype.hasOwnProperty.call(object, name))
|
|
594
|
+
return false;
|
|
595
|
+
if (Object.getPrototypeOf(object) !== prototype)
|
|
596
|
+
return false;
|
|
597
|
+
const descriptor = Object.getOwnPropertyDescriptor(prototype, name);
|
|
598
|
+
return !!descriptor && "value" in descriptor && descriptor.value === expected;
|
|
599
|
+
}
|
|
600
|
+
function inheritedMethod(object, name, expected, primitiveConstructor) {
|
|
601
|
+
if (Object.prototype.hasOwnProperty.call(object, name))
|
|
602
|
+
return false;
|
|
603
|
+
const prototype = Object.getPrototypeOf(object);
|
|
604
|
+
const originalPrimitiveValuePrototype = Object.getPrototypeOf(primitiveConstructor.prototype);
|
|
605
|
+
if (prototype !== primitiveConstructor.prototype ||
|
|
606
|
+
Object.getPrototypeOf(prototype) !== originalPrimitiveValuePrototype) {
|
|
607
|
+
return false;
|
|
608
|
+
}
|
|
609
|
+
const descriptor = prototype && Object.getOwnPropertyDescriptor(prototype, name);
|
|
610
|
+
if (descriptor)
|
|
611
|
+
return false;
|
|
612
|
+
const parentDescriptor = Object.getOwnPropertyDescriptor(originalPrimitiveValuePrototype, name);
|
|
613
|
+
return !!parentDescriptor && "value" in parentDescriptor && parentDescriptor.value === expected;
|
|
614
|
+
}
|
|
615
|
+
function plainPayload(value, allowEmpty = false) {
|
|
616
|
+
if (!(value instanceof Uint8Array) || Object.getPrototypeOf(value) !== Uint8Array.prototype)
|
|
617
|
+
return undefined;
|
|
618
|
+
for (const name of ["buffer", "byteOffset", "byteLength", "length", "slice", "constructor"]) {
|
|
619
|
+
if (Object.prototype.hasOwnProperty.call(value, name))
|
|
620
|
+
return undefined;
|
|
621
|
+
}
|
|
622
|
+
const constructorDescriptor = Object.getOwnPropertyDescriptor(Uint8Array.prototype, "constructor");
|
|
623
|
+
if (!constructorDescriptor ||
|
|
624
|
+
!("value" in constructorDescriptor) ||
|
|
625
|
+
constructorDescriptor.value !== originalUint8ArrayConstructor)
|
|
626
|
+
return undefined;
|
|
627
|
+
if (!stableInheritedMethod(Uint8Array.prototype, "slice", originalUint8ArraySliceInfo))
|
|
628
|
+
return undefined;
|
|
629
|
+
try {
|
|
630
|
+
const buffer = value.buffer;
|
|
631
|
+
if (!(buffer instanceof ArrayBuffer) || Object.getPrototypeOf(buffer) !== ArrayBuffer.prototype)
|
|
632
|
+
return undefined;
|
|
633
|
+
if (Object.prototype.hasOwnProperty.call(buffer, "byteLength"))
|
|
634
|
+
return undefined;
|
|
635
|
+
if (value.byteLength !== value.length || (!allowEmpty && value.byteLength === 0))
|
|
636
|
+
return undefined;
|
|
637
|
+
if (value.byteOffset < 0 || value.byteOffset + value.byteLength > buffer.byteLength)
|
|
638
|
+
return undefined;
|
|
639
|
+
}
|
|
640
|
+
catch {
|
|
641
|
+
return undefined;
|
|
642
|
+
}
|
|
643
|
+
return value;
|
|
644
|
+
}
|
|
645
|
+
function validIdBlock(block, constructed, registry) {
|
|
646
|
+
if (Object.getPrototypeOf(block) !== registry.LocalIdentificationBlock.prototype)
|
|
647
|
+
return false;
|
|
648
|
+
if (!prototypeMethod(block, registry.LocalIdentificationBlock.prototype, "toBER", registry.originalIdentificationToBER))
|
|
649
|
+
return false;
|
|
650
|
+
const tagClass = dataProperty(block, "tagClass");
|
|
651
|
+
const tagNumber = dataProperty(block, "tagNumber");
|
|
652
|
+
const isConstructed = dataProperty(block, "isConstructed");
|
|
653
|
+
const isHexOnly = dataProperty(block, "isHexOnly");
|
|
654
|
+
const valueHexView = dataProperty(block, "valueHexView");
|
|
655
|
+
if (typeof tagClass !== "number" || !Number.isInteger(tagClass) || tagClass < 1 || tagClass > 4)
|
|
656
|
+
return false;
|
|
657
|
+
if (typeof tagNumber !== "number" || !Number.isInteger(tagNumber) || tagNumber < 0)
|
|
658
|
+
return false;
|
|
659
|
+
if (isConstructed !== constructed || typeof isHexOnly !== "boolean")
|
|
660
|
+
return false;
|
|
661
|
+
if (isHexOnly)
|
|
662
|
+
return !!plainPayload(valueHexView);
|
|
663
|
+
return Number.isSafeInteger(tagNumber);
|
|
664
|
+
}
|
|
665
|
+
function validLengthBlock(block, allowIndefinite, registry) {
|
|
666
|
+
if (Object.getPrototypeOf(block) !== registry.LocalLengthBlock.prototype)
|
|
667
|
+
return false;
|
|
668
|
+
if (!prototypeMethod(block, registry.LocalLengthBlock.prototype, "toBER", registry.originalLengthToBER))
|
|
669
|
+
return false;
|
|
670
|
+
const indefinite = dataProperty(block, "isIndefiniteForm");
|
|
671
|
+
const longForm = dataProperty(block, "longFormUsed");
|
|
672
|
+
const lengthDescriptor = Object.getOwnPropertyDescriptor(block, "length");
|
|
673
|
+
const length = lengthDescriptor && "value" in lengthDescriptor ? lengthDescriptor.value : undefined;
|
|
674
|
+
const longFormDescriptor = Object.getOwnPropertyDescriptor(block, "longFormUsed");
|
|
675
|
+
return (typeof indefinite === "boolean" &&
|
|
676
|
+
(indefinite === false || allowIndefinite) &&
|
|
677
|
+
typeof longForm === "boolean" &&
|
|
678
|
+
!!longFormDescriptor &&
|
|
679
|
+
"value" in longFormDescriptor &&
|
|
680
|
+
longFormDescriptor.writable === true &&
|
|
681
|
+
!!lengthDescriptor &&
|
|
682
|
+
"value" in lengthDescriptor &&
|
|
683
|
+
lengthDescriptor.writable === true &&
|
|
684
|
+
typeof length === "number" &&
|
|
685
|
+
Number.isSafeInteger(length) &&
|
|
686
|
+
length >= 0);
|
|
687
|
+
}
|
|
688
|
+
function validBaseBlock(block, isConstructed, registry) {
|
|
689
|
+
const idBlock = dataProperty(block, "idBlock");
|
|
690
|
+
const lenBlock = dataProperty(block, "lenBlock");
|
|
691
|
+
return (!!idBlock &&
|
|
692
|
+
!!lenBlock &&
|
|
693
|
+
validIdBlock(idBlock, isConstructed, registry) &&
|
|
694
|
+
validLengthBlock(lenBlock, isConstructed, registry));
|
|
695
|
+
}
|
|
696
|
+
function constructedChild(block, registry) {
|
|
697
|
+
const valueBlock = dataProperty(block, "valueBlock");
|
|
698
|
+
if (!valueBlock || Object.getPrototypeOf(valueBlock) !== registry.LocalConstructedValueBlock.prototype)
|
|
699
|
+
return undefined;
|
|
700
|
+
if (!prototypeMethod(valueBlock, registry.LocalConstructedValueBlock.prototype, "toBER", registry.originalConstructedToBER))
|
|
701
|
+
return undefined;
|
|
702
|
+
const values = dataProperty(valueBlock, "value");
|
|
703
|
+
if (!Array.isArray(values) || Object.getPrototypeOf(values) !== Array.prototype)
|
|
704
|
+
return undefined;
|
|
705
|
+
const lengthDescriptor = Object.getOwnPropertyDescriptor(values, "length");
|
|
706
|
+
if (!lengthDescriptor || !("value" in lengthDescriptor) || lengthDescriptor.value !== 1)
|
|
707
|
+
return undefined;
|
|
708
|
+
if (Object.prototype.hasOwnProperty.call(values, Symbol.iterator))
|
|
709
|
+
return undefined;
|
|
710
|
+
const iteratorDescriptor = Object.getOwnPropertyDescriptor(Array.prototype, Symbol.iterator);
|
|
711
|
+
if (!iteratorDescriptor || !("value" in iteratorDescriptor) || iteratorDescriptor.value !== originalArrayIterator)
|
|
712
|
+
return undefined;
|
|
713
|
+
const indexDescriptor = Object.getOwnPropertyDescriptor(values, "0");
|
|
714
|
+
if (!indexDescriptor || !("value" in indexDescriptor))
|
|
715
|
+
return undefined;
|
|
716
|
+
if (Object.getOwnPropertyNames(values).length !== 2)
|
|
717
|
+
return undefined;
|
|
718
|
+
return indexDescriptor.value;
|
|
719
|
+
}
|
|
720
|
+
function bitPayload(block, registry) {
|
|
721
|
+
const valueBlock = dataProperty(block, "valueBlock");
|
|
722
|
+
if (!valueBlock || Object.getPrototypeOf(valueBlock) !== registry.LocalBitStringValueBlock.prototype)
|
|
723
|
+
return undefined;
|
|
724
|
+
if (!prototypeMethod(valueBlock, registry.LocalBitStringValueBlock.prototype, "toBER", registry.originalBitStringToBER))
|
|
725
|
+
return undefined;
|
|
726
|
+
if (dataProperty(valueBlock, "isConstructed") !== false)
|
|
727
|
+
return undefined;
|
|
728
|
+
const unusedBits = dataProperty(valueBlock, "unusedBits");
|
|
729
|
+
if (typeof unusedBits !== "number" || !Number.isInteger(unusedBits) || unusedBits < 0 || unusedBits > 7)
|
|
730
|
+
return undefined;
|
|
731
|
+
const payload = plainPayload(dataProperty(valueBlock, "valueHexView"), true);
|
|
732
|
+
if (!payload)
|
|
733
|
+
return undefined;
|
|
734
|
+
return { payload, prefix: Uint8Array.of(payload.byteLength ? unusedBits : 0) };
|
|
735
|
+
}
|
|
736
|
+
function primitivePayload(block, kind, registry) {
|
|
737
|
+
const valueBlock = dataProperty(block, "valueBlock");
|
|
738
|
+
if (!valueBlock)
|
|
739
|
+
return undefined;
|
|
740
|
+
if (kind === "integer") {
|
|
741
|
+
if (Object.getPrototypeOf(valueBlock) !== registry.LocalIntegerValueBlock.prototype)
|
|
742
|
+
return undefined;
|
|
743
|
+
if (!prototypeMethod(valueBlock, registry.LocalIntegerValueBlock.prototype, "toBER", registry.originalIntegerToBER))
|
|
744
|
+
return undefined;
|
|
745
|
+
}
|
|
746
|
+
else if (kind === "octet") {
|
|
747
|
+
if (Object.getPrototypeOf(valueBlock) !== registry.LocalOctetStringValueBlock.prototype)
|
|
748
|
+
return undefined;
|
|
749
|
+
if (!prototypeMethod(valueBlock, registry.LocalOctetStringValueBlock.prototype, "toBER", registry.originalOctetStringToBER))
|
|
750
|
+
return undefined;
|
|
751
|
+
if (dataProperty(valueBlock, "isConstructed") !== false)
|
|
752
|
+
return undefined;
|
|
753
|
+
}
|
|
754
|
+
else {
|
|
755
|
+
if (Object.getPrototypeOf(valueBlock) !== registry.LocalPrimitiveValueBlock.prototype)
|
|
756
|
+
return undefined;
|
|
757
|
+
if (!inheritedMethod(valueBlock, "toBER", registry.originalPrimitiveToBER, registry.LocalPrimitiveValueBlock))
|
|
758
|
+
return undefined;
|
|
759
|
+
}
|
|
760
|
+
if (kind === "primitive" && dataProperty(valueBlock, "isHexOnly") !== true)
|
|
761
|
+
return undefined;
|
|
762
|
+
if (typeof dataProperty(valueBlock, "isHexOnly") !== "boolean")
|
|
763
|
+
return undefined;
|
|
764
|
+
return plainPayload(dataProperty(valueBlock, "valueHexView"));
|
|
765
|
+
}
|
|
766
|
+
function validOuterMethod(block, registry) {
|
|
767
|
+
if (Object.prototype.hasOwnProperty.call(block, "toBER"))
|
|
768
|
+
return false;
|
|
769
|
+
let prototype = block;
|
|
770
|
+
while (prototype) {
|
|
771
|
+
const descriptor = Object.getOwnPropertyDescriptor(prototype, "toBER");
|
|
772
|
+
if (descriptor)
|
|
773
|
+
return "value" in descriptor && descriptor.value === registry.originalBaseBlockToBER;
|
|
774
|
+
prototype = Object.getPrototypeOf(prototype);
|
|
775
|
+
}
|
|
776
|
+
return false;
|
|
777
|
+
}
|
|
778
|
+
function isPrimitive(block, type, registry) {
|
|
779
|
+
const constructor = registry[type];
|
|
780
|
+
return !!constructor && Object.getPrototypeOf(block) === constructor.prototype;
|
|
781
|
+
}
|
|
782
|
+
function isConstructed(block, registry) {
|
|
783
|
+
return (Object.getPrototypeOf(block) === registry.Sequence.prototype ||
|
|
784
|
+
Object.getPrototypeOf(block) === registry.Set.prototype ||
|
|
785
|
+
Object.getPrototypeOf(block) === registry.Constructed.prototype);
|
|
786
|
+
}
|
|
787
|
+
function inspectNode(block, depth, registry) {
|
|
788
|
+
if (depth > BUILTIN_DISPATCH_MAX_DEPTH || !block || typeof block !== "object")
|
|
789
|
+
return undefined;
|
|
790
|
+
try {
|
|
791
|
+
if (!validOuterMethod(block, registry))
|
|
792
|
+
return undefined;
|
|
793
|
+
const primitiveKind = isPrimitive(block, "BitString", registry)
|
|
794
|
+
? "bit"
|
|
795
|
+
: isPrimitive(block, "Integer", registry)
|
|
796
|
+
? "integer"
|
|
797
|
+
: isPrimitive(block, "OctetString", registry)
|
|
798
|
+
? "octet"
|
|
799
|
+
: isPrimitive(block, "Primitive", registry)
|
|
800
|
+
? "primitive"
|
|
801
|
+
: undefined;
|
|
802
|
+
const constructed = primitiveKind === undefined && isConstructed(block, registry);
|
|
803
|
+
if (!primitiveKind && !constructed)
|
|
804
|
+
return undefined;
|
|
805
|
+
if (!validBaseBlock(block, constructed, registry))
|
|
806
|
+
return undefined;
|
|
807
|
+
const idBlock = dataProperty(block, "idBlock");
|
|
808
|
+
const lenBlock = dataProperty(block, "lenBlock");
|
|
809
|
+
if (!idBlock || !lenBlock)
|
|
810
|
+
return undefined;
|
|
811
|
+
if (primitiveKind) {
|
|
812
|
+
const bit = primitiveKind === "bit" ? bitPayload(block, registry) : undefined;
|
|
813
|
+
const payload = primitiveKind === "bit" ? bit === null || bit === void 0 ? void 0 : bit.payload : primitivePayload(block, primitiveKind, registry);
|
|
814
|
+
return payload
|
|
815
|
+
? { block, kind: primitiveKind, idBlock, lenBlock, indefinite: false, payload, prefix: bit === null || bit === void 0 ? void 0 : bit.prefix }
|
|
816
|
+
: undefined;
|
|
817
|
+
}
|
|
818
|
+
const child = constructedChild(block, registry);
|
|
819
|
+
const validatedChild = child && inspectNode(child, depth + 1, registry);
|
|
820
|
+
const indefinite = dataProperty(lenBlock, "isIndefiniteForm");
|
|
821
|
+
return validatedChild
|
|
822
|
+
? { block, kind: "constructed", idBlock, lenBlock, indefinite: indefinite === true, child: validatedChild }
|
|
823
|
+
: undefined;
|
|
824
|
+
}
|
|
825
|
+
catch {
|
|
826
|
+
return undefined;
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
function buildNode(node, sizeOnly, registry) {
|
|
830
|
+
var _a, _b;
|
|
831
|
+
const id = Reflect.apply(registry.originalIdentificationToBER, node.idBlock, [sizeOnly]);
|
|
832
|
+
if (!(id instanceof ArrayBuffer) || id.byteLength === 0)
|
|
833
|
+
throw TypeError("Built-in identifier encoding failed");
|
|
834
|
+
let payload;
|
|
835
|
+
if (node.kind === "constructed") {
|
|
836
|
+
payload = buildNode(node.child, sizeOnly, registry);
|
|
837
|
+
}
|
|
838
|
+
else {
|
|
839
|
+
payload = node.payload;
|
|
840
|
+
}
|
|
841
|
+
const length = (payload instanceof Uint8Array ? payload.byteLength : payload.total) + ((_b = (_a = node.prefix) === null || _a === void 0 ? void 0 : _a.byteLength) !== null && _b !== void 0 ? _b : 0);
|
|
842
|
+
let len;
|
|
843
|
+
if (node.indefinite) {
|
|
844
|
+
len = Uint8Array.of(0x80).buffer;
|
|
845
|
+
}
|
|
846
|
+
else {
|
|
847
|
+
node.lenBlock.length = length;
|
|
848
|
+
len = Reflect.apply(registry.originalLengthToBER, node.lenBlock, [sizeOnly]);
|
|
849
|
+
if (!(len instanceof ArrayBuffer) || len.byteLength === 0)
|
|
850
|
+
throw TypeError("Built-in length encoding failed");
|
|
851
|
+
}
|
|
852
|
+
const total = id.byteLength + len.byteLength + length + (node.indefinite ? 2 : 0);
|
|
853
|
+
if (!Number.isSafeInteger(total))
|
|
854
|
+
throw RangeError("Built-in encoding is too large");
|
|
855
|
+
return { id, len, payload, length, total, indefinite: node.indefinite, prefix: node.prefix };
|
|
856
|
+
}
|
|
857
|
+
function flatten(node, output, offset, sizeOnly) {
|
|
858
|
+
output.set(new Uint8Array(node.id), offset);
|
|
859
|
+
offset += node.id.byteLength;
|
|
860
|
+
output.set(new Uint8Array(node.len), offset);
|
|
861
|
+
offset += node.len.byteLength;
|
|
862
|
+
if (node.prefix) {
|
|
863
|
+
if (!sizeOnly)
|
|
864
|
+
output.set(node.prefix, offset);
|
|
865
|
+
offset += node.prefix.byteLength;
|
|
866
|
+
}
|
|
867
|
+
if (node.payload instanceof Uint8Array) {
|
|
868
|
+
if (!sizeOnly)
|
|
869
|
+
output.set(node.payload, offset);
|
|
870
|
+
offset += node.payload.byteLength;
|
|
871
|
+
}
|
|
872
|
+
else {
|
|
873
|
+
offset = flatten(node.payload, output, offset, sizeOnly);
|
|
874
|
+
}
|
|
875
|
+
if (node.indefinite)
|
|
876
|
+
offset += 2;
|
|
877
|
+
return offset;
|
|
878
|
+
}
|
|
879
|
+
function tryEncodeBuiltin(block, sizeOnly = false) {
|
|
880
|
+
const registry = builtinRegistry;
|
|
881
|
+
if (!registry || !writerMethodsStable(registry))
|
|
882
|
+
return undefined;
|
|
883
|
+
const validated = inspectNode(block, 0, registry);
|
|
884
|
+
if (!validated)
|
|
885
|
+
return undefined;
|
|
886
|
+
const node = buildNode(validated, sizeOnly, registry);
|
|
887
|
+
const output = new Uint8Array(node.total);
|
|
888
|
+
flatten(node, output, 0, sizeOnly);
|
|
889
|
+
return output.buffer;
|
|
890
|
+
}
|
|
891
|
+
|
|
470
892
|
class BaseBlock extends LocalBaseBlock {
|
|
471
893
|
constructor({ name = EMPTY_STRING, optional = false, primitiveSchema, ...parameters } = {}, valueBlockType) {
|
|
472
894
|
super(parameters);
|
|
@@ -480,9 +902,7 @@ class BaseBlock extends LocalBaseBlock {
|
|
|
480
902
|
this.valueBlock = valueBlockType ? new valueBlockType(parameters) : new ValueBlock(parameters);
|
|
481
903
|
}
|
|
482
904
|
fromBER(inputBuffer, inputOffset, inputLength, context) {
|
|
483
|
-
const resultOffset = this.valueBlock.fromBER(inputBuffer, inputOffset,
|
|
484
|
-
? inputLength
|
|
485
|
-
: this.lenBlock.length, context);
|
|
905
|
+
const resultOffset = this.valueBlock.fromBER(inputBuffer, inputOffset, this.lenBlock.isIndefiniteForm ? inputLength : this.lenBlock.length, context);
|
|
486
906
|
if (resultOffset === -1) {
|
|
487
907
|
this.error = this.valueBlock.error;
|
|
488
908
|
return resultOffset;
|
|
@@ -499,6 +919,13 @@ class BaseBlock extends LocalBaseBlock {
|
|
|
499
919
|
const _writer = writer || new ViewWriter();
|
|
500
920
|
if (!writer) {
|
|
501
921
|
prepareIndefiniteForm(this);
|
|
922
|
+
if (sizeOnly === true || sizeOnly === false || sizeOnly === undefined) {
|
|
923
|
+
if (shouldUseBuiltinEncoder(this)) {
|
|
924
|
+
const encoded = tryEncodeBuiltin(this, sizeOnly === true);
|
|
925
|
+
if (encoded)
|
|
926
|
+
return encoded;
|
|
927
|
+
}
|
|
928
|
+
}
|
|
502
929
|
}
|
|
503
930
|
const idBlockBuf = this.idBlock.toBER(sizeOnly);
|
|
504
931
|
_writer.write(idBlockBuf);
|
|
@@ -526,7 +953,7 @@ class BaseBlock extends LocalBaseBlock {
|
|
|
526
953
|
lenBlock: this.lenBlock.toJSON(),
|
|
527
954
|
valueBlock: this.valueBlock.toJSON(),
|
|
528
955
|
name: this.name,
|
|
529
|
-
optional: this.optional
|
|
956
|
+
optional: this.optional
|
|
530
957
|
};
|
|
531
958
|
if (this.primitiveSchema)
|
|
532
959
|
object.primitiveSchema = this.primitiveSchema.toJSON();
|
|
@@ -556,6 +983,7 @@ class BaseBlock extends LocalBaseBlock {
|
|
|
556
983
|
}
|
|
557
984
|
}
|
|
558
985
|
BaseBlock.NAME = "BaseBlock";
|
|
986
|
+
const ORIGINAL_BASE_BLOCK_TO_BER = BaseBlock.prototype.toBER;
|
|
559
987
|
function prepareIndefiniteForm(baseBlock) {
|
|
560
988
|
var _a;
|
|
561
989
|
if (baseBlock instanceof typeStore.Constructed) {
|
|
@@ -582,9 +1010,7 @@ class BaseStringBlock extends BaseBlock {
|
|
|
582
1010
|
}
|
|
583
1011
|
}
|
|
584
1012
|
fromBER(inputBuffer, inputOffset, inputLength) {
|
|
585
|
-
const resultOffset = this.valueBlock.fromBER(inputBuffer, inputOffset,
|
|
586
|
-
? inputLength
|
|
587
|
-
: this.lenBlock.length);
|
|
1013
|
+
const resultOffset = this.valueBlock.fromBER(inputBuffer, inputOffset, this.lenBlock.isIndefiniteForm ? inputLength : this.lenBlock.length);
|
|
588
1014
|
if (resultOffset === -1) {
|
|
589
1015
|
this.error = this.valueBlock.error;
|
|
590
1016
|
return resultOffset;
|
|
@@ -604,6 +1030,7 @@ class BaseStringBlock extends BaseBlock {
|
|
|
604
1030
|
}
|
|
605
1031
|
BaseStringBlock.NAME = "BaseStringBlock";
|
|
606
1032
|
|
|
1033
|
+
var _a$x;
|
|
607
1034
|
class LocalPrimitiveValueBlock extends HexBlock(ValueBlock) {
|
|
608
1035
|
constructor({ isHexOnly = true, ...parameters } = {}) {
|
|
609
1036
|
super(parameters);
|
|
@@ -611,6 +1038,7 @@ class LocalPrimitiveValueBlock extends HexBlock(ValueBlock) {
|
|
|
611
1038
|
}
|
|
612
1039
|
}
|
|
613
1040
|
LocalPrimitiveValueBlock.NAME = "PrimitiveValueBlock";
|
|
1041
|
+
const ORIGINAL_LOCAL_PRIMITIVE_TO_BER = (_a$x = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(LocalPrimitiveValueBlock.prototype), "toBER")) === null || _a$x === void 0 ? void 0 : _a$x.value;
|
|
614
1042
|
|
|
615
1043
|
var _a$w;
|
|
616
1044
|
class Primitive extends BaseBlock {
|
|
@@ -625,6 +1053,101 @@ _a$w = Primitive;
|
|
|
625
1053
|
})();
|
|
626
1054
|
Primitive.NAME = "PRIMITIVE";
|
|
627
1055
|
|
|
1056
|
+
let fastParserRegistry;
|
|
1057
|
+
function registerFastParser(constructors) {
|
|
1058
|
+
fastParserRegistry = {
|
|
1059
|
+
Integer: constructors.Integer,
|
|
1060
|
+
Null: constructors.Null,
|
|
1061
|
+
Sequence: constructors.Sequence
|
|
1062
|
+
};
|
|
1063
|
+
}
|
|
1064
|
+
function fastParserContext(context) {
|
|
1065
|
+
const nodes = Object.getOwnPropertyDescriptor(context, "nodesCount");
|
|
1066
|
+
const maxNodes = Object.getOwnPropertyDescriptor(context, "maxNodes");
|
|
1067
|
+
const maxContentLength = Object.getOwnPropertyDescriptor(context, "maxContentLength");
|
|
1068
|
+
if (!nodes || !("value" in nodes) || nodes.writable !== true)
|
|
1069
|
+
return false;
|
|
1070
|
+
if (!maxNodes || !("value" in maxNodes) || !maxContentLength || !("value" in maxContentLength))
|
|
1071
|
+
return false;
|
|
1072
|
+
return (typeof nodes.value === "number" &&
|
|
1073
|
+
Number.isSafeInteger(nodes.value) &&
|
|
1074
|
+
nodes.value >= 0 &&
|
|
1075
|
+
typeof maxNodes.value === "number" &&
|
|
1076
|
+
Number.isSafeInteger(maxNodes.value) &&
|
|
1077
|
+
maxNodes.value >= 0 &&
|
|
1078
|
+
typeof maxContentLength.value === "number" &&
|
|
1079
|
+
Number.isSafeInteger(maxContentLength.value) &&
|
|
1080
|
+
maxContentLength.value >= 0 &&
|
|
1081
|
+
nodes.value < maxNodes.value);
|
|
1082
|
+
}
|
|
1083
|
+
function fastParserType(store, name, value) {
|
|
1084
|
+
const descriptor = Object.getOwnPropertyDescriptor(store, name);
|
|
1085
|
+
return !!descriptor && "value" in descriptor && descriptor.value === value;
|
|
1086
|
+
}
|
|
1087
|
+
function tryFastFromBER(inputBuffer, inputOffset, inputLength, context) {
|
|
1088
|
+
const registry = fastParserRegistry;
|
|
1089
|
+
if (!registry)
|
|
1090
|
+
return undefined;
|
|
1091
|
+
let Constructor;
|
|
1092
|
+
let length = 0;
|
|
1093
|
+
try {
|
|
1094
|
+
if (Object.getPrototypeOf(inputBuffer) !== Uint8Array.prototype)
|
|
1095
|
+
return undefined;
|
|
1096
|
+
if (!Number.isSafeInteger(inputOffset) ||
|
|
1097
|
+
inputOffset < 0 ||
|
|
1098
|
+
!Number.isSafeInteger(inputLength) ||
|
|
1099
|
+
inputLength < 2) {
|
|
1100
|
+
return undefined;
|
|
1101
|
+
}
|
|
1102
|
+
if (inputOffset > inputBuffer.byteLength || inputLength > inputBuffer.byteLength - inputOffset)
|
|
1103
|
+
return undefined;
|
|
1104
|
+
const tag = inputBuffer[inputOffset];
|
|
1105
|
+
if (tag !== 0x02 && tag !== 0x05 && tag !== 0x30)
|
|
1106
|
+
return undefined;
|
|
1107
|
+
length = inputBuffer[inputOffset + 1];
|
|
1108
|
+
if (length >= 0x80 || length > inputLength - 2)
|
|
1109
|
+
return undefined;
|
|
1110
|
+
if (tag === 0x05 && length !== 0)
|
|
1111
|
+
return undefined;
|
|
1112
|
+
if (!fastParserContext(context))
|
|
1113
|
+
return undefined;
|
|
1114
|
+
if (length > Object.getOwnPropertyDescriptor(context, "maxContentLength").value) {
|
|
1115
|
+
return undefined;
|
|
1116
|
+
}
|
|
1117
|
+
const constructorName = tag === 0x02 ? "Integer" : tag === 0x05 ? "Null" : "Sequence";
|
|
1118
|
+
Constructor = registry[constructorName];
|
|
1119
|
+
if (!fastParserType(typeStore, constructorName, Constructor))
|
|
1120
|
+
return undefined;
|
|
1121
|
+
const identificationFromBER = Object.getOwnPropertyDescriptor(LocalIdentificationBlock.prototype, "fromBER");
|
|
1122
|
+
const lengthFromBER = Object.getOwnPropertyDescriptor(LocalLengthBlock.prototype, "fromBER");
|
|
1123
|
+
if (!identificationFromBER ||
|
|
1124
|
+
!("value" in identificationFromBER) ||
|
|
1125
|
+
identificationFromBER.value !== ORIGINAL_LOCAL_IDENTIFICATION_FROM_BER ||
|
|
1126
|
+
!lengthFromBER ||
|
|
1127
|
+
!("value" in lengthFromBER) ||
|
|
1128
|
+
lengthFromBER.value !== ORIGINAL_LOCAL_LENGTH_FROM_BER)
|
|
1129
|
+
return undefined;
|
|
1130
|
+
}
|
|
1131
|
+
catch {
|
|
1132
|
+
return undefined;
|
|
1133
|
+
}
|
|
1134
|
+
if (!Constructor)
|
|
1135
|
+
return undefined;
|
|
1136
|
+
const result = new Constructor();
|
|
1137
|
+
result.idBlock.tagClass = 1;
|
|
1138
|
+
result.idBlock.tagNumber = inputBuffer[inputOffset] & 0x1f;
|
|
1139
|
+
result.idBlock.isConstructed = inputBuffer[inputOffset] === 0x30;
|
|
1140
|
+
result.idBlock.isHexOnly = false;
|
|
1141
|
+
result.idBlock.blockLength = 1;
|
|
1142
|
+
result.lenBlock.isIndefiniteForm = false;
|
|
1143
|
+
result.lenBlock.longFormUsed = false;
|
|
1144
|
+
result.lenBlock.length = length;
|
|
1145
|
+
result.lenBlock.blockLength = 1;
|
|
1146
|
+
context.nodesCount += 1;
|
|
1147
|
+
const resultOffset = result.fromBER(inputBuffer, inputOffset + 2, length, context);
|
|
1148
|
+
result.valueBeforeDecodeView = inputBuffer.subarray(inputOffset, inputOffset + result.blockLength);
|
|
1149
|
+
return { offset: resultOffset, result };
|
|
1150
|
+
}
|
|
628
1151
|
const DEFAULT_MAX_DEPTH = 100;
|
|
629
1152
|
const DEFAULT_MAX_NODES = 10000;
|
|
630
1153
|
const DEFAULT_MAX_CONTENT_LENGTH = 16 * 1024 * 1024;
|
|
@@ -632,13 +1155,14 @@ const MAX_DEPTH_EXCEEDED_ERROR = "Maximum ASN.1 nesting depth exceeded";
|
|
|
632
1155
|
const MAX_NODES_EXCEEDED_ERROR = "Maximum ASN.1 node count exceeded";
|
|
633
1156
|
const MAX_CONTENT_LENGTH_EXCEEDED_ERROR = "Maximum ASN.1 content length exceeded";
|
|
634
1157
|
function createFromBerContext(options = {}) {
|
|
635
|
-
var _a, _b, _c;
|
|
1158
|
+
var _a, _b, _c, _d;
|
|
636
1159
|
return {
|
|
637
1160
|
depth: 0,
|
|
638
1161
|
maxDepth: (_a = options.maxDepth) !== null && _a !== void 0 ? _a : DEFAULT_MAX_DEPTH,
|
|
639
1162
|
nodesCount: 0,
|
|
640
1163
|
maxNodes: (_b = options.maxNodes) !== null && _b !== void 0 ? _b : DEFAULT_MAX_NODES,
|
|
641
1164
|
maxContentLength: (_c = options.maxContentLength) !== null && _c !== void 0 ? _c : DEFAULT_MAX_CONTENT_LENGTH,
|
|
1165
|
+
parseEmbedded: (_d = options.parseEmbedded) !== null && _d !== void 0 ? _d : true
|
|
642
1166
|
};
|
|
643
1167
|
}
|
|
644
1168
|
function createErrorResult(error) {
|
|
@@ -646,7 +1170,7 @@ function createErrorResult(error) {
|
|
|
646
1170
|
result.error = error;
|
|
647
1171
|
return {
|
|
648
1172
|
offset: -1,
|
|
649
|
-
result
|
|
1173
|
+
result
|
|
650
1174
|
};
|
|
651
1175
|
}
|
|
652
1176
|
function checkNodesLimit(context) {
|
|
@@ -687,22 +1211,23 @@ function localChangeType(inputObject, newType) {
|
|
|
687
1211
|
return newObject;
|
|
688
1212
|
}
|
|
689
1213
|
function localFromBER(inputBuffer, inputOffset = 0, inputLength = inputBuffer.length, context = createFromBerContext()) {
|
|
1214
|
+
const fastResult = tryFastFromBER(inputBuffer, inputOffset, inputLength, context);
|
|
1215
|
+
if (fastResult)
|
|
1216
|
+
return fastResult;
|
|
690
1217
|
const incomingOffset = inputOffset;
|
|
691
1218
|
let returnObject = new BaseBlock({}, ValueBlock);
|
|
692
|
-
|
|
693
|
-
if (!checkBufferParams(baseBlock, inputBuffer, inputOffset, inputLength)) {
|
|
694
|
-
returnObject.error = baseBlock.error;
|
|
1219
|
+
if (!checkBufferParams(returnObject, inputBuffer, inputOffset, inputLength)) {
|
|
695
1220
|
return {
|
|
696
1221
|
offset: -1,
|
|
697
|
-
result: returnObject
|
|
1222
|
+
result: returnObject
|
|
698
1223
|
};
|
|
699
1224
|
}
|
|
700
|
-
const
|
|
701
|
-
if (
|
|
1225
|
+
const fastArgs = Number.isInteger(inputOffset) && Number.isInteger(inputLength);
|
|
1226
|
+
if (fastArgs ? inputLength === 0 : inputBuffer.subarray(inputOffset, inputOffset + inputLength).length === 0) {
|
|
702
1227
|
returnObject.error = "Zero buffer length";
|
|
703
1228
|
return {
|
|
704
1229
|
offset: -1,
|
|
705
|
-
result: returnObject
|
|
1230
|
+
result: returnObject
|
|
706
1231
|
};
|
|
707
1232
|
}
|
|
708
1233
|
const nodesLimitError = checkNodesLimit(context);
|
|
@@ -710,7 +1235,7 @@ function localFromBER(inputBuffer, inputOffset = 0, inputLength = inputBuffer.le
|
|
|
710
1235
|
returnObject.error = nodesLimitError;
|
|
711
1236
|
return {
|
|
712
1237
|
offset: -1,
|
|
713
|
-
result: returnObject
|
|
1238
|
+
result: returnObject
|
|
714
1239
|
};
|
|
715
1240
|
}
|
|
716
1241
|
let resultOffset = returnObject.idBlock.fromBER(inputBuffer, inputOffset, inputLength);
|
|
@@ -721,7 +1246,7 @@ function localFromBER(inputBuffer, inputOffset = 0, inputLength = inputBuffer.le
|
|
|
721
1246
|
returnObject.error = returnObject.idBlock.error;
|
|
722
1247
|
return {
|
|
723
1248
|
offset: -1,
|
|
724
|
-
result: returnObject
|
|
1249
|
+
result: returnObject
|
|
725
1250
|
};
|
|
726
1251
|
}
|
|
727
1252
|
inputOffset = resultOffset;
|
|
@@ -734,7 +1259,7 @@ function localFromBER(inputBuffer, inputOffset = 0, inputLength = inputBuffer.le
|
|
|
734
1259
|
returnObject.error = returnObject.lenBlock.error;
|
|
735
1260
|
return {
|
|
736
1261
|
offset: -1,
|
|
737
|
-
result: returnObject
|
|
1262
|
+
result: returnObject
|
|
738
1263
|
};
|
|
739
1264
|
}
|
|
740
1265
|
inputOffset = resultOffset;
|
|
@@ -745,36 +1270,33 @@ function localFromBER(inputBuffer, inputOffset = 0, inputLength = inputBuffer.le
|
|
|
745
1270
|
returnObject.error = contentLengthError;
|
|
746
1271
|
return {
|
|
747
1272
|
offset: -1,
|
|
748
|
-
result: returnObject
|
|
1273
|
+
result: returnObject
|
|
749
1274
|
};
|
|
750
1275
|
}
|
|
751
|
-
if (!returnObject.idBlock.isConstructed
|
|
752
|
-
&& returnObject.lenBlock.isIndefiniteForm) {
|
|
1276
|
+
if (!returnObject.idBlock.isConstructed && returnObject.lenBlock.isIndefiniteForm) {
|
|
753
1277
|
returnObject.error = "Indefinite length form used for primitive encoding form";
|
|
754
1278
|
return {
|
|
755
1279
|
offset: -1,
|
|
756
|
-
result: returnObject
|
|
1280
|
+
result: returnObject
|
|
757
1281
|
};
|
|
758
1282
|
}
|
|
759
1283
|
let newASN1Type = BaseBlock;
|
|
760
1284
|
switch (returnObject.idBlock.tagClass) {
|
|
761
1285
|
case 1:
|
|
762
|
-
if (
|
|
763
|
-
&& (returnObject.idBlock.isHexOnly === false)) {
|
|
1286
|
+
if (returnObject.idBlock.tagNumber >= 37 && returnObject.idBlock.isHexOnly === false) {
|
|
764
1287
|
returnObject.error = "UNIVERSAL 37 and upper tags are reserved by ASN.1 standard";
|
|
765
1288
|
return {
|
|
766
1289
|
offset: -1,
|
|
767
|
-
result: returnObject
|
|
1290
|
+
result: returnObject
|
|
768
1291
|
};
|
|
769
1292
|
}
|
|
770
1293
|
switch (returnObject.idBlock.tagNumber) {
|
|
771
1294
|
case 0:
|
|
772
|
-
if (
|
|
773
|
-
&& (returnObject.lenBlock.length > 0)) {
|
|
1295
|
+
if (returnObject.idBlock.isConstructed && returnObject.lenBlock.length > 0) {
|
|
774
1296
|
returnObject.error = "Type [UNIVERSAL 0] is reserved";
|
|
775
1297
|
return {
|
|
776
1298
|
offset: -1,
|
|
777
|
-
result: returnObject
|
|
1299
|
+
result: returnObject
|
|
778
1300
|
};
|
|
779
1301
|
}
|
|
780
1302
|
newASN1Type = typeStore.EndOfContent;
|
|
@@ -813,7 +1335,7 @@ function localFromBER(inputBuffer, inputOffset = 0, inputLength = inputBuffer.le
|
|
|
813
1335
|
returnObject.error = "[UNIVERSAL 15] is reserved by ASN.1 standard";
|
|
814
1336
|
return {
|
|
815
1337
|
offset: -1,
|
|
816
|
-
result: returnObject
|
|
1338
|
+
result: returnObject
|
|
817
1339
|
};
|
|
818
1340
|
case 16:
|
|
819
1341
|
newASN1Type = typeStore.Sequence;
|
|
@@ -887,9 +1409,7 @@ function localFromBER(inputBuffer, inputOffset = 0, inputLength = inputBuffer.le
|
|
|
887
1409
|
case 3:
|
|
888
1410
|
case 4:
|
|
889
1411
|
default: {
|
|
890
|
-
newASN1Type = returnObject.idBlock.isConstructed
|
|
891
|
-
? typeStore.Constructed
|
|
892
|
-
: typeStore.Primitive;
|
|
1412
|
+
newASN1Type = returnObject.idBlock.isConstructed ? typeStore.Constructed : typeStore.Primitive;
|
|
893
1413
|
}
|
|
894
1414
|
}
|
|
895
1415
|
returnObject = localChangeType(returnObject, newASN1Type);
|
|
@@ -897,7 +1417,7 @@ function localFromBER(inputBuffer, inputOffset = 0, inputLength = inputBuffer.le
|
|
|
897
1417
|
returnObject.valueBeforeDecodeView = inputBuffer.subarray(incomingOffset, incomingOffset + returnObject.blockLength);
|
|
898
1418
|
return {
|
|
899
1419
|
offset: resultOffset,
|
|
900
|
-
result: returnObject
|
|
1420
|
+
result: returnObject
|
|
901
1421
|
};
|
|
902
1422
|
}
|
|
903
1423
|
function fromBER(inputBuffer, options = {}) {
|
|
@@ -906,10 +1426,12 @@ function fromBER(inputBuffer, options = {}) {
|
|
|
906
1426
|
result.error = "Input buffer has zero length";
|
|
907
1427
|
return {
|
|
908
1428
|
offset: -1,
|
|
909
|
-
result
|
|
1429
|
+
result
|
|
910
1430
|
};
|
|
911
1431
|
}
|
|
912
|
-
|
|
1432
|
+
const inputView = pvtsutils.BufferSourceConverter.toUint8Array(inputBuffer);
|
|
1433
|
+
const normalizedInput = options.copyInput === false ? inputView : inputView.slice();
|
|
1434
|
+
return localFromBER(normalizedInput, 0, inputBuffer.byteLength, createFromBerContext(options));
|
|
913
1435
|
}
|
|
914
1436
|
|
|
915
1437
|
function checkLen(indefiniteLength, length) {
|
|
@@ -975,7 +1497,7 @@ class LocalConstructedValueBlock extends ValueBlock {
|
|
|
975
1497
|
const object = {
|
|
976
1498
|
...super.toJSON(),
|
|
977
1499
|
isIndefiniteForm: this.isIndefiniteForm,
|
|
978
|
-
value: []
|
|
1500
|
+
value: []
|
|
979
1501
|
};
|
|
980
1502
|
for (const value of this.value) {
|
|
981
1503
|
object.value.push(value.toJSON());
|
|
@@ -984,6 +1506,7 @@ class LocalConstructedValueBlock extends ValueBlock {
|
|
|
984
1506
|
}
|
|
985
1507
|
}
|
|
986
1508
|
LocalConstructedValueBlock.NAME = "ConstructedValueBlock";
|
|
1509
|
+
const ORIGINAL_LOCAL_CONSTRUCTED_TO_BER = LocalConstructedValueBlock.prototype.toBER;
|
|
987
1510
|
|
|
988
1511
|
var _a$v;
|
|
989
1512
|
class Constructed extends BaseBlock {
|
|
@@ -993,7 +1516,7 @@ class Constructed extends BaseBlock {
|
|
|
993
1516
|
}
|
|
994
1517
|
fromBER(inputBuffer, inputOffset, inputLength, context) {
|
|
995
1518
|
this.valueBlock.isIndefiniteForm = this.lenBlock.isIndefiniteForm;
|
|
996
|
-
const resultOffset = this.valueBlock.fromBER(inputBuffer, inputOffset,
|
|
1519
|
+
const resultOffset = this.valueBlock.fromBER(inputBuffer, inputOffset, this.lenBlock.isIndefiniteForm ? inputLength : this.lenBlock.length, context);
|
|
997
1520
|
if (resultOffset === -1) {
|
|
998
1521
|
this.error = this.valueBlock.error;
|
|
999
1522
|
return resultOffset;
|
|
@@ -1009,11 +1532,13 @@ class Constructed extends BaseBlock {
|
|
|
1009
1532
|
onAsciiEncoding() {
|
|
1010
1533
|
const values = [];
|
|
1011
1534
|
for (const value of this.valueBlock.value) {
|
|
1012
|
-
values.push(value
|
|
1535
|
+
values.push(value
|
|
1536
|
+
.toString("ascii")
|
|
1537
|
+
.split("\n")
|
|
1538
|
+
.map(o => ` ${o}`)
|
|
1539
|
+
.join("\n"));
|
|
1013
1540
|
}
|
|
1014
|
-
const blockName = this.idBlock.tagClass === 3
|
|
1015
|
-
? `[${this.idBlock.tagNumber}]`
|
|
1016
|
-
: this.constructor.NAME;
|
|
1541
|
+
const blockName = this.idBlock.tagClass === 3 ? `[${this.idBlock.tagNumber}]` : this.constructor.NAME;
|
|
1017
1542
|
return values.length
|
|
1018
1543
|
? `${blockName} :\n${values.join("\n")}`
|
|
1019
1544
|
: `${blockName} :`;
|
|
@@ -1064,11 +1589,11 @@ class Null extends BaseBlock {
|
|
|
1064
1589
|
if (!this.lenBlock.error.length)
|
|
1065
1590
|
this.blockLength += this.lenBlock.blockLength;
|
|
1066
1591
|
this.blockLength += inputLength;
|
|
1067
|
-
if (
|
|
1592
|
+
if (inputOffset + inputLength > inputBuffer.byteLength) {
|
|
1068
1593
|
this.error = "End of input reached before message was fully decoded (inconsistent offset and length values)";
|
|
1069
1594
|
return -1;
|
|
1070
1595
|
}
|
|
1071
|
-
return
|
|
1596
|
+
return inputOffset + inputLength;
|
|
1072
1597
|
}
|
|
1073
1598
|
toBER(sizeOnly, writer) {
|
|
1074
1599
|
const retBuf = new ArrayBuffer(2);
|
|
@@ -1102,7 +1627,7 @@ class LocalBooleanValueBlock extends HexBlock(ValueBlock) {
|
|
|
1102
1627
|
return false;
|
|
1103
1628
|
}
|
|
1104
1629
|
set value(value) {
|
|
1105
|
-
this.valueHexView[0] = value ?
|
|
1630
|
+
this.valueHexView[0] = value ? 0xff : 0x00;
|
|
1106
1631
|
}
|
|
1107
1632
|
constructor({ value, ...parameters } = {}) {
|
|
1108
1633
|
super(parameters);
|
|
@@ -1127,15 +1652,15 @@ class LocalBooleanValueBlock extends HexBlock(ValueBlock) {
|
|
|
1127
1652
|
this.isHexOnly = true;
|
|
1128
1653
|
pvutils.utilDecodeTC.call(this);
|
|
1129
1654
|
this.blockLength = inputLength;
|
|
1130
|
-
return
|
|
1655
|
+
return inputOffset + inputLength;
|
|
1131
1656
|
}
|
|
1132
1657
|
toBER() {
|
|
1133
|
-
return this.valueHexView.slice();
|
|
1658
|
+
return this.valueHexView.slice().buffer;
|
|
1134
1659
|
}
|
|
1135
1660
|
toJSON() {
|
|
1136
1661
|
return {
|
|
1137
1662
|
...super.toJSON(),
|
|
1138
|
-
value: this.value
|
|
1663
|
+
value: this.value
|
|
1139
1664
|
};
|
|
1140
1665
|
}
|
|
1141
1666
|
}
|
|
@@ -1202,18 +1727,17 @@ class LocalOctetStringValueBlock extends HexBlock(LocalConstructedValueBlock) {
|
|
|
1202
1727
|
toBER(sizeOnly, writer) {
|
|
1203
1728
|
if (this.isConstructed)
|
|
1204
1729
|
return LocalConstructedValueBlock.prototype.toBER.call(this, sizeOnly, writer);
|
|
1205
|
-
return sizeOnly
|
|
1206
|
-
? new ArrayBuffer(this.valueHexView.byteLength)
|
|
1207
|
-
: this.valueHexView.slice().buffer;
|
|
1730
|
+
return sizeOnly ? new ArrayBuffer(this.valueHexView.byteLength) : this.valueHexView.slice().buffer;
|
|
1208
1731
|
}
|
|
1209
1732
|
toJSON() {
|
|
1210
1733
|
return {
|
|
1211
1734
|
...super.toJSON(),
|
|
1212
|
-
isConstructed: this.isConstructed
|
|
1735
|
+
isConstructed: this.isConstructed
|
|
1213
1736
|
};
|
|
1214
1737
|
}
|
|
1215
1738
|
}
|
|
1216
1739
|
LocalOctetStringValueBlock.NAME = "OctetStringValueBlock";
|
|
1740
|
+
const ORIGINAL_LOCAL_OCTET_STRING_TO_BER = LocalOctetStringValueBlock.prototype.toBER;
|
|
1217
1741
|
|
|
1218
1742
|
var _a$r;
|
|
1219
1743
|
class OctetString extends BaseBlock {
|
|
@@ -1223,13 +1747,13 @@ class OctetString extends BaseBlock {
|
|
|
1223
1747
|
super({
|
|
1224
1748
|
idBlock: {
|
|
1225
1749
|
isConstructed: parameters.isConstructed,
|
|
1226
|
-
...idBlock
|
|
1750
|
+
...idBlock
|
|
1227
1751
|
},
|
|
1228
1752
|
lenBlock: {
|
|
1229
1753
|
...lenBlock,
|
|
1230
|
-
isIndefiniteForm: !!parameters.isIndefiniteForm
|
|
1754
|
+
isIndefiniteForm: !!parameters.isIndefiniteForm
|
|
1231
1755
|
},
|
|
1232
|
-
...parameters
|
|
1756
|
+
...parameters
|
|
1233
1757
|
}, LocalOctetStringValueBlock);
|
|
1234
1758
|
this.idBlock.tagClass = 1;
|
|
1235
1759
|
this.idBlock.tagNumber = 4;
|
|
@@ -1244,7 +1768,7 @@ class OctetString extends BaseBlock {
|
|
|
1244
1768
|
this.blockLength += this.lenBlock.blockLength;
|
|
1245
1769
|
return inputOffset;
|
|
1246
1770
|
}
|
|
1247
|
-
if (!this.valueBlock.isConstructed) {
|
|
1771
|
+
if (!this.valueBlock.isConstructed && (context === null || context === void 0 ? void 0 : context.parseEmbedded) !== false) {
|
|
1248
1772
|
const view = inputBuffer instanceof ArrayBuffer ? new Uint8Array(inputBuffer) : inputBuffer;
|
|
1249
1773
|
const buf = view.subarray(inputOffset, inputOffset + inputLength);
|
|
1250
1774
|
try {
|
|
@@ -1319,8 +1843,8 @@ class LocalBitStringValueBlock extends HexBlock(LocalConstructedValueBlock) {
|
|
|
1319
1843
|
return -1;
|
|
1320
1844
|
}
|
|
1321
1845
|
const valueBlock = value.valueBlock;
|
|
1322
|
-
if (
|
|
1323
|
-
this.error =
|
|
1846
|
+
if (this.unusedBits > 0 && valueBlock.unusedBits > 0) {
|
|
1847
|
+
this.error = 'Using of "unused bits" inside constructive BIT STRING allowed for least one only';
|
|
1324
1848
|
return -1;
|
|
1325
1849
|
}
|
|
1326
1850
|
this.unusedBits = valueBlock.unusedBits;
|
|
@@ -1337,13 +1861,13 @@ class LocalBitStringValueBlock extends HexBlock(LocalConstructedValueBlock) {
|
|
|
1337
1861
|
this.error = "Unused bits for BitString must be in range 0-7";
|
|
1338
1862
|
return -1;
|
|
1339
1863
|
}
|
|
1340
|
-
if (!this.unusedBits) {
|
|
1864
|
+
if (!this.unusedBits && (context === null || context === void 0 ? void 0 : context.parseEmbedded) !== false) {
|
|
1341
1865
|
const buf = intBuffer.subarray(1);
|
|
1342
1866
|
try {
|
|
1343
1867
|
if (buf.byteLength) {
|
|
1344
1868
|
const parseContext = context !== null && context !== void 0 ? context : createFromBerContext();
|
|
1345
1869
|
const asn = localFromBERWithChildContext(buf, 0, buf.byteLength, parseContext);
|
|
1346
|
-
if (asn.offset !== -1 && asn.offset ===
|
|
1870
|
+
if (asn.offset !== -1 && asn.offset === inputLength - 1) {
|
|
1347
1871
|
this.value = [asn.result];
|
|
1348
1872
|
}
|
|
1349
1873
|
}
|
|
@@ -1353,7 +1877,7 @@ class LocalBitStringValueBlock extends HexBlock(LocalConstructedValueBlock) {
|
|
|
1353
1877
|
}
|
|
1354
1878
|
this.valueHexView = intBuffer.subarray(1);
|
|
1355
1879
|
this.blockLength = intBuffer.length;
|
|
1356
|
-
return
|
|
1880
|
+
return inputOffset + inputLength;
|
|
1357
1881
|
}
|
|
1358
1882
|
toBER(sizeOnly, writer) {
|
|
1359
1883
|
if (this.isConstructed) {
|
|
@@ -1376,11 +1900,12 @@ class LocalBitStringValueBlock extends HexBlock(LocalConstructedValueBlock) {
|
|
|
1376
1900
|
return {
|
|
1377
1901
|
...super.toJSON(),
|
|
1378
1902
|
unusedBits: this.unusedBits,
|
|
1379
|
-
isConstructed: this.isConstructed
|
|
1903
|
+
isConstructed: this.isConstructed
|
|
1380
1904
|
};
|
|
1381
1905
|
}
|
|
1382
1906
|
}
|
|
1383
1907
|
LocalBitStringValueBlock.NAME = "BitStringValueBlock";
|
|
1908
|
+
const ORIGINAL_LOCAL_BIT_STRING_TO_BER = LocalBitStringValueBlock.prototype.toBER;
|
|
1384
1909
|
|
|
1385
1910
|
var _a$q;
|
|
1386
1911
|
class BitString extends BaseBlock {
|
|
@@ -1390,13 +1915,13 @@ class BitString extends BaseBlock {
|
|
|
1390
1915
|
super({
|
|
1391
1916
|
idBlock: {
|
|
1392
1917
|
isConstructed: parameters.isConstructed,
|
|
1393
|
-
...idBlock
|
|
1918
|
+
...idBlock
|
|
1394
1919
|
},
|
|
1395
1920
|
lenBlock: {
|
|
1396
1921
|
...lenBlock,
|
|
1397
|
-
isIndefiniteForm: !!parameters.isIndefiniteForm
|
|
1922
|
+
isIndefiniteForm: !!parameters.isIndefiniteForm
|
|
1398
1923
|
},
|
|
1399
|
-
...parameters
|
|
1924
|
+
...parameters
|
|
1400
1925
|
}, LocalBitStringValueBlock);
|
|
1401
1926
|
this.idBlock.tagClass = 1;
|
|
1402
1927
|
this.idBlock.tagNumber = 3;
|
|
@@ -1429,94 +1954,53 @@ _a$q = BitString;
|
|
|
1429
1954
|
})();
|
|
1430
1955
|
BitString.NAME = BIT_STRING_NAME;
|
|
1431
1956
|
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
const
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
digits = pvutils.utilConcatView(c, digits);
|
|
1477
|
-
powers2.push(digits);
|
|
1478
|
-
}
|
|
1479
|
-
}
|
|
1480
|
-
return powers2[n];
|
|
1481
|
-
}
|
|
1482
|
-
function viewSub(first, second) {
|
|
1483
|
-
let b = 0;
|
|
1484
|
-
const firstView = new Uint8Array(first);
|
|
1485
|
-
const secondView = new Uint8Array(second);
|
|
1486
|
-
const firstViewCopy = firstView.slice(0);
|
|
1487
|
-
const firstViewCopyLength = firstViewCopy.length - 1;
|
|
1488
|
-
const secondViewCopy = secondView.slice(0);
|
|
1489
|
-
const secondViewCopyLength = secondViewCopy.length - 1;
|
|
1490
|
-
let value;
|
|
1491
|
-
let counter = 0;
|
|
1492
|
-
for (let i = secondViewCopyLength; i >= 0; i--, counter++) {
|
|
1493
|
-
value = firstViewCopy[firstViewCopyLength - counter] - secondViewCopy[secondViewCopyLength - counter] - b;
|
|
1494
|
-
switch (true) {
|
|
1495
|
-
case (value < 0):
|
|
1496
|
-
b = 1;
|
|
1497
|
-
firstViewCopy[firstViewCopyLength - counter] = value + 10;
|
|
1498
|
-
break;
|
|
1499
|
-
default:
|
|
1500
|
-
b = 0;
|
|
1501
|
-
firstViewCopy[firstViewCopyLength - counter] = value;
|
|
1502
|
-
}
|
|
1503
|
-
}
|
|
1504
|
-
if (b > 0) {
|
|
1505
|
-
for (let i = (firstViewCopyLength - secondViewCopyLength + 1); i >= 0; i--, counter++) {
|
|
1506
|
-
value = firstViewCopy[firstViewCopyLength - counter] - b;
|
|
1507
|
-
if (value < 0) {
|
|
1508
|
-
b = 1;
|
|
1509
|
-
firstViewCopy[firstViewCopyLength - counter] = value + 10;
|
|
1510
|
-
}
|
|
1511
|
-
else {
|
|
1512
|
-
b = 0;
|
|
1513
|
-
firstViewCopy[firstViewCopyLength - counter] = value;
|
|
1514
|
-
break;
|
|
1515
|
-
}
|
|
1516
|
-
}
|
|
1517
|
-
}
|
|
1518
|
-
return firstViewCopy.slice();
|
|
1957
|
+
function bytesToSignedBigInt(view) {
|
|
1958
|
+
if (!view.byteLength)
|
|
1959
|
+
return BigInt(0);
|
|
1960
|
+
const value = BigInt(`0x${pvtsutils.Convert.ToHex(view)}`);
|
|
1961
|
+
if (view[0] & 0x80)
|
|
1962
|
+
return value - (BigInt(1) << BigInt(view.byteLength * 8));
|
|
1963
|
+
return value;
|
|
1964
|
+
}
|
|
1965
|
+
function bytesToSignedDecimal(view) {
|
|
1966
|
+
if (typeof BigInt !== "undefined")
|
|
1967
|
+
return bytesToSignedBigInt(view).toString(10);
|
|
1968
|
+
const BASE = 10000000;
|
|
1969
|
+
const DECIMAL_DIGITS = 7;
|
|
1970
|
+
if (!view.byteLength)
|
|
1971
|
+
return "0";
|
|
1972
|
+
const negative = !!(view[0] & 0x80);
|
|
1973
|
+
let magnitude = view;
|
|
1974
|
+
if (negative) {
|
|
1975
|
+
magnitude = new Uint8Array(view.length);
|
|
1976
|
+
let carry = 1;
|
|
1977
|
+
for (let i = view.length - 1; i >= 0; i--) {
|
|
1978
|
+
const value = (view[i] ^ 0xff) + carry;
|
|
1979
|
+
magnitude[i] = value & 0xff;
|
|
1980
|
+
carry = value >> 8;
|
|
1981
|
+
}
|
|
1982
|
+
}
|
|
1983
|
+
const limbs = [0];
|
|
1984
|
+
for (let index = 0; index < magnitude.length; index++) {
|
|
1985
|
+
let carry = magnitude[index];
|
|
1986
|
+
for (let i = 0; i < limbs.length; i++) {
|
|
1987
|
+
const value = limbs[i] * 256 + carry;
|
|
1988
|
+
limbs[i] = value % BASE;
|
|
1989
|
+
carry = Math.floor(value / BASE);
|
|
1990
|
+
}
|
|
1991
|
+
if (carry)
|
|
1992
|
+
limbs.push(carry);
|
|
1993
|
+
}
|
|
1994
|
+
let top = limbs.length - 1;
|
|
1995
|
+
while (top > 0 && limbs[top] === 0)
|
|
1996
|
+
top--;
|
|
1997
|
+
let result = String(limbs[top]);
|
|
1998
|
+
for (let i = top - 1; i >= 0; i--)
|
|
1999
|
+
result += String(limbs[i]).padStart(DECIMAL_DIGITS, "0");
|
|
2000
|
+
return negative && result !== "0" ? `-${result}` : result;
|
|
1519
2001
|
}
|
|
2002
|
+
|
|
2003
|
+
var _a$p;
|
|
1520
2004
|
class LocalIntegerValueBlock extends HexBlock(ValueBlock) {
|
|
1521
2005
|
setValueHex() {
|
|
1522
2006
|
if (this.valueHexView.length >= 4) {
|
|
@@ -1554,13 +2038,13 @@ class LocalIntegerValueBlock extends HexBlock(ValueBlock) {
|
|
|
1554
2038
|
if (offset === -1)
|
|
1555
2039
|
return offset;
|
|
1556
2040
|
const view = this.valueHexView;
|
|
1557
|
-
if (
|
|
2041
|
+
if (view[0] === 0x00 && (view[1] & 0x80) !== 0) {
|
|
1558
2042
|
this.valueHexView = view.subarray(1);
|
|
1559
2043
|
}
|
|
1560
2044
|
else {
|
|
1561
2045
|
if (expectedLength !== 0) {
|
|
1562
2046
|
if (view.length < expectedLength) {
|
|
1563
|
-
if (
|
|
2047
|
+
if (expectedLength - view.length > 1)
|
|
1564
2048
|
expectedLength = view.length + 1;
|
|
1565
2049
|
this.valueHexView = view.subarray(expectedLength - view.length);
|
|
1566
2050
|
}
|
|
@@ -1571,7 +2055,7 @@ class LocalIntegerValueBlock extends HexBlock(ValueBlock) {
|
|
|
1571
2055
|
toDER(sizeOnly = false) {
|
|
1572
2056
|
const view = this.valueHexView;
|
|
1573
2057
|
switch (true) {
|
|
1574
|
-
case (
|
|
2058
|
+
case (view[0] & 0x80) !== 0:
|
|
1575
2059
|
{
|
|
1576
2060
|
const updatedView = new Uint8Array(this.valueHexView.length + 1);
|
|
1577
2061
|
updatedView[0] = 0x00;
|
|
@@ -1579,7 +2063,7 @@ class LocalIntegerValueBlock extends HexBlock(ValueBlock) {
|
|
|
1579
2063
|
this.valueHexView = updatedView;
|
|
1580
2064
|
}
|
|
1581
2065
|
break;
|
|
1582
|
-
case
|
|
2066
|
+
case view[0] === 0x00 && (view[1] & 0x80) === 0:
|
|
1583
2067
|
{
|
|
1584
2068
|
this.valueHexView = this.valueHexView.subarray(1);
|
|
1585
2069
|
}
|
|
@@ -1596,50 +2080,16 @@ class LocalIntegerValueBlock extends HexBlock(ValueBlock) {
|
|
|
1596
2080
|
return resultOffset;
|
|
1597
2081
|
}
|
|
1598
2082
|
toBER(sizeOnly) {
|
|
1599
|
-
return sizeOnly
|
|
1600
|
-
? new ArrayBuffer(this.valueHexView.length)
|
|
1601
|
-
: this.valueHexView.slice().buffer;
|
|
2083
|
+
return sizeOnly ? new ArrayBuffer(this.valueHexView.length) : this.valueHexView.slice().buffer;
|
|
1602
2084
|
}
|
|
1603
2085
|
toJSON() {
|
|
1604
2086
|
return {
|
|
1605
2087
|
...super.toJSON(),
|
|
1606
|
-
valueDec: this.valueDec
|
|
2088
|
+
valueDec: this.valueDec
|
|
1607
2089
|
};
|
|
1608
2090
|
}
|
|
1609
2091
|
toString() {
|
|
1610
|
-
|
|
1611
|
-
let digits = new Uint8Array((this.valueHexView.length * 8) / 3);
|
|
1612
|
-
let bitNumber = 0;
|
|
1613
|
-
let currentByte;
|
|
1614
|
-
const asn1View = this.valueHexView;
|
|
1615
|
-
let result = "";
|
|
1616
|
-
let flag = false;
|
|
1617
|
-
for (let byteNumber = (asn1View.byteLength - 1); byteNumber >= 0; byteNumber--) {
|
|
1618
|
-
currentByte = asn1View[byteNumber];
|
|
1619
|
-
for (let i = 0; i < 8; i++) {
|
|
1620
|
-
if ((currentByte & 1) === 1) {
|
|
1621
|
-
switch (bitNumber) {
|
|
1622
|
-
case firstBit:
|
|
1623
|
-
digits = viewSub(power2(bitNumber), digits);
|
|
1624
|
-
result = "-";
|
|
1625
|
-
break;
|
|
1626
|
-
default:
|
|
1627
|
-
digits = viewAdd(digits, power2(bitNumber));
|
|
1628
|
-
}
|
|
1629
|
-
}
|
|
1630
|
-
bitNumber++;
|
|
1631
|
-
currentByte >>= 1;
|
|
1632
|
-
}
|
|
1633
|
-
}
|
|
1634
|
-
for (let i = 0; i < digits.length; i++) {
|
|
1635
|
-
if (digits[i])
|
|
1636
|
-
flag = true;
|
|
1637
|
-
if (flag)
|
|
1638
|
-
result += digitsString.charAt(digits[i]);
|
|
1639
|
-
}
|
|
1640
|
-
if (flag === false)
|
|
1641
|
-
result += digitsString.charAt(0);
|
|
1642
|
-
return result;
|
|
2092
|
+
return bytesToSignedDecimal(this.valueHexView);
|
|
1643
2093
|
}
|
|
1644
2094
|
}
|
|
1645
2095
|
_a$p = LocalIntegerValueBlock;
|
|
@@ -1652,9 +2102,11 @@ LocalIntegerValueBlock.NAME = "IntegerValueBlock";
|
|
|
1652
2102
|
},
|
|
1653
2103
|
get: function () {
|
|
1654
2104
|
return this.valueHexView.slice().buffer;
|
|
1655
|
-
}
|
|
2105
|
+
}
|
|
1656
2106
|
});
|
|
1657
2107
|
})();
|
|
2108
|
+
const ORIGINAL_LOCAL_INTEGER_TO_BER = LocalIntegerValueBlock.prototype.toBER;
|
|
2109
|
+
const ORIGINAL_LOCAL_INTEGER_TO_STRING = LocalIntegerValueBlock.prototype.toString;
|
|
1658
2110
|
|
|
1659
2111
|
var _a$o;
|
|
1660
2112
|
class Integer extends BaseBlock {
|
|
@@ -1665,7 +2117,11 @@ class Integer extends BaseBlock {
|
|
|
1665
2117
|
}
|
|
1666
2118
|
toBigInt() {
|
|
1667
2119
|
assertBigInt();
|
|
1668
|
-
|
|
2120
|
+
const valueBlock = this.valueBlock;
|
|
2121
|
+
const toString = valueBlock.toString;
|
|
2122
|
+
if (toString === ORIGINAL_LOCAL_INTEGER_TO_STRING)
|
|
2123
|
+
return bytesToSignedBigInt(valueBlock.valueHexView);
|
|
2124
|
+
return BigInt(Reflect.apply(toString, valueBlock, []));
|
|
1669
2125
|
}
|
|
1670
2126
|
static fromBigInt(value) {
|
|
1671
2127
|
assertBigInt();
|
|
@@ -1698,9 +2154,7 @@ class Integer extends BaseBlock {
|
|
|
1698
2154
|
}
|
|
1699
2155
|
convertFromDER() {
|
|
1700
2156
|
return new _a$o({
|
|
1701
|
-
valueHex: this.valueBlock.valueHexView[0] === 0
|
|
1702
|
-
? this.valueBlock.valueHexView.subarray(1)
|
|
1703
|
-
: this.valueBlock.valueHexView,
|
|
2157
|
+
valueHex: this.valueBlock.valueHexView[0] === 0 ? this.valueBlock.valueHexView.subarray(1) : this.valueBlock.valueHexView
|
|
1704
2158
|
});
|
|
1705
2159
|
}
|
|
1706
2160
|
onAsciiEncoding() {
|
|
@@ -1742,18 +2196,34 @@ class LocalSidValueBlock extends HexBlock(ValueBlock) {
|
|
|
1742
2196
|
return -1;
|
|
1743
2197
|
}
|
|
1744
2198
|
const intBuffer = inputView.subarray(inputOffset, inputOffset + inputLength);
|
|
1745
|
-
this.
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
2199
|
+
const fastPath = this.blockLength === 0 && Number.isInteger(inputOffset) && Number.isInteger(inputLength);
|
|
2200
|
+
if (fastPath) {
|
|
2201
|
+
let sidLength = 0;
|
|
2202
|
+
while (sidLength < inputLength) {
|
|
2203
|
+
const octet = intBuffer[sidLength];
|
|
2204
|
+
sidLength++;
|
|
2205
|
+
if ((octet & 0x80) === 0x00)
|
|
2206
|
+
break;
|
|
2207
|
+
}
|
|
2208
|
+
this.blockLength = sidLength;
|
|
2209
|
+
this.valueHexView = new Uint8Array(sidLength);
|
|
2210
|
+
for (let i = 0; i < sidLength; i++)
|
|
2211
|
+
this.valueHexView[i] = intBuffer[i] & 0x7f;
|
|
1751
2212
|
}
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
2213
|
+
else {
|
|
2214
|
+
this.valueHexView = new Uint8Array(inputLength);
|
|
2215
|
+
for (let i = 0; i < inputLength; i++) {
|
|
2216
|
+
this.valueHexView[i] = intBuffer[i] & 0x7f;
|
|
2217
|
+
this.blockLength++;
|
|
2218
|
+
if ((intBuffer[i] & 0x80) === 0x00)
|
|
2219
|
+
break;
|
|
2220
|
+
}
|
|
2221
|
+
const tempView = new Uint8Array(this.blockLength);
|
|
2222
|
+
for (let i = 0; i < this.blockLength; i++) {
|
|
2223
|
+
tempView[i] = this.valueHexView[i];
|
|
2224
|
+
}
|
|
2225
|
+
this.valueHexView = tempView;
|
|
1755
2226
|
}
|
|
1756
|
-
this.valueHexView = tempView;
|
|
1757
2227
|
if ((intBuffer[this.blockLength - 1] & 0x80) !== 0x00) {
|
|
1758
2228
|
this.error = "End of input reached before message was fully decoded";
|
|
1759
2229
|
return -1;
|
|
@@ -1766,7 +2236,7 @@ class LocalSidValueBlock extends HexBlock(ValueBlock) {
|
|
|
1766
2236
|
this.isHexOnly = true;
|
|
1767
2237
|
this.warnings.push("Too big SID for decoding, hex only");
|
|
1768
2238
|
}
|
|
1769
|
-
return
|
|
2239
|
+
return inputOffset + this.blockLength;
|
|
1770
2240
|
}
|
|
1771
2241
|
set valueBigInt(value) {
|
|
1772
2242
|
assertBigInt();
|
|
@@ -1783,13 +2253,13 @@ class LocalSidValueBlock extends HexBlock(ValueBlock) {
|
|
|
1783
2253
|
toBER(sizeOnly) {
|
|
1784
2254
|
if (this.isHexOnly) {
|
|
1785
2255
|
if (sizeOnly)
|
|
1786
|
-
return
|
|
2256
|
+
return new ArrayBuffer(this.valueHexView.byteLength);
|
|
1787
2257
|
const curView = this.valueHexView;
|
|
1788
2258
|
const retView = new Uint8Array(this.blockLength);
|
|
1789
|
-
for (let i = 0; i <
|
|
2259
|
+
for (let i = 0; i < this.blockLength - 1; i++)
|
|
1790
2260
|
retView[i] = curView[i] | 0x80;
|
|
1791
2261
|
retView[this.blockLength - 1] = curView[this.blockLength - 1];
|
|
1792
|
-
return retView
|
|
2262
|
+
return pvtsutils.BufferSourceConverter.toArrayBuffer(retView);
|
|
1793
2263
|
}
|
|
1794
2264
|
const encodedBuf = pvutils.utilToBase(this.valueDec, 7);
|
|
1795
2265
|
if (encodedBuf.byteLength === 0) {
|
|
@@ -1804,7 +2274,7 @@ class LocalSidValueBlock extends HexBlock(ValueBlock) {
|
|
|
1804
2274
|
retView[i] = encodedView[i] | 0x80;
|
|
1805
2275
|
retView[len] = encodedView[len];
|
|
1806
2276
|
}
|
|
1807
|
-
return retView;
|
|
2277
|
+
return pvtsutils.BufferSourceConverter.toArrayBuffer(retView);
|
|
1808
2278
|
}
|
|
1809
2279
|
toString() {
|
|
1810
2280
|
let result = "";
|
|
@@ -1836,7 +2306,7 @@ class LocalSidValueBlock extends HexBlock(ValueBlock) {
|
|
|
1836
2306
|
return {
|
|
1837
2307
|
...super.toJSON(),
|
|
1838
2308
|
valueDec: this.valueDec,
|
|
1839
|
-
isFirstSid: this.isFirstSid
|
|
2309
|
+
isFirstSid: this.isFirstSid
|
|
1840
2310
|
};
|
|
1841
2311
|
}
|
|
1842
2312
|
}
|
|
@@ -1959,7 +2429,7 @@ class LocalObjectIdentifierValueBlock extends ValueBlock {
|
|
|
1959
2429
|
const object = {
|
|
1960
2430
|
...super.toJSON(),
|
|
1961
2431
|
value: this.toString(),
|
|
1962
|
-
sidArray: []
|
|
2432
|
+
sidArray: []
|
|
1963
2433
|
};
|
|
1964
2434
|
for (let i = 0; i < this.value.length; i++) {
|
|
1965
2435
|
object.sidArray.push(this.value[i].toJSON());
|
|
@@ -1988,7 +2458,7 @@ class ObjectIdentifier extends BaseBlock {
|
|
|
1988
2458
|
toJSON() {
|
|
1989
2459
|
return {
|
|
1990
2460
|
...super.toJSON(),
|
|
1991
|
-
value: this.getValue()
|
|
2461
|
+
value: this.getValue()
|
|
1992
2462
|
};
|
|
1993
2463
|
}
|
|
1994
2464
|
}
|
|
@@ -2010,17 +2480,33 @@ class LocalRelativeSidValueBlock extends HexBlock(LocalBaseBlock) {
|
|
|
2010
2480
|
if (!checkBufferParams(this, inputView, inputOffset, inputLength))
|
|
2011
2481
|
return -1;
|
|
2012
2482
|
const intBuffer = inputView.subarray(inputOffset, inputOffset + inputLength);
|
|
2013
|
-
this.
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2483
|
+
const fastPath = this.blockLength === 0 && Number.isInteger(inputOffset) && Number.isInteger(inputLength);
|
|
2484
|
+
if (fastPath) {
|
|
2485
|
+
let sidLength = 0;
|
|
2486
|
+
while (sidLength < inputLength) {
|
|
2487
|
+
const octet = intBuffer[sidLength];
|
|
2488
|
+
sidLength++;
|
|
2489
|
+
if ((octet & 0x80) === 0x00)
|
|
2490
|
+
break;
|
|
2491
|
+
}
|
|
2492
|
+
this.blockLength = sidLength;
|
|
2493
|
+
this.valueHexView = new Uint8Array(sidLength);
|
|
2494
|
+
for (let i = 0; i < sidLength; i++)
|
|
2495
|
+
this.valueHexView[i] = intBuffer[i] & 0x7f;
|
|
2496
|
+
}
|
|
2497
|
+
else {
|
|
2498
|
+
this.valueHexView = new Uint8Array(inputLength);
|
|
2499
|
+
for (let i = 0; i < inputLength; i++) {
|
|
2500
|
+
this.valueHexView[i] = intBuffer[i] & 0x7f;
|
|
2501
|
+
this.blockLength++;
|
|
2502
|
+
if ((intBuffer[i] & 0x80) === 0x00)
|
|
2503
|
+
break;
|
|
2504
|
+
}
|
|
2505
|
+
const tempView = new Uint8Array(this.blockLength);
|
|
2506
|
+
for (let i = 0; i < this.blockLength; i++)
|
|
2507
|
+
tempView[i] = this.valueHexView[i];
|
|
2508
|
+
this.valueHexView = tempView;
|
|
2019
2509
|
}
|
|
2020
|
-
const tempView = new Uint8Array(this.blockLength);
|
|
2021
|
-
for (let i = 0; i < this.blockLength; i++)
|
|
2022
|
-
tempView[i] = this.valueHexView[i];
|
|
2023
|
-
this.valueHexView = tempView;
|
|
2024
2510
|
if ((intBuffer[this.blockLength - 1] & 0x80) !== 0x00) {
|
|
2025
2511
|
this.error = "End of input reached before message was fully decoded";
|
|
2026
2512
|
return -1;
|
|
@@ -2033,15 +2519,15 @@ class LocalRelativeSidValueBlock extends HexBlock(LocalBaseBlock) {
|
|
|
2033
2519
|
this.isHexOnly = true;
|
|
2034
2520
|
this.warnings.push("Too big SID for decoding, hex only");
|
|
2035
2521
|
}
|
|
2036
|
-
return
|
|
2522
|
+
return inputOffset + this.blockLength;
|
|
2037
2523
|
}
|
|
2038
2524
|
toBER(sizeOnly) {
|
|
2039
2525
|
if (this.isHexOnly) {
|
|
2040
2526
|
if (sizeOnly)
|
|
2041
|
-
return
|
|
2527
|
+
return new ArrayBuffer(this.valueHexView.byteLength);
|
|
2042
2528
|
const curView = this.valueHexView;
|
|
2043
2529
|
const retView = new Uint8Array(this.blockLength);
|
|
2044
|
-
for (let i = 0; i <
|
|
2530
|
+
for (let i = 0; i < this.blockLength - 1; i++)
|
|
2045
2531
|
retView[i] = curView[i] | 0x80;
|
|
2046
2532
|
retView[this.blockLength - 1] = curView[this.blockLength - 1];
|
|
2047
2533
|
return retView.buffer;
|
|
@@ -2073,7 +2559,7 @@ class LocalRelativeSidValueBlock extends HexBlock(LocalBaseBlock) {
|
|
|
2073
2559
|
toJSON() {
|
|
2074
2560
|
return {
|
|
2075
2561
|
...super.toJSON(),
|
|
2076
|
-
valueDec: this.valueDec
|
|
2562
|
+
valueDec: this.valueDec
|
|
2077
2563
|
};
|
|
2078
2564
|
}
|
|
2079
2565
|
}
|
|
@@ -2156,7 +2642,7 @@ class LocalRelativeObjectIdentifierValueBlock extends ValueBlock {
|
|
|
2156
2642
|
const object = {
|
|
2157
2643
|
...super.toJSON(),
|
|
2158
2644
|
value: this.toString(),
|
|
2159
|
-
sidArray: []
|
|
2645
|
+
sidArray: []
|
|
2160
2646
|
};
|
|
2161
2647
|
for (let i = 0; i < this.value.length; i++)
|
|
2162
2648
|
object.sidArray.push(this.value[i].toJSON());
|
|
@@ -2184,7 +2670,7 @@ class RelativeObjectIdentifier extends BaseBlock {
|
|
|
2184
2670
|
toJSON() {
|
|
2185
2671
|
return {
|
|
2186
2672
|
...super.toJSON(),
|
|
2187
|
-
value: this.getValue()
|
|
2673
|
+
value: this.getValue()
|
|
2188
2674
|
};
|
|
2189
2675
|
}
|
|
2190
2676
|
}
|
|
@@ -2231,7 +2717,7 @@ class LocalStringValueBlock extends HexBlock(ValueBlock) {
|
|
|
2231
2717
|
toJSON() {
|
|
2232
2718
|
return {
|
|
2233
2719
|
...super.toJSON(),
|
|
2234
|
-
value: this.value
|
|
2720
|
+
value: this.value
|
|
2235
2721
|
};
|
|
2236
2722
|
}
|
|
2237
2723
|
}
|
|
@@ -2250,7 +2736,7 @@ class LocalSimpleStringBlock extends BaseStringBlock {
|
|
|
2250
2736
|
}
|
|
2251
2737
|
fromString(inputString) {
|
|
2252
2738
|
const strLen = inputString.length;
|
|
2253
|
-
const view = this.valueBlock.valueHexView = new Uint8Array(strLen);
|
|
2739
|
+
const view = (this.valueBlock.valueHexView = new Uint8Array(strLen));
|
|
2254
2740
|
for (let i = 0; i < strLen; i++)
|
|
2255
2741
|
view[i] = inputString.charCodeAt(i);
|
|
2256
2742
|
this.valueBlock.value = inputString;
|
|
@@ -2330,14 +2816,14 @@ class LocalUniversalStringValueBlock extends LocalSimpleStringBlock {
|
|
|
2330
2816
|
}
|
|
2331
2817
|
fromString(inputString) {
|
|
2332
2818
|
const strLength = inputString.length;
|
|
2333
|
-
const valueHexView = this.valueBlock.valueHexView = new Uint8Array(strLength * 4);
|
|
2819
|
+
const valueHexView = (this.valueBlock.valueHexView = new Uint8Array(strLength * 4));
|
|
2334
2820
|
for (let i = 0; i < strLength; i++) {
|
|
2335
2821
|
const codeBuf = pvutils.utilToBase(inputString.charCodeAt(i), 8);
|
|
2336
2822
|
const codeView = new Uint8Array(codeBuf);
|
|
2337
2823
|
if (codeView.length > 4)
|
|
2338
2824
|
continue;
|
|
2339
2825
|
const dif = 4 - codeView.length;
|
|
2340
|
-
for (let j =
|
|
2826
|
+
for (let j = codeView.length - 1; j >= 0; j--)
|
|
2341
2827
|
valueHexView[i * 4 + j + dif] = codeView[j];
|
|
2342
2828
|
}
|
|
2343
2829
|
this.valueBlock.value = inputString;
|
|
@@ -2528,10 +3014,10 @@ class UTCTime extends VisibleString {
|
|
|
2528
3014
|
this.second = inputDate.getUTCSeconds();
|
|
2529
3015
|
}
|
|
2530
3016
|
toDate() {
|
|
2531
|
-
return
|
|
3017
|
+
return new Date(Date.UTC(this.year, this.month - 1, this.day, this.hour, this.minute, this.second));
|
|
2532
3018
|
}
|
|
2533
3019
|
fromString(inputString) {
|
|
2534
|
-
const parser = /(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})Z/
|
|
3020
|
+
const parser = /(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})Z/gi;
|
|
2535
3021
|
const parserArray = parser.exec(inputString);
|
|
2536
3022
|
if (parserArray === null) {
|
|
2537
3023
|
this.error = "Wrong input string for conversion";
|
|
@@ -2550,8 +3036,8 @@ class UTCTime extends VisibleString {
|
|
|
2550
3036
|
}
|
|
2551
3037
|
toString(encoding = "iso") {
|
|
2552
3038
|
if (encoding === "iso") {
|
|
2553
|
-
const outputArray =
|
|
2554
|
-
outputArray[0] = pvutils.padNumber(
|
|
3039
|
+
const outputArray = Array.from({ length: 7 });
|
|
3040
|
+
outputArray[0] = pvutils.padNumber(this.year < 2000 ? this.year - 1900 : this.year - 2000, 2);
|
|
2555
3041
|
outputArray[1] = pvutils.padNumber(this.month, 2);
|
|
2556
3042
|
outputArray[2] = pvutils.padNumber(this.day, 2);
|
|
2557
3043
|
outputArray[3] = pvutils.padNumber(this.hour, 2);
|
|
@@ -2573,7 +3059,7 @@ class UTCTime extends VisibleString {
|
|
|
2573
3059
|
day: this.day,
|
|
2574
3060
|
hour: this.hour,
|
|
2575
3061
|
minute: this.minute,
|
|
2576
|
-
second: this.second
|
|
3062
|
+
second: this.second
|
|
2577
3063
|
};
|
|
2578
3064
|
}
|
|
2579
3065
|
}
|
|
@@ -2598,7 +3084,7 @@ class GeneralizedTime extends UTCTime {
|
|
|
2598
3084
|
}
|
|
2599
3085
|
toDate() {
|
|
2600
3086
|
const utcDate = Date.UTC(this.year, this.month - 1, this.day, this.hour, this.minute, this.second, this.millisecond);
|
|
2601
|
-
return
|
|
3087
|
+
return new Date(utcDate);
|
|
2602
3088
|
}
|
|
2603
3089
|
fromString(inputString) {
|
|
2604
3090
|
let isUTC = false;
|
|
@@ -2635,7 +3121,7 @@ class GeneralizedTime extends UTCTime {
|
|
|
2635
3121
|
if (differencePosition !== -1) {
|
|
2636
3122
|
differenceString = timeString.substring(differencePosition + 1);
|
|
2637
3123
|
timeString = timeString.substring(0, differencePosition);
|
|
2638
|
-
if (
|
|
3124
|
+
if (differenceString.length !== 2 && differenceString.length !== 4)
|
|
2639
3125
|
throw new Error("Wrong input string for conversion");
|
|
2640
3126
|
let number = parseInt(differenceString.substring(0, 2), 10);
|
|
2641
3127
|
if (isNaN(number.valueOf()))
|
|
@@ -2662,13 +3148,13 @@ class GeneralizedTime extends UTCTime {
|
|
|
2662
3148
|
else
|
|
2663
3149
|
dateTimeString = timeString;
|
|
2664
3150
|
switch (true) {
|
|
2665
|
-
case
|
|
2666
|
-
parser = /(\d{4})(\d{2})(\d{2})/
|
|
3151
|
+
case dateTimeString.length === 8:
|
|
3152
|
+
parser = /(\d{4})(\d{2})(\d{2})/gi;
|
|
2667
3153
|
if (fractionPointPosition !== -1)
|
|
2668
3154
|
throw new Error("Wrong input string for conversion");
|
|
2669
3155
|
break;
|
|
2670
|
-
case
|
|
2671
|
-
parser = /(\d{4})(\d{2})(\d{2})(\d{2})/
|
|
3156
|
+
case dateTimeString.length === 10:
|
|
3157
|
+
parser = /(\d{4})(\d{2})(\d{2})(\d{2})/gi;
|
|
2672
3158
|
if (fractionPointPosition !== -1) {
|
|
2673
3159
|
let fractionResult = 60 * fractionPart;
|
|
2674
3160
|
this.minute = Math.floor(fractionResult);
|
|
@@ -2678,8 +3164,8 @@ class GeneralizedTime extends UTCTime {
|
|
|
2678
3164
|
this.millisecond = Math.floor(fractionResult);
|
|
2679
3165
|
}
|
|
2680
3166
|
break;
|
|
2681
|
-
case
|
|
2682
|
-
parser = /(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})/
|
|
3167
|
+
case dateTimeString.length === 12:
|
|
3168
|
+
parser = /(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})/gi;
|
|
2683
3169
|
if (fractionPointPosition !== -1) {
|
|
2684
3170
|
let fractionResult = 60 * fractionPart;
|
|
2685
3171
|
this.second = Math.floor(fractionResult);
|
|
@@ -2687,8 +3173,8 @@ class GeneralizedTime extends UTCTime {
|
|
|
2687
3173
|
this.millisecond = Math.floor(fractionResult);
|
|
2688
3174
|
}
|
|
2689
3175
|
break;
|
|
2690
|
-
case
|
|
2691
|
-
parser = /(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/
|
|
3176
|
+
case dateTimeString.length === 14:
|
|
3177
|
+
parser = /(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/gi;
|
|
2692
3178
|
if (fractionPointPosition !== -1) {
|
|
2693
3179
|
const fractionResult = 1000 * fractionPart;
|
|
2694
3180
|
this.millisecond = Math.floor(fractionResult);
|
|
@@ -2746,7 +3232,7 @@ class GeneralizedTime extends UTCTime {
|
|
|
2746
3232
|
outputArray.push(pvutils.padNumber(this.second, 2));
|
|
2747
3233
|
if (this.millisecond !== 0) {
|
|
2748
3234
|
outputArray.push(".");
|
|
2749
|
-
outputArray.push(pvutils.padNumber(this.millisecond, 3));
|
|
3235
|
+
outputArray.push(pvutils.padNumber(this.millisecond, 3).replace(/0+$/, ""));
|
|
2750
3236
|
}
|
|
2751
3237
|
outputArray.push("Z");
|
|
2752
3238
|
return outputArray.join("");
|
|
@@ -2756,7 +3242,7 @@ class GeneralizedTime extends UTCTime {
|
|
|
2756
3242
|
toJSON() {
|
|
2757
3243
|
return {
|
|
2758
3244
|
...super.toJSON(),
|
|
2759
|
-
millisecond: this.millisecond
|
|
3245
|
+
millisecond: this.millisecond
|
|
2760
3246
|
};
|
|
2761
3247
|
}
|
|
2762
3248
|
}
|
|
@@ -2885,14 +3371,14 @@ function compareSchema(root, inputData, inputSchema) {
|
|
|
2885
3371
|
if (result.verified) {
|
|
2886
3372
|
return {
|
|
2887
3373
|
verified: true,
|
|
2888
|
-
result: root
|
|
3374
|
+
result: root
|
|
2889
3375
|
};
|
|
2890
3376
|
}
|
|
2891
3377
|
}
|
|
2892
3378
|
{
|
|
2893
3379
|
const _result = {
|
|
2894
3380
|
verified: false,
|
|
2895
|
-
result: { error: "Wrong values for Choice type" }
|
|
3381
|
+
result: { error: "Wrong values for Choice type" }
|
|
2896
3382
|
};
|
|
2897
3383
|
if (inputSchema.hasOwnProperty(NAME))
|
|
2898
3384
|
_result.name = inputSchema.name;
|
|
@@ -2904,112 +3390,112 @@ function compareSchema(root, inputData, inputSchema) {
|
|
|
2904
3390
|
root[inputSchema.name] = inputData;
|
|
2905
3391
|
return {
|
|
2906
3392
|
verified: true,
|
|
2907
|
-
result: root
|
|
3393
|
+
result: root
|
|
2908
3394
|
};
|
|
2909
3395
|
}
|
|
2910
|
-
if (
|
|
3396
|
+
if (root instanceof Object === false) {
|
|
2911
3397
|
return {
|
|
2912
3398
|
verified: false,
|
|
2913
|
-
result: { error: "Wrong root object" }
|
|
3399
|
+
result: { error: "Wrong root object" }
|
|
2914
3400
|
};
|
|
2915
3401
|
}
|
|
2916
|
-
if (
|
|
3402
|
+
if (inputData instanceof Object === false) {
|
|
2917
3403
|
return {
|
|
2918
3404
|
verified: false,
|
|
2919
|
-
result: { error: "Wrong ASN.1 data" }
|
|
3405
|
+
result: { error: "Wrong ASN.1 data" }
|
|
2920
3406
|
};
|
|
2921
3407
|
}
|
|
2922
|
-
if (
|
|
3408
|
+
if (inputSchema instanceof Object === false) {
|
|
2923
3409
|
return {
|
|
2924
3410
|
verified: false,
|
|
2925
|
-
result: { error: "Wrong ASN.1 schema" }
|
|
3411
|
+
result: { error: "Wrong ASN.1 schema" }
|
|
2926
3412
|
};
|
|
2927
3413
|
}
|
|
2928
|
-
if (
|
|
3414
|
+
if (ID_BLOCK in inputSchema === false) {
|
|
2929
3415
|
return {
|
|
2930
3416
|
verified: false,
|
|
2931
|
-
result: { error: "Wrong ASN.1 schema" }
|
|
3417
|
+
result: { error: "Wrong ASN.1 schema" }
|
|
2932
3418
|
};
|
|
2933
3419
|
}
|
|
2934
|
-
if (
|
|
3420
|
+
if (FROM_BER in inputSchema.idBlock === false) {
|
|
2935
3421
|
return {
|
|
2936
3422
|
verified: false,
|
|
2937
|
-
result: { error: "Wrong ASN.1 schema" }
|
|
3423
|
+
result: { error: "Wrong ASN.1 schema" }
|
|
2938
3424
|
};
|
|
2939
3425
|
}
|
|
2940
|
-
if (
|
|
3426
|
+
if (TO_BER in inputSchema.idBlock === false) {
|
|
2941
3427
|
return {
|
|
2942
3428
|
verified: false,
|
|
2943
|
-
result: { error: "Wrong ASN.1 schema" }
|
|
3429
|
+
result: { error: "Wrong ASN.1 schema" }
|
|
2944
3430
|
};
|
|
2945
3431
|
}
|
|
2946
3432
|
const encodedId = inputSchema.idBlock.toBER(false);
|
|
2947
3433
|
if (encodedId.byteLength === 0) {
|
|
2948
3434
|
return {
|
|
2949
3435
|
verified: false,
|
|
2950
|
-
result: { error: "Error encoding idBlock for ASN.1 schema" }
|
|
3436
|
+
result: { error: "Error encoding idBlock for ASN.1 schema" }
|
|
2951
3437
|
};
|
|
2952
3438
|
}
|
|
2953
3439
|
const decodedOffset = inputSchema.idBlock.fromBER(encodedId, 0, encodedId.byteLength);
|
|
2954
3440
|
if (decodedOffset === -1) {
|
|
2955
3441
|
return {
|
|
2956
3442
|
verified: false,
|
|
2957
|
-
result: { error: "Error decoding idBlock for ASN.1 schema" }
|
|
3443
|
+
result: { error: "Error decoding idBlock for ASN.1 schema" }
|
|
2958
3444
|
};
|
|
2959
3445
|
}
|
|
2960
3446
|
if (inputSchema.idBlock.hasOwnProperty(TAG_CLASS) === false) {
|
|
2961
3447
|
return {
|
|
2962
3448
|
verified: false,
|
|
2963
|
-
result: { error: "Wrong ASN.1 schema" }
|
|
3449
|
+
result: { error: "Wrong ASN.1 schema" }
|
|
2964
3450
|
};
|
|
2965
3451
|
}
|
|
2966
3452
|
if (inputSchema.idBlock.tagClass !== inputData.idBlock.tagClass) {
|
|
2967
3453
|
return {
|
|
2968
3454
|
verified: false,
|
|
2969
|
-
result: root
|
|
3455
|
+
result: root
|
|
2970
3456
|
};
|
|
2971
3457
|
}
|
|
2972
3458
|
if (inputSchema.idBlock.hasOwnProperty(TAG_NUMBER) === false) {
|
|
2973
3459
|
return {
|
|
2974
3460
|
verified: false,
|
|
2975
|
-
result: { error: "Wrong ASN.1 schema" }
|
|
3461
|
+
result: { error: "Wrong ASN.1 schema" }
|
|
2976
3462
|
};
|
|
2977
3463
|
}
|
|
2978
3464
|
if (inputSchema.idBlock.tagNumber !== inputData.idBlock.tagNumber) {
|
|
2979
3465
|
return {
|
|
2980
3466
|
verified: false,
|
|
2981
|
-
result: root
|
|
3467
|
+
result: root
|
|
2982
3468
|
};
|
|
2983
3469
|
}
|
|
2984
3470
|
if (inputSchema.idBlock.hasOwnProperty(IS_CONSTRUCTED) === false) {
|
|
2985
3471
|
return {
|
|
2986
3472
|
verified: false,
|
|
2987
|
-
result: { error: "Wrong ASN.1 schema" }
|
|
3473
|
+
result: { error: "Wrong ASN.1 schema" }
|
|
2988
3474
|
};
|
|
2989
3475
|
}
|
|
2990
3476
|
if (inputSchema.idBlock.isConstructed !== inputData.idBlock.isConstructed) {
|
|
2991
3477
|
return {
|
|
2992
3478
|
verified: false,
|
|
2993
|
-
result: root
|
|
3479
|
+
result: root
|
|
2994
3480
|
};
|
|
2995
3481
|
}
|
|
2996
3482
|
if (!(IS_HEX_ONLY in inputSchema.idBlock)) {
|
|
2997
3483
|
return {
|
|
2998
3484
|
verified: false,
|
|
2999
|
-
result: { error: "Wrong ASN.1 schema" }
|
|
3485
|
+
result: { error: "Wrong ASN.1 schema" }
|
|
3000
3486
|
};
|
|
3001
3487
|
}
|
|
3002
3488
|
if (inputSchema.idBlock.isHexOnly !== inputData.idBlock.isHexOnly) {
|
|
3003
3489
|
return {
|
|
3004
3490
|
verified: false,
|
|
3005
|
-
result: root
|
|
3491
|
+
result: root
|
|
3006
3492
|
};
|
|
3007
3493
|
}
|
|
3008
3494
|
if (inputSchema.idBlock.isHexOnly) {
|
|
3009
|
-
if (
|
|
3495
|
+
if (VALUE_HEX_VIEW in inputSchema.idBlock === false) {
|
|
3010
3496
|
return {
|
|
3011
3497
|
verified: false,
|
|
3012
|
-
result: { error: "Wrong ASN.1 schema" }
|
|
3498
|
+
result: { error: "Wrong ASN.1 schema" }
|
|
3013
3499
|
};
|
|
3014
3500
|
}
|
|
3015
3501
|
const schemaView = inputSchema.idBlock.valueHexView;
|
|
@@ -3017,14 +3503,14 @@ function compareSchema(root, inputData, inputSchema) {
|
|
|
3017
3503
|
if (schemaView.length !== asn1View.length) {
|
|
3018
3504
|
return {
|
|
3019
3505
|
verified: false,
|
|
3020
|
-
result: root
|
|
3506
|
+
result: root
|
|
3021
3507
|
};
|
|
3022
3508
|
}
|
|
3023
3509
|
for (let i = 0; i < schemaView.length; i++) {
|
|
3024
3510
|
if (schemaView[i] !== asn1View[1]) {
|
|
3025
3511
|
return {
|
|
3026
3512
|
verified: false,
|
|
3027
|
-
result: root
|
|
3513
|
+
result: root
|
|
3028
3514
|
};
|
|
3029
3515
|
}
|
|
3030
3516
|
}
|
|
@@ -3038,7 +3524,7 @@ function compareSchema(root, inputData, inputSchema) {
|
|
|
3038
3524
|
let admission = 0;
|
|
3039
3525
|
let result = {
|
|
3040
3526
|
verified: false,
|
|
3041
|
-
result: { error: "Unknown error" }
|
|
3527
|
+
result: { error: "Unknown error" }
|
|
3042
3528
|
};
|
|
3043
3529
|
let maxLength = inputSchema.valueBlock.value.length;
|
|
3044
3530
|
if (maxLength > 0) {
|
|
@@ -3049,18 +3535,17 @@ function compareSchema(root, inputData, inputSchema) {
|
|
|
3049
3535
|
if (maxLength === 0) {
|
|
3050
3536
|
return {
|
|
3051
3537
|
verified: true,
|
|
3052
|
-
result: root
|
|
3538
|
+
result: root
|
|
3053
3539
|
};
|
|
3054
3540
|
}
|
|
3055
|
-
if (
|
|
3056
|
-
&& (inputSchema.valueBlock.value.length !== 0)) {
|
|
3541
|
+
if (inputData.valueBlock.value.length === 0 && inputSchema.valueBlock.value.length !== 0) {
|
|
3057
3542
|
let _optional = true;
|
|
3058
3543
|
for (let i = 0; i < inputSchema.valueBlock.value.length; i++)
|
|
3059
3544
|
_optional = _optional && (inputSchema.valueBlock.value[i].optional || false);
|
|
3060
3545
|
if (_optional) {
|
|
3061
3546
|
return {
|
|
3062
3547
|
verified: true,
|
|
3063
|
-
result: root
|
|
3548
|
+
result: root
|
|
3064
3549
|
};
|
|
3065
3550
|
}
|
|
3066
3551
|
if (inputSchema.name) {
|
|
@@ -3071,15 +3556,15 @@ function compareSchema(root, inputData, inputSchema) {
|
|
|
3071
3556
|
root.error = "Inconsistent object length";
|
|
3072
3557
|
return {
|
|
3073
3558
|
verified: false,
|
|
3074
|
-
result: root
|
|
3559
|
+
result: root
|
|
3075
3560
|
};
|
|
3076
3561
|
}
|
|
3077
3562
|
for (let i = 0; i < maxLength; i++) {
|
|
3078
|
-
if (
|
|
3563
|
+
if (i - admission >= inputData.valueBlock.value.length) {
|
|
3079
3564
|
if (inputSchema.valueBlock.value[i].optional === false) {
|
|
3080
3565
|
const _result = {
|
|
3081
3566
|
verified: false,
|
|
3082
|
-
result: root
|
|
3567
|
+
result: root
|
|
3083
3568
|
};
|
|
3084
3569
|
root.error = "Inconsistent length between ASN.1 data and schema";
|
|
3085
3570
|
if (inputSchema.name) {
|
|
@@ -3107,9 +3592,9 @@ function compareSchema(root, inputData, inputSchema) {
|
|
|
3107
3592
|
return result;
|
|
3108
3593
|
}
|
|
3109
3594
|
}
|
|
3110
|
-
if (
|
|
3595
|
+
if (NAME in inputSchema.valueBlock.value[0] && inputSchema.valueBlock.value[0].name.length > 0) {
|
|
3111
3596
|
let arrayRoot = {};
|
|
3112
|
-
if (
|
|
3597
|
+
if (LOCAL in inputSchema.valueBlock.value[0] && inputSchema.valueBlock.value[0].local)
|
|
3113
3598
|
arrayRoot = inputData;
|
|
3114
3599
|
else
|
|
3115
3600
|
arrayRoot = root;
|
|
@@ -3138,7 +3623,7 @@ function compareSchema(root, inputData, inputSchema) {
|
|
|
3138
3623
|
if (result.verified === false) {
|
|
3139
3624
|
const _result = {
|
|
3140
3625
|
verified: false,
|
|
3141
|
-
result: root
|
|
3626
|
+
result: root
|
|
3142
3627
|
};
|
|
3143
3628
|
if (inputSchema.name) {
|
|
3144
3629
|
inputSchema.name = inputSchema.name.replace(/^\s+|\s+$/g, EMPTY_STRING);
|
|
@@ -3151,16 +3636,15 @@ function compareSchema(root, inputData, inputSchema) {
|
|
|
3151
3636
|
}
|
|
3152
3637
|
return {
|
|
3153
3638
|
verified: true,
|
|
3154
|
-
result: root
|
|
3639
|
+
result: root
|
|
3155
3640
|
};
|
|
3156
3641
|
}
|
|
3157
|
-
if (inputSchema.primitiveSchema
|
|
3158
|
-
&& (VALUE_HEX_VIEW in inputData.valueBlock)) {
|
|
3642
|
+
if (inputSchema.primitiveSchema && VALUE_HEX_VIEW in inputData.valueBlock) {
|
|
3159
3643
|
const asn1 = localFromBER(inputData.valueBlock.valueHexView);
|
|
3160
3644
|
if (asn1.offset === -1) {
|
|
3161
3645
|
const _result = {
|
|
3162
3646
|
verified: false,
|
|
3163
|
-
result: asn1.result
|
|
3647
|
+
result: asn1.result
|
|
3164
3648
|
};
|
|
3165
3649
|
if (inputSchema.name) {
|
|
3166
3650
|
inputSchema.name = inputSchema.name.replace(/^\s+|\s+$/g, EMPTY_STRING);
|
|
@@ -3175,24 +3659,47 @@ function compareSchema(root, inputData, inputSchema) {
|
|
|
3175
3659
|
}
|
|
3176
3660
|
return {
|
|
3177
3661
|
verified: true,
|
|
3178
|
-
result: root
|
|
3662
|
+
result: root
|
|
3179
3663
|
};
|
|
3180
3664
|
}
|
|
3181
3665
|
function verifySchema(inputBuffer, inputSchema) {
|
|
3182
|
-
if (
|
|
3666
|
+
if (inputSchema instanceof Object === false) {
|
|
3183
3667
|
return {
|
|
3184
3668
|
verified: false,
|
|
3185
|
-
result: { error: "Wrong ASN.1 schema type" }
|
|
3669
|
+
result: { error: "Wrong ASN.1 schema type" }
|
|
3186
3670
|
};
|
|
3187
3671
|
}
|
|
3188
3672
|
const asn1 = localFromBER(pvtsutils.BufferSourceConverter.toUint8Array(inputBuffer));
|
|
3189
3673
|
if (asn1.offset === -1) {
|
|
3190
3674
|
return {
|
|
3191
3675
|
verified: false,
|
|
3192
|
-
result: asn1.result
|
|
3676
|
+
result: asn1.result
|
|
3193
3677
|
};
|
|
3194
3678
|
}
|
|
3195
3679
|
return compareSchema(asn1.result, asn1.result, inputSchema);
|
|
3196
3680
|
}
|
|
3197
3681
|
|
|
3682
|
+
registerBuiltinEncoder({ BitString, Integer, OctetString, Primitive, Constructed, Sequence, Set }, {
|
|
3683
|
+
BaseBlock,
|
|
3684
|
+
ViewWriter,
|
|
3685
|
+
LocalIdentificationBlock,
|
|
3686
|
+
LocalLengthBlock,
|
|
3687
|
+
LocalIntegerValueBlock,
|
|
3688
|
+
LocalOctetStringValueBlock,
|
|
3689
|
+
LocalConstructedValueBlock,
|
|
3690
|
+
LocalBitStringValueBlock,
|
|
3691
|
+
LocalPrimitiveValueBlock,
|
|
3692
|
+
originalBaseBlockToBER: ORIGINAL_BASE_BLOCK_TO_BER,
|
|
3693
|
+
originalWriterWrite: ORIGINAL_VIEW_WRITER_WRITE,
|
|
3694
|
+
originalWriterFinal: ORIGINAL_VIEW_WRITER_FINAL,
|
|
3695
|
+
originalIdentificationToBER: ORIGINAL_LOCAL_IDENTIFICATION_TO_BER,
|
|
3696
|
+
originalLengthToBER: ORIGINAL_LOCAL_LENGTH_TO_BER,
|
|
3697
|
+
originalIntegerToBER: ORIGINAL_LOCAL_INTEGER_TO_BER,
|
|
3698
|
+
originalOctetStringToBER: ORIGINAL_LOCAL_OCTET_STRING_TO_BER,
|
|
3699
|
+
originalBitStringToBER: ORIGINAL_LOCAL_BIT_STRING_TO_BER,
|
|
3700
|
+
originalConstructedToBER: ORIGINAL_LOCAL_CONSTRUCTED_TO_BER,
|
|
3701
|
+
originalPrimitiveToBER: ORIGINAL_LOCAL_PRIMITIVE_TO_BER
|
|
3702
|
+
});
|
|
3703
|
+
registerFastParser({ Integer, Null, Sequence });
|
|
3704
|
+
|
|
3198
3705
|
export { Any, BaseBlock, BaseStringBlock, BitString, BmpString, Boolean, CharacterString, Choice, Constructed, DATE, DEFAULT_MAX_CONTENT_LENGTH, DEFAULT_MAX_DEPTH, DEFAULT_MAX_NODES, DateTime, Duration, EndOfContent, Enumerated, GeneralString, GeneralizedTime, GraphicString, HexBlock, IA5String, Integer, Null, NumericString, ObjectIdentifier, OctetString, Primitive, PrintableString, RawData, RelativeObjectIdentifier, Repeated, Sequence, Set, TIME, TeletexString, TimeOfDay, UTCTime, UniversalString, Utf8String, ValueBlock, VideotexString, ViewWriter, VisibleString, compareSchema, fromBER, verifySchema };
|