cockpitTargetRefToken function

String cockpitTargetRefToken(
  1. String registrationId
)

Returns the deterministic opaque token used by short live target refs.

The token carries no application data. Callers may expose the shortest unique prefix for the current mounted target set and resolve it again against the live tree before executing an action.

Implementation

String cockpitTargetRefToken(String registrationId) {
  var fnv = 0x811c9dc5;
  var djb = 5381;
  for (final unit in registrationId.codeUnits) {
    fnv = ((fnv ^ unit) * 0x01000193) & _cockpitHashMask;
    djb = ((djb * 33) ^ unit) & _cockpitHashMask;
  }
  return '${fnv.toRadixString(36).padLeft(7, '0')}'
      '${djb.toRadixString(36).padLeft(7, '0')}';
}