Open objectx opened 5 years ago
Following code should run without errors, but h.process throws a RangeError.
h.process
RangeError
import 'dart:convert'; import 'dart:typed_data'; import 'package:typed_data/typed_data.dart'; import 'package:pointycastle/digests/blake2b.dart'; main() { final enc = AsciiEncoder(); final key = enc.convert('foo'); //final key = null; final h = Blake2bDigest(key: key, salt: makeBlake2Salt(enc.convert('bar'))); final msg = enc.convert('baz'); final out = h.process(msg); print('out = ${_dumpHex(out)}'); } Uint8List makeBlake2Salt(Uint8List s) { final b = Uint8Buffer(16); b ..fillRange(0, 16, 0) ..setRange(0, s.length, s); assert(b.length == 16); return b.buffer.asUint8List(); } String _dumpHex(Uint8List l) { return l.map((x) => x.toRadixString(16).padLeft(2, '0')).join(''); }
Digging into the source, I've found:
_bufferPos
update
remainingLength
0
_compress
unpack
I also encountered similar problems. https://github.com/PointyCastle/pointycastle/issues/221
I have found another blake2b library which can work well. https://github.com/ilap/pinenacl-dart
Following code should run without errors, but
h.process
throws aRangeError
.Digging into the source, I've found:
_bufferPos
was initialized to the end when the key was supplied.update
, theremainingLength
is0
_compress
was calledunpack
triggers theRangeError