renewKeys method
- Uint8List? preparedRenewal,
- SealdGeneratedPrivateKeys? privateKeys,
- Duration expireAfter = const Duration(days: 5 * 365),
Renews the keys of the current device, extending their validity. If the current device has expired, you will need to call renewKeys before you are able to do anything else. Warning: if the identity of the current device is stored externally, for example on SSKS, you will want to re-export it and store it again, otherwise the previously stored identity will not be recognized anymore.
preparedRenewal
- Optional. A prepared renewal, returned by a call to SealdSdk.prepareRenew. If preparedRenewal is given, privateKeys will be ignored.
privateKeys
- Optional. Pre-generated private keys, returned by a call to SealdSdk.generatePrivateKeysAsync.
expireAfter
- The duration during which the renewed device key will be valid without further renewal. Optional, defaults to 5 years.
Implementation
void renewKeys({
Uint8List? preparedRenewal,
SealdGeneratedPrivateKeys? privateKeys,
Duration expireAfter = const Duration(days: 5 * 365),
}) {
if (_closed) {
throw SealdException(
code: "INSTANCE_CLOSED",
id: "FLUTTER_INSTANCE_CLOSED",
description: "Instance already closed.");
}
final Pointer<Pointer<NativeSealdError>> err =
calloc<Pointer<NativeSealdError>>();
final Pointer<Utf8> nativeEncryptionKey = preparedRenewal != null
? nullptr
: privateKeys?.encryptionKey.toNativeUtf8() ?? nullptr;
final Pointer<Utf8> nativeSigningKey = preparedRenewal != null
? nullptr
: privateKeys?.signingKey.toNativeUtf8() ?? nullptr;
Pointer<Uint8> nativePreparedRenewal = nullptr;
if (preparedRenewal != null) {
// Dart FFI forces us to copy the data from Uint8List to a newly allocated Pointer<Uint8>
nativePreparedRenewal = calloc<Uint8>(preparedRenewal.length);
final pointerList =
nativePreparedRenewal.asTypedList(preparedRenewal.length);
pointerList.setAll(0, preparedRenewal);
}
final int resultCode = _bindings.SealdSdk_RenewKeys(
_ptr.pointer(),
expireAfter.inSeconds,
nativeEncryptionKey,
nativeSigningKey,
nativePreparedRenewal,
preparedRenewal?.length ?? 0,
err);
calloc.free(nativePreparedRenewal);
calloc.free(nativeEncryptionKey);
calloc.free(nativeSigningKey);
if (resultCode != 0) {
throw SealdException._fromCPtr(err);
} else {
calloc.free(err);
}
}