node-opcua-crypto 4.2.0 → 4.3.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.
Files changed (143) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +1 -1
  3. package/dist/chunk-5NV4OKIV.mjs +1 -0
  4. package/dist/chunk-KPKFYTZJ.mjs +173 -0
  5. package/dist/chunk-QSSIRHMR.mjs +6243 -0
  6. package/dist/index.js +6521 -0
  7. package/dist/index.mjs +224 -0
  8. package/dist/source/index.js +6346 -0
  9. package/dist/source/index.mjs +192 -0
  10. package/dist/source/index_web.js +6346 -0
  11. package/dist/source/index_web.mjs +191 -0
  12. package/dist/source_nodejs/index.js +4170 -0
  13. package/dist/source_nodejs/index.mjs +37 -0
  14. package/dist-types/index.d.ts +2 -0
  15. package/dist-types/source/common.d.ts +21 -1
  16. package/dist-types/source/crypto_utils2.d.ts +2 -3
  17. package/dist-types/source/make_private_key_from_pem.d.ts +1 -1
  18. package/dist-types/source/x509/coerce_private_key.d.ts +5 -3
  19. package/dist-types/source/x509/create_key_pair.d.ts +6 -0
  20. package/dist-types/source/x509/create_self_signed_certificate.d.ts +4 -0
  21. package/dist-types/source_nodejs/read.d.ts +1 -0
  22. package/node-opcua-crypto-4.2.0.tgz +0 -0
  23. package/package.json +84 -91
  24. package/dist-cjs/source/asn1.js +0 -304
  25. package/dist-cjs/source/asn1.js.map +0 -1
  26. package/dist-cjs/source/buffer_utils.js +0 -9
  27. package/dist-cjs/source/buffer_utils.js.map +0 -1
  28. package/dist-cjs/source/common.js +0 -11
  29. package/dist-cjs/source/common.js.map +0 -1
  30. package/dist-cjs/source/crypto_explore_certificate.js +0 -367
  31. package/dist-cjs/source/crypto_explore_certificate.js.map +0 -1
  32. package/dist-cjs/source/crypto_utils.js +0 -200
  33. package/dist-cjs/source/crypto_utils.js.map +0 -1
  34. package/dist-cjs/source/crypto_utils2.js +0 -71
  35. package/dist-cjs/source/crypto_utils2.js.map +0 -1
  36. package/dist-cjs/source/derived_keys.js +0 -133
  37. package/dist-cjs/source/derived_keys.js.map +0 -1
  38. package/dist-cjs/source/explore_certificate.js +0 -37
  39. package/dist-cjs/source/explore_certificate.js.map +0 -1
  40. package/dist-cjs/source/explore_certificate_revocation_list.js +0 -69
  41. package/dist-cjs/source/explore_certificate_revocation_list.js.map +0 -1
  42. package/dist-cjs/source/explore_certificate_signing_request.js +0 -45
  43. package/dist-cjs/source/explore_certificate_signing_request.js.map +0 -1
  44. package/dist-cjs/source/explore_private_key.js +0 -77
  45. package/dist-cjs/source/explore_private_key.js.map +0 -1
  46. package/dist-cjs/source/index.js +0 -38
  47. package/dist-cjs/source/index.js.map +0 -1
  48. package/dist-cjs/source/make_private_key_from_pem.js +0 -8
  49. package/dist-cjs/source/make_private_key_from_pem.js.map +0 -1
  50. package/dist-cjs/source/oid_map.js +0 -300
  51. package/dist-cjs/source/oid_map.js.map +0 -1
  52. package/dist-cjs/source/public_private_match.js +0 -32
  53. package/dist-cjs/source/public_private_match.js.map +0 -1
  54. package/dist-cjs/source/subject.js +0 -92
  55. package/dist-cjs/source/subject.js.map +0 -1
  56. package/dist-cjs/source/verify_certificate_signature.js +0 -117
  57. package/dist-cjs/source/verify_certificate_signature.js.map +0 -1
  58. package/dist-cjs/source/x509/_build_public_key.js +0 -69
  59. package/dist-cjs/source/x509/_build_public_key.js.map +0 -1
  60. package/dist-cjs/source/x509/_crypto.js +0 -52
  61. package/dist-cjs/source/x509/_crypto.js.map +0 -1
  62. package/dist-cjs/source/x509/_get_attributes.js +0 -39
  63. package/dist-cjs/source/x509/_get_attributes.js.map +0 -1
  64. package/dist-cjs/source/x509/coerce_private_key.js +0 -90
  65. package/dist-cjs/source/x509/coerce_private_key.js.map +0 -1
  66. package/dist-cjs/source/x509/create_certificate_signing_request.js +0 -92
  67. package/dist-cjs/source/x509/create_certificate_signing_request.js.map +0 -1
  68. package/dist-cjs/source/x509/create_key_pair.js +0 -123
  69. package/dist-cjs/source/x509/create_key_pair.js.map +0 -1
  70. package/dist-cjs/source/x509/create_self_signed_certificate.js +0 -103
  71. package/dist-cjs/source/x509/create_self_signed_certificate.js.map +0 -1
  72. package/dist-cjs/source_nodejs/generate_private_key_filename.js +0 -88
  73. package/dist-cjs/source_nodejs/generate_private_key_filename.js.map +0 -1
  74. package/dist-cjs/source_nodejs/index.js +0 -21
  75. package/dist-cjs/source_nodejs/index.js.map +0 -1
  76. package/dist-cjs/source_nodejs/read.js +0 -115
  77. package/dist-cjs/source_nodejs/read.js.map +0 -1
  78. package/dist-cjs/source_nodejs/read_certificate_revocation_list.js +0 -64
  79. package/dist-cjs/source_nodejs/read_certificate_revocation_list.js.map +0 -1
  80. package/dist-cjs/source_nodejs/read_certificate_signing_request.js +0 -64
  81. package/dist-cjs/source_nodejs/read_certificate_signing_request.js.map +0 -1
  82. package/dist-esm/source/asn1.js +0 -275
  83. package/dist-esm/source/asn1.js.map +0 -1
  84. package/dist-esm/source/buffer_utils.js +0 -6
  85. package/dist-esm/source/buffer_utils.js.map +0 -1
  86. package/dist-esm/source/common.js +0 -8
  87. package/dist-esm/source/common.js.map +0 -1
  88. package/dist-esm/source/crypto_explore_certificate.js +0 -356
  89. package/dist-esm/source/crypto_explore_certificate.js.map +0 -1
  90. package/dist-esm/source/crypto_utils.js +0 -179
  91. package/dist-esm/source/crypto_utils.js.map +0 -1
  92. package/dist-esm/source/crypto_utils2.js +0 -58
  93. package/dist-esm/source/crypto_utils2.js.map +0 -1
  94. package/dist-esm/source/derived_keys.js +0 -117
  95. package/dist-esm/source/derived_keys.js.map +0 -1
  96. package/dist-esm/source/explore_certificate.js +0 -29
  97. package/dist-esm/source/explore_certificate.js.map +0 -1
  98. package/dist-esm/source/explore_certificate_revocation_list.js +0 -64
  99. package/dist-esm/source/explore_certificate_revocation_list.js.map +0 -1
  100. package/dist-esm/source/explore_certificate_signing_request.js +0 -40
  101. package/dist-esm/source/explore_certificate_signing_request.js.map +0 -1
  102. package/dist-esm/source/explore_private_key.js +0 -73
  103. package/dist-esm/source/explore_private_key.js.map +0 -1
  104. package/dist-esm/source/index.js +0 -19
  105. package/dist-esm/source/index.js.map +0 -1
  106. package/dist-esm/source/make_private_key_from_pem.js +0 -4
  107. package/dist-esm/source/make_private_key_from_pem.js.map +0 -1
  108. package/dist-esm/source/oid_map.js +0 -297
  109. package/dist-esm/source/oid_map.js.map +0 -1
  110. package/dist-esm/source/public_private_match.js +0 -27
  111. package/dist-esm/source/public_private_match.js.map +0 -1
  112. package/dist-esm/source/subject.js +0 -89
  113. package/dist-esm/source/subject.js.map +0 -1
  114. package/dist-esm/source/verify_certificate_signature.js +0 -110
  115. package/dist-esm/source/verify_certificate_signature.js.map +0 -1
  116. package/dist-esm/source/x509/_build_public_key.js +0 -65
  117. package/dist-esm/source/x509/_build_public_key.js.map +0 -1
  118. package/dist-esm/source/x509/_crypto.js +0 -25
  119. package/dist-esm/source/x509/_crypto.js.map +0 -1
  120. package/dist-esm/source/x509/_get_attributes.js +0 -35
  121. package/dist-esm/source/x509/_get_attributes.js.map +0 -1
  122. package/dist-esm/source/x509/coerce_private_key.js +0 -85
  123. package/dist-esm/source/x509/coerce_private_key.js.map +0 -1
  124. package/dist-esm/source/x509/create_certificate_signing_request.js +0 -88
  125. package/dist-esm/source/x509/create_certificate_signing_request.js.map +0 -1
  126. package/dist-esm/source/x509/create_key_pair.js +0 -115
  127. package/dist-esm/source/x509/create_key_pair.js.map +0 -1
  128. package/dist-esm/source/x509/create_self_signed_certificate.js +0 -99
  129. package/dist-esm/source/x509/create_self_signed_certificate.js.map +0 -1
  130. package/dist-esm/source_nodejs/generate_private_key_filename.js +0 -80
  131. package/dist-esm/source_nodejs/generate_private_key_filename.js.map +0 -1
  132. package/dist-esm/source_nodejs/index.js +0 -5
  133. package/dist-esm/source_nodejs/index.js.map +0 -1
  134. package/dist-esm/source_nodejs/read.js +0 -99
  135. package/dist-esm/source_nodejs/read.js.map +0 -1
  136. package/dist-esm/source_nodejs/read_certificate_revocation_list.js +0 -57
  137. package/dist-esm/source_nodejs/read_certificate_revocation_list.js.map +0 -1
  138. package/dist-esm/source_nodejs/read_certificate_signing_request.js +0 -57
  139. package/dist-esm/source_nodejs/read_certificate_signing_request.js.map +0 -1
  140. package/index.d.ts +0 -2
  141. package/index.js +0 -4
  142. package/index_web.d.ts +0 -1
  143. package/index_web.js +0 -3
@@ -0,0 +1,37 @@
1
+ import {
2
+ generatePrivateKeyFile,
3
+ generatePrivateKeyFileAlternate,
4
+ getCertificateStore,
5
+ makePrivateKeyThumbPrint,
6
+ readCertificate,
7
+ readCertificatePEM,
8
+ readCertificateRevocationList,
9
+ readCertificateSigningRequest,
10
+ readPrivateKey,
11
+ readPrivateKeyPEM,
12
+ readPrivateRsaKey,
13
+ readPublicKey,
14
+ readPublicKeyPEM,
15
+ readPublicRsaKey,
16
+ setCertificateStore
17
+ } from "../chunk-KPKFYTZJ.mjs";
18
+ import "../chunk-5NV4OKIV.mjs";
19
+ import "../chunk-QSSIRHMR.mjs";
20
+ export {
21
+ generatePrivateKeyFile,
22
+ generatePrivateKeyFileAlternate,
23
+ getCertificateStore,
24
+ makePrivateKeyThumbPrint,
25
+ readCertificate,
26
+ readCertificatePEM,
27
+ readCertificateRevocationList,
28
+ readCertificateSigningRequest,
29
+ readPrivateKey,
30
+ readPrivateKeyPEM,
31
+ readPrivateRsaKey,
32
+ readPublicKey,
33
+ readPublicKeyPEM,
34
+ readPublicRsaKey,
35
+ setCertificateStore
36
+ };
37
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1,2 @@
1
+ export * from "./source/index.js";
2
+ export * from "./source_nodejs/index.js";
@@ -1,6 +1,25 @@
1
1
  /// <reference types="node" />
2
2
  /// <reference types="node" />
3
- import { KeyObject } from "crypto";
3
+ import __crypto from "crypto";
4
+ export declare const createPrivateKeyFromNodeJSCrypto: typeof __crypto.createPrivateKey;
5
+ type KeyFormat = "pem" | "der" | "jwk";
6
+ type KeyObjectType = "secret" | "public" | "private";
7
+ interface KeyExportOptions<T extends KeyFormat> {
8
+ type: "pkcs1" | "spki" | "pkcs8" | "sec1";
9
+ format: T;
10
+ cipher?: string | undefined;
11
+ passphrase?: string | Buffer | undefined;
12
+ }
13
+ interface JwkKeyExportOptions {
14
+ format: "jwk";
15
+ }
16
+ export interface KeyObject {
17
+ export(options: KeyExportOptions<"pem">): string | Buffer;
18
+ export(options: KeyExportOptions<"der">): Buffer;
19
+ export(options: JwkKeyExportOptions): JsonWebKey;
20
+ type: KeyObjectType;
21
+ }
22
+ export declare function isKeyObject(mayBeKeyObject: any): boolean;
4
23
  export type PrivateKey = {
5
24
  hidden: string;
6
25
  } | {
@@ -22,3 +41,4 @@ export declare enum CertificatePurpose {
22
41
  ForApplication = 2,
23
42
  ForUserAuthentication = 3
24
43
  }
44
+ export {};
@@ -1,6 +1,5 @@
1
1
  /// <reference types="node" />
2
- /// <reference types="node" />
3
- import { KeyObject } from "crypto";
2
+ import { KeyObject } from "./common.js";
4
3
  import { PublicKey, PublicKeyPEM, PrivateKeyPEM, PrivateKey } from "./common.js";
5
4
  /***
6
5
  * @method rsaLengthPrivateKey
@@ -23,6 +22,6 @@ export declare function rsaLengthPrivateKey(key: PrivateKey): number;
23
22
  export declare function toPem2(raw_key: Buffer | string | KeyObject | PrivateKey, pem: string): string;
24
23
  export declare function coercePrivateKeyPem(privateKey: PrivateKey): PrivateKeyPEM;
25
24
  export declare function coercePublicKeyPem(publicKey: PublicKey | PublicKeyPEM): PublicKeyPEM;
26
- export declare function coerceRsaPublicKeyPem(publicKey: PublicKey | PublicKeyPEM): PublicKeyPEM;
25
+ export declare function coerceRsaPublicKeyPem(publicKey: PublicKey | KeyObject | PublicKeyPEM): PublicKeyPEM;
27
26
  export declare function rsaLengthPublicKey(key: PublicKeyPEM | PublicKey): number;
28
27
  export declare function rsaLengthRsaPublicKey(key: PublicKeyPEM | PublicKey): number;
@@ -1,2 +1,2 @@
1
- import { PrivateKey } from "./common";
1
+ import { PrivateKey } from "./common.js";
2
2
  export declare function makePrivateKeyFromPem(privateKeyInPem: string): PrivateKey;
@@ -1,6 +1,8 @@
1
1
  /// <reference types="node" />
2
- /// <reference types="node" />
3
- import { PrivateKey } from "../common";
4
- import { KeyObject } from "crypto";
2
+ import { PrivateKey, KeyObject } from "../common.js";
5
3
  export declare function coercePEMorDerToPrivateKey(privateKeyInDerOrPem: string | Buffer): PrivateKey;
4
+ /**
5
+ *
6
+ * @private
7
+ */
6
8
  export declare function _coercePrivateKey(privateKey: any): Promise<KeyObject>;
@@ -1,5 +1,11 @@
1
1
  export declare function generateKeyPair(modulusLength?: 1024 | 2048 | 3072 | 4096): Promise<CryptoKeyPair>;
2
+ /**
3
+ * generate a pair of private/public keys of length 1024,2048, 3072, or 4096 bits
4
+ */
2
5
  export declare function generatePrivateKey(modulusLength?: 1024 | 2048 | 3072 | 4096): Promise<CryptoKey>;
6
+ /**
7
+ * convert a CryptoKey to a PEM string
8
+ */
3
9
  export declare function privateKeyToPEM(privateKey: CryptoKey): Promise<{
4
10
  privPem: string;
5
11
  privDer: ArrayBuffer;
@@ -11,6 +11,10 @@ export interface CreateSelfSignCertificateOptions {
11
11
  applicationUri?: string;
12
12
  purpose: CertificatePurpose;
13
13
  }
14
+ /**
15
+ *
16
+ * construct a self-signed certificate
17
+ */
14
18
  export declare function createSelfSignedCertificate({ privateKey, notAfter, notBefore, validity, subject, dns, ip, applicationUri, purpose, }: CreateSelfSignCertificateOptions): Promise<{
15
19
  cert: string;
16
20
  der: x509.X509Certificate;
@@ -21,6 +21,7 @@ export declare function readPublicKeyPEM(filename: string): PublicKeyPEM;
21
21
  */
22
22
  export declare function readPrivateKeyPEM(filename: string): PrivateKeyPEM;
23
23
  export declare function setCertificateStore(store: string): string;
24
+ export declare function getCertificateStore(): string;
24
25
  /**
25
26
  *
26
27
  * @param filename
Binary file
package/package.json CHANGED
@@ -1,91 +1,84 @@
1
- {
2
- "name": "node-opcua-crypto",
3
- "version": "4.2.0",
4
- "description": "Crypto tools for Node-OPCUA",
5
- "main": "./index.js",
6
- "types": "./index.d.ts",
7
- "browser": "./index_web.js",
8
- "exports": {
9
- ".": {
10
- "import": {
11
- "default": "./dist-esm/index.js"
12
- },
13
- "require": {
14
- "types": "./index.d.ts",
15
- "default": "./index.js"
16
- }
17
- }
18
- },
19
- "scripts": {
20
- "compile": "tsc -b ./tsconfig.cjs.json ./tsconfig.esm.json ./tsconfig.types.json",
21
- "compile:test": "tsc -b ./tsconfig-test.cjs.json",
22
- "build:demo": "node web/esbuild.mjs",
23
- "build:clean": "npx rimraf ./dist ./dist-* *.tsbuildinfo",
24
- "build": "npm run build:clean && npm run compile && node ./scripts/prepare-package-json.mjs",
25
- "build:test": "npm run compile:test && node ./scripts/prepare-package-json.mjs",
26
- "prepare": "npm run build",
27
- "tslint": "tslint --project . --fix",
28
- "lint": "eslint . --ext .ts",
29
- "test:esm": "mocha test -R spec --recursive --timeout 200000 --bail",
30
- "test:cjs": "mocha dist-test -R spec --recursive --timeout 200000 --bail",
31
- "test:esm:no": "cross-env NO_CREATE_PRIVATEKEY=1 npm run test:esm",
32
- "test:cjs:no": "cross-env NO_CREATE_PRIVATEKEY=1 npm run test:cjs",
33
- "test": "npm run build:test && npm run test:esm && npm run test:cjs && npm run test:esm:no && npm run test:cjs:no",
34
- "makedoc": "npx typedoc -out doc",
35
- "cost-of-modules": "npx cost-of-modules --no-install",
36
- "release-it": "npx release-it",
37
- "prettier-format": "prettier --config .prettierrc.js source/**/*.ts test/**/*.ts --write",
38
- "ncu": "npx npm-check-updates -u -x env-paths,chalk",
39
- "experiment": "tsc test/test_peculiar_edge_case.ts -t es2021 -m nodenext"
40
- },
41
- "keywords": [
42
- "OPCUA",
43
- "opcua",
44
- "m2m",
45
- "iot",
46
- "opc ua",
47
- "internet of things"
48
- ],
49
- "author": "Etienne Rossignon",
50
- "license": "MIT",
51
- "engine": {
52
- "node": ">15.0"
53
- },
54
- "devDependencies": {
55
- "@types/mocha": "^10.0.1",
56
- "@types/node": "^20.5.0",
57
- "@typescript-eslint/eslint-plugin": "^6.4.0",
58
- "@typescript-eslint/parser": "^6.4.0",
59
- "cross-env": "^7.0.3",
60
- "esbuild-plugin-polyfill-node": "^0.3.0",
61
- "eslint": "^8.47.0",
62
- "eslint-config-prettier": "^9.0.0",
63
- "eslint-plugin-prettier": "^5.0.0",
64
- "lorem-ipsum": "^2.0.8",
65
- "mocha": "^10.2.0",
66
- "prettier": "^3.0.1",
67
- "should": "^13.2.3",
68
- "source-map-support": "^0.5.21",
69
- "ts-node": "^10.9.1",
70
- "typescript": "^5.1.6"
71
- },
72
- "dependencies": {
73
- "@peculiar/webcrypto": "^1.4.3",
74
- "@peculiar/x509": "^1.9.3",
75
- "@types/jsrsasign": "^10.5.8",
76
- "assert": "^2.0.0",
77
- "better-assert": "^1.0.2",
78
- "chalk": "^4.1.2",
79
- "crypto": "^1.0.1",
80
- "hexy": "0.3.5",
81
- "jsrsasign": "^10.8.6",
82
- "sshpk": "^1.17.0"
83
- },
84
- "repository": {
85
- "type": "git",
86
- "url": "git://github.com/node-opcua/node-opcua-crypto.git"
87
- },
88
- "bugs": {
89
- "url": "https://github.com/node-opcua/node-opcua-crypto/issues"
90
- }
91
- }
1
+ {
2
+ "name": "node-opcua-crypto",
3
+ "version": "4.3.1",
4
+ "description": "Crypto tools for Node-OPCUA",
5
+ "types": "./dist-types/index.d.ts",
6
+ "main": "./dist/index.js",
7
+ "exports": {
8
+ ".": {
9
+ "import": {
10
+ "types": "./dist-types/index.d.ts",
11
+ "default": "./dist/index.mjs"
12
+ },
13
+ "require": {
14
+ "types": "./dist-types/index.d.ts",
15
+ "default": "./dist/index.js"
16
+ }
17
+ },
18
+ "./web": {
19
+ "import": {
20
+ "types": "./dist-types/source/index.d.ts",
21
+ "default": "./dist/source/index.mjs"
22
+ },
23
+ "require": {
24
+ "types": "./dist-types/source/index.d.ts",
25
+ "default": "./dist/source/index.js"
26
+ }
27
+ }
28
+ },
29
+ "scripts": {
30
+ "build:tsup": "tsup ./index.ts ./source/index.ts ./source/index_web.ts ./source_nodejs/index.ts --shims --format esm,cjs,iife --sourcemap --clean",
31
+ "build:types": "tsc -p tsconfig.types.json",
32
+ "compile": "tsc -b ./tsconfig.cjs.json ./tsconfig.esm.json ./tsconfig.types.json",
33
+ "build:demo": "node web/esbuild.mjs",
34
+ "build:clean": "npx rimraf ./dist ./dist-* *.tsbuildinfo",
35
+ "build:old": "npm run build:clean && npm run compile && node ../../scripts/prepare-package-json.mjs",
36
+ "build": "npm run build:tsup",
37
+ "prepare": "npm run build",
38
+ "tslint": "tslint --project . --fix",
39
+ "lint": "eslint . --ext .ts",
40
+ "makedoc": "npx typedoc index.ts --excludeNotDocumented --exclude \"_*\" --excludePrivate --excludeProtected --excludeExternals -out doc",
41
+ "cost-of-modules": "npx cost-of-modules --no-install",
42
+ "prettier-format": "prettier --config .prettierrc.js source/**/*.ts test/**/*.ts --write",
43
+ "ncu": "npx npm-check-updates -u -x env-paths,chalk",
44
+ "experiment": "tsc test/test_peculiar_edge_case.ts -t es2021 -m nodenext"
45
+ },
46
+ "keywords": [
47
+ "OPCUA",
48
+ "opcua",
49
+ "m2m",
50
+ "iot",
51
+ "opc ua",
52
+ "internet of things"
53
+ ],
54
+ "makedoc": "npx typedoc packages/node-opcua-crypto/index.ts -out doc",
55
+ "author": "Etienne Rossignon",
56
+ "license": "MIT",
57
+ "engine": {
58
+ "node": ">15.0"
59
+ },
60
+ "devDependencies": {
61
+ "@types/node": "^20.5.9",
62
+ "lorem-ipsum": "^2.0.8"
63
+ },
64
+ "dependencies": {
65
+ "@peculiar/webcrypto": "^1.4.3",
66
+ "@peculiar/x509": "^1.9.5",
67
+ "@types/jsrsasign": "^10.5.8",
68
+ "@types/sshpk": "^1.17.1",
69
+ "assert": "^2.0.0",
70
+ "better-assert": "^1.0.2",
71
+ "chalk": "^4.1.2",
72
+ "hexy": "0.3.5",
73
+ "jsrsasign": "^10.8.6",
74
+ "sshpk": "^1.17.0"
75
+ },
76
+ "repository": {
77
+ "type": "git",
78
+ "url": "git://github.com/node-opcua/node-opcua-crypto.git"
79
+ },
80
+ "bugs": {
81
+ "url": "https://github.com/node-opcua/node-opcua-crypto/issues"
82
+ },
83
+ "gitHead": "0aa3e491d5d63ce1e718aaf5fa6a4a7d4321d415"
84
+ }
@@ -1,304 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports._readTime = exports._findBlockAtIndex = exports._readDirectoryName = exports.compactDirectoryName = exports._readValue = exports._readVersionValue = exports._readBooleanValue = exports._readIntegerValue = exports._readLongIntegerValue = exports._readSignatureValue = exports._readSignatureValueBin = exports._readECCAlgorithmIdentifier = exports._readAlgorithmIdentifier = exports._readObjectIdentifier = exports._readListOfInteger = exports._readIntegerAsByteString = exports._getBlock = exports._readOctetString = exports.formatBuffer2DigitHexWithColum = exports._readBitString = exports.parseBitString = exports._readStruct = exports.readTag = exports.TagType = void 0;
7
- var assert_1 = __importDefault(require("assert"));
8
- var oid_map_js_1 = require("./oid_map.js");
9
- var TagType;
10
- (function (TagType) {
11
- TagType[TagType["BOOLEAN"] = 1] = "BOOLEAN";
12
- TagType[TagType["INTEGER"] = 2] = "INTEGER";
13
- TagType[TagType["BIT_STRING"] = 3] = "BIT_STRING";
14
- TagType[TagType["OCTET_STRING"] = 4] = "OCTET_STRING";
15
- TagType[TagType["NULL"] = 5] = "NULL";
16
- TagType[TagType["OBJECT_IDENTIFIER"] = 6] = "OBJECT_IDENTIFIER";
17
- TagType[TagType["UTF8String"] = 12] = "UTF8String";
18
- TagType[TagType["NumericString"] = 18] = "NumericString";
19
- TagType[TagType["PrintableString"] = 19] = "PrintableString";
20
- TagType[TagType["TeletexString"] = 20] = "TeletexString";
21
- TagType[TagType["IA5String"] = 22] = "IA5String";
22
- TagType[TagType["UTCTime"] = 23] = "UTCTime";
23
- TagType[TagType["GeneralizedTime"] = 24] = "GeneralizedTime";
24
- TagType[TagType["GraphicString"] = 25] = "GraphicString";
25
- TagType[TagType["VisibleString"] = 26] = "VisibleString";
26
- TagType[TagType["GeneralString"] = 27] = "GeneralString";
27
- TagType[TagType["UniversalString"] = 28] = "UniversalString";
28
- TagType[TagType["BMPString"] = 30] = "BMPString";
29
- TagType[TagType["SEQUENCE"] = 48] = "SEQUENCE";
30
- TagType[TagType["SET"] = 49] = "SET";
31
- TagType[TagType["A3"] = 163] = "A3";
32
- })(TagType || (exports.TagType = TagType = {}));
33
- function readTag(buf, pos) {
34
- (0, assert_1.default)(buf instanceof Buffer);
35
- (0, assert_1.default)(Number.isFinite(pos) && pos >= 0);
36
- if (buf.length <= pos) {
37
- throw new Error("Invalid position : buf.length=" + buf.length + " pos =" + pos);
38
- }
39
- var tag = buf.readUInt8(pos);
40
- pos += 1;
41
- var length = buf.readUInt8(pos);
42
- pos += 1;
43
- if (length > 127) {
44
- var nbBytes = length & 0x7f;
45
- length = 0;
46
- for (var i = 0; i < nbBytes; i++) {
47
- length = length * 256 + buf.readUInt8(pos);
48
- pos += 1;
49
- }
50
- }
51
- return { tag: tag, position: pos, length: length };
52
- }
53
- exports.readTag = readTag;
54
- function _readStruct(buf, blockInfo) {
55
- var length = blockInfo.length;
56
- var cursor = blockInfo.position;
57
- var end = blockInfo.position + length;
58
- var blocks = [];
59
- while (cursor < end) {
60
- var inner = readTag(buf, cursor);
61
- cursor = inner.position + inner.length;
62
- blocks.push(inner);
63
- }
64
- return blocks;
65
- }
66
- exports._readStruct = _readStruct;
67
- function parseBitString(buffer, start, end, maxLength) {
68
- var unusedBit = buffer.readUInt8(start), lenBit = ((end - start - 1) << 3) - unusedBit, intro = "(" + lenBit + " bit)\n";
69
- var s = "", skip = unusedBit;
70
- for (var i = end - 1; i > start; --i) {
71
- var b = buffer.readUInt8(i);
72
- for (var j = skip; j < 8; ++j) {
73
- s += (b >> j) & 1 ? "1" : "0";
74
- }
75
- skip = 0;
76
- (0, assert_1.default)(s.length <= maxLength);
77
- }
78
- return intro + s;
79
- }
80
- exports.parseBitString = parseBitString;
81
- function _readBitString(buffer, block) {
82
- (0, assert_1.default)(block.tag === TagType.BIT_STRING);
83
- var data = _getBlock(buffer, block);
84
- var ignore_bits = data.readUInt8(0);
85
- return {
86
- lengthInBits: data.length * 8 - ignore_bits,
87
- lengthInBytes: data.length - 1,
88
- data: data.subarray(1),
89
- debug: parseBitString(buffer, block.position, block.length + block.position, 4 * 16 * 1024),
90
- };
91
- }
92
- exports._readBitString = _readBitString;
93
- function formatBuffer2DigitHexWithColum(buffer) {
94
- var value = [];
95
- for (var i = 0; i < buffer.length; i++) {
96
- value.push(("00" + buffer.readUInt8(i).toString(16)).substr(-2, 2));
97
- }
98
- return value
99
- .join(":")
100
- .toUpperCase()
101
- .replace(/^(00:)*/, "");
102
- }
103
- exports.formatBuffer2DigitHexWithColum = formatBuffer2DigitHexWithColum;
104
- function _readOctetString(buffer, block) {
105
- (0, assert_1.default)(block.tag === TagType.OCTET_STRING);
106
- var tag = readTag(buffer, block.position);
107
- (0, assert_1.default)(tag.tag === TagType.OCTET_STRING);
108
- var nbBytes = tag.length;
109
- var pos = tag.position;
110
- var b = buffer.subarray(pos, pos + nbBytes);
111
- return b;
112
- }
113
- exports._readOctetString = _readOctetString;
114
- function _getBlock(buffer, block) {
115
- var start = block.position;
116
- var end = block.position + block.length;
117
- return buffer.subarray(start, end);
118
- }
119
- exports._getBlock = _getBlock;
120
- function _readIntegerAsByteString(buffer, block) {
121
- return _getBlock(buffer, block);
122
- }
123
- exports._readIntegerAsByteString = _readIntegerAsByteString;
124
- function _readListOfInteger(buffer) {
125
- var block = readTag(buffer, 0);
126
- var inner_blocks = _readStruct(buffer, block);
127
- return inner_blocks.map(function (bblock) {
128
- return _readIntegerAsByteString(buffer, bblock);
129
- });
130
- }
131
- exports._readListOfInteger = _readListOfInteger;
132
- function parseOID(buffer, start, end) {
133
- var s = "", n = 0, bits = 0;
134
- for (var i = start; i < end; ++i) {
135
- var v = buffer.readUInt8(i);
136
- n = n * 128 + (v & 0x7f);
137
- bits += 7;
138
- if (!(v & 0x80)) {
139
- if (s === "") {
140
- var m = n < 80 ? (n < 40 ? 0 : 1) : 2;
141
- s = m + "." + (n - m * 40);
142
- }
143
- else {
144
- s += "." + n.toString();
145
- }
146
- n = 0;
147
- bits = 0;
148
- }
149
- }
150
- (0, assert_1.default)(bits === 0);
151
- return s;
152
- }
153
- function _readObjectIdentifier(buffer, block) {
154
- (0, assert_1.default)(block.tag === TagType.OBJECT_IDENTIFIER);
155
- var b = buffer.subarray(block.position, block.position + block.length);
156
- var oid = parseOID(b, 0, block.length);
157
- return {
158
- oid: oid,
159
- name: oid_map_js_1.oid_map[oid] ? oid_map_js_1.oid_map[oid].d : oid,
160
- };
161
- }
162
- exports._readObjectIdentifier = _readObjectIdentifier;
163
- function _readAlgorithmIdentifier(buffer, block) {
164
- var inner_blocks = _readStruct(buffer, block);
165
- return {
166
- identifier: _readObjectIdentifier(buffer, inner_blocks[0]).name,
167
- };
168
- }
169
- exports._readAlgorithmIdentifier = _readAlgorithmIdentifier;
170
- ;
171
- function _readECCAlgorithmIdentifier(buffer, block) {
172
- var inner_blocks = _readStruct(buffer, block);
173
- return {
174
- identifier: _readObjectIdentifier(buffer, inner_blocks[1]).name,
175
- };
176
- }
177
- exports._readECCAlgorithmIdentifier = _readECCAlgorithmIdentifier;
178
- ;
179
- function _readSignatureValueBin(buffer, block) {
180
- return _readBitString(buffer, block).data;
181
- }
182
- exports._readSignatureValueBin = _readSignatureValueBin;
183
- function _readSignatureValue(buffer, block) {
184
- return _readSignatureValueBin(buffer, block).toString("hex");
185
- }
186
- exports._readSignatureValue = _readSignatureValue;
187
- function _readLongIntegerValue(buffer, block) {
188
- (0, assert_1.default)(block.tag === TagType.INTEGER, "expecting a INTEGER tag");
189
- var pos = block.position;
190
- var nbBytes = block.length;
191
- var buf = buffer.subarray(pos, pos + nbBytes);
192
- return buf;
193
- }
194
- exports._readLongIntegerValue = _readLongIntegerValue;
195
- function _readIntegerValue(buffer, block) {
196
- (0, assert_1.default)(block.tag === TagType.INTEGER, "expecting a INTEGER tag");
197
- var pos = block.position;
198
- var nbBytes = block.length;
199
- (0, assert_1.default)(nbBytes < 4);
200
- var value = 0;
201
- for (var i = 0; i < nbBytes; i++) {
202
- value = value * 256 + buffer.readUInt8(pos);
203
- pos += 1;
204
- }
205
- return value;
206
- }
207
- exports._readIntegerValue = _readIntegerValue;
208
- function _readBooleanValue(buffer, block) {
209
- (0, assert_1.default)(block.tag === TagType.BOOLEAN, "expecting a BOOLEAN tag. got " + TagType[block.tag]);
210
- var pos = block.position;
211
- var nbBytes = block.length;
212
- (0, assert_1.default)(nbBytes < 4);
213
- var value = buffer.readUInt8(pos) ? true : false;
214
- return value;
215
- }
216
- exports._readBooleanValue = _readBooleanValue;
217
- function _readVersionValue(buffer, block) {
218
- block = readTag(buffer, block.position);
219
- return _readIntegerValue(buffer, block);
220
- }
221
- exports._readVersionValue = _readVersionValue;
222
- function convertGeneralizedTime(str) {
223
- var year = parseInt(str.substr(0, 4), 10);
224
- var month = parseInt(str.substr(4, 2), 10) - 1;
225
- var day = parseInt(str.substr(6, 2), 10);
226
- var hours = parseInt(str.substr(8, 2), 10);
227
- var mins = parseInt(str.substr(10, 2), 10);
228
- var secs = parseInt(str.substr(12, 2), 10);
229
- return new Date(Date.UTC(year, month, day, hours, mins, secs));
230
- }
231
- function _readBMPString(buffer, block) {
232
- var strBuff = _getBlock(buffer, block);
233
- var str = "";
234
- for (var i = 0; i < strBuff.length; i += 2) {
235
- var word = strBuff.readUInt16BE(i);
236
- str += String.fromCharCode(word);
237
- }
238
- return str;
239
- }
240
- function convertUTCTime(str) {
241
- var year = parseInt(str.substr(0, 2), 10);
242
- var month = parseInt(str.substr(2, 2), 10) - 1;
243
- var day = parseInt(str.substr(4, 2), 10);
244
- var hours = parseInt(str.substr(6, 2), 10);
245
- var mins = parseInt(str.substr(8, 2), 10);
246
- var secs = parseInt(str.substr(10, 2), 10);
247
- year += year >= 50 ? 1900 : 2000;
248
- return new Date(Date.UTC(year, month, day, hours, mins, secs));
249
- }
250
- function _readValue(buffer, block) {
251
- switch (block.tag) {
252
- case TagType.BOOLEAN:
253
- return _readBooleanValue(buffer, block);
254
- case TagType.BMPString:
255
- return _readBMPString(buffer, block);
256
- case TagType.PrintableString:
257
- case TagType.TeletexString:
258
- case TagType.UTF8String:
259
- case TagType.NumericString:
260
- case TagType.IA5String:
261
- return _getBlock(buffer, block).toString("ascii");
262
- case TagType.UTCTime:
263
- return convertUTCTime(_getBlock(buffer, block).toString("ascii"));
264
- case TagType.GeneralizedTime:
265
- return convertGeneralizedTime(_getBlock(buffer, block).toString("ascii"));
266
- default:
267
- throw new Error("Invalid tag 0x" + block.tag.toString(16) + "");
268
- }
269
- }
270
- exports._readValue = _readValue;
271
- function compactDirectoryName(d) {
272
- return JSON.stringify(d);
273
- }
274
- exports.compactDirectoryName = compactDirectoryName;
275
- function _readDirectoryName(buffer, block) {
276
- var set_blocks = _readStruct(buffer, block);
277
- var names = {};
278
- for (var _i = 0, set_blocks_1 = set_blocks; _i < set_blocks_1.length; _i++) {
279
- var set_block = set_blocks_1[_i];
280
- (0, assert_1.default)(set_block.tag === 0x31);
281
- var blocks = _readStruct(buffer, set_block);
282
- (0, assert_1.default)(blocks.length === 1);
283
- (0, assert_1.default)(blocks[0].tag === 0x30);
284
- var sequenceBlock = _readStruct(buffer, blocks[0]);
285
- (0, assert_1.default)(sequenceBlock.length === 2);
286
- var type = _readObjectIdentifier(buffer, sequenceBlock[0]);
287
- names[type.name] = _readValue(buffer, sequenceBlock[1]);
288
- }
289
- return names;
290
- }
291
- exports._readDirectoryName = _readDirectoryName;
292
- function _findBlockAtIndex(blocks, index) {
293
- var tmp = blocks.filter(function (b) { return b.tag === 0xa0 + index || b.tag === 0x80 + index; });
294
- if (tmp.length === 0) {
295
- return null;
296
- }
297
- return tmp[0];
298
- }
299
- exports._findBlockAtIndex = _findBlockAtIndex;
300
- function _readTime(buffer, block) {
301
- return _readValue(buffer, block);
302
- }
303
- exports._readTime = _readTime;
304
- //# sourceMappingURL=asn1.js.map