Encrypted

extension MoEngageStorage.UserDefaultStorage.Encrypted
  • Intercepts get, set, and dictionary to apply AES encryption/decryption.

    The processor is a no-op when:

    • The scope is not .sdk(.instance).
    • Encryption is disabled in sdkInstance.storedConfig.storageConfig.encryptionConfig. In that case all encrypted data is cleared from the suite before delegating to the upstream closures, so a device that had encryption enabled previously is cleaned up automatically.

    When encryption is enabled, the processor:

    1. Calls encryptionResult(userDefaults:scope:sdkInstance:get:set:dictionary:) on every read/write to determine (and lazily apply) the encryption state.
    2. Decrypts values on get using aesHandler(withKey:).
    3. Encrypts values on set via encryptAndSet(userDefaults:key:value:encryptionKey:sdkInstance:action:).

    Throws

    Error/noEncryptionKey when a key is needed but unavailable.

    Declaration

    Swift

    public func process(
        get: @escaping @Sendable (isolated MoEngageSDKInstance, UserDefaults, String) throws -> Any?,
        set: @escaping @Sendable (isolated MoEngageSDKInstance, UserDefaults, String, Any?) throws -> Void,
        dictionary: @escaping @Sendable (isolated MoEngageSDKInstance, UserDefaults) throws -> [String: Any],
        scope: MoEngageStorage.UserDefaultStorage<Value>.Scope,
        sdkInstance: isolated MoEngageSDKInstance = #isolation
    ) throws -> MoEngageStorage.UserDefaultStorage<Value>.ProcessorResult

    Parameters

    get

    The upstream get closure accumulated by prior processors.

    set

    The upstream set closure accumulated by prior processors.

    dictionary

    The upstream dictionary closure accumulated by prior processors.

    scope

    The scope of the owning MoEngageStorage/UserDefaultStorage.

    sdkInstance

    The isolated SDK instance providing encryption config.

    Return Value

    .skip when the scope or config does not require encryption; otherwise .transformed with closures that wrap the originals with encrypt/decrypt logic.