node_modules/node-forge/lib/pkcs7.js
/**
 * Reads the "common part" of an PKCS#7 content block (in ASN.1 format)
 *
 * This function reads the "common part" of the PKCS#7 content blocks
 * EncryptedData and EnvelopedData, i.e. version number and symmetrically
 * encrypted content block.
 *
 * The result of the ASN.1 validate and capture process is returned
 * to allow the caller to extract further data, e.g. the list of recipients
 * in case of a EnvelopedData object.
 *
 * @param msg the PKCS#7 object to read the data to.
 * @param obj the ASN.1 representation of the content block.
 * @param validator the ASN.1 structure validator object to use.
 *
 * @return the value map captured by validator object.
 */
Reads the "common part" of an PKCS#7 content block (in ASN.1 format)
This function reads the "common part" of the PKCS#7 content blocks
EncryptedData and EnvelopedData, i.e. version number and symmetrically
encrypted content block.

The result of the ASN.1 validate and capture process is returned
to allow the caller to extract further data, e.g. the list of recipients
in case of a EnvelopedData object.

@param msg the PKCS#7 object to read the data to.
@param obj the ASN.1 representation of the content block.
@param validator the ASN.1 structure validator object to use.

@return the value map captured by validator object.
Reads the " common part " of an PKCS#7 content block ( in ASN . 1 format ) This function reads the " common part " of the PKCS#7 content blocks EncryptedData and EnvelopedData i . e . version number and symmetrically encrypted content block . The result of the ASN . 1 validate and capture process is returned to allow the caller to extract further data e . g . the list of recipients in case of a EnvelopedData object . @param msg the PKCS#7 object to read the data to . @param obj the ASN . 1 representation of the content block . @param validator the ASN . 1 structure validator object to use . @return the value map captured by validator object .
function _fromAsn1(msg, obj, validator) {
  var capture = {};
  var errors = [];
  if(!asn1.validate(obj, validator, capture, errors)) {
    var error = new Error('Cannot read PKCS#7 message. ' +
      'ASN.1 object is not a supported PKCS#7 message.');
    error.errors = error;
    throw error;
  }
  var contentType = asn1.derToOid(capture.contentType);
  if(contentType !== forge.pki.oids.data) {
    throw new Error('Unsupported PKCS#7 message. ' +
      'Only wrapped ContentType Data supported.');
  }
  if(capture.encryptedContent) {
    var content = '';
    if(forge.util.isArray(capture.encryptedContent)) {
      for(var i = 0; i < capture.encryptedContent.length; ++i) {
        if(capture.encryptedContent[i].type !== asn1.Type.OCTETSTRING) {
          throw new Error('Malformed PKCS#7 message, expecting encrypted ' +
            'content constructed of only OCTET STRING objects.');
        }
        content += capture.encryptedContent[i].value;
      }
    } else {
      content = capture.encryptedContent;
    }
    msg.encryptedContent = {
      algorithm: asn1.derToOid(capture.encAlgorithm),
      parameter: forge.util.createBuffer(capture.encParameter.value),
      content: forge.util.createBuffer(content)
    };
  }
  if(capture.content) {
    var content = '';
    if(forge.util.isArray(capture.content)) {
      for(var i = 0; i < capture.content.length; ++i) {
        if(capture.content[i].type !== asn1.Type.OCTETSTRING) {
          throw new Error('Malformed PKCS#7 message, expecting ' +
            'content constructed of only OCTET STRING objects.');
        }
        content += capture.content[i].value;
      }
    } else {
      content = capture.content;
    }
    msg.content = forge.util.createBuffer(content);
  }
  msg.version = capture.version.charCodeAt(0);
  msg.rawCapture = capture;
  return capture;
}
function _fromAsn1 ( msg , obj , validator ) { var capture = { } ; var errors = [ ] ; if ( ! asn1 . validate ( obj , validator , capture , errors ) ) { var error = new Error ( 'Cannot read PKCS#7 message. ' + 'ASN.1 object is not a supported PKCS#7 message.' ) ; error . errors = error ; throw error ; } var contentType = asn1 . derToOid ( capture . contentType ) ; if ( contentType !== forge . pki . oids . data ) { throw new Error ( 'Unsupported PKCS#7 message. ' + 'Only wrapped ContentType Data supported.' ) ; } if ( capture . encryptedContent ) { var content = '' ; if ( forge . util . isArray ( capture . encryptedContent ) ) { for ( var i = 0 ; i < capture . encryptedContent . length ; ++ i ) { if ( capture . encryptedContent [ i ] . type !== asn1 . Type . OCTETSTRING ) { throw new Error ( 'Malformed PKCS#7 message, expecting encrypted ' + 'content constructed of only OCTET STRING objects.' ) ; } content += capture . encryptedContent [ i ] . value ; } } else { content = capture . encryptedContent ; } msg . encryptedContent = { algorithm : asn1 . derToOid ( capture . encAlgorithm ) , parameter : forge . util . createBuffer ( capture . encParameter . value ) , content : forge . util . createBuffer ( content ) } ; } if ( capture . content ) { var content = '' ; if ( forge . util . isArray ( capture . content ) ) { for ( var i = 0 ; i < capture . content . length ; ++ i ) { if ( capture . content [ i ] . type !== asn1 . Type . OCTETSTRING ) { throw new Error ( 'Malformed PKCS#7 message, expecting ' + 'content constructed of only OCTET STRING objects.' ) ; } content += capture . content [ i ] . value ; } } else { content = capture . content ; } msg . content = forge . util . createBuffer ( content ) ; } msg . version = capture . version . charCodeAt ( 0 ) ; msg . rawCapture = capture ; return capture ; }
Reads the "common part" of an PKCS#7 content block (in ASN.1 format)
 This function reads the "common part" of the PKCS#7 content blocks
 EncryptedData and EnvelopedData, i.e.
Reads the " common part " of an PKCS#7 content block ( in ASN . 1 format ) This function reads the " common part " of the PKCS#7 content blocks EncryptedData and EnvelopedData i . e .
// Check contentType, so far we only support (raw) Data.