Class InMemoryTotpStore

java.lang.Object
com.revetsec.totp.InMemoryTotpStore
All Implemented Interfaces:
TotpStore

@ThreadSafe @CheckReturnValue public final class InMemoryTotpStore extends Object implements TotpStore
Explicit bounded, volatile, single-process TOTP demonstration store. Restart loses factors, recovery consumption, replay marks and every recovery/clock fence. Never use it as an automatic fallback, as authoritative storage for established accounts or across independent processes. No record is evicted or expired. A configured namespace begins NEW and activates only through an atomic initialization write. Fresh recovery epochs retain old records and permanently fence old writers; this process-local history is not a substitute for an external durable controller.

The first operational call establishes this store's own volatile UTC projection and metadata. The authenticator's worker Clock is not its time source. The store checks its elapsed projection against a fresh host UTC sample on each operation. A discontinuity starts a new clock generation, fencing work from the old generation; after a backward step the store remains unavailable until host UTC reaches the last published point. This is a local demonstration assertion, not external UTC, restore, device-durability or suspend/rate qualification.

Since:
1.0.0
  • Method Details

    • withNamespace

      public static @NonNull InMemoryTotpStore.Builder withNamespace(@NonNull String credentialNamespace, @NonNull String recoveryEpoch)
      Starts configuration for one explicit volatile namespace and fresh recovery epoch.
      Parameters:
      credentialNamespace - the visible ASCII namespace
      recoveryEpoch - the never-reused recovery epoch
      Returns:
      a caller-thread builder
      Since:
      1.0.0
    • provisionRecoveryEpoch

      Provisions and fences to a fresh epoch in this demonstration store. The application must close admission and drain operations before calling it. Existing records remain retained and count against capacity. An epoch previously used by this store can never be selected again. The time projection and authority identity continue; only data recovery admission changes. This cannot repair lost clock continuity or establish shared-store recovery after restart.
      Parameters:
      recoveryEpoch - the fresh never-reused epoch
      remainingBudget - remaining positive administration budget
      Returns:
      factual COMMITTED, or CAPACITY_REFUSED/UNAVAILABLE before mutation
      Since:
      1.0.0
    • read

      Description copied from interface: TotpStore
      Reads exactly the requested nonempty bounded scope at one authoritative snapshot point, checking the active epoch and operational admission in the same transaction. The entries and fresh admitted time or time-only unavailability form one coherent observation. Explicitly represent every absence; no cleanup, quota update or floor write belongs to a read.
      Specified by:
      read in interface TotpStore
      Parameters:
      keys - one namespace and recovery epoch, at most 16 addresses
      remainingBudget - remaining positive operation budget
      Returns:
      a complete snapshot, fenced epoch or unavailable read
    • compareAndCommit

      Description copied from interface: TotpStore
      Atomically compares current admission, epoch and all snapshot predicates, then validates fresh store-authoritative time after every wait, including for condition-only writes.
      Specified by:
      compareAndCommit in interface TotpStore
      Parameters:
      write - the exact predicates and complete change set
      remainingBudget - remaining positive operation budget
      Returns:
      the factual contextual receipt, with required validation timing for COMMITTED
    • toString

      Redacts stored records and recovery configuration.
      Overrides:
      toString in class Object
      Returns:
      the fixed redacted description
      Since:
      1.0.0