node-forge 0.7.5 → 0.7.6

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/pkcs7.js CHANGED
@@ -328,8 +328,11 @@ p7.createSignedData = function() {
328
328
 
329
329
  /**
330
330
  * Signs the content.
331
+ * @param options Options to apply when signing:
332
+ * [detached] boolean. If signing should be done in detached mode. Defaults to false.
331
333
  */
332
- sign: function() {
334
+ sign: function(options) {
335
+ options = options || {};
333
336
  // auto-generate content info
334
337
  if(typeof msg.content !== 'object' || msg.contentInfo === null) {
335
338
  // use Data ContentInfo
@@ -349,12 +352,16 @@ p7.createSignedData = function() {
349
352
  content = forge.util.encodeUtf8(msg.content);
350
353
  }
351
354
 
352
- msg.contentInfo.value.push(
353
- // [0] EXPLICIT content
354
- asn1.create(asn1.Class.CONTEXT_SPECIFIC, 0, true, [
355
- asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OCTETSTRING, false,
356
- content)
357
- ]));
355
+ if (options.detached) {
356
+ msg.detachedContent = asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OCTETSTRING, false, content);
357
+ } else {
358
+ msg.contentInfo.value.push(
359
+ // [0] EXPLICIT content
360
+ asn1.create(asn1.Class.CONTEXT_SPECIFIC, 0, true, [
361
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OCTETSTRING, false,
362
+ content)
363
+ ]));
364
+ }
358
365
  }
359
366
  }
360
367
 
@@ -437,10 +444,22 @@ p7.createSignedData = function() {
437
444
  }
438
445
 
439
446
  function addSignerInfos(mds) {
440
- // Note: ContentInfo is a SEQUENCE with 2 values, second value is
441
- // the content field and is optional for a ContentInfo but required here
442
- // since signers are present
443
- if(msg.contentInfo.value.length < 2) {
447
+ var content;
448
+
449
+ if (msg.detachedContent) {
450
+ // Signature has been made in detached mode.
451
+ content = msg.detachedContent;
452
+ } else {
453
+ // Note: ContentInfo is a SEQUENCE with 2 values, second value is
454
+ // the content field and is optional for a ContentInfo but required here
455
+ // since signers are present
456
+ // get ContentInfo content
457
+ content = msg.contentInfo.value[1];
458
+ // skip [0] EXPLICIT content wrapper
459
+ content = content.value[0];
460
+ }
461
+
462
+ if(!content) {
444
463
  throw new Error(
445
464
  'Could not sign PKCS#7 message; there is no content to sign.');
446
465
  }
@@ -448,11 +467,6 @@ p7.createSignedData = function() {
448
467
  // get ContentInfo content type
449
468
  var contentType = asn1.derToOid(msg.contentInfo.value[0].value);
450
469
 
451
- // get ContentInfo content
452
- var content = msg.contentInfo.value[1];
453
- // skip [0] EXPLICIT content wrapper
454
- content = content.value[0];
455
-
456
470
  // serialize content
457
471
  var bytes = asn1.toDer(content);
458
472
 
package/lib/util.js CHANGED
@@ -13,8 +13,10 @@ var util = module.exports = forge.util = forge.util || {};
13
13
 
14
14
  // define setImmediate and nextTick
15
15
  (function() {
16
- // use native nextTick
17
- if(typeof process !== 'undefined' && process.nextTick) {
16
+ // use native nextTick (unless we're in webpack)
17
+ // webpack (or better node-libs-browser polyfill) sets process.browser.
18
+ // this way we can detect webpack properly
19
+ if(typeof process !== 'undefined' && process.nextTick && !process.browser) {
18
20
  util.nextTick = process.nextTick;
19
21
  if(typeof setImmediate === 'function') {
20
22
  util.setImmediate = setImmediate;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-forge",
3
- "version": "0.7.5",
3
+ "version": "0.7.6",
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": {