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
  • // use with commonJS
    const { MultiFormatReader, BarcodeFormat } = require('@zxing/library');
    // or with ES6 modules
    import { MultiFormatReader, BarcodeFormat } from '@zxing/library';
    
    const hints = new Map();
    const formats = [BarcodeFormat.QR_CODE, BarcodeFormat.DATA_MATRIX/*, ...*/];
    
    hints.set(DecodeHintType.POSSIBLE_FORMATS, formats);
    
    const reader = new MultiFormatReader();
    
    reader.setHints(hints);
    
    const luminanceSource = new RGBLuminanceSource(imgByteArray, imgWidth, imgHeight);
    const binaryBitmap = new BinaryBitmap(new HybridBinarizer(luminanceSource));
    
    reader.decode(binaryBitmap);
    Docs
  • // test-utils.js
    import {render, queries} from '@testing-library/react'
    import * as customQueries from './custom-queries'
    
    const customRender = (ui, options) =>
      render(ui, {queries: {...queries, ...customQueries}, ...options})
    
    // re-export everything
    export * from '@testing-library/react'
    
    // override render method
    export {customRender as render}
    Docs
  • // test-utils.ts
    import {render, queries, RenderOptions} from '@testing-library/react'
    import * as customQueries from './custom-queries'
    import {ReactElement} from 'react'
    
    const customRender = (
      ui: ReactElement,
      options?: Omit<RenderOptions, 'queries'>,
    ) => render(ui, {queries: {...queries, ...customQueries}, ...options})
    
    export * from '@testing-library/react'
    export {customRender as render}
    Docs
  • import {render} from '@testing-library/preact'
    
    const {results} = render(<YourComponent />, {options})
    Docs
  • Powered by Official black Bloop logo with a period
    download the IDE extension

    View other examples