Skip to content

Conversation

@xiazhvera
Copy link
Contributor

Issue #, if available:

Description of changes:

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@xiazhvera xiazhvera changed the base branch from main to iot February 19, 2024 21:40
@xiazhvera xiazhvera changed the base branch from iot to apple_ci February 29, 2024 22:10
Base automatically changed from apple_ci to iot March 25, 2024 16:26
Copy link
Contributor

@waahm7 waahm7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix & Ship.

/// Initializes TlsContextOptions for mutual TLS (mTLS), with client certificate and private key. These are in memory
/// buffers. These buffers must be in the PEM format.
///
/// NOTE: This is unsupported on iOS.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

debatable: You can use the @available(iOS, unavailable) declaration so that it fails at compile time. However, that will probably require consumers to do an if else to call this API.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking about it, it's better to set restrictions early on instead of adding them later. I added the available here for the path and data API.

    @available(iOS, unavailable)
    @available(tvOS, unavailable)
    @available(watchOS, unavailable)
    public static func makeMTLS(
        certificateData: String,
        privateKeyData: String) throws -> TLSContextOptions {
        try TLSContextOptions(certificateData: certificateData, privateKeyData: privateKeyData)
    }

For the pkcs12 one, it seems that @available only works for Apple platforms, we dont have a way to disable the API for linux/windows. I will leave it there for now.

path: String,
/// Initializes TlsContextOptions for mutual TLS (mTLS), with client certificate and private key in the PKCS#12 format.
///
/// NOTE: This only works on Apple devices.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@available directive?
Pros:

  • Compile time safety instead of runtime error

Cons:

  • Consumers of this API will have to do IF/ELSE at compile time, although they should probably do that anyhow if it is a cross-platform application.

@xiazhvera xiazhvera changed the base branch from iot to main April 1, 2024 17:48
@xiazhvera xiazhvera changed the base branch from main to iot April 1, 2024 22:21
@xiazhvera xiazhvera mentioned this pull request Apr 1, 2024
@xiazhvera
Copy link
Contributor Author

The changes are brought in new PR: #246

@xiazhvera xiazhvera closed this Apr 1, 2024
@xiazhvera xiazhvera deleted the tls_options branch April 10, 2024 16:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants