Make `correlationId` optional for stored messages.

Move various utility methods. Add `ProtectionType`.