Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/Security/SecIdentity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,33 @@ public SecKey PrivateKey {
return new SecKey (p, true);
}
}

[SupportedOSPlatform ("ios26.0")]
[SupportedOSPlatform ("maccatalyst26.0")]
[SupportedOSPlatform ("macos26.0")]
[SupportedOSPlatform ("tvos26.0")]
[DllImport (Constants.SecurityLibrary)]
extern static /* __nullable CF_RETURNS_RETAINED SecIdentityRef */ IntPtr SecIdentityCreate (
IntPtr /* CFAllocatorRef __nullable */ allocator,
IntPtr /* SecCertificateRef */ certificate,
IntPtr /* SecKeyRef */ privateKey);

/// <summary>Create a <see cref="SecIdentity" /> instance from a certificate and a private key.</summary>
/// <param name="certificate">The certificate to use for the new <see cref="SecIdentity" /> instance.</param>
/// <param name="privateKey">The private to use for the new <see cref="SecIdentity" /> instance.</param>
/// <returns>A new <see cref="SecIdentity" /> instance if successful, otherwise <see langword="null" />.</returns>
[SupportedOSPlatform ("ios26.0")]
[SupportedOSPlatform ("maccatalyst26.0")]
[SupportedOSPlatform ("macos26.0")]
[SupportedOSPlatform ("tvos26.0")]
public static SecIdentity? Create (SecCertificate certificate, SecKey privateKey)
{
var rv = SecIdentityCreate (IntPtr.Zero, certificate.GetNonNullHandle (nameof (certificate)), privateKey.GetNonNullHandle (nameof (privateKey)));
GC.KeepAlive (certificate);
GC.KeepAlive (privateKey);
if (rv == IntPtr.Zero)
return null;
return new SecIdentity (rv, true /* CF_RETURNS_RETAINED */);
}
}
}
10 changes: 10 additions & 0 deletions tests/monotouch-test/Security/IdentityTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ static public SecIdentity GetIdentity ()
}
}

[Test]
public void Create ()
{
TestRuntime.AssertXcodeVersion (26, 0);

using var identity = GetIdentity ();
using var newIdentity = SecIdentity.Create (identity.Certificate, identity.PrivateKey);
Assert.That (newIdentity, Is.Not.Null, "new identity");
}

[Test]
public void Identity ()
{
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading