node_modules/hybrid-crypto-js/web/hybrid-crypto.js
/**
 * 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.
@param attr the attribute object.


Convert an attribute object to an ASN . 1 Attribute . @param attr the attribute object .
function _attributeToAsn1(attr) {
  var value;
  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) {
    var jan_1_1950 = new Date('1950-01-01T00:00:00Z');
    var jan_1_2050 = new Date('2050-01-01T00:00:00Z');
    var date = attr.value;
    if(typeof date === 'string') {
      var timestamp = Date.parse(date);
      if(!isNaN(timestamp)) {
        date = new Date(timestamp);
      } else if(date.length === 13) {
        date = asn1.utcTimeToDate(date);
      } else {
        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));
    }
  }
  return asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [
    asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OID, false,
      asn1.oidToDer(attr.type).getBytes()),
    asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SET, true, [
      value
    ])
  ]);
}
function _attributeToAsn1 ( attr ) { var value ; 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 ) { var jan_1_1950 = new Date ( '1950-01-01T00:00:00Z' ) ; var jan_1_2050 = new Date ( '2050-01-01T00:00:00Z' ) ; var date = attr . value ; if ( typeof date === 'string' ) { var timestamp = Date . parse ( date ) ; if ( ! isNaN ( timestamp ) ) { date = new Date ( timestamp ) ; } else if ( date . length === 13 ) { date = asn1 . utcTimeToDate ( date ) ; } else { 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 ) ) ; } } return asn1 . create ( asn1 . Class . UNIVERSAL , asn1 . Type . SEQUENCE , true , [ asn1 . create ( asn1 . Class . UNIVERSAL , asn1 . Type . OID , false , asn1 . oidToDer ( attr . type ) . getBytes ( ) ) , asn1 . create ( asn1 . Class . UNIVERSAL , asn1 . Type . SET , true , [ value ] ) ] ) ; }
Convert an attribute object to an ASN.1 Attribute.
Convert an attribute object to an ASN . 1 Attribute .
// TODO: generalize to support more attributes /* 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 // try to parse date // YYMMDDHHMMSSZ (13 chars for UTCTime) // assume generalized time // 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 // AttributeType // AttributeValue