How to use where clause in Knex
Create refunds with Stripe
Load HTML with Cheerio
How to send POST request with Axios
Find intersection of array in Lodash
Powered by Official white Bloop logo with a period

Terms / Privacy / Search / Support

  • var asn1 = forge.asn1;
     
    // create a SubjectPublicKeyInfo
    // create a SubjectPublicKeyInfo
    var subjectPublicKeyInfo =
      asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [
        // AlgorithmIdentifier
    // AlgorithmIdentifier
        asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [
          // algorithm
    // algorithm
          asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OID, false,
            asn1.oidToDer(pki.oids['rsaEncryption']).getBytes()),
          // parameters (null)
    // parameters (null)
          asn1.create(asn1.Class.UNIVERSAL, asn1.Type.NULL, false, '')
        ]),
        // subjectPublicKey
    // subjectPublicKey
        asn1.create(asn1.Class.UNIVERSAL, asn1.Type.BITSTRING, false, [
          // RSAPublicKey
    // RSAPublicKey
          asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [
            // modulus (n)
    // modulus (n)
            asn1.create(asn1.Class.UNIVERSAL, asn1.Type.INTEGER, false,
              _bnToBytes(key.n)),
            // publicExponent (e)
    // publicExponent (e)
            asn1.create(asn1.Class.UNIVERSAL, asn1.Type.INTEGER, false,
              _bnToBytes(key.e))
          ])
        ])
      ]);
     
    // serialize an ASN.1 object to DER format
    // serialize an ASN.1 object to DER format
    var derBuffer = asn1.toDer(subjectPublicKeyInfo);
     
    // deserialize to an ASN.1 object from a byte buffer filled with DER data
    // deserialize to an ASN.1 object from a byte buffer filled with DER data
    var object = asn1.fromDer(derBuffer);
     
    // convert an OID dot-separated string to a byte buffer
    // convert an OID dot-separated string to a byte buffer
    var derOidBuffer = asn1.oidToDer('1.2.840.113549.1.1.5');
     
    // convert a byte buffer with a DER-encoded OID to a dot-separated string
    // convert a byte buffer with a DER-encoded OID to a dot-separated string
    console.log(asn1.derToOid(derOidBuffer));
    // output: 1.2.840.113549.1.1.5
    // output: 1.2.840.113549.1.1.5
     
    // validates that an ASN.1 object matches a particular ASN.1 structure and
    // validates that an ASN.1 object matches a particular ASN.1 structure and
    // captures data of interest from that structure for easy access
    // captures data of interest from that structure for easy access
    var publicKeyValidator = {
      name: 'SubjectPublicKeyInfo',
      tagClass: asn1.Class.UNIVERSAL,
      type: asn1.Type.SEQUENCE,
      constructed: true,
      captureAsn1: 'subjectPublicKeyInfo',
      value: [{
        name: 'SubjectPublicKeyInfo.AlgorithmIdentifier',
        tagClass: asn1.Class.UNIVERSAL,
        type: asn1.Type.SEQUENCE,
        constructed: true,
        value: [{
          name: 'AlgorithmIdentifier.algorithm',
          tagClass: asn1.Class.UNIVERSAL,
          type: asn1.Type.OID,
          constructed: false,
          capture: 'publicKeyOid'
        }]
      }, {
        // subjectPublicKey
    // subjectPublicKey
        name: 'SubjectPublicKeyInfo.subjectPublicKey',
        tagClass: asn1.Class.UNIVERSAL,
        type: asn1.Type.BITSTRING,
        constructed: false,
        value: [{
          // RSAPublicKey
    // RSAPublicKey
          name: 'SubjectPublicKeyInfo.subjectPublicKey.RSAPublicKey',
          tagClass: asn1.Class.UNIVERSAL,
          type: asn1.Type.SEQUENCE,
          constructed: true,
          optional: true,
          captureAsn1: 'rsaPublicKey'
        }]
      }]
    };
     
    var capture = {};
    var errors = [];
    if(!asn1.validate(
      publicKeyValidator, subjectPublicKeyInfo, validator, capture, errors)) {
      throw 'ASN.1 object is not a SubjectPublicKeyInfo.';
    }
    // capture.subjectPublicKeyInfo contains the full ASN.1 object
    // capture.subjectPublicKeyInfo contains the full ASN.1 object
    // capture.rsaPublicKey contains the full ASN.1 object for the RSA public key
    // capture.rsaPublicKey contains the full ASN.1 object for the RSA public key
    // capture.publicKeyOid only contains the value for the OID
    // capture.publicKeyOid only contains the value for the OID
    var oid = asn1.derToOid(capture.publicKeyOid);
    if(oid !== pki.oids['rsaEncryption']) {
      throw 'Unsupported OID.';
    }
     
    // pretty print an ASN.1 object to a string for debugging purposes
    // pretty print an ASN.1 object to a string for debugging purposes
    asn1.prettyPrint(object);
    Docs
  • // In an `async` function
    // In an `async` function
    await csvWriter.writeRecords(records1)
    await csvWriter.writeRecords(records2)
    ...
    Docs
  • const writableStream = new WritableStream({
      start(controller) {
      },
      write(chunk, controller) {
        ...
      },
      close(controller) {
        ...
      },
      abort(err) {
        ...
      }
    }, queuingStrategy);
    
    ...
    
    const writer = writableStream.getWriter();
    
    ..
    
    // check if the stream is closed
    writer.closed.then(() => {
      console.log('writer closed');
    })
    
    Docs
  • Animated.sequence([
      // decay, then spring to start and twirl
      Animated.decay(position, {
        // coast to a stop
        velocity: { x: gestureState.vx, y: gestureState.vy }, // velocity from gesture release
        deceleration: 0.997
      }),
      Animated.parallel([
        // after decay, in parallel:
        Animated.spring(position, {
          toValue: { x: 0, y: 0 } // return to start
        }),
        Animated.timing(twirl, {
          // and twirl
          toValue: 360
        })
      ])
    ]).start(); // start the sequence group
    Docs
  • import { getApplicationKeyMap } from 'react-hotkeys';
    import React from 'react';
     
    // ...
    // ...
     
    renderDialog(){
      if (this.state.showDialog) {
        const keyMap = getApplicationKeyMap();
     
        return (
          <div style={styles.DIALOG}>
            <h2>
              Keyboard shortcuts
            </h2>
     
            <table>
              <tbody>
              { Object.keys(keyMap).reduce((memo, actionName) => {
                  const { sequences, name } = keyMap[actionName];
                  
                  memo.push(
                    <tr key={name || actionName}>
                      <td style={styles.KEYMAP_TABLE_CELL}>
                        { name }
                      </td>
                      <td style={styles.KEYMAP_TABLE_CELL}>
                        { sequences.map(({sequence}) => <span key={sequence}>{sequence}</span>) }
                      </td>
                    </tr>
                  );
                  
                  return memo;
                })
               }
              </tbody>
            </table>
          </div>
        );
      }
    }
    Docs
  • Powered by Official black Bloop logo with a period
    download the IDE extension

    View other examples