Skip to content

Commit

Permalink
Merge branch 'skit-474-add-list-to-storagemanagerinterface-and-implem…
Browse files Browse the repository at this point in the history
…ent-in-wallet' of github.com:spruceid/mobile-sdk-swift into skit-474-add-list-to-storagemanagerinterface-and-implement-in-wallet
  • Loading branch information
todd-spruceid committed Aug 6, 2024
2 parents d1bb7cc + 54c1d21 commit 65eab9c
Showing 1 changed file with 41 additions and 56 deletions.
97 changes: 41 additions & 56 deletions Sources/MobileSdk/StorageManager.swift
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
// File: Storage Manager
//
// Store and retrieve sensitive data. Data is stored in the Application Support directory of the app, encrypted in place
// via the .completeFileProtection option, and marked as excluded from backups so it will not be included in iCloud backps.

//
// Imports
//
/// Storage Manager
///
/// Store and retrieve sensitive data. Data is stored in the Application Support directory of the app, encrypted in place
/// via the .completeFileProtection option, and marked as excluded from backups so it will not be included in iCloud backps.

import Foundation

// import SpruceIDMobileSdkRs
import SpruceIDMobileSdkRs

// The following is a stripped-down version of the protocol definition from mobile-sdk-rs against which the storage
// manager is intended to link.
Expand All @@ -34,23 +30,16 @@ public protocol StorageManagerInterface: AnyObject {
}
*/

//
// Code
//

// Class: StorageManager
// Store and retrieve sensitive data.

/// Store and retrieve sensitive data.
class StorageManager: NSObject, StorageManagerInterface {
// Local-Method: path()
// Get the path to the application support dir, appending the given file name to it. We use the application support
// directory because its contents are not shared.
//
// Arguments:
// file - the name of the file
//
// Returns:
// An URL for the named file in the app's Application Support directory.
/// Get the path to the application support dir, appending the given file name to it.
///
/// We use the application support directory because its contents are not shared.
///
/// - Parameters:
/// - file: the name of the file
///
/// - Returns: An URL for the named file in the app's Application Support directory.

private func path(file: String) -> URL? {
do {
Expand Down Expand Up @@ -87,15 +76,13 @@ class StorageManager: NSObject, StorageManagerInterface {
}
}

// Method: add()
// Store a value for a specified key, encrypted in place.
//
// Arguments:
// key - the name of the file
// value - the data to store
//
// Returns:
// A boolean indicating success.
/// Store a value for a specified key, encrypted in place.
///
/// - Parameters:
/// - key: the name of the file
/// - value: the data to store
///
/// - Returns: a boolean indicating success

func add(key: Key, value: Value) throws {
guard let file = path(file: key) else { return }
Expand All @@ -107,14 +94,12 @@ class StorageManager: NSObject, StorageManagerInterface {
}
}

// Method: get()
// Get a value for the specified key.
//
// Arguments:
// key - the name associated with the data
//
// Returns:
// Optional data potentially containing the value associated with the key; may be `nil`.
/// Get a value for the specified key.
///
/// - Parameters:
/// - key: the name associated with the data
///
/// - Returns: optional data potentially containing the value associated with the key; may be `nil`

func get(key: Key) throws -> Value {
guard let file = path(file: key) else { return Data() }
Expand All @@ -127,12 +112,12 @@ class StorageManager: NSObject, StorageManagerInterface {
}
}

// Method: list()
// List the the items in storage. Note that this will list all items in the `application support` directory,
// potentially including any files created by other systems.
//
// Returns:
// A list of items in storage.
/// List the the items in storage.
///
/// Note that this will list all items in the `application support` directory, potentially including any files created
/// by other systems.
///
/// - Returns: a list of items in storage

func list() -> [Key] {
guard let asdir = path(file: "")?.path else { return [String]() }
Expand All @@ -144,14 +129,14 @@ class StorageManager: NSObject, StorageManagerInterface {
}
}

// Method: remove()
// Remove a key/value pair. Removing a nonexistent key/value pair is not an error.
//
// Arguments:
// key - the name of the file
//
// Returns:
// A boolean indicating success; at present, there is no failure path, but this may change in the future.
/// Remove a key/value pair.
///
/// Removing a nonexistent key/value pair is not an error.
///
/// - Parameters:
/// - key: the name of the file
///
/// - Returns: a boolean indicating success; at present, there is no failure path, but this may change in the future

func remove(key: Key) throws {
guard let file = path(file: key) else { return }
Expand Down

0 comments on commit 65eab9c

Please sign in to comment.