open_after_len method

Uint8List open_after_len(
  1. Uint8List box,
  2. int boxoff,
  3. int boxlen,
  4. Uint8List theNonce,
)

Implementation

Uint8List open_after_len(
    Uint8List box, final int boxoff, final int boxlen, Uint8List theNonce) {
  // check message
  if (!(box != null &&
      box.length >= (boxoff + boxlen) &&
      boxlen >= boxzerobytesLength)) return null;

  // cipher buffer
  Uint8List c = Uint8List(boxlen + boxzerobytesLength);

  // message buffer
  Uint8List m = Uint8List(c.length);

  for (int i = 0; i < boxlen; i++)
    c[i + boxzerobytesLength] = box[i + boxoff];

  if (TweetNaclFast.crypto_box_open_afternm(
          m, c, c.length, theNonce, _sharedKey) !=
      0) return null;

  // wrap byte_buf_t on m offset@zerobytesLength
  ///return new byte_buf_t(m, zerobytesLength, m.length-zerobytesLength);
  Uint8List ret = Uint8List(m.length - zerobytesLength);

  for (int i = 0; i < ret.length; i++) ret[i] = m[i + zerobytesLength];

  return ret;
}