cryptoBoxOpenEasy static method

Uint8List cryptoBoxOpenEasy(
  1. Uint8List c,
  2. Uint8List n,
  3. Uint8List pk,
  4. Uint8List sk,
)

Implementation

static Uint8List cryptoBoxOpenEasy(
    Uint8List c, Uint8List n, Uint8List pk, Uint8List sk) {
  RangeError.checkValueInInterval(n.length, cryptoBoxNoncebytes,
      cryptoBoxNoncebytes, 'n', 'Invalid length');
  RangeError.checkValueInInterval(pk.length, cryptoBoxPublickeybytes,
      cryptoBoxPublickeybytes, 'pk', 'Invalid length');
  RangeError.checkValueInInterval(sk.length, cryptoBoxSecretkeybytes,
      cryptoBoxSecretkeybytes, 'sk', 'Invalid length');

  final _m = calloc<Uint8>(c.length - cryptoBoxMacbytes);
  final _c = c.toPointer();
  final _n = n.toPointer();
  final _pk = pk.toPointer();
  final _sk = sk.toPointer();

  try {
    _cryptoBox
        .crypto_box_open_easy(_m, _c, c.length, _n, _pk, _sk)
        .mustSucceed('crypto_box_open_easy');

    return _m.toList(c.length - cryptoBoxMacbytes);
  } finally {
    calloc.free(_m);
    calloc.free(_c);
    calloc.free(_n);
    calloc.free(_pk);
    calloc.free(_sk);
  }
}