done: https://bugzilla.gnome.org/show_bug.cgi?id=765338
Thanks On Wed, Apr 20, 2016 at 6:09 PM, Giovanni Campagna < scampa.giova...@gmail.com> wrote: > On Wed, 2016-04-20 at 13:51 +0100, Andrea Giammarchi wrote: > > FYI actually I got it working via https://developer.gnome.org/glib/2. > > 48/glib-Data-HMACs.html#g-compute-hmac-for-string > > > > ``` > > GLib.compute_hmac_for_string( > > ChecksumType.SHA1, > > secret, > > str, > > str.length > > ); > > ``` > > This is slightly incorrect: it should be > GLib.compute_hmac_for_string( > ChecksumType.SHA1, > secret, str, -1); > > The reason is that length should be in bytes but str.length is in UTF- > 16 units. -1 means that str is nul-terminated (which it will be after > UTF16-to-UTF8 conversion) > > As for g_compute_hmac_for_data(), indeed there seems to be an > annotation problem: argument data should be marked (array > length=length). > Right now for some reason it's inferred as guint8 (ie, the pointer is > lost), which is very wrong. > > Care to file a bug for glib? > > Cheers, > > Giovanni > > > Yet I think the data version should not fail with a core dumped. > > > > Best Regards > > > > > > > > On Wed, Apr 20, 2016 at 1:25 PM, Andrea Giammarchi <andrea.giammarchi > > @gmail.com> wrote: > > > Thanks Alan, > > > I've tried them "all" but nothing seems to work: > > > > > > ```js > > > const GLib = imports.gi.GLib; > > > > > > // this works > > > // https://developer.gnome.org/glib/2.48/glib-Data-Checksums.html#g > > > -compute-checksum-for-data > > > GLib.compute_checksum_for_data( > > > GLib.ChecksumType.SHA1, > > > 'the string', > > > 'the string'.length > > > ); > > > > > > // this doesn't > > > // https://developer.gnome.org/glib/2.48/glib-Data-HMACs.html#g-com > > > pute-hmac-for-data > > > GLib.compute_hmac_for_data( > > > GLib.ChecksumType.SHA1, > > > 'secret', > > > 'secret'.length, > > > 'the string', > > > 'the string'.length > > > ); > > > ``` > > > > > > If I try to create `utf8` strings I have got: > > > ``` > > > Error: Unsupported type gint64 for (out caller-allocates) > > > ``` > > > so `GLib.utf16_to_utf8` is not usable here. > > > > > > Should I file a bug? > > > > > > Best Regards > > > > > > > > > > > > On Wed, Apr 20, 2016 at 4:45 AM, Alan Knowles <a...@roojs.com> > > > wrote: > > > > Andrea, > > > > > > > > probably worth trying this. > > > > > > > > Syntax: > > > > GLib.compute_hmac_for_string (ChecksumType digest_type, String > > > > key, guint64 key_len, String str, gint64 length) : String > > > > > > > > var out = GLib.compute_hmac_for_string ( > > > > GLib.Checksum.SHA1, > > > > 'secret', > > > > 'secret'.length, > > > > 'the string', > > > > 'the string'.length > > > > ) > > > > > > > > The doc's indicate that the last arg can be -1 if a \0 terminated > > > > string is passed - I can't remember if that occurs by default > > > > though. > > > > > > > > Otherwise it might be worth messing around with the gir file and > > > > changing the key into a utf8 string, rather than an array of > > > > chars > > > > > > > > Regards > > > > Alan > > > > > > > > > > > > > > > > > > > > > > > > On Tuesday, April 19, 2016 05:19 PM, Andrea Giammarchi wrote: > > > > > Hello there, > > > > > I wonder if I'm doing it wrong or if there's actually a bug > > > > > in either GJS or the GLib I'm using. > > > > > > > > > > While it's straight forward to `new > > > > > GLib.Checksum(GLib.Checksum.SHA1);` and then use > > > > > `.update(data)` and `.get_string()`, it's basically impossible > > > > > to do the same with `GLib.Hmac`. > > > > > > > > > > This is not exposed as constructor, so any attempt to `new > > > > > GLib.Hmac` would fail, and on top of that, any attempt to use > > > > > `GLib.compute_hmac_for_data` fails. > > > > > > > > > > Example: > > > > > ```js > > > > > GLib.compute_hmac_for_data( > > > > > GLib.Checksum.SHA1, > > > > > 'secret', > > > > > 'secret'.length, > > > > > 'generic data content', > > > > > GLib.checksum_type_get_length(GLib.Checksum.SHA1) > > > > > ); > > > > > ``` > > > > > > > > > > I'm not sure there's something wrong in my invoke but I keep > > > > > having this kind of error, no matter how I shuffle those > > > > > parameters (well, actually in some case I also have > > > > > Segmentation fault (core dumped)) > > > > > > > > > > ``` > > > > > (gjs:7105): GLib-CRITICAL **: g_compute_hmac_for_data: > > > > > assertion 'length == 0 || data != NULL' failed > > > > > null > > > > > ``` > > > > > > > > > > Thanks in advance for any sort of outcome. > > > > > > > > > > Best Regards > > > > > > > > > > > > > > > _______________________________________________ > > > > > javascript-list mailing list > > > > > javascript-list@gnome.org > > > > > https://mail.gnome.org/mailman/listinfo/javascript-list > > > > > > > > _______________________________________________ > > > > javascript-list mailing list > > > > javascript-list@gnome.org > > > > https://mail.gnome.org/mailman/listinfo/javascript-list > > > > > > > > > _______________________________________________ > > javascript-list mailing list > > javascript-list@gnome.org > > https://mail.gnome.org/mailman/listinfo/javascript-list >
_______________________________________________ javascript-list mailing list javascript-list@gnome.org https://mail.gnome.org/mailman/listinfo/javascript-list