build/authorify.js
function _extensionsToAsn1(exts) {
  // create top-level extension container
  var rval = asn1.create(asn1.Class.CONTEXT_SPECIFIC, 3, true, []);

  // create extension sequence (stores a sequence for each extension)
  var seq = asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, []);
  rval.value.push(seq);

  var ext, extseq;
  for(var i = 0; i < exts.length; ++i) {
    ext = exts[i];

    // create a sequence for each extension
    extseq = asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, []);
    seq.value.push(extseq);

    // extnID (OID)
    extseq.value.push(asn1.create(
      asn1.Class.UNIVERSAL, asn1.Type.OID, false,
      asn1.oidToDer(ext.id).getBytes()));

    // critical defaults to false
    if(ext.critical) {
      // critical BOOLEAN DEFAULT FALSE
      extseq.value.push(asn1.create(
        asn1.Class.UNIVERSAL, asn1.Type.BOOLEAN, false,
        String.fromCharCode(0xFF)));
    }

    var value = ext.value;
    if(typeof ext.value !== 'string') {
      // value is asn.1
      value = asn1.toDer(value).getBytes();
    }

    // extnValue (OCTET STRING)
    extseq.value.push(asn1.create(
      asn1.Class.UNIVERSAL, asn1.Type.OCTETSTRING, false, value));
  }

  return rval;
}
function _extensionsToAsn1(exts) {
  // create top-level extension container
  var rval = asn1.create(asn1.Class.CONTEXT_SPECIFIC, 3, true, []);

  // create extension sequence (stores a sequence for each extension)
  var seq = asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, []);
  rval.value.push(seq);

  var ext, extseq;
  for(var i = 0; i < exts.length; ++i) {
    ext = exts[i];

    // create a sequence for each extension
    extseq = asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, []);
    seq.value.push(extseq);

    // extnID (OID)
    extseq.value.push(asn1.create(
      asn1.Class.UNIVERSAL, asn1.Type.OID, false,
      asn1.oidToDer(ext.id).getBytes()));

    // critical defaults to false
    if(ext.critical) {
      // critical BOOLEAN DEFAULT FALSE
      extseq.value.push(asn1.create(
        asn1.Class.UNIVERSAL, asn1.Type.BOOLEAN, false,
        String.fromCharCode(0xFF)));
    }

    var value = ext.value;
    if(typeof ext.value !== 'string') {
      // value is asn.1
      value = asn1.toDer(value).getBytes();
    }

    // extnValue (OCTET STRING)
    extseq.value.push(asn1.create(
      asn1.Class.UNIVERSAL, asn1.Type.OCTETSTRING, false, value));
  }

  return rval;
}
function _extensionsToAsn1 ( exts ) { // create top-level extension container var rval = asn1 . create ( asn1 . Class . CONTEXT_SPECIFIC , 3 , true , [ ] ) ; // create extension sequence (stores a sequence for each extension) var seq = asn1 . create ( asn1 . Class . UNIVERSAL , asn1 . Type . SEQUENCE , true , [ ] ) ; rval . value . push ( seq ) ; var ext , extseq ; for ( var i = 0 ; i < exts . length ; ++ i ) { ext = exts [ i ] ; // create a sequence for each extension extseq = asn1 . create ( asn1 . Class . UNIVERSAL , asn1 . Type . SEQUENCE , true , [ ] ) ; seq . value . push ( extseq ) ; // extnID (OID) extseq . value . push ( asn1 . create ( asn1 . Class . UNIVERSAL , asn1 . Type . OID , false , asn1 . oidToDer ( ext . id ) . getBytes ( ) ) ) ; // critical defaults to false if ( ext . critical ) { // critical BOOLEAN DEFAULT FALSE extseq . value . push ( asn1 . create ( asn1 . Class . UNIVERSAL , asn1 . Type . BOOLEAN , false , String . fromCharCode ( 0xFF ) ) ) ; } var value = ext . value ; if ( typeof ext . value !== 'string' ) { // value is asn.1 value = asn1 . toDer ( value ) . getBytes ( ) ; } // extnValue (OCTET STRING) extseq . value . push ( asn1 . create ( asn1 . Class . UNIVERSAL , asn1 . Type . OCTETSTRING , false , value ) ) ; } return rval ; }
Converts X.509v3 certificate extensions to ASN.1.

@param exts the extensions to convert.

@return the extensions in ASN.1 format.
Converts X . 509v3 certificate extensions to ASN . 1 .