9
let textBytes = ctypes.uint8_t("hello"); 
let a = new SECItem;
a.type = siBuffer;
a.data = textBytes.address();
a.len = textBytes.length;

I got ReferenceError: can't access lexical declaration textBytes before initialization.

Noitidart
  • 35,443
  • 37
  • 154
  • 323
Nona Haron
  • 171
  • 1
  • 1
  • 6

1 Answers1

0

I can't reproduce the reference error you are getting, but I think change

let textBytes = ctypes.uint8_t("hello"); 

as this throws TypeError: expected type uint8_t, got "hello" to

let textBytes = ctypes.uint8_t.array()("hello"); 

This will give you a null-terminated string, of length 6. If you want it to be length 5, no null termination then do let textBytes = ctypes.uint8_t.array(5)("hello");

as I am thinking, change

let a = new SECItem;

to

let a = SECItem();

or let a = new SECItem(); they are both same.

If that doesn't fix it, please share the structure of SECItem and what is siBuffer.

peterh
  • 11,875
  • 18
  • 85
  • 108
Noitidart
  • 35,443
  • 37
  • 154
  • 323
  • 1
    on let textBytes = ctypes.uint8_t.array()("hello"); it throws TypeError: expected type array, got "hello". Add info const siBuffer = 0; const SECItem = ctypes.StructType("SECItem", [ { "type": SECItemType }, { "data": ctypes.uint8_t.ptr }, { "len": ctypes.int } ]); – Nona Haron Jun 30 '15 at 13:56
  • Use `unsigned_char` instead, so like this: `let textBytes = ctypes.unsigned_char.array()("hello"); ` – Noitidart Jun 30 '15 at 15:08
  • 1
    Thanks :) Any books or reference you recommend regarding jsctypes? – Nona Haron Jun 30 '15 at 18:10
  • The best source for js-ctypes is looking at how others did it. I share a ton of snippets on my gists.github i link to them from here: https://developer.mozilla.org/en-US/docs/Mozilla/js-ctypes/Standard_OS_Libraries thats a great page to learn from. Or you can search my gists: https://gist.github.com/search?q=ctypes+%40noitidart and then there are a lots of stuff on github like here are my ctypes repos: https://github.com/search?q=ctypes+%40noitidart&type=Code&utf8=%E2%9C%93 definitely read up on MDN it has lots of good stuff https://developer.mozilla.org/en-US/docs/Mozilla/js-ctypes – Noitidart Jul 01 '15 at 02:01
  • I learned best though from others helping me personally, if you need that help join mozilla irc channel for jsctypes: https://client00.chat.mibbit.com/?url=irc%3A%2F%2Firc.mozilla.org%2F%23jsctypes thats the mibbit link or if you have a client: irc://moznet/jsctypes – Noitidart Jul 01 '15 at 02:03