node-forge 0.9.2 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/x509.js CHANGED
@@ -689,6 +689,101 @@ var _readSignatureParameters = function(oid, obj, fillDefaults) {
689
689
  return params;
690
690
  };
691
691
 
692
+ /**
693
+ * Create signature digest for OID.
694
+ *
695
+ * @param options
696
+ * signatureOid: the OID specifying the signature algorithm.
697
+ * type: a human readable type for error messages
698
+ * @return a created md instance. throws if unknown oid.
699
+ */
700
+ var _createSignatureDigest = function(options) {
701
+ switch(oids[options.signatureOid]) {
702
+ case 'sha1WithRSAEncryption':
703
+ // deprecated alias
704
+ case 'sha1WithRSASignature':
705
+ return forge.md.sha1.create();
706
+ case 'md5WithRSAEncryption':
707
+ return forge.md.md5.create();
708
+ case 'sha256WithRSAEncryption':
709
+ return forge.md.sha256.create();
710
+ case 'sha384WithRSAEncryption':
711
+ return forge.md.sha384.create();
712
+ case 'sha512WithRSAEncryption':
713
+ return forge.md.sha512.create();
714
+ case 'RSASSA-PSS':
715
+ return forge.md.sha256.create();
716
+ default:
717
+ var error = new Error(
718
+ 'Could not compute ' + options.type + ' digest. ' +
719
+ 'Unknown signature OID.');
720
+ error.signatureOid = options.signatureOid;
721
+ throw error;
722
+ }
723
+ };
724
+
725
+ /**
726
+ * Verify signature on certificate or CSR.
727
+ *
728
+ * @param options:
729
+ * certificate the certificate or CSR to verify.
730
+ * md the signature digest.
731
+ * signature the signature
732
+ * @return a created md instance. throws if unknown oid.
733
+ */
734
+ var _verifySignature = function(options) {
735
+ var cert = options.certificate;
736
+ var scheme;
737
+
738
+ switch(cert.signatureOid) {
739
+ case oids.sha1WithRSAEncryption:
740
+ // deprecated alias
741
+ case oids.sha1WithRSASignature:
742
+ /* use PKCS#1 v1.5 padding scheme */
743
+ break;
744
+ case oids['RSASSA-PSS']:
745
+ var hash, mgf;
746
+
747
+ /* initialize mgf */
748
+ hash = oids[cert.signatureParameters.mgf.hash.algorithmOid];
749
+ if(hash === undefined || forge.md[hash] === undefined) {
750
+ var error = new Error('Unsupported MGF hash function.');
751
+ error.oid = cert.signatureParameters.mgf.hash.algorithmOid;
752
+ error.name = hash;
753
+ throw error;
754
+ }
755
+
756
+ mgf = oids[cert.signatureParameters.mgf.algorithmOid];
757
+ if(mgf === undefined || forge.mgf[mgf] === undefined) {
758
+ var error = new Error('Unsupported MGF function.');
759
+ error.oid = cert.signatureParameters.mgf.algorithmOid;
760
+ error.name = mgf;
761
+ throw error;
762
+ }
763
+
764
+ mgf = forge.mgf[mgf].create(forge.md[hash].create());
765
+
766
+ /* initialize hash function */
767
+ hash = oids[cert.signatureParameters.hash.algorithmOid];
768
+ if(hash === undefined || forge.md[hash] === undefined) {
769
+ var error = new Error('Unsupported RSASSA-PSS hash function.');
770
+ error.oid = cert.signatureParameters.hash.algorithmOid;
771
+ error.name = hash;
772
+ throw error;
773
+ }
774
+
775
+ scheme = forge.pss.create(
776
+ forge.md[hash].create(), mgf, cert.signatureParameters.saltLength
777
+ );
778
+ break;
779
+ }
780
+
781
+ // verify signature on cert using public key
782
+ return cert.publicKey.verify(
783
+ options.md.digest().getBytes(), options.signature, scheme
784
+ );
785
+ };
786
+
692
787
  /**
693
788
  * Converts an X.509 certificate from PEM format.
694
789
  *
@@ -1069,43 +1164,18 @@ pki.createCertificate = function() {
1069
1164
  'The parent certificate did not issue the given child ' +
1070
1165
  'certificate; the child certificate\'s issuer does not match the ' +
1071
1166
  'parent\'s subject.');
1072
- error.expectedIssuer = issuer.attributes;
1073
- error.actualIssuer = subject.attributes;
1167
+ error.expectedIssuer = subject.attributes;
1168
+ error.actualIssuer = issuer.attributes;
1074
1169
  throw error;
1075
1170
  }
1076
1171
 
1077
1172
  var md = child.md;
1078
1173
  if(md === null) {
1079
- // check signature OID for supported signature types
1080
- if(child.signatureOid in oids) {
1081
- var oid = oids[child.signatureOid];
1082
- switch(oid) {
1083
- case 'sha1WithRSAEncryption':
1084
- md = forge.md.sha1.create();
1085
- break;
1086
- case 'md5WithRSAEncryption':
1087
- md = forge.md.md5.create();
1088
- break;
1089
- case 'sha256WithRSAEncryption':
1090
- md = forge.md.sha256.create();
1091
- break;
1092
- case 'sha384WithRSAEncryption':
1093
- md = forge.md.sha384.create();
1094
- break;
1095
- case 'sha512WithRSAEncryption':
1096
- md = forge.md.sha512.create();
1097
- break;
1098
- case 'RSASSA-PSS':
1099
- md = forge.md.sha256.create();
1100
- break;
1101
- }
1102
- }
1103
- if(md === null) {
1104
- var error = new Error('Could not compute certificate digest. ' +
1105
- 'Unknown signature OID.');
1106
- error.signatureOid = child.signatureOid;
1107
- throw error;
1108
- }
1174
+ // create digest for OID signature types
1175
+ md = _createSignatureDigest({
1176
+ signatureOid: child.signatureOid,
1177
+ type: 'certificate'
1178
+ });
1109
1179
 
1110
1180
  // produce DER formatted TBSCertificate and digest it
1111
1181
  var tbsCertificate = child.tbsCertificate || pki.getTBSCertificate(child);
@@ -1114,52 +1184,9 @@ pki.createCertificate = function() {
1114
1184
  }
1115
1185
 
1116
1186
  if(md !== null) {
1117
- var scheme;
1118
-
1119
- switch(child.signatureOid) {
1120
- case oids.sha1WithRSAEncryption:
1121
- scheme = undefined; /* use PKCS#1 v1.5 padding scheme */
1122
- break;
1123
- case oids['RSASSA-PSS']:
1124
- var hash, mgf;
1125
-
1126
- /* initialize mgf */
1127
- hash = oids[child.signatureParameters.mgf.hash.algorithmOid];
1128
- if(hash === undefined || forge.md[hash] === undefined) {
1129
- var error = new Error('Unsupported MGF hash function.');
1130
- error.oid = child.signatureParameters.mgf.hash.algorithmOid;
1131
- error.name = hash;
1132
- throw error;
1133
- }
1134
-
1135
- mgf = oids[child.signatureParameters.mgf.algorithmOid];
1136
- if(mgf === undefined || forge.mgf[mgf] === undefined) {
1137
- var error = new Error('Unsupported MGF function.');
1138
- error.oid = child.signatureParameters.mgf.algorithmOid;
1139
- error.name = mgf;
1140
- throw error;
1141
- }
1142
-
1143
- mgf = forge.mgf[mgf].create(forge.md[hash].create());
1144
-
1145
- /* initialize hash function */
1146
- hash = oids[child.signatureParameters.hash.algorithmOid];
1147
- if(hash === undefined || forge.md[hash] === undefined) {
1148
- throw {
1149
- message: 'Unsupported RSASSA-PSS hash function.',
1150
- oid: child.signatureParameters.hash.algorithmOid,
1151
- name: hash
1152
- };
1153
- }
1154
-
1155
- scheme = forge.pss.create(forge.md[hash].create(), mgf,
1156
- child.signatureParameters.saltLength);
1157
- break;
1158
- }
1159
-
1160
- // verify signature on cert using public key
1161
- rval = cert.publicKey.verify(
1162
- md.digest().getBytes(), child.signature, scheme);
1187
+ rval = _verifySignature({
1188
+ certificate: cert, md: md, signature: child.signature
1189
+ });
1163
1190
  }
1164
1191
 
1165
1192
  return rval;
@@ -1333,37 +1360,11 @@ pki.certificateFromAsn1 = function(obj, computeHash) {
1333
1360
  cert.tbsCertificate = capture.tbsCertificate;
1334
1361
 
1335
1362
  if(computeHash) {
1336
- // check signature OID for supported signature types
1337
- cert.md = null;
1338
- if(cert.signatureOid in oids) {
1339
- var oid = oids[cert.signatureOid];
1340
- switch(oid) {
1341
- case 'sha1WithRSAEncryption':
1342
- cert.md = forge.md.sha1.create();
1343
- break;
1344
- case 'md5WithRSAEncryption':
1345
- cert.md = forge.md.md5.create();
1346
- break;
1347
- case 'sha256WithRSAEncryption':
1348
- cert.md = forge.md.sha256.create();
1349
- break;
1350
- case 'sha384WithRSAEncryption':
1351
- cert.md = forge.md.sha384.create();
1352
- break;
1353
- case 'sha512WithRSAEncryption':
1354
- cert.md = forge.md.sha512.create();
1355
- break;
1356
- case 'RSASSA-PSS':
1357
- cert.md = forge.md.sha256.create();
1358
- break;
1359
- }
1360
- }
1361
- if(cert.md === null) {
1362
- var error = new Error('Could not compute certificate digest. ' +
1363
- 'Unknown signature OID.');
1364
- error.signatureOid = cert.signatureOid;
1365
- throw error;
1366
- }
1363
+ // create digest for OID signature type
1364
+ cert.md = _createSignatureDigest({
1365
+ signatureOid: cert.signatureOid,
1366
+ type: 'certificate'
1367
+ });
1367
1368
 
1368
1369
  // produce DER formatted TBSCertificate and digest it
1369
1370
  var bytes = asn1.toDer(cert.tbsCertificate);
@@ -1372,6 +1373,8 @@ pki.certificateFromAsn1 = function(obj, computeHash) {
1372
1373
 
1373
1374
  // handle issuer, build issuer message digest
1374
1375
  var imd = forge.md.sha1.create();
1376
+ var ibytes = asn1.toDer(capture.certIssuer);
1377
+ imd.update(ibytes.getBytes());
1375
1378
  cert.issuer.getField = function(sn) {
1376
1379
  return _getAttribute(cert.issuer, sn);
1377
1380
  };
@@ -1379,7 +1382,7 @@ pki.certificateFromAsn1 = function(obj, computeHash) {
1379
1382
  _fillMissingFields([attr]);
1380
1383
  cert.issuer.attributes.push(attr);
1381
1384
  };
1382
- cert.issuer.attributes = pki.RDNAttributesAsArray(capture.certIssuer, imd);
1385
+ cert.issuer.attributes = pki.RDNAttributesAsArray(capture.certIssuer);
1383
1386
  if(capture.certIssuerUniqueId) {
1384
1387
  cert.issuer.uniqueId = capture.certIssuerUniqueId;
1385
1388
  }
@@ -1387,6 +1390,8 @@ pki.certificateFromAsn1 = function(obj, computeHash) {
1387
1390
 
1388
1391
  // handle subject, build subject message digest
1389
1392
  var smd = forge.md.sha1.create();
1393
+ var sbytes = asn1.toDer(capture.certSubject);
1394
+ smd.update(sbytes.getBytes());
1390
1395
  cert.subject.getField = function(sn) {
1391
1396
  return _getAttribute(cert.subject, sn);
1392
1397
  };
@@ -1394,7 +1399,7 @@ pki.certificateFromAsn1 = function(obj, computeHash) {
1394
1399
  _fillMissingFields([attr]);
1395
1400
  cert.subject.attributes.push(attr);
1396
1401
  };
1397
- cert.subject.attributes = pki.RDNAttributesAsArray(capture.certSubject, smd);
1402
+ cert.subject.attributes = pki.RDNAttributesAsArray(capture.certSubject);
1398
1403
  if(capture.certSubjectUniqueId) {
1399
1404
  cert.subject.uniqueId = capture.certSubjectUniqueId;
1400
1405
  }
@@ -1677,37 +1682,11 @@ pki.certificationRequestFromAsn1 = function(obj, computeHash) {
1677
1682
  csr.certificationRequestInfo = capture.certificationRequestInfo;
1678
1683
 
1679
1684
  if(computeHash) {
1680
- // check signature OID for supported signature types
1681
- csr.md = null;
1682
- if(csr.signatureOid in oids) {
1683
- var oid = oids[csr.signatureOid];
1684
- switch(oid) {
1685
- case 'sha1WithRSAEncryption':
1686
- csr.md = forge.md.sha1.create();
1687
- break;
1688
- case 'md5WithRSAEncryption':
1689
- csr.md = forge.md.md5.create();
1690
- break;
1691
- case 'sha256WithRSAEncryption':
1692
- csr.md = forge.md.sha256.create();
1693
- break;
1694
- case 'sha384WithRSAEncryption':
1695
- csr.md = forge.md.sha384.create();
1696
- break;
1697
- case 'sha512WithRSAEncryption':
1698
- csr.md = forge.md.sha512.create();
1699
- break;
1700
- case 'RSASSA-PSS':
1701
- csr.md = forge.md.sha256.create();
1702
- break;
1703
- }
1704
- }
1705
- if(csr.md === null) {
1706
- var error = new Error('Could not compute certification request digest. ' +
1707
- 'Unknown signature OID.');
1708
- error.signatureOid = csr.signatureOid;
1709
- throw error;
1710
- }
1685
+ // create digest for OID signature type
1686
+ csr.md = _createSignatureDigest({
1687
+ signatureOid: csr.signatureOid,
1688
+ type: 'certification request'
1689
+ });
1711
1690
 
1712
1691
  // produce DER formatted CertificationRequestInfo and digest it
1713
1692
  var bytes = asn1.toDer(csr.certificationRequestInfo);
@@ -1847,38 +1826,10 @@ pki.createCertificationRequest = function() {
1847
1826
 
1848
1827
  var md = csr.md;
1849
1828
  if(md === null) {
1850
- // check signature OID for supported signature types
1851
- if(csr.signatureOid in oids) {
1852
- // TODO: create DRY `OID to md` function
1853
- var oid = oids[csr.signatureOid];
1854
- switch(oid) {
1855
- case 'sha1WithRSAEncryption':
1856
- md = forge.md.sha1.create();
1857
- break;
1858
- case 'md5WithRSAEncryption':
1859
- md = forge.md.md5.create();
1860
- break;
1861
- case 'sha256WithRSAEncryption':
1862
- md = forge.md.sha256.create();
1863
- break;
1864
- case 'sha384WithRSAEncryption':
1865
- md = forge.md.sha384.create();
1866
- break;
1867
- case 'sha512WithRSAEncryption':
1868
- md = forge.md.sha512.create();
1869
- break;
1870
- case 'RSASSA-PSS':
1871
- md = forge.md.sha256.create();
1872
- break;
1873
- }
1874
- }
1875
- if(md === null) {
1876
- var error = new Error(
1877
- 'Could not compute certification request digest. ' +
1878
- 'Unknown signature OID.');
1879
- error.signatureOid = csr.signatureOid;
1880
- throw error;
1881
- }
1829
+ md = _createSignatureDigest({
1830
+ signatureOid: csr.signatureOid,
1831
+ type: 'certification request'
1832
+ });
1882
1833
 
1883
1834
  // produce DER formatted CertificationRequestInfo and digest it
1884
1835
  var cri = csr.certificationRequestInfo ||
@@ -1888,51 +1839,9 @@ pki.createCertificationRequest = function() {
1888
1839
  }
1889
1840
 
1890
1841
  if(md !== null) {
1891
- var scheme;
1892
-
1893
- switch(csr.signatureOid) {
1894
- case oids.sha1WithRSAEncryption:
1895
- /* use PKCS#1 v1.5 padding scheme */
1896
- break;
1897
- case oids['RSASSA-PSS']:
1898
- var hash, mgf;
1899
-
1900
- /* initialize mgf */
1901
- hash = oids[csr.signatureParameters.mgf.hash.algorithmOid];
1902
- if(hash === undefined || forge.md[hash] === undefined) {
1903
- var error = new Error('Unsupported MGF hash function.');
1904
- error.oid = csr.signatureParameters.mgf.hash.algorithmOid;
1905
- error.name = hash;
1906
- throw error;
1907
- }
1908
-
1909
- mgf = oids[csr.signatureParameters.mgf.algorithmOid];
1910
- if(mgf === undefined || forge.mgf[mgf] === undefined) {
1911
- var error = new Error('Unsupported MGF function.');
1912
- error.oid = csr.signatureParameters.mgf.algorithmOid;
1913
- error.name = mgf;
1914
- throw error;
1915
- }
1916
-
1917
- mgf = forge.mgf[mgf].create(forge.md[hash].create());
1918
-
1919
- /* initialize hash function */
1920
- hash = oids[csr.signatureParameters.hash.algorithmOid];
1921
- if(hash === undefined || forge.md[hash] === undefined) {
1922
- var error = new Error('Unsupported RSASSA-PSS hash function.');
1923
- error.oid = csr.signatureParameters.hash.algorithmOid;
1924
- error.name = hash;
1925
- throw error;
1926
- }
1927
-
1928
- scheme = forge.pss.create(forge.md[hash].create(), mgf,
1929
- csr.signatureParameters.saltLength);
1930
- break;
1931
- }
1932
-
1933
- // verify signature on csr using its public key
1934
- rval = csr.publicKey.verify(
1935
- md.digest().getBytes(), csr.signature, scheme);
1842
+ rval = _verifySignature({
1843
+ certificate: csr, md: md, signature: csr.signature
1844
+ });
1936
1845
  }
1937
1846
 
1938
1847
  return rval;
package/lib/xhr.js CHANGED
@@ -151,7 +151,7 @@ xhrApi.init = function(options) {
151
151
  getPrivateKey: options.getPrivateKey,
152
152
  getSignature: options.getSignature
153
153
  });
154
- _clients[_client.url.full] = _client;
154
+ _clients[_client.url.origin] = _client;
155
155
 
156
156
  forge.log.debug(cat, 'ready');
157
157
  };
@@ -380,8 +380,10 @@ xhrApi.create = function(options) {
380
380
  // use default
381
381
  _state.client = _client;
382
382
  } else {
383
- var url = http.parseUrl(options.url);
384
- if(!url) {
383
+ var url;
384
+ try {
385
+ url = new URL(options.url);
386
+ } catch(e) {
385
387
  var error = new Error('Invalid url.');
386
388
  error.details = {
387
389
  url: options.url
@@ -389,9 +391,9 @@ xhrApi.create = function(options) {
389
391
  }
390
392
 
391
393
  // find client
392
- if(url.full in _clients) {
394
+ if(url.origin in _clients) {
393
395
  // client found
394
- _state.client = _clients[url.full];
396
+ _state.client = _clients[url.origin];
395
397
  } else {
396
398
  // create client
397
399
  _state.client = http.createClient({
@@ -409,7 +411,7 @@ xhrApi.create = function(options) {
409
411
  getPrivateKey: options.getPrivateKey,
410
412
  getSignature: options.getSignature
411
413
  });
412
- _clients[url.full] = _state.client;
414
+ _clients[url.origin] = _state.client;
413
415
  }
414
416
  }
415
417
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-forge",
3
- "version": "0.9.2",
3
+ "version": "1.2.0",
4
4
  "description": "JavaScript implementations of network transports, cryptography, ciphers, PKI, message digests, and various utilities.",
5
5
  "homepage": "https://github.com/digitalbazaar/forge",
6
6
  "author": {
@@ -15,31 +15,32 @@
15
15
  "Christoph Dorn <christoph@christophdorn.com>"
16
16
  ],
17
17
  "devDependencies": {
18
- "browserify": "^16.1.0",
18
+ "browserify": "^16.5.2",
19
19
  "commander": "^2.20.0",
20
- "cross-env": "^5.1.3",
21
- "eslint": "^5.16.0",
22
- "eslint-config-digitalbazaar": "^2.0.0",
20
+ "cross-env": "^5.2.1",
21
+ "eslint": "^7.27.0",
22
+ "eslint-config-digitalbazaar": "^2.8.0",
23
23
  "express": "^4.16.2",
24
- "karma": "^3.1.4",
25
- "karma-browserify": "^6.0.0",
26
- "karma-chrome-launcher": "^2.2.0",
24
+ "karma": "^4.4.1",
25
+ "karma-browserify": "^7.0.0",
26
+ "karma-chrome-launcher": "^3.1.0",
27
27
  "karma-edge-launcher": "^0.4.2",
28
- "karma-firefox-launcher": "^1.1.0",
28
+ "karma-firefox-launcher": "^1.3.0",
29
29
  "karma-ie-launcher": "^1.0.0",
30
30
  "karma-mocha": "^1.3.0",
31
31
  "karma-mocha-reporter": "^2.2.5",
32
32
  "karma-safari-launcher": "^1.0.0",
33
- "karma-sauce-launcher": "^1.2.0",
34
- "karma-sourcemap-loader": "^0.3.7",
33
+ "karma-sauce-launcher": "^2.0.2",
34
+ "karma-sourcemap-loader": "^0.3.8",
35
35
  "karma-tap-reporter": "0.0.6",
36
- "karma-webpack": "^3.0.5",
36
+ "karma-webpack": "^4.0.2",
37
37
  "mocha": "^5.2.0",
38
38
  "mocha-lcov-reporter": "^1.2.0",
39
39
  "nodejs-websocket": "^1.7.1",
40
- "nyc": "^14.1.1",
41
- "opts": "^1.2.2",
42
- "webpack": "^3.11.0",
40
+ "nyc": "^15.1.0",
41
+ "opts": "^1.2.7",
42
+ "webpack": "^4.44.1",
43
+ "webpack-cli": "^3.3.12",
43
44
  "worker-loader": "^2.0.0"
44
45
  },
45
46
  "repository": {
@@ -59,7 +60,7 @@
59
60
  "dist/*.min.js.map"
60
61
  ],
61
62
  "engines": {
62
- "node": ">= 4.5.0"
63
+ "node": ">= 6.13.0"
63
64
  },
64
65
  "keywords": [
65
66
  "aes",
@@ -94,13 +95,15 @@
94
95
  "prepublish": "npm run build",
95
96
  "build": "webpack",
96
97
  "test-build": "webpack --config webpack-tests.config.js",
97
- "test": "cross-env NODE_ENV=test mocha -t 30000 -R ${REPORTER:-spec} tests/unit/index.js",
98
+ "test": "npm run test-node",
99
+ "test-node": "cross-env NODE_ENV=test mocha -t 30000 -R ${REPORTER:-spec} tests/unit/index.js",
98
100
  "test-karma": "karma start",
99
101
  "test-karma-sauce": "karma start karma-sauce.conf",
100
102
  "test-server": "node tests/server.js",
101
103
  "test-server-ws": "node tests/websockets/server-ws.js",
102
104
  "test-server-webid": "node tests/websockets/server-webid.js",
103
105
  "coverage": "rm -rf coverage && nyc --reporter=lcov --reporter=text-summary npm test",
106
+ "coverage-ci": "rm -rf coverage && nyc --reporter=lcovonly npm test",
104
107
  "coverage-report": "nyc report",
105
108
  "lint": "eslint *.js lib/*.js tests/*.js tests/**/*.js examples/*.js flash/*.js"
106
109
  },
package/lib/debug.js DELETED
@@ -1,78 +0,0 @@
1
- /**
2
- * Debugging support for web applications.
3
- *
4
- * @author David I. Lehn <dlehn@digitalbazaar.com>
5
- *
6
- * Copyright 2008-2013 Digital Bazaar, Inc.
7
- */
8
- var forge = require('./forge');
9
-
10
- /* DEBUG API */
11
- module.exports = forge.debug = forge.debug || {};
12
-
13
- // Private storage for debugging.
14
- // Useful to expose data that is otherwise unviewable behind closures.
15
- // NOTE: remember that this can hold references to data and cause leaks!
16
- // format is "forge._debug.<modulename>.<dataname> = data"
17
- // Example:
18
- // (function() {
19
- // var cat = 'forge.test.Test'; // debugging category
20
- // var sState = {...}; // local state
21
- // forge.debug.set(cat, 'sState', sState);
22
- // })();
23
- forge.debug.storage = {};
24
-
25
- /**
26
- * Gets debug data. Omit name for all cat data Omit name and cat for
27
- * all data.
28
- *
29
- * @param cat name of debugging category.
30
- * @param name name of data to get (optional).
31
- * @return object with requested debug data or undefined.
32
- */
33
- forge.debug.get = function(cat, name) {
34
- var rval;
35
- if(typeof(cat) === 'undefined') {
36
- rval = forge.debug.storage;
37
- } else if(cat in forge.debug.storage) {
38
- if(typeof(name) === 'undefined') {
39
- rval = forge.debug.storage[cat];
40
- } else {
41
- rval = forge.debug.storage[cat][name];
42
- }
43
- }
44
- return rval;
45
- };
46
-
47
- /**
48
- * Sets debug data.
49
- *
50
- * @param cat name of debugging category.
51
- * @param name name of data to set.
52
- * @param data data to set.
53
- */
54
- forge.debug.set = function(cat, name, data) {
55
- if(!(cat in forge.debug.storage)) {
56
- forge.debug.storage[cat] = {};
57
- }
58
- forge.debug.storage[cat][name] = data;
59
- };
60
-
61
- /**
62
- * Clears debug data. Omit name for all cat data. Omit name and cat for
63
- * all data.
64
- *
65
- * @param cat name of debugging category.
66
- * @param name name of data to clear or omit to clear entire category.
67
- */
68
- forge.debug.clear = function(cat, name) {
69
- if(typeof(cat) === 'undefined') {
70
- forge.debug.storage = {};
71
- } else if(cat in forge.debug.storage) {
72
- if(typeof(name) === 'undefined') {
73
- delete forge.debug.storage[cat];
74
- } else {
75
- delete forge.debug.storage[cat][name];
76
- }
77
- }
78
- };