CryptoHelper

final class CryptoHelper

Helper for random crypto related stuff.

  • Bcrypt work factor for user passwords. configureMiddleware installs it as the app’s password hasher.

    Declaration

    Swift

    static let bcryptCost: Int
  • Bcrypt hash of a random throwaway value, at bcryptCost. When an account lookup fails, verify the submitted secret against this anyway, so the response takes about as long as it would for a real account.

    Declaration

    Swift

    static let dummyPasswordHash: String
  • Burns one bcrypt verification’s worth of time. The result is always discarded.

    Declaration

    Swift

    static func dummyPasswordVerify(_ secret: String, on req: Request) async
  • Bcrypt work factor for recovery keys. Higher than bcryptCost because a 3-word recovery key has far less entropy than a typical password, and recovery keys are hashed and verified rarely enough that the cost is cheap.

    Declaration

    Swift

    static let recoveryKeyBcryptCost: Int
  • Bcrypt hash of a random throwaway value, at recoveryKeyBcryptCost. See dummyPasswordHash.

    Declaration

    Swift

    static let dummyRecoveryKeyHash: String
  • hashRecoveryKey(_:on:) Asynchronous

    Hashes a normalized recovery key at recoveryKeyBcryptCost on the thread pool, off the event loop.

    Declaration

    Swift

    static func hashRecoveryKey(_ normalizedKey: String, on req: Request) async throws -> String
  • Burns one recovery-key verification’s worth of time. The result is always discarded.

    Declaration

    Swift

    static func dummyRecoveryKeyVerify(_ secret: String, on req: Request) async
  • Hash a String. ChatGPT wrote this.

    Declaration

    Swift

    static func sha256Hash(of string: String) -> String