cadrumo.application.user_profile.login_session_port module

Typed application boundary for profile login-session infrastructure.

The login transaction owns ordering, rollback, and operator-facing outcomes. Persistence owns the live bucket session, throttle record, acceleration receipt, and key-buffer wipe. This module is the single dependency boundary between those responsibilities: it declares the exact structural DTOs the application observes and binds one concrete port for an explicit host lifetime.

class ProfileBucketSessionPort(*args, **kwargs)[source]

Bases: Protocol

Live bucket-session capability exposed across the application boundary.

property bucket_id: str

The bucket this live session was opened against.

property dek: bytes

The session’s bound data-encryption key.

property idle_deadline: datetime

The sliding deadline the next activity advances.

property absolute_deadline: datetime

The immutable cap no activity can extend.

property opened_at: datetime

When this session was authenticated.

property sealed: bool

Whether this session has been closed and its key material zeroised.

touch(now)[source]

Advance the sliding idle deadline.

Return type:

None

Parameters:

now (datetime)

is_expired(now)[source]

Return whether this session has crossed either deadline.

Return type:

bool

Parameters:

now (datetime)

close()[source]

Zeroise and retire this session’s local key material.

Return type:

None

class ProfilePersistedSessionPort(*args, **kwargs)[source]

Bases: Protocol

Persisted acceleration-receipt fields needed by login orchestration.

property profile_id: UUID

The profile this receipt accelerates.

property session_id: UUID

The receipt’s own identity.

property custody_generation: int

The custody generation this receipt was minted against.

property dek_epoch: str

The DEK epoch this receipt was minted against.

property issued_at: datetime

When the receipt was minted.

property idle_deadline: datetime

The sliding deadline a resume may advance.

property absolute_deadline: datetime

The immutable cap no resume can extend.

class ProfileSessionResumeOutcomePort(*args, **kwargs)[source]

Bases: Protocol

Fail-closed persisted-session evaluation result.

property resumed: bool

Whether the persisted receipt was accepted.

property refusal: ProfileSessionRefusalReason | None

The typed reason a resume was refused, if it was.

property record: ProfilePersistedSessionPort | None

The evaluated receipt, present whether or not it was accepted.

class ProfileLoginThrottleEvaluationPort(*args, **kwargs)[source]

Bases: Protocol

Failed-login backoff decision exposed to the application.

property throttled: bool

Whether the caller must wait before another attempt.

property remaining_seconds: int

Seconds left on the current backoff window.

class ProfileLoginSessionPort(*args, **kwargs)[source]

Bases: Protocol

Complete infrastructure capability used by the login-session aggregate.

Methods return the persistence substrate’s existing DTOs through structural protocols. The boundary never copies them: live-session identity is part of rollback and the exact receipt instance anchors idle-deadline renewal.

load_handover_journal(*, storage_root)[source]

Load the durable profile-switch witness, if present.

Return type:

ProfileLoginHandoverJournal | None

Parameters:

storage_root (Path)

save_handover_journal(*, storage_root, journal)[source]

Persist one monotonic profile-switch witness.

Return type:

None

Parameters:
clear_handover_journal(*, storage_root, journal)[source]

Compare and clear the completed profile-switch witness.

Return type:

None

Parameters:
current_session()[source]

Return the process-bound live session, if one exists.

Return type:

ProfileBucketSessionPort | None

open_resumed_session(*, bucket_id, dek, idle_minutes, opened_at, idle_deadline, absolute_deadline, storage_root)[source]

Open one live session over the supplied authenticated DEK.

Return type:

ProfileBucketSessionPort

Parameters:
bind_session(session)[source]

Bind one authenticated session to the process context.

Return type:

None

Parameters:

session (ProfileBucketSessionPort)

close_active_session()[source]

Close and zeroise the process-bound live session.

Return type:

None

session_serves_bucket(session, bucket_id)[source]

Return whether session serves the exact profile UUID.

Return type:

bool

Parameters:
evaluate_throttle(*, storage_root, bucket_id, now)[source]

Evaluate failed-login backoff before password derivation.

Return type:

ProfileLoginThrottleEvaluationPort

Parameters:
record_login_failure(*, storage_root, bucket_id, now)[source]

Record one refused password proof without replacing its refusal.

Return type:

None

Parameters:
reset_throttle(*, storage_root, bucket_id)[source]

Clear the revocable failed-login backoff cache.

Return type:

None

Parameters:
  • storage_root (Path)

  • bucket_id (str)

acceleration_receipt_path(*, storage_root, profile_id)[source]

Return the exact local receipt locator for one profile.

Return type:

Path

Parameters:
mint_acceleration_receipt(*, storage_root, profile_id, custody_generation, dek_epoch, dek, now, idle_minutes, absolute_minutes)[source]

Mint and return the canonical persisted acceleration receipt.

Return type:

ProfilePersistedSessionPort

Parameters:
resume_acceleration_receipt(*, storage_root, profile_id, custody_generation, dek_epoch, now)[source]

Evaluate one receipt and return its owned wipeable DEK buffer.

Return type:

tuple[ProfileSessionResumeOutcomePort, bytearray | None]

Parameters:
delete_acceleration_receipt(*, storage_root, profile_id)[source]

Revoke one profile’s split-knowledge acceleration receipt.

Return type:

None

Parameters:
advance_acceleration_idle_deadline(*, storage_root, profile_id, record, new_idle_deadline)[source]

Advance a receipt while preserving its concrete DTO identity.

Return type:

ProfilePersistedSessionPort

Parameters:
is_persisted_receipt(record)[source]

Narrow a resume record to the canonical persisted receipt DTO.

Return type:

TypeGuard[ProfilePersistedSessionPort]

Parameters:

record (object)

zeroise_owned_buffer(buffer)[source]

Overwrite the exact mutable key buffer owned by the caller.

Return type:

None

Parameters:

buffer (bytearray)

bind_profile_login_session_port(port)[source]

Bind one outward-composed port for the current host execution context.

Return type:

Generator[ProfileLoginSessionPort]

Parameters:

port (ProfileLoginSessionPort)

profile_login_session_port()[source]

Resolve the explicitly composed port for the current host context.

Return type:

ProfileLoginSessionPort

profile_session_serves_bucket(session, bucket_id)[source]

Return whether a live bucket session serves the exact profile UUID.

Return type:

bool

Parameters:
profile_current_bucket_session()[source]

Observe the currently bound bucket session through the login-session port.

Return type:

ProfileBucketSessionPort | None