-
-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Android alignment #25
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adaptions, I would propose to wait for @PSchmiedmayer and @Supereg input as well, but I will leave some additional thoughts on the state and some improvements from my pov:
SecureStorageScope
– belongs to the LocalStorage
target. In the SecureStorage
target, we are only using the accessGroup property of it which can safely be required as a nullable string in the store method. A hint in the code that these components do not belong together: assert(!(.secureEnclave ~= storageScope), "Storing of keys in the secure enclave is not supported by Apple.")
.
Newly added KeyStorage
also belongs to the LocalStorage
target.
Dependencies should then be reversed: SecureStorage
should depend on LocalStorage
– however only as long as we continue to support the deprecations.
After that, we can completely cut the dependency between the two targets - We achieve a lower coupling this way between the targets
/// A pair of username and password credentials. | ||
public struct Credentials: Equatable, Identifiable { | ||
/// A user's credential containing username and password. | ||
public struct Credential: Equatable, Identifiable { | ||
/// The username. | ||
public var username: String | ||
/// The password. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we consider adding server
parameter as well? It is not a breaking change if you initialize it with null
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would be the only change that would kind of force us to make a major-version update... Is it really worth it?
Alternatively, we could have those deprecation functions with the server-property being explicit and then we override in the deprecated function just to keep the minor version update. But what behavior should we choose there? Keeping the old struct with the slightly different name but without the server-property, always overriding the struct-property with the function parameter or doing something like server ?? credential.server
or the other way around?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nevermind, changed it and deprecated SecureStorage as a whole. We now don't even have SecureStorage on Android anymore, since it isn't needed and just builds a Façade that isn't really necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that would make sense to ensure that we don't have to take a breaking change for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But soft-deprecation is fine, right? Like I still kept the implementation of SecureStorage on iOS, but marked the whole class as deprecated. So, one can still use it as-is, but internally we are pretty much just calling the new functions instead.
Credential now has a server
property, but if you use the deprecated functions, we internally only use the function parameter and ignore what was set in the Credential struct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exactly; that would be ideal. Once we tag a new major version we can remove all these deprecated function implementations.
Sounds like a good plan!
/// - size: The size of the key in bits. The default value is 256 bits. | ||
/// - storageScope: The ``SecureStorageScope`` used to store the newly generate key. | ||
/// - Returns: Returns the `SecKey` private key generated and stored in the keychain or the secure enclave. | ||
@discardableResult |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't be needed, it's quite an expensive operation and we should at least warn the clients to use the result 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be fine to allow this result be be discardable; given the fact that the key generation already takes a decent amount of time this might not make a huge difference. I don't think we require the user to store or process the private key as they could always get it again if needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It may not be obvious, but both on Android and on iOS the key is actually already stored in the create function. So, even if you throw away the result, it wouldn't really matter much... I'm ultimately indifferent about this being marked discardableResult or not though, so I would rather keep it as it was.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good; we can keep it as it was for now, makes this backward compatible as well 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for all the improvements; great to see this aligned with Android @pauljohanneskraft!
I only had minor comments, they were mainly targeted at enduring backward compatibility before e update to a few major version.
Thank you for the input @eldcn!
Happy to see this merged once the comments and discussion elements are addressed.
@@ -306,17 +192,23 @@ public final class SecureStorage: Module, DefaultInitializable, EnvironmentAcces | |||
/// - removeDuplicate: A flag indicating if any existing key for the `username` of the new credentials and `newServer` | |||
/// combination should be overwritten when storing the credentials. | |||
/// - storageScope: The ``SecureStorageScope`` of the newly stored credentials. | |||
public func updateCredentials( // swiftlint:disable:this function_default_parameter_at_end | |||
public func updateCredential( // swiftlint:disable:this function_default_parameter_at_end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We will also add a deprecated overload here; please ensure this for all methods that have changed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I now made sure to not change the interface of SecureStorage at all and just deprecated it as a whole.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good 👍
/// - size: The size of the key in bits. The default value is 256 bits. | ||
/// - storageScope: The ``SecureStorageScope`` used to store the newly generate key. | ||
/// - Returns: Returns the `SecKey` private key generated and stored in the keychain or the secure enclave. | ||
@discardableResult |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be fine to allow this result be be discardable; given the fact that the key generation already takes a decent amount of time this might not make a huge difference. I don't think we require the user to store or process the private key as they could always get it again if needed.
…le also soft-deprecating it
Android alignment
♻️ Current situation & Problem
@eldcn brought up a couple of improvement ideas for SpeziStorage. Since we aim to keep the Android and iOS interfaces similar, this pull request brings those changes to the iOS frameworks. This is mostly a conversation starter to discuss those changes and ultimately build the best version of Spezi for both platforms.
@Supereg Please let me know what you think. More context regarding these changes is also contained in StanfordSpezi/SpeziKt#123 and StanfordSpezi/SpeziKt#108.
⚙️ Release Notes
📚 Documentation
Please ensure that you properly document any additions in conformance to Spezi Documentation Guide.
You can use this section to describe your solution, but we encourage contributors to document your reasoning and changes using in-line documentation.
✅ Testing
Please ensure that the PR meets the testing requirements set by CodeCov and that new functionality is appropriately tested.
This section describes important information about the tests and why some elements might not be testable.
📝 Code of Conduct & Contributing Guidelines
By submitting creating this pull request, you agree to follow our Code of Conduct and Contributing Guidelines: