@@ -15,10 +15,9 @@ internal static partial class AppleCrypto
15
15
[ DllImport ( Libraries . AppleCryptoNative , EntryPoint = "AppleCryptoNative_RsaGenerateKey" ) ]
16
16
private static extern int AppleCryptoNative_RsaGenerateKey (
17
17
int keySizeInBits ,
18
- SafeKeychainHandle keychain ,
19
18
out SafeSecKeyRefHandle pPublicKey ,
20
19
out SafeSecKeyRefHandle pPrivateKey ,
21
- out int pOSStatus ) ;
20
+ out SafeCFErrorHandle pErrorOut ) ;
22
21
23
22
[ DllImport ( Libraries . AppleCryptoNative ) ]
24
23
private static extern int AppleCryptoNative_RsaSignaturePrimitive (
@@ -125,20 +124,19 @@ internal static void RsaGenerateKey(
125
124
out SafeSecKeyRefHandle pPublicKey ,
126
125
out SafeSecKeyRefHandle pPrivateKey )
127
126
{
128
- using ( SafeTemporaryKeychainHandle tempKeychain = CreateTemporaryKeychain ( ) )
127
+ SafeSecKeyRefHandle keychainPublic ;
128
+ SafeSecKeyRefHandle keychainPrivate ;
129
+ SafeCFErrorHandle error ;
130
+
131
+ int result = AppleCryptoNative_RsaGenerateKey (
132
+ keySizeInBits ,
133
+ out keychainPublic ,
134
+ out keychainPrivate ,
135
+ out error ) ;
136
+
137
+ using ( error )
129
138
{
130
- SafeSecKeyRefHandle keychainPublic ;
131
- SafeSecKeyRefHandle keychainPrivate ;
132
- int osStatus ;
133
-
134
- int result = AppleCryptoNative_RsaGenerateKey (
135
- keySizeInBits ,
136
- tempKeychain ,
137
- out keychainPublic ,
138
- out keychainPrivate ,
139
- out osStatus ) ;
140
-
141
- if ( result == 1 )
139
+ if ( result == kSuccess )
142
140
{
143
141
pPublicKey = keychainPublic ;
144
142
pPrivateKey = keychainPrivate ;
@@ -148,9 +146,9 @@ internal static void RsaGenerateKey(
148
146
using ( keychainPrivate )
149
147
using ( keychainPublic )
150
148
{
151
- if ( result == 0 )
149
+ if ( result == kErrorSeeError )
152
150
{
153
- throw CreateExceptionForOSStatus ( osStatus ) ;
151
+ throw CreateExceptionForCFError ( error ) ;
154
152
}
155
153
156
154
Debug . Fail ( $ "Unexpected result from AppleCryptoNative_RsaGenerateKey: { result } ") ;
@@ -258,9 +256,6 @@ private static bool ProcessPrimitiveResponse(
258
256
Span < byte > destination ,
259
257
out int bytesWritten )
260
258
{
261
- const int kErrorSeeError = - 2 ;
262
- const int kSuccess = 1 ;
263
-
264
259
if ( returnValue == kErrorSeeError )
265
260
{
266
261
throw CreateExceptionForCFError ( cfError ) ;
0 commit comments