-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Conversation
@@ -51,6 +51,14 @@ public override byte[] SignHash(byte[] hash) | |||
} | |||
} | |||
|
|||
public override unsafe bool TrySignHash(ReadOnlySpan<byte> source, Span<byte> destination, out int bytesWritten) |
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.
What here (and at VerifyHash) requires the unsafe keyword?
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.
The null
argument to TrySignHash is a void*
.
Thanks for reviewing, @bartonjs. |
@stephentoub - Quick question: The code currently pins spans for P/Invoke, e.g.: private static unsafe int RsaEncryptPkcs(
SafeSecKeyRefHandle publicKey,
ReadOnlySpan<byte> pbData,
int cbData,
out SafeCFDataHandle pEncryptedOut,
out SafeCFErrorHandle pErrorOut)
{
fixed (byte* pbDataPtr = &pbData.DangerousGetPinnableReference())
{
return RsaEncryptPkcs(publicKey, pbDataPtr, cbData, out pEncryptedOut, out pErrorOut);
}
} Is that required or could the P/Invoke method defined to accept a private static int RsaEncryptPkcs(
SafeSecKeyRefHandle publicKey,
ReadOnlySpan<byte> pbData,
out SafeCFDataHandle pEncryptedOut,
out SafeCFErrorHandle pErrorOut)
{
return RsaEncryptPkcs(publicKey, ref pbData.DangerousGetPinnableReference(), pbData.Length, out pEncryptedOut, out pErrorOut);
}
[DllImport(Libraries.AppleCryptoNative, EntryPoint = "AppleCryptoNative_RsaEncryptPkcs")]
private static extern int RsaEncryptPkcs(
SafeSecKeyRefHandle publicKey,
ref byte pbData,
int cbData,
out SafeCFDataHandle pEncryptedOut,
out SafeCFErrorHandle pErrorOut); I'm wondering because manual pinning is usually not required when passing, for example, a field by reference: class A { public int B; }
[DllImport(...)]
static extern void Foo(ref int value);
static void Main()
{
var a = new A();
Foo(ref a.B);
} |
That's a good question. I actually hadn't considered doing that, but I don't see why it wouldn't work. I'll try and submit a PR to clean it up assuming it works. |
Commit migrated from dotnet/corefx@1d7b43d
cc: @bartonjs
Closes https://github.com/dotnet/corefx/issues/22615