index.js
/**
   * Creates the DER encoding for various simple ASN.1 types like strings etc.
   * The complete DER encoding should consist of the value in tl appended with the provided str .
   * @param {number} etype The type of the string to be encoded (ASN1_ETYPE_)
   * @param {string} str the string data.
   * @param {string} [encoding] valid nodejs string encoding.
   * @returns {[Buffer, number]} the encoded tag with length; ASN1_SUCCESS if successful or an error value.
   */
Creates the DER encoding for various simple ASN.1 types like strings etc.
The complete DER encoding should consist of the value in tl appended with the provided str .
@param {number} etype The type of the string to be encoded (ASN1_ETYPE_)
@param {string} str the string data.
@param {string} [encoding] valid nodejs string encoding.
@returns {[Buffer, number]} the encoded tag with length; ASN1_SUCCESS if successful or an error value.
Creates the DER encoding for various simple ASN . 1 types like strings etc . The complete DER encoding should consist of the value in tl appended with the provided str . @param { number } etype The type of the string to be encoded ( ASN1_ETYPE_ ) @param { string } str the string data . @param { string } [ encoding ] valid nodejs string encoding . @returns { [ Buffer number ] } the encoded tag with length ; ASN1_SUCCESS if successful or an error value .
encode_simple_der(etype, str, encoding = 'ascii') {
    assertint(etype);
    const in_ptr = this.salloc(str, encoding);
    const in_length = Buffer.byteLength(str, encoding);
    const out_tl = this.malloc(ASN1_MAX_TL_SIZE);
    const out_tl_size = this.malloc(ASN1_MAX_TAG_SIZE); 
    const ret = this[_module]._asn1_encode_simple_der(
      etype,
      in_ptr,
      in_length,
      out_tl,
      out_tl_size
    );
    const tl_size = Buffer.from(
      this.memory.buffer,
      out_tl_size,
      ASN1_MAX_TAG_SIZE
    ).readUInt32BE(0);
    const view_tl = Buffer.from(this.memory.buffer, out_tl, tl_size);
    const tl = Buffer.from(view_tl); 
    this.free(in_ptr);
    this.free(out_tl);
    this.free(out_tl_size);
    return [tl, ret];
  }
encode_simple_der ( etype , str , encoding = 'ascii' ) { assertint ( etype ) ; const in_ptr = this . salloc ( str , encoding ) ; const in_length = Buffer . byteLength ( str , encoding ) ; const out_tl = this . malloc ( ASN1_MAX_TL_SIZE ) ; const out_tl_size = this . malloc ( ASN1_MAX_TAG_SIZE ) ; const ret = this [ _module ] . _asn1_encode_simple_der ( etype , in_ptr , in_length , out_tl , out_tl_size ) ; const tl_size = Buffer . from ( this . memory . buffer , out_tl_size , ASN1_MAX_TAG_SIZE ) . readUInt32BE ( 0 ) ; const view_tl = Buffer . from ( this . memory . buffer , out_tl , tl_size ) ; const tl = Buffer . from ( view_tl ) ; this . free ( in_ptr ) ; this . free ( out_tl ) ; this . free ( out_tl_size ) ; return [ tl , ret ] ; }
Creates the DER encoding for various simple ASN.1 types like strings etc.
Creates the DER encoding for various simple ASN . 1 types like strings etc .
// size of int, 4 in wasm32 // copy data wasm -> node