package com.vayunmathur.testsupport /** * Shared host-test sealing logic for the per-app `TokenSealer` interfaces * (code, fooddelivery, taxi each declare their own interface in main, so no * single shared class can implement all three; each app keeps a thin * `FakeTokenSealer : TokenSealer` adapter delegating here). * * Mirrors the real sealers' contract: sealed values carry the `v1:` prefix * (every app's `KeystoreTokenSealer.PREFIX`), this fake's own output carries * `v1:fake:`, legacy values pass through, and foreign sealed values fail * (null) rather than passing through. Robolectric has no AndroidKeyStore, * so tests seal with this reversible marker transform instead of AES-GCM. */ object FakeTokenSealing { private const val SEALED_PREFIX = "v1:fake:" private const val REAL_PREFIX = "v1:" fun seal(plain: String): String = SEALED_PREFIX + plain fun unseal(stored: String): String? = when { stored.startsWith(SEALED_PREFIX) -> stored.removePrefix(SEALED_PREFIX) isSealed(stored) -> null else -> stored } fun isSealed(stored: String): Boolean = stored.startsWith(REAL_PREFIX) }