OathError

public enum OathError : LocalizedError, Sendable

Errors that can occur during OATH operations.

OathError provides comprehensive error handling for all OATH-related operations, including credential management, URI parsing, code generation, and policy enforcement. Each error case includes detailed information to help developers diagnose and resolve issues.

Error Categories

  • Credential Management: Errors related to storing, retrieving, and managing credentials
  • URI Parsing: Errors that occur when parsing otpauth:// or mfauth:// URIs
  • Authentication: Errors during OTP code generation and validation
  • Policy: Errors related to policy enforcement and credential locking
  • System: General system and initialization errors

Usage Examples

do {
    let credential = try await client.addCredentialFromUri(uri)
    let code = try await client.generateCode(credential.id)
} catch let error as OathError {
    switch error {
    case .invalidUri(let message):
        print("Invalid URI format: \(message)")
        // Show user-friendly error about QR code format
    case .credentialLocked(let id):
        print("Credential is locked: \(id)")
        // Prompt user for authentication or wait for unlock
    case .codeGenerationFailed(let message, let underlying):
        print("Code generation failed: \(message)")
        // Check device time or credential validity
    default:
        print("OATH error: \(error.localizedDescription)")
    }
}

Error Recovery

Many errors provide recovery suggestions through the recoverySuggestion property:

if let suggestion = error.recoverySuggestion {
    print("Suggestion: \(suggestion)")
}

Credential Management Errors

URI Parsing Errors

  • The provided URI is invalid or malformed.

    Declaration

    Swift

    case invalidUri(String)
  • A required parameter is missing from the URI.

    Declaration

    Swift

    case missingRequiredParameter(String)
  • A parameter value is invalid.

    Declaration

    Swift

    case invalidParameterValue(String)
  • Failed to format the credential as a URI.

    Declaration

    Swift

    case uriFormatting(String)

Authentication Errors

  • The secret key is invalid or corrupted.

    Declaration

    Swift

    case invalidSecret(String)
  • The OATH type string is not recognized.

    Declaration

    Swift

    case invalidOathType(String)
  • The algorithm string is not supported.

    Declaration

    Swift

    case invalidAlgorithm(String)
  • Code generation failed due to cryptographic errors.

    Declaration

    Swift

    case codeGenerationFailed(String, _: Error? = nil)

Policy Errors

  • A policy violation occurred.

    Declaration

    Swift

    case policyViolation(String, String)

System Errors

  • Client initialization failed.

    Declaration

    Swift

    case initializationFailed(String, _: Error? = nil)
  • Cleanup operations failed.

    Declaration

    Swift

    case cleanupFailed(String, _: Error? = nil)

LocalizedError Implementation

  • Declaration

    Swift

    public var errorDescription: String? { get }
  • Declaration

    Swift

    public var failureReason: String? { get }
  • Declaration

    Swift

    public var recoverySuggestion: String? { get }