Skip to content

SslCipherSuite size #11498

@rolfbjarne

Description

@rolfbjarne

Apple defines SSLCipherSuite as:

/*
 * Defined as enum for debugging, but in the protocol
 * it is actually exactly two bytes
 */
#if ((TARGET_OS_IPHONE && !TARGET_OS_MACCATALYST) || (TARGET_OS_OSX && TARGET_CPU_ARM64))
/* 16-bit value on iOS */
typedef uint16_t SSLCipherSuite;
#else
/* 32-bit value elsewhere */
typedef uint32_t SSLCipherSuite;
#endif

Apple's documentation about SSLCipherSuite says (including as a screenshot, because it's changed in the past):

Screen Shot 2021-05-11 at 14 46 37

  1. The comments in the headers are wrong.
  2. The comments do not match the documentation.
  3. The documentation is also wrong.

The truth is:

uint16_t uint32_t
iOS X
tvOS X  
watchOS X
Mac Catalyst X
macOS (x64) X
macOS (arm64) X  

The question is how to model this in C#, and there are two ways:

1️⃣ Make our enum size match Apple's

Pros:

  • It matches Apple, which is always good.
  • Less likely to run into unwelcome surprises in API updates in the future.

Cons:

  • It requires us to build different assemblies for x64 and arm64 for macOS.
  • It makes code that works on iOS not work on Mac Catalyst.

2️⃣ Choose an enum size for all platforms, and hide the underlying size differences from app developers

Pros:

  • Unified managed API.
  • Simpler build logic (for our platform assemblies)
  • Faster build (for Xamarin.Mac: no need to build multiple versions).

Cons:

  • More work on our side (for the C# code). We'd have to:
    • Make sure we don't use SslCipherSuite in any P/Invoke and instead use the correct underlying type based on the platform and architecture.
  • App developers would run into the same size problem if they were to create P/Invokes with our enum type.
  • More likely that Apple comes up with something that breaks us in the future.

Until macOS (arm64) I leaned towards option 1, since it was the simpler option for us to implement, and just one of several API differences between iOS and Mac Catalyst. With the difference between x64 and arm64 on macOS, I'm leaning towards option 2, since having different managed API depending on only the architecture is something we've been able to avoid in the past (re: native enums).

To recap: thumbs up for option 2️⃣, thumbs down for option 1️⃣


This test ignore must be reverted when this is fixed: #11613

Metadata

Metadata

Assignees

No one assigned

    Labels

    dotnetAn issue or pull request related to .NET (6)dotnet-pri3.NET 6: wishlist for stable releaseestimate-4hrequest-for-commentsThe issue is a suggested idea seeking feedback

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions