web_modules/forge.bundle.js
function _attributeToAsn1(attr) {
  var value;

  // TODO: generalize to support more attributes
  if(attr.type === forge.pki.oids.contentType) {
    value = asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OID, false,
      asn1.oidToDer(attr.value).getBytes());
  } else if(attr.type === forge.pki.oids.messageDigest) {
    value = asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OCTETSTRING, false,
      attr.value.bytes());
  } else if(attr.type === forge.pki.oids.signingTime) {
    /* Note per RFC 2985: Dates between 1 January 1950 and 31 December 2049
      (inclusive) MUST be encoded as UTCTime. Any dates with year values
      before 1950 or after 2049 MUST be encoded as GeneralizedTime. [Further,]
      UTCTime values MUST be expressed in Greenwich Mean Time (Zulu) and MUST
      include seconds (i.e., times are YYMMDDHHMMSSZ), even where the
      number of seconds is zero.  Midnight (GMT) must be represented as
      "YYMMDD000000Z". */
    // TODO: make these module-level constants
    var jan_1_1950 = new Date('Jan 1, 1950 00:00:00Z');
    var jan_1_2050 = new Date('Jan 1, 2050 00:00:00Z');
    var date = attr.value;
    if(typeof date === 'string') {
      // try to parse date
      var timestamp = Date.parse(date);
      if(!isNaN(timestamp)) {
        date = new Date(timestamp);
      } else if(date.length === 13) {
        // YYMMDDHHMMSSZ (13 chars for UTCTime)
        date = asn1.utcTimeToDate(date);
      } else {
        // assume generalized time
        date = asn1.generalizedTimeToDate(date);
      }
    }

    if(date >= jan_1_1950 && date < jan_1_2050) {
      value = asn1.create(
        asn1.Class.UNIVERSAL, asn1.Type.UTCTIME, false,
        asn1.dateToUtcTime(date));
    } else {
      value = asn1.create(
        asn1.Class.UNIVERSAL, asn1.Type.GENERALIZEDTIME, false,
        asn1.dateToGeneralizedTime(date));
    }
  }

  // TODO: expose as common API call
  // create a RelativeDistinguishedName set
  // each value in the set is an AttributeTypeAndValue first
  // containing the type (an OID) and second the value
  return asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [
    // AttributeType
    asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OID, false,
      asn1.oidToDer(attr.type).getBytes()),
    asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SET, true, [
      // AttributeValue
      value
    ])
  ]);
}
function _attributeToAsn1(attr) {
  var value;

  // TODO: generalize to support more attributes
  if(attr.type === forge.pki.oids.contentType) {
    value = asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OID, false,
      asn1.oidToDer(attr.value).getBytes());
  } else if(attr.type === forge.pki.oids.messageDigest) {
    value = asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OCTETSTRING, false,
      attr.value.bytes());
  } else if(attr.type === forge.pki.oids.signingTime) {
    /* Note per RFC 2985: Dates between 1 January 1950 and 31 December 2049
      (inclusive) MUST be encoded as UTCTime. Any dates with year values
      before 1950 or after 2049 MUST be encoded as GeneralizedTime. [Further,]
      UTCTime values MUST be expressed in Greenwich Mean Time (Zulu) and MUST
      include seconds (i.e., times are YYMMDDHHMMSSZ), even where the
      number of seconds is zero.  Midnight (GMT) must be represented as
      "YYMMDD000000Z". */
    // TODO: make these module-level constants
    var jan_1_1950 = new Date('Jan 1, 1950 00:00:00Z');
    var jan_1_2050 = new Date('Jan 1, 2050 00:00:00Z');
    var date = attr.value;
    if(typeof date === 'string') {
      // try to parse date
      var timestamp = Date.parse(date);
      if(!isNaN(timestamp)) {
        date = new Date(timestamp);
      } else if(date.length === 13) {
        // YYMMDDHHMMSSZ (13 chars for UTCTime)
        date = asn1.utcTimeToDate(date);
      } else {
        // assume generalized time
        date = asn1.generalizedTimeToDate(date);
      }
    }

    if(date >= jan_1_1950 && date < jan_1_2050) {
      value = asn1.create(
        asn1.Class.UNIVERSAL, asn1.Type.UTCTIME, false,
        asn1.dateToUtcTime(date));
    } else {
      value = asn1.create(
        asn1.Class.UNIVERSAL, asn1.Type.GENERALIZEDTIME, false,
        asn1.dateToGeneralizedTime(date));
    }
  }

  // TODO: expose as common API call
  // create a RelativeDistinguishedName set
  // each value in the set is an AttributeTypeAndValue first
  // containing the type (an OID) and second the value
  return asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [
    // AttributeType
    asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OID, false,
      asn1.oidToDer(attr.type).getBytes()),
    asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SET, true, [
      // AttributeValue
      value
    ])
  ]);
}
function _attributeToAsn1 ( attr ) { var value ; // TODO: generalize to support more attributes
 if ( attr . type === forge . pki . oids . contentType ) { value = asn1 . create ( asn1 . Class . UNIVERSAL , asn1 . Type . OID , false , asn1 . oidToDer ( attr . value ) . getBytes ( ) ) ; } else if ( attr . type === forge . pki . oids . messageDigest ) { value = asn1 . create ( asn1 . Class . UNIVERSAL , asn1 . Type . OCTETSTRING , false , attr . value . bytes ( ) ) ; } else if ( attr . type === forge . pki . oids . signingTime ) { /* Note per RFC 2985: Dates between 1 January 1950 and 31 December 2049
      (inclusive) MUST be encoded as UTCTime. Any dates with year values
      before 1950 or after 2049 MUST be encoded as GeneralizedTime. [Further,]
      UTCTime values MUST be expressed in Greenwich Mean Time (Zulu) and MUST
      include seconds (i.e., times are YYMMDDHHMMSSZ), even where the
      number of seconds is zero.  Midnight (GMT) must be represented as
      "YYMMDD000000Z". */ // TODO: make these module-level constants
 var jan_1_1950 = new Date ( 'Jan 1, 1950 00:00:00Z' ) ; var jan_1_2050 = new Date ( 'Jan 1, 2050 00:00:00Z' ) ; var date = attr . value ; if ( typeof date === 'string' ) { // try to parse date
 var timestamp = Date . parse ( date ) ; if ( ! isNaN ( timestamp ) ) { date = new Date ( timestamp ) ; } else if ( date . length === 13 ) { // YYMMDDHHMMSSZ (13 chars for UTCTime)
 date = asn1 . utcTimeToDate ( date ) ; } else { // assume generalized time
 date = asn1 . generalizedTimeToDate ( date ) ; } } if ( date >= jan_1_1950 && date < jan_1_2050 ) { value = asn1 . create ( asn1 . Class . UNIVERSAL , asn1 . Type . UTCTIME , false , asn1 . dateToUtcTime ( date ) ) ; } else { value = asn1 . create ( asn1 . Class . UNIVERSAL , asn1 . Type . GENERALIZEDTIME , false , asn1 . dateToGeneralizedTime ( date ) ) ; } } // TODO: expose as common API call
 // create a RelativeDistinguishedName set
 // each value in the set is an AttributeTypeAndValue first
 // containing the type (an OID) and second the value
 return asn1 . create ( asn1 . Class . UNIVERSAL , asn1 . Type . SEQUENCE , true , [ // AttributeType
 asn1 . create ( asn1 . Class . UNIVERSAL , asn1 . Type . OID , false , asn1 . oidToDer ( attr . type ) . getBytes ( ) ) , asn1 . create ( asn1 . Class . UNIVERSAL , asn1 . Type . SET , true , [ // AttributeValue
 value ] ) ] ) ; }
Convert an attribute object to an ASN.1 Attribute.

@param attr the attribute object.

@return the ASN.1 Attribute.
Convert an attribute object to an ASN . 1 Attribute .