putAsCurrent method

void putAsCurrent(
  1. String owner,
  2. String namespace,
  3. ContentKey ck,
  4. String nskeyKid, {
  5. String? ownNskeyKid,
  6. DateTime? cutAt,
})

Cache ck and make it the key new writes in (owner, namespace) encrypt under, recording the nskey generation it was conveyed to.

nskeyKid is what lets a sender notice a rotation: once the recipient's advertised generation no longer matches, the current CK is stale. ownNskeyKid is the sender's own generation a shared CK's sibling copy was sealed to, null when it has none; once the sender holds a newer own generation, the current CK is stale too. cutAt is when the CK came into being, which a rotation policy judges it against: the caller that cut it passes nothing and gets this device's clock, while one that read it back passes the conveyance record's createdAt, the only date two devices can agree on.

Implementation

void putAsCurrent(
    String owner, String namespace, ContentKey ck, String nskeyKid,
    {String? ownNskeyKid, DateTime? cutAt}) {
  put(owner, namespace, ck);
  final scope = _scope(owner, namespace);
  _currentKidByNamespace[scope] = ck.ckKid;
  _currentNskeyKidByNamespace[scope] = nskeyKid;
  if (ownNskeyKid == null) {
    _currentOwnNskeyKidByNamespace.remove(scope);
  } else {
    _currentOwnNskeyKidByNamespace[scope] = ownNskeyKid;
  }
  _currentCutAtByNamespace[scope] = cutAt ?? DateTime.now().toUtc();
}