cryptoPwhash static method

Uint8List cryptoPwhash(
  1. int outlen,
  2. Uint8List passwd,
  3. Uint8List salt,
  4. int opslimit,
  5. int memlimit,
  6. int alg,
)

Implementation

static Uint8List cryptoPwhash(int outlen, Uint8List passwd, Uint8List salt,
    int opslimit, int memlimit, int alg) {
  RangeError.checkValueInInterval(
      outlen, cryptoPwhashBytesMin, cryptoPwhashBytesMax, 'outlen');
  RangeError.checkValueInInterval(passwd.length, cryptoPwhashPasswdMin,
      cryptoPwhashPasswdMax, 'passwd', 'Invalid length');
  RangeError.checkValueInInterval(salt.length, cryptoPwhashSaltbytes,
      cryptoPwhashSaltbytes, 'salt', 'Invalid length');
  if (alg == cryptoPwhashAlgArgon2i13) {
    RangeError.checkValueInInterval(opslimit, cryptoPwhashArgon2iOpslimitMin,
        cryptoPwhashArgon2iOpslimitMax, 'opslimit');
    RangeError.checkValueInInterval(memlimit, cryptoPwhashArgon2iMemlimitMin,
        cryptoPwhashArgon2iMemlimitMax, 'memlimit');
  } else {
    RangeError.checkValueInInterval(opslimit, cryptoPwhashOpslimitMin,
        cryptoPwhashOpslimitMax, 'opslimit');
    RangeError.checkValueInInterval(memlimit, cryptoPwhashMemlimitMin,
        cryptoPwhashMemlimitMax, 'memlimit');
  }
  RangeError.checkValueInInterval(
      alg, cryptoPwhashAlgArgon2i13, cryptoPwhashAlgArgon2id13, 'alg');

  final _out = calloc<Uint8>(outlen);
  final _passwd = passwd.toPointer();
  final _salt = salt.toPointer();
  try {
    _cryptoPwhash
        .crypto_pwhash(_out, outlen, _passwd, passwd.length, _salt, opslimit,
            memlimit, alg)
        .mustSucceed('crypto_pwhash');

    return _out.toList(outlen);
  } finally {
    calloc.free(_out);
    calloc.free(_passwd);
    calloc.free(_salt);
  }
}