rotate method
Rotates a token by re-encrypting it under the MultiFernet instance's
primary key. This preserves the timestamp that was originally saved with
the token. If a token has successfully been rotated then the rotated
token will be returned. If rotation fails this will throw an exception.
Implementation
Uint8List rotate(final dynamic token) {
if (token is! Uint8List && token is! String) {
throw ArgumentError('token must be Uint8List or String');
}
final (int timestamp, Uint8List data) = Fernet._getUnverifiedTokenData(
token,
);
Uint8List? p;
for (final Fernet f in _fernets) {
try {
p = f._decryptData(data, timestamp, null);
break;
} on InvalidToken {
continue;
}
}
if (p == null) {
throw InvalidToken();
}
final Uint8List iv = CryptoUtils.secureRandomBytes(16);
return _fernets[0]._encryptFromParts(p, timestamp, iv);
}