Re: GLib.Hmac unusable?



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-compute-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 <alan 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




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