Re: GLib.Hmac unusable?



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



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]