objc2-security 0.3.2

Bindings to the Security framework
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::ffi::*;
use core::ptr::NonNull;
#[cfg(feature = "objc2")]
use objc2::__framework_prelude::*;
use objc2_core_foundation::*;

use crate::*;

/// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeykeyclass?language=objc)
#[deprecated = "No longer supported"]
pub const kSecKeyKeyClass: c_int = 0;
/// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyprintname?language=objc)
#[deprecated = "No longer supported"]
pub const kSecKeyPrintName: c_int = 1;
/// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalias?language=objc)
#[deprecated = "No longer supported"]
pub const kSecKeyAlias: c_int = 2;
/// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeypermanent?language=objc)
#[deprecated = "No longer supported"]
pub const kSecKeyPermanent: c_int = 3;
/// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyprivate?language=objc)
#[deprecated = "No longer supported"]
pub const kSecKeyPrivate: c_int = 4;
/// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeymodifiable?language=objc)
#[deprecated = "No longer supported"]
pub const kSecKeyModifiable: c_int = 5;
/// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeylabel?language=objc)
#[deprecated = "No longer supported"]
pub const kSecKeyLabel: c_int = 6;
/// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyapplicationtag?language=objc)
#[deprecated = "No longer supported"]
pub const kSecKeyApplicationTag: c_int = 7;
/// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeykeycreator?language=objc)
#[deprecated = "No longer supported"]
pub const kSecKeyKeyCreator: c_int = 8;
/// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeykeytype?language=objc)
#[deprecated = "No longer supported"]
pub const kSecKeyKeyType: c_int = 9;
/// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeykeysizeinbits?language=objc)
#[deprecated = "No longer supported"]
pub const kSecKeyKeySizeInBits: c_int = 10;
/// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyeffectivekeysize?language=objc)
#[deprecated = "No longer supported"]
pub const kSecKeyEffectiveKeySize: c_int = 11;
/// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeystartdate?language=objc)
#[deprecated = "No longer supported"]
pub const kSecKeyStartDate: c_int = 12;
/// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyenddate?language=objc)
#[deprecated = "No longer supported"]
pub const kSecKeyEndDate: c_int = 13;
/// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeysensitive?language=objc)
#[deprecated = "No longer supported"]
pub const kSecKeySensitive: c_int = 14;
/// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalwayssensitive?language=objc)
#[deprecated = "No longer supported"]
pub const kSecKeyAlwaysSensitive: c_int = 15;
/// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyextractable?language=objc)
#[deprecated = "No longer supported"]
pub const kSecKeyExtractable: c_int = 16;
/// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyneverextractable?language=objc)
#[deprecated = "No longer supported"]
pub const kSecKeyNeverExtractable: c_int = 17;
/// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyencrypt?language=objc)
#[deprecated = "No longer supported"]
pub const kSecKeyEncrypt: c_int = 18;
/// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeydecrypt?language=objc)
#[deprecated = "No longer supported"]
pub const kSecKeyDecrypt: c_int = 19;
/// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyderive?language=objc)
#[deprecated = "No longer supported"]
pub const kSecKeyDerive: c_int = 20;
/// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeysign?language=objc)
#[deprecated = "No longer supported"]
pub const kSecKeySign: c_int = 21;
/// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyverify?language=objc)
#[deprecated = "No longer supported"]
pub const kSecKeyVerify: c_int = 22;
/// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeysignrecover?language=objc)
#[deprecated = "No longer supported"]
pub const kSecKeySignRecover: c_int = 23;
/// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyverifyrecover?language=objc)
#[deprecated = "No longer supported"]
pub const kSecKeyVerifyRecover: c_int = 24;
/// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeywrap?language=objc)
#[deprecated = "No longer supported"]
pub const kSecKeyWrap: c_int = 25;
/// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyunwrap?language=objc)
#[deprecated = "No longer supported"]
pub const kSecKeyUnwrap: c_int = 26;

/// Determines the type of credential returned by SecKeyGetCredentials.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/security/seccredentialtype?language=objc)
// NS_ENUM
#[cfg(feature = "cssmconfig")]
#[deprecated = "No longer supported"]
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct SecCredentialType(pub uint32);
#[cfg(feature = "cssmconfig")]
impl SecCredentialType {
    #[doc(alias = "kSecCredentialTypeDefault")]
    #[deprecated = "No longer supported"]
    pub const Default: Self = Self(0);
    #[doc(alias = "kSecCredentialTypeWithUI")]
    #[deprecated = "No longer supported"]
    pub const WithUI: Self = Self(1);
    #[doc(alias = "kSecCredentialTypeNoUI")]
    #[deprecated = "No longer supported"]
    pub const NoUI: Self = Self(2);
}

#[cfg(all(feature = "cssmconfig", feature = "objc2"))]
unsafe impl Encode for SecCredentialType {
    const ENCODING: Encoding = uint32::ENCODING;
}

#[cfg(all(feature = "cssmconfig", feature = "objc2"))]
unsafe impl RefEncode for SecCredentialType {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

/// Supported padding types.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/security/secpadding?language=objc)
// NS_OPTIONS
#[deprecated = "Replaced with SecKeyAlgorithm"]
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct SecPadding(pub u32);
bitflags::bitflags! {
    impl SecPadding: u32 {
        #[doc(alias = "kSecPaddingNone")]
#[deprecated = "Replaced with SecKeyAlgorithm"]
        const None = 0;
        #[doc(alias = "kSecPaddingPKCS1")]
#[deprecated = "Replaced with SecKeyAlgorithm"]
        const PKCS1 = 1;
        #[doc(alias = "kSecPaddingOAEP")]
#[deprecated = "Replaced with SecKeyAlgorithm"]
        const OAEP = 2;
        #[doc(alias = "kSecPaddingSigRaw")]
#[deprecated = "Replaced with SecKeyAlgorithm"]
        const SigRaw = 0x4000;
        #[doc(alias = "kSecPaddingPKCS1MD2")]
#[deprecated = "Replaced with SecKeyAlgorithm"]
        const PKCS1MD2 = 0x8000;
        #[doc(alias = "kSecPaddingPKCS1MD5")]
#[deprecated = "Replaced with SecKeyAlgorithm"]
        const PKCS1MD5 = 0x8001;
        #[doc(alias = "kSecPaddingPKCS1SHA1")]
#[deprecated = "Replaced with SecKeyAlgorithm"]
        const PKCS1SHA1 = 0x8002;
        #[doc(alias = "kSecPaddingPKCS1SHA224")]
#[deprecated = "Replaced with SecKeyAlgorithm"]
        const PKCS1SHA224 = 0x8003;
        #[doc(alias = "kSecPaddingPKCS1SHA256")]
#[deprecated = "Replaced with SecKeyAlgorithm"]
        const PKCS1SHA256 = 0x8004;
        #[doc(alias = "kSecPaddingPKCS1SHA384")]
#[deprecated = "Replaced with SecKeyAlgorithm"]
        const PKCS1SHA384 = 0x8005;
        #[doc(alias = "kSecPaddingPKCS1SHA512")]
#[deprecated = "Replaced with SecKeyAlgorithm"]
        const PKCS1SHA512 = 0x8006;
    }
}

#[cfg(feature = "objc2")]
unsafe impl Encode for SecPadding {
    const ENCODING: Encoding = u32::ENCODING;
}

#[cfg(feature = "objc2")]
unsafe impl RefEncode for SecPadding {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

/// Supported key lengths.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/security/seckeysizes?language=objc)
// NS_ENUM
#[deprecated = "No longer supported"]
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct SecKeySizes(pub u32);
impl SecKeySizes {
    #[doc(alias = "kSecDefaultKeySize")]
    #[deprecated = "No longer supported"]
    pub const SecDefaultKeySize: Self = Self(0);
    #[doc(alias = "kSec3DES192")]
    #[deprecated = "No longer supported"]
    pub const Sec3DES192: Self = Self(192);
    #[doc(alias = "kSecAES128")]
    #[deprecated = "No longer supported"]
    pub const SecAES128: Self = Self(128);
    #[doc(alias = "kSecAES192")]
    #[deprecated = "No longer supported"]
    pub const SecAES192: Self = Self(192);
    #[doc(alias = "kSecAES256")]
    #[deprecated = "No longer supported"]
    pub const SecAES256: Self = Self(256);
    #[doc(alias = "kSecp192r1")]
    #[deprecated = "No longer supported"]
    pub const Secp192r1: Self = Self(192);
    #[doc(alias = "kSecp256r1")]
    #[deprecated = "No longer supported"]
    pub const Secp256r1: Self = Self(256);
    #[doc(alias = "kSecp384r1")]
    #[deprecated = "No longer supported"]
    pub const Secp384r1: Self = Self(384);
    #[doc(alias = "kSecp521r1")]
    #[deprecated = "No longer supported"]
    pub const Secp521r1: Self = Self(521);
    #[doc(alias = "kSecRSAMin")]
    #[deprecated = "No longer supported"]
    pub const SecRSAMin: Self = Self(1024);
    #[doc(alias = "kSecRSAMax")]
    #[deprecated = "No longer supported"]
    pub const SecRSAMax: Self = Self(4096);
}

#[cfg(feature = "objc2")]
unsafe impl Encode for SecKeySizes {
    const ENCODING: Encoding = u32::ENCODING;
}

#[cfg(feature = "objc2")]
unsafe impl RefEncode for SecKeySizes {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

extern "C" {
    /// Predefined key constants used to get or set values in a dictionary.
    /// These are used to provide explicit parameters to key generation functions
    /// when non-default values are desired. See the description of the
    /// SecKeyGeneratePair API for usage information.
    ///
    /// containing attributes specific for the private key to be generated.
    ///
    /// containing attributes specific for the public key to be generated.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/security/ksecprivatekeyattrs?language=objc)
    pub static kSecPrivateKeyAttrs: &'static CFString;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/security/ksecpublickeyattrs?language=objc)
    pub static kSecPublicKeyAttrs: &'static CFString;
}

#[cfg(feature = "SecBase")]
unsafe impl ConcreteType for SecKey {
    /// Returns the type identifier of SecKey instances.
    ///
    /// Returns: The CFTypeID of SecKey instances.
    #[doc(alias = "SecKeyGetTypeID")]
    #[inline]
    fn type_id() -> CFTypeID {
        extern "C-unwind" {
            fn SecKeyGetTypeID() -> CFTypeID;
        }
        unsafe { SecKeyGetTypeID() }
    }
}

#[cfg(feature = "SecBase")]
impl SecKey {
    /// Creates an asymmetric key pair and stores it in a specified keychain.
    ///
    /// Parameter `keychainRef`: A reference to the keychain in which to store the private and public key items. Specify NULL for the default keychain.
    ///
    /// Parameter `algorithm`: An algorithm for the key pair. This parameter is ignored if a valid (non-zero) contextHandle is supplied.
    ///
    /// Parameter `keySizeInBits`: A key size for the key pair. This parameter is ignored if a valid (non-zero) contextHandle is supplied.
    ///
    /// Parameter `contextHandle`: (optional) A CSSM_CC_HANDLE, or 0. If this argument is supplied, the algorithm and keySizeInBits parameters are ignored. If extra parameters are needed to generate a key (some algorithms require this), you should create a context using CSSM_CSP_CreateKeyGenContext, using the CSPHandle obtained by calling SecKeychainGetCSPHandle. Then use CSSM_UpdateContextAttributes to add parameters, and dispose of the context using CSSM_DeleteContext after calling this function.
    ///
    /// Parameter `publicKeyUsage`: A bit mask indicating all permitted uses for the new public key. CSSM_KEYUSE bit mask values are defined in cssmtype.h.
    ///
    /// Parameter `publicKeyAttr`: A bit mask defining attribute values for the new public key. The bit mask values are equivalent to a CSSM_KEYATTR_FLAGS and are defined in cssmtype.h.
    ///
    /// Parameter `privateKeyUsage`: A bit mask indicating all permitted uses for the new private key. CSSM_KEYUSE bit mask values are defined in cssmtype.h.
    ///
    /// Parameter `privateKeyAttr`: A bit mask defining attribute values for the new private key. The bit mask values are equivalent to a CSSM_KEYATTR_FLAGS and are defined in cssmtype.h.
    ///
    /// Parameter `initialAccess`: (optional) A SecAccess object that determines the initial access rights to the private key. The public key is given "any/any" access rights by default.
    ///
    /// Parameter `publicKey`: (optional) On return, the keychain item reference of the generated public key. Use the SecKeyGetCSSMKey function to obtain the CSSM_KEY. The caller must call CFRelease on this value if it is returned. Pass NULL if a reference to this key is not required.
    ///
    /// Parameter `privateKey`: (optional) On return, the keychain item reference of the generated private key. Use the SecKeyGetCSSMKey function to obtain the CSSM_KEY. The caller must call CFRelease on this value if it is returned. Pass NULL if a reference to this key is not required.
    ///
    /// Returns: A result code. See "Security Error Codes" (SecBase.h).
    ///
    /// This API is deprecated for 10.7. Please use the SecKeyGeneratePair API instead.
    ///
    /// # Safety
    ///
    /// - `public_key` must be a valid pointer or null.
    /// - `private_key` must be a valid pointer or null.
    #[doc(alias = "SecKeyCreatePair")]
    #[cfg(all(feature = "SecBase", feature = "cssmconfig", feature = "cssmtype"))]
    #[deprecated = "CSSM is not supported"]
    #[inline]
    pub unsafe fn create_pair(
        keychain_ref: Option<&SecKeychain>,
        algorithm: CSSM_ALGORITHMS,
        key_size_in_bits: uint32,
        context_handle: CSSM_CC_HANDLE,
        public_key_usage: CSSM_KEYUSE,
        public_key_attr: uint32,
        private_key_usage: CSSM_KEYUSE,
        private_key_attr: uint32,
        initial_access: Option<&SecAccess>,
        public_key: *mut *mut SecKey,
        private_key: *mut *mut SecKey,
    ) -> OSStatus {
        extern "C-unwind" {
            fn SecKeyCreatePair(
                keychain_ref: Option<&SecKeychain>,
                algorithm: CSSM_ALGORITHMS,
                key_size_in_bits: uint32,
                context_handle: CSSM_CC_HANDLE,
                public_key_usage: CSSM_KEYUSE,
                public_key_attr: uint32,
                private_key_usage: CSSM_KEYUSE,
                private_key_attr: uint32,
                initial_access: Option<&SecAccess>,
                public_key: *mut *mut SecKey,
                private_key: *mut *mut SecKey,
            ) -> OSStatus;
        }
        unsafe {
            SecKeyCreatePair(
                keychain_ref,
                algorithm,
                key_size_in_bits,
                context_handle,
                public_key_usage,
                public_key_attr,
                private_key_usage,
                private_key_attr,
                initial_access,
                public_key,
                private_key,
            )
        }
    }

    /// Creates a symmetric key and optionally stores it in a specified keychain.
    ///
    /// Parameter `keychainRef`: (optional) A reference to the keychain in which to store the generated key. Specify NULL to generate a transient key.
    ///
    /// Parameter `algorithm`: An algorithm for the symmetric key. This parameter is ignored if a valid (non-zero) contextHandle is supplied.
    ///
    /// Parameter `keySizeInBits`: A key size for the key pair. This parameter is ignored if a valid (non-zero) contextHandle is supplied.
    ///
    /// Parameter `contextHandle`: (optional) A CSSM_CC_HANDLE, or 0. If this argument is supplied, the algorithm and keySizeInBits parameters are ignored. If extra parameters are needed to generate a key (some algorithms require this), you should create a context using CSSM_CSP_CreateKeyGenContext, using the CSPHandle obtained by calling SecKeychainGetCSPHandle. Then use CSSM_UpdateContextAttributes to add parameters, and dispose of the context using CSSM_DeleteContext after calling this function.
    ///
    /// Parameter `keyUsage`: A bit mask indicating all permitted uses for the new key. CSSM_KEYUSE bit mask values are defined in cssmtype.h.
    ///
    /// Parameter `keyAttr`: A bit mask defining attribute values for the new key. The bit mask values are equivalent to a CSSM_KEYATTR_FLAGS and are defined in cssmtype.h.
    ///
    /// Parameter `initialAccess`: (optional) A SecAccess object that determines the initial access rights for the key. This parameter is ignored if the keychainRef is NULL.
    ///
    /// Parameter `keyRef`: On return, a reference to the generated key. Use the SecKeyGetCSSMKey function to obtain the CSSM_KEY. The caller must call CFRelease on this value if it is returned.
    ///
    /// Returns: A result code.  See "Security Error Codes" (SecBase.h).
    ///
    /// This API is deprecated for 10.7.  Please use the SecKeyGenerateSymmetric API instead.
    ///
    /// # Safety
    ///
    /// `key_ref` must be a valid pointer or null.
    #[doc(alias = "SecKeyGenerate")]
    #[cfg(all(feature = "SecBase", feature = "cssmconfig", feature = "cssmtype"))]
    #[deprecated = "CSSM is not supported"]
    #[inline]
    pub unsafe fn generate(
        keychain_ref: Option<&SecKeychain>,
        algorithm: CSSM_ALGORITHMS,
        key_size_in_bits: uint32,
        context_handle: CSSM_CC_HANDLE,
        key_usage: CSSM_KEYUSE,
        key_attr: uint32,
        initial_access: Option<&SecAccess>,
        key_ref: *mut *mut SecKey,
    ) -> OSStatus {
        extern "C-unwind" {
            fn SecKeyGenerate(
                keychain_ref: Option<&SecKeychain>,
                algorithm: CSSM_ALGORITHMS,
                key_size_in_bits: uint32,
                context_handle: CSSM_CC_HANDLE,
                key_usage: CSSM_KEYUSE,
                key_attr: uint32,
                initial_access: Option<&SecAccess>,
                key_ref: *mut *mut SecKey,
            ) -> OSStatus;
        }
        unsafe {
            SecKeyGenerate(
                keychain_ref,
                algorithm,
                key_size_in_bits,
                context_handle,
                key_usage,
                key_attr,
                initial_access,
                key_ref,
            )
        }
    }

    /// Returns a pointer to the CSSM_KEY for the given key item reference.
    ///
    /// Parameter `key`: A keychain key item reference. The key item must be of class type kSecPublicKeyItemClass, kSecPrivateKeyItemClass, or kSecSymmetricKeyItemClass.
    ///
    /// Parameter `cssmKey`: On return, a pointer to a CSSM_KEY structure for the given key. This pointer remains valid until the key reference is released. The caller should not attempt to modify or free this data.
    ///
    /// Returns: A result code. See "Security Error Codes" (SecBase.h).
    ///
    /// The CSSM_KEY is valid until the key item reference is released. This API is deprecated in 10.7. Its use should no longer be needed.
    ///
    /// # Safety
    ///
    /// `cssm_key` must be a valid pointer.
    #[doc(alias = "SecKeyGetCSSMKey")]
    #[cfg(all(
        feature = "SecAsn1Types",
        feature = "SecBase",
        feature = "cssmconfig",
        feature = "cssmtype"
    ))]
    #[deprecated]
    #[inline]
    pub unsafe fn cssm_key(&self, cssm_key: NonNull<*const CSSM_KEY>) -> OSStatus {
        extern "C-unwind" {
            fn SecKeyGetCSSMKey(key: &SecKey, cssm_key: NonNull<*const CSSM_KEY>) -> OSStatus;
        }
        unsafe { SecKeyGetCSSMKey(self, cssm_key) }
    }

    /// Returns the CSSM_CSP_HANDLE for the given key reference. The handle is valid until the key reference is released.
    ///
    /// Parameter `keyRef`: A key reference.
    ///
    /// Parameter `cspHandle`: On return, the CSSM_CSP_HANDLE for the given keychain.
    ///
    /// Returns: A result code. See "Security Error Codes" (SecBase.h).
    ///
    /// This API is deprecated in 10.7. Its use should no longer be needed.
    ///
    /// # Safety
    ///
    /// `csp_handle` must be a valid pointer.
    #[doc(alias = "SecKeyGetCSPHandle")]
    #[cfg(all(feature = "SecBase", feature = "cssmconfig", feature = "cssmtype"))]
    #[deprecated]
    #[inline]
    pub unsafe fn csp_handle(&self, csp_handle: NonNull<CSSM_CSP_HANDLE>) -> OSStatus {
        extern "C-unwind" {
            fn SecKeyGetCSPHandle(
                key_ref: &SecKey,
                csp_handle: NonNull<CSSM_CSP_HANDLE>,
            ) -> OSStatus;
        }
        unsafe { SecKeyGetCSPHandle(self, csp_handle) }
    }

    /// For a given key, return a pointer to a CSSM_ACCESS_CREDENTIALS structure which will allow the key to be used.
    ///
    /// Parameter `keyRef`: The key for which a credential is requested.
    ///
    /// Parameter `operation`: The type of operation to be performed with this key. See "Authorization tag type" for defined operations (cssmtype.h).
    ///
    /// Parameter `credentialType`: The type of credential requested.
    ///
    /// Parameter `outCredentials`: On return, a pointer to a CSSM_ACCESS_CREDENTIALS structure. This pointer remains valid until the key reference is released. The caller should not attempt to modify or free this data.
    ///
    /// Returns: A result code. See "Security Error Codes" (SecBase.h).
    ///
    /// # Safety
    ///
    /// `out_credentials` must be a valid pointer.
    #[doc(alias = "SecKeyGetCredentials")]
    #[cfg(all(
        feature = "SecAsn1Types",
        feature = "SecBase",
        feature = "cssmconfig",
        feature = "cssmtype"
    ))]
    #[deprecated]
    #[inline]
    pub unsafe fn credentials(
        &self,
        operation: CSSM_ACL_AUTHORIZATION_TAG,
        credential_type: SecCredentialType,
        out_credentials: NonNull<*const CSSM_ACCESS_CREDENTIALS>,
    ) -> OSStatus {
        extern "C-unwind" {
            fn SecKeyGetCredentials(
                key_ref: &SecKey,
                operation: CSSM_ACL_AUTHORIZATION_TAG,
                credential_type: SecCredentialType,
                out_credentials: NonNull<*const CSSM_ACCESS_CREDENTIALS>,
            ) -> OSStatus;
        }
        unsafe { SecKeyGetCredentials(self, operation, credential_type, out_credentials) }
    }

    /// Generates a random symmetric key with the specified length
    /// and algorithm type.
    ///
    ///
    /// Parameter `parameters`: A dictionary containing one or more key-value pairs.
    /// See the discussion sections below for a complete overview of options.
    ///
    /// Parameter `error`: An optional pointer to a CFErrorRef. This value is set
    /// if an error occurred. If not NULL, the caller is responsible for
    /// releasing the CFErrorRef.
    ///
    /// Returns: On return, a SecKeyRef reference to the symmetric key, or
    /// NULL if the key could not be created.
    ///
    ///
    /// In order to generate a symmetric key, the parameters dictionary
    /// must at least contain the following keys:
    ///
    /// kSecAttrKeyType with a value of kSecAttrKeyTypeAES or any other
    /// kSecAttrKeyType defined in SecItem.h
    /// kSecAttrKeySizeInBits with a value being a CFNumberRef containing
    /// the requested key size in bits.  Example sizes for AES keys are:
    /// 128, 192, 256, 512.
    ///
    /// To store the generated symmetric key in a keychain, set these keys:
    /// kSecUseKeychain (value is a SecKeychainRef)
    /// kSecAttrLabel (a user-visible label whose value is a CFStringRef,
    /// e.g. "My App's Encryption Key")
    /// kSecAttrApplicationLabel (a label defined by your application, whose
    /// value is a CFDataRef and which can be used to find this key in a
    /// subsequent call to SecItemCopyMatching, e.g. "ID-1234567890-9876-0151")
    ///
    /// To specify the generated key's access control settings, set this key:
    /// kSecAttrAccess (value is a SecAccessRef)
    ///
    /// The keys below may be optionally set in the parameters dictionary
    /// (with a CFBooleanRef value) to override the default usage values:
    ///
    /// kSecAttrCanEncrypt (defaults to true if not explicitly specified)
    /// kSecAttrCanDecrypt (defaults to true if not explicitly specified)
    /// kSecAttrCanWrap (defaults to true if not explicitly specified)
    /// kSecAttrCanUnwrap (defaults to true if not explicitly specified)
    ///
    /// # Safety
    ///
    /// - `parameters` generics must be of the correct type.
    /// - `error` must be a valid pointer or null.
    #[doc(alias = "SecKeyGenerateSymmetric")]
    #[cfg(feature = "SecBase")]
    #[deprecated = "No longer supported"]
    #[inline]
    pub unsafe fn generate_symmetric(
        parameters: &CFDictionary,
        error: *mut *mut CFError,
    ) -> Option<CFRetained<SecKey>> {
        extern "C-unwind" {
            fn SecKeyGenerateSymmetric(
                parameters: &CFDictionary,
                error: *mut *mut CFError,
            ) -> Option<NonNull<SecKey>>;
        }
        let ret = unsafe { SecKeyGenerateSymmetric(parameters, error) };
        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
    }

    /// Creates a symmetric key with the given data and sets the
    /// algorithm type specified.
    ///
    ///
    /// Parameter `parameters`: A dictionary containing one or more key-value pairs.
    /// See the discussion sections below for a complete overview of options.
    ///
    /// Returns: On return, a SecKeyRef reference to the symmetric key.
    ///
    ///
    /// In order to generate a symmetric key the parameters dictionary must
    /// at least contain the following keys:
    ///
    /// kSecAttrKeyType with a value of kSecAttrKeyTypeAES or any other
    /// kSecAttrKeyType defined in SecItem.h
    ///
    /// The keys below may be optionally set in the parameters dictionary
    /// (with a CFBooleanRef value) to override the default usage values:
    ///
    /// kSecAttrCanEncrypt (defaults to true if not explicitly specified)
    /// kSecAttrCanDecrypt (defaults to true if not explicitly specified)
    /// kSecAttrCanWrap (defaults to true if not explicitly specified)
    /// kSecAttrCanUnwrap (defaults to true if not explicitly specified)
    ///
    /// # Safety
    ///
    /// - `parameters` generics must be of the correct type.
    /// - `error` must be a valid pointer or null.
    #[doc(alias = "SecKeyCreateFromData")]
    #[cfg(feature = "SecBase")]
    #[deprecated = "No longer supported"]
    #[inline]
    pub unsafe fn from_data(
        parameters: &CFDictionary,
        key_data: &CFData,
        error: *mut *mut CFError,
    ) -> Option<CFRetained<SecKey>> {
        extern "C-unwind" {
            fn SecKeyCreateFromData(
                parameters: &CFDictionary,
                key_data: &CFData,
                error: *mut *mut CFError,
            ) -> Option<NonNull<SecKey>>;
        }
        let ret = unsafe { SecKeyCreateFromData(parameters, key_data, error) };
        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
    }
}

/// Delivers the result from an asynchronous key pair generation.
///
/// Parameter `publicKey`: - the public key generated.   You must retain publicKey if you wish to use it after your block returns.
///
/// Parameter `privateKey`: - the private key generated.  You must retain publicKey if you wish to use it after your block returns.
///
/// Parameter `error`: - Any errors returned.   You must retain error if you wish to use it after your block returns.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/security/seckeygeneratepairblock?language=objc)
#[cfg(all(feature = "SecBase", feature = "block2"))]
pub type SecKeyGeneratePairBlock =
    *mut block2::DynBlock<dyn Fn(NonNull<SecKey>, NonNull<SecKey>, NonNull<CFError>)>;

#[cfg(feature = "SecBase")]
impl SecKey {
    /// Derives a symmetric key from a password.
    ///
    ///
    /// Parameter `password`: The password from which the keyis to be derived.
    ///
    /// Parameter `parameters`: A dictionary containing one or more key-value pairs.
    ///
    /// Parameter `error`: If the call fails this will contain the error code.
    ///
    ///
    /// In order to derive a key the parameters dictionary must contain at least contain the following keys:
    /// kSecAttrSalt - a CFData for the salt value for mixing in the pseudo-random rounds.
    /// kSecAttrPRF - the algorithm to use for the pseudo-random-function.
    /// If 0, this defaults to kSecAttrPRFHmacAlgSHA1. Possible values are:
    ///
    /// kSecAttrPRFHmacAlgSHA1
    /// kSecAttrPRFHmacAlgSHA224
    /// kSecAttrPRFHmacAlgSHA256
    /// kSecAttrPRFHmacAlgSHA384
    /// kSecAttrPRFHmacAlgSHA512
    ///
    /// kSecAttrRounds - the number of rounds to call the pseudo random function.
    /// If 0, a count will be computed to average 1/10 of a second.
    /// kSecAttrKeySizeInBits with a value being a CFNumberRef
    /// containing the requested key size in bits.  Example sizes for RSA keys are:
    /// 512, 768, 1024, 2048.
    ///
    ///
    /// Returns: On success a SecKeyRef is returned.  On failure this result is NULL and the
    /// error parameter contains the reason.
    ///
    /// # Safety
    ///
    /// - `parameters` generics must be of the correct type.
    /// - `error` must be a valid pointer or null.
    #[doc(alias = "SecKeyDeriveFromPassword")]
    #[cfg(feature = "SecBase")]
    #[deprecated = "No longer supported"]
    #[inline]
    pub unsafe fn derive_from_password(
        password: &CFString,
        parameters: &CFDictionary,
        error: *mut *mut CFError,
    ) -> Option<CFRetained<SecKey>> {
        extern "C-unwind" {
            fn SecKeyDeriveFromPassword(
                password: &CFString,
                parameters: &CFDictionary,
                error: *mut *mut CFError,
            ) -> Option<NonNull<SecKey>>;
        }
        let ret = unsafe { SecKeyDeriveFromPassword(password, parameters, error) };
        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
    }

    /// Wraps a symmetric key with a symmetric key.
    ///
    ///
    /// Parameter `keyToWrap`: The key which is to be wrapped.
    ///
    /// Parameter `wrappingKey`: The key wrapping key.
    ///
    /// Parameter `parameters`: The parameter list to use for wrapping the key.
    ///
    /// Parameter `error`: If the call fails this will contain the error code.
    ///
    ///
    /// Returns: On success a CFDataRef is returned.  On failure this result is NULL and the
    /// error parameter contains the reason.
    ///
    ///
    /// In order to wrap a key the parameters dictionary may contain the following key:
    /// kSecSalt - a CFData for the salt value for the encrypt.
    ///
    /// # Safety
    ///
    /// - `parameters` generics must be of the correct type.
    /// - `error` must be a valid pointer or null.
    #[doc(alias = "SecKeyWrapSymmetric")]
    #[cfg(feature = "SecBase")]
    #[deprecated = "No longer supported"]
    #[inline]
    pub unsafe fn wrap_symmetric(
        &self,
        wrapping_key: &SecKey,
        parameters: &CFDictionary,
        error: *mut *mut CFError,
    ) -> Option<CFRetained<CFData>> {
        extern "C-unwind" {
            fn SecKeyWrapSymmetric(
                key_to_wrap: &SecKey,
                wrapping_key: &SecKey,
                parameters: &CFDictionary,
                error: *mut *mut CFError,
            ) -> Option<NonNull<CFData>>;
        }
        let ret = unsafe { SecKeyWrapSymmetric(self, wrapping_key, parameters, error) };
        ret.map(|ret| unsafe { CFRetained::retain(ret) })
    }

    /// Unwrap a wrapped symmetric key.
    ///
    ///
    /// Parameter `keyToUnwrap`: The wrapped key to unwrap.
    ///
    /// Parameter `unwrappingKey`: The key unwrapping key.
    ///
    /// Parameter `parameters`: The parameter list to use for unwrapping the key.
    ///
    /// Parameter `error`: If the call fails this will contain the error code.
    ///
    ///
    /// Returns: On success a SecKeyRef is returned.  On failure this result is NULL and the
    /// error parameter contains the reason.
    ///
    ///
    /// In order to unwrap a key the parameters dictionary may contain the following key:
    /// kSecSalt - a CFData for the salt value for the decrypt.
    ///
    /// # Safety
    ///
    /// - `key_to_unwrap` must be a valid pointer.
    /// - `parameters` generics must be of the correct type.
    /// - `error` must be a valid pointer or null.
    #[doc(alias = "SecKeyUnwrapSymmetric")]
    #[cfg(feature = "SecBase")]
    #[deprecated = "No longer supported"]
    #[inline]
    pub unsafe fn unwrap_symmetric(
        key_to_unwrap: NonNull<*const CFData>,
        unwrapping_key: &SecKey,
        parameters: &CFDictionary,
        error: *mut *mut CFError,
    ) -> Option<CFRetained<SecKey>> {
        extern "C-unwind" {
            fn SecKeyUnwrapSymmetric(
                key_to_unwrap: NonNull<*const CFData>,
                unwrapping_key: &SecKey,
                parameters: &CFDictionary,
                error: *mut *mut CFError,
            ) -> Option<NonNull<SecKey>>;
        }
        let ret =
            unsafe { SecKeyUnwrapSymmetric(key_to_unwrap, unwrapping_key, parameters, error) };
        ret.map(|ret| unsafe { CFRetained::retain(ret) })
    }

    /// Generate a private/public keypair.
    ///
    /// Parameter `parameters`: A dictionary containing one or more key-value pairs.
    /// See the discussion sections below for a complete overview of options.
    ///
    /// Parameter `publicKey`: On return, a SecKeyRef reference to the public key.
    ///
    /// Parameter `privateKey`: On return, a SecKeyRef reference to the private key.
    ///
    /// Returns: A result code. See "Security Error Codes" (SecBase.h).
    ///
    ///
    /// In order to generate a keypair the parameters dictionary must
    /// at least contain the following keys:
    ///
    /// kSecAttrKeyType with a value of kSecAttrKeyTypeRSA or any other
    /// kSecAttrKeyType defined in SecItem.h
    /// kSecAttrKeySizeInBits with a value being a CFNumberRef containing
    /// the requested key size in bits.  Example sizes for RSA keys are:
    /// 512, 768, 1024, 2048.
    ///
    /// The values below may be set either in the top-level dictionary or in a
    /// dictionary that is the value of the kSecPrivateKeyAttrs or
    /// kSecPublicKeyAttrs key in the top-level dictionary.  Setting these
    /// attributes explicitly will override the defaults below.  See SecItem.h
    /// for detailed information on these attributes including the types of
    /// the values.
    ///
    /// kSecAttrLabel default NULL
    /// kSecUseKeychain default NULL, which specifies the default keychain
    /// kSecAttrIsPermanent default false
    /// if this key is present and has a Boolean value of true, the key or
    /// key pair will be added to the keychain.
    /// kSecAttrTokenID default NULL
    /// The CFStringRef ID of the token to generate the key or keypair on. This
    /// attribute can contain CFStringRef and can be present only in the top-level
    /// parameters dictionary.
    /// kSecAttrApplicationTag default NULL
    /// kSecAttrEffectiveKeySize default NULL same as kSecAttrKeySizeInBits
    /// kSecAttrCanEncrypt default false for private keys, true for public keys
    /// kSecAttrCanDecrypt default true for private keys, false for public keys
    /// kSecAttrCanDerive default true
    /// kSecAttrCanSign default true for private keys, false for public keys
    /// kSecAttrCanVerify default false for private keys, true for public keys
    /// kSecAttrCanWrap default false for private keys, true for public keys
    /// kSecAttrCanUnwrap default true for private keys, false for public keys
    ///
    /// NOTE: The function always saves keys in the keychain on macOS and as such attribute
    /// kSecAttrIsPermanent is ignored. The function respects attribute kSecAttrIsPermanent
    /// on iOS, tvOS and watchOS.
    /// It is recommended to use SecKeyCreateRandomKey() which respects kSecAttrIsPermanent
    /// on all platforms.
    ///
    /// # Safety
    ///
    /// - `parameters` generics must be of the correct type.
    /// - `public_key` must be a valid pointer or null.
    /// - `private_key` must be a valid pointer or null.
    #[doc(alias = "SecKeyGeneratePair")]
    #[cfg(feature = "SecBase")]
    #[deprecated = "Use SecKeyCreateRandomKey"]
    #[inline]
    pub unsafe fn generate_pair(
        parameters: &CFDictionary,
        public_key: *mut *mut SecKey,
        private_key: *mut *mut SecKey,
    ) -> OSStatus {
        extern "C-unwind" {
            fn SecKeyGeneratePair(
                parameters: &CFDictionary,
                public_key: *mut *mut SecKey,
                private_key: *mut *mut SecKey,
            ) -> OSStatus;
        }
        unsafe { SecKeyGeneratePair(parameters, public_key, private_key) }
    }

    /// Generates a new public/private key pair.
    ///
    /// Parameter `parameters`: A dictionary containing one or more key-value pairs.
    /// See the discussion sections below for a complete overview of options.
    ///
    /// Parameter `error`: On error, will be populated with an error object describing the failure.
    /// See "Security Error Codes" (SecBase.h).
    ///
    /// Returns: Newly generated private key.  To get associated public key, use SecKeyCopyPublicKey().
    ///
    /// In order to generate a keypair the parameters dictionary must
    /// at least contain the following keys:
    ///
    /// kSecAttrKeyType with a value being kSecAttrKeyTypeRSA or any other
    /// kSecAttrKeyType defined in SecItem.h
    /// kSecAttrKeySizeInBits with a value being a CFNumberRef or CFStringRef
    /// containing the requested key size in bits.  Example sizes for RSA
    /// keys are: 512, 768, 1024, 2048.
    ///
    /// The values below may be set either in the top-level dictionary or in a
    /// dictionary that is the value of the kSecPrivateKeyAttrs or
    /// kSecPublicKeyAttrs key in the top-level dictionary.  Setting these
    /// attributes explicitly will override the defaults below.  See SecItem.h
    /// for detailed information on these attributes including the types of
    /// the values.
    ///
    /// kSecAttrLabel default NULL
    /// kSecAttrIsPermanent if this key is present and has a Boolean value of true,
    /// the key or key pair will be added to the default keychain.
    /// kSecAttrTokenID if this key should be generated on specified token.  This
    /// attribute can contain CFStringRef and can be present only in the top-level
    /// parameters dictionary.
    /// kSecAttrApplicationTag default NULL
    /// kSecAttrEffectiveKeySize default NULL same as kSecAttrKeySizeInBits
    /// kSecAttrCanEncrypt default false for private keys, true for public keys
    /// kSecAttrCanDecrypt default true for private keys, false for public keys
    /// kSecAttrCanDerive default true
    /// kSecAttrCanSign default true for private keys, false for public keys
    /// kSecAttrCanVerify default false for private keys, true for public keys
    /// kSecAttrCanWrap default false for private keys, true for public keys
    /// kSecAttrCanUnwrap default true for private keys, false for public keys
    ///
    /// # Safety
    ///
    /// - `parameters` generics must be of the correct type.
    /// - `error` must be a valid pointer or null.
    #[doc(alias = "SecKeyCreateRandomKey")]
    #[cfg(feature = "SecBase")]
    #[inline]
    pub unsafe fn new_random_key(
        parameters: &CFDictionary,
        error: *mut *mut CFError,
    ) -> Option<CFRetained<SecKey>> {
        extern "C-unwind" {
            fn SecKeyCreateRandomKey(
                parameters: &CFDictionary,
                error: *mut *mut CFError,
            ) -> Option<NonNull<SecKey>>;
        }
        let ret = unsafe { SecKeyCreateRandomKey(parameters, error) };
        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
    }

    /// Create a SecKey from a well-defined external representation.
    ///
    /// Parameter `keyData`: CFData representing the key. The format of the data depends on the type of key being created.
    ///
    /// Parameter `attributes`: Dictionary containing attributes describing the key to be imported. The keys in this dictionary
    /// are kSecAttr* constants from SecItem.h.  Mandatory attributes are:
    /// kSecAttrKeyType
    /// kSecAttrKeyClass
    ///
    /// Parameter `error`: On error, will be populated with an error object describing the failure.
    /// See "Security Error Codes" (SecBase.h).
    ///
    /// Returns: A SecKey object representing the key, or NULL on failure.
    ///
    /// This function does not add keys to any keychain, but the SecKey object it returns can be added
    /// to keychain using the SecItemAdd function.
    /// The requested data format depend on the type of key (kSecAttrKeyType) being created:
    /// kSecAttrKeyTypeRSA               PKCS#1 format, public key can be also in x509 public key format
    /// kSecAttrKeyTypeECSECPrimeRandom  ANSI X9.63 format (04 || X || Y [ || K])
    ///
    /// # Safety
    ///
    /// - `attributes` generics must be of the correct type.
    /// - `error` must be a valid pointer or null.
    #[doc(alias = "SecKeyCreateWithData")]
    #[cfg(feature = "SecBase")]
    #[inline]
    pub unsafe fn with_data(
        key_data: &CFData,
        attributes: &CFDictionary,
        error: *mut *mut CFError,
    ) -> Option<CFRetained<SecKey>> {
        extern "C-unwind" {
            fn SecKeyCreateWithData(
                key_data: &CFData,
                attributes: &CFDictionary,
                error: *mut *mut CFError,
            ) -> Option<NonNull<SecKey>>;
        }
        let ret = unsafe { SecKeyCreateWithData(key_data, attributes, error) };
        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
    }

    /// Returns block length of the key in bytes.
    ///
    /// Parameter `key`: The key for which the block length is requested.
    ///
    /// Returns: The block length of the key in bytes.
    ///
    /// If for example key is an RSA key the value returned by
    /// this function is the size of the modulus.
    #[doc(alias = "SecKeyGetBlockSize")]
    #[cfg(feature = "SecBase")]
    #[inline]
    pub unsafe fn block_size(&self) -> usize {
        extern "C-unwind" {
            fn SecKeyGetBlockSize(key: &SecKey) -> usize;
        }
        unsafe { SecKeyGetBlockSize(self) }
    }

    /// Create an external representation for the given key suitable for the key's type.
    ///
    /// Parameter `key`: The key to be exported.
    ///
    /// Parameter `error`: On error, will be populated with an error object describing the failure.
    /// See "Security Error Codes" (SecBase.h).
    ///
    /// Returns: A CFData representing the key in a format suitable for that key type.
    ///
    /// This function may fail if the key is not exportable (e.g., bound to a smart card or Secure Enclave).
    /// The format in which the key will be exported depends on the type of key:
    /// kSecAttrKeyTypeRSA               PKCS#1 format
    /// kSecAttrKeyTypeECSECPrimeRandom  ANSI X9.63 format (04 || X || Y [ || K])
    ///
    /// # Safety
    ///
    /// `error` must be a valid pointer or null.
    #[doc(alias = "SecKeyCopyExternalRepresentation")]
    #[cfg(feature = "SecBase")]
    #[inline]
    pub unsafe fn external_representation(
        &self,
        error: *mut *mut CFError,
    ) -> Option<CFRetained<CFData>> {
        extern "C-unwind" {
            fn SecKeyCopyExternalRepresentation(
                key: &SecKey,
                error: *mut *mut CFError,
            ) -> Option<NonNull<CFData>>;
        }
        let ret = unsafe { SecKeyCopyExternalRepresentation(self, error) };
        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
    }

    /// Retrieve keychain attributes of a key.
    ///
    /// Parameter `key`: The key whose attributes are to be retrieved.
    ///
    /// Returns: Dictionary containing attributes of the key. The keys that populate this dictionary are defined
    /// and discussed in SecItem.h.
    ///
    /// The attributes provided by this function are:
    /// kSecAttrCanEncrypt
    /// kSecAttrCanDecrypt
    /// kSecAttrCanDerive
    /// kSecAttrCanSign
    /// kSecAttrCanVerify
    /// kSecAttrKeyClass
    /// kSecAttrKeyType
    /// kSecAttrKeySizeInBits
    /// kSecAttrTokenID
    /// kSecAttrApplicationLabel
    /// The set of values is not fixed. Future versions may return more values in this dictionary.
    #[doc(alias = "SecKeyCopyAttributes")]
    #[cfg(feature = "SecBase")]
    #[inline]
    pub unsafe fn attributes(&self) -> Option<CFRetained<CFDictionary>> {
        extern "C-unwind" {
            fn SecKeyCopyAttributes(key: &SecKey) -> Option<NonNull<CFDictionary>>;
        }
        let ret = unsafe { SecKeyCopyAttributes(self) };
        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
    }

    /// Retrieve the public key from a key pair or private key.
    ///
    /// Parameter `key`: The key from which to retrieve a public key.
    ///
    /// Returns: The public key or NULL if public key is not available for specified key.
    ///
    /// Fails if key does not contain a public key or no public key can be computed from it.
    #[doc(alias = "SecKeyCopyPublicKey")]
    #[cfg(feature = "SecBase")]
    #[inline]
    pub unsafe fn public_key(&self) -> Option<CFRetained<SecKey>> {
        extern "C-unwind" {
            fn SecKeyCopyPublicKey(key: &SecKey) -> Option<NonNull<SecKey>>;
        }
        let ret = unsafe { SecKeyCopyPublicKey(self) };
        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
    }
}

/// Available algorithms for performing cryptographic operations with SecKey object.  String representation
/// of constant can be used for logging or debugging purposes, because they contain human readable names of the algorithm.
///
///
/// Raw RSA sign/verify operation, size of input data must be the same as value returned by SecKeyGetBlockSize().
///
///
/// RSA sign/verify operation, assumes that input data is digest and OID and digest algorithm as specified in PKCS# v1.5.
/// This algorithm is typically not used directly, instead use algorithm with specified digest, like
/// kSecKeyAlgorithmRSASignatureDigestPKCS1v15SHA256.
///
///
/// RSA signature with PKCS#1 padding, input data must be SHA-1 generated digest.
///
///
/// RSA signature with PKCS#1 padding, input data must be SHA-224 generated digest.
///
///
/// RSA signature with PKCS#1 padding, input data must be SHA-256 generated digest.
///
///
/// RSA signature with PKCS#1 padding, input data must be SHA-384 generated digest.
///
///
/// RSA signature with PKCS#1 padding, input data must be SHA-512 generated digest.
///
///
/// RSA signature with PKCS#1 padding, SHA-1 digest is generated by called function automatically from input data of any size.
///
///
/// RSA signature with PKCS#1 padding, SHA-224 digest is generated by called function automatically from input data of any size.
///
///
/// RSA signature with PKCS#1 padding, SHA-256 digest is generated by called function automatically from input data of any size.
///
///
/// RSA signature with PKCS#1 padding, SHA-384 digest is generated by called function automatically from input data of any size.
///
///
/// RSA signature with PKCS#1 padding, SHA-512 digest is generated by called function automatically from input data of any size.
///
///
/// RSA signature with RSASSA-PSS padding according to PKCS#1 v2.1, input data must be SHA-1 generated digest.
/// PSS padding is calculated using MGF1 with SHA1 and saltLength parameter is set to 20 (SHA-1 output size).
///
///
/// RSA signature with RSASSA-PSS padding according to PKCS#1 v2.1, input data must be SHA-224 generated digest.
/// PSS padding is calculated using MGF1 with SHA224 and saltLength parameter is set to 28 (SHA-224 output size).
///
///
/// RSA signature with RSASSA-PSS padding according to PKCS#1 v2.1, input data must be SHA-256 generated digest.
/// PSS padding is calculated using MGF1 with SHA256 and saltLength parameter is set to 32 (SHA-256 output size).
///
///
/// RSA signature with RSASSA-PSS padding according to PKCS#1 v2.1, input data must be SHA-384 generated digest.
/// PSS padding is calculated using MGF1 with SHA384 and saltLength parameter is set to 48 (SHA-384 output size).
///
///
/// RSA signature with RSASSA-PSS padding according to PKCS#1 v2.1, input data must be SHA-512 generated digest.
/// PSS padding is calculated using MGF1 with SHA512 and saltLength parameter is set to 64 (SHA-512 output size).
///
///
/// RSA signature with RSASSA-PSS padding according to PKCS#1 v2.1, SHA-1 digest is generated by called function automatically from input data of any size.
/// PSS padding is calculated using MGF1 with SHA1 and saltLength parameter is set to 20 (SHA-1 output size).
///
///
/// RSA signature with RSASSA-PSS padding according to PKCS#1 v2.1, SHA-224 digest is generated by called function automatically from input data of any size.
/// PSS padding is calculated using MGF1 with SHA224 and saltLength parameter is set to 28 (SHA-224 output size).
///
///
/// RSA signature with RSASSA-PSS padding according to PKCS#1 v2.1, SHA-256 digest is generated by called function automatically from input data of any size.
/// PSS padding is calculated using MGF1 with SHA256 and saltLength parameter is set to 32 (SHA-256 output size).
///
///
/// RSA signature with RSASSA-PSS padding according to PKCS#1 v2.1, SHA-384 digest is generated by called function automatically from input data of any size.
/// PSS padding is calculated using MGF1 with SHA384 and saltLength parameter is set to 48 (SHA-384 output size).
///
///
/// RSA signature with RSASSA-PSS padding according to PKCS#1 v2.1, SHA-512 digest is generated by called function automatically from input data of any size.
/// PSS padding is calculated using MGF1 with SHA512 and saltLength parameter is set to 64 (SHA-512 output size).
///
///
/// ECDSA algorithm, signature is in DER x9.62 encoding, input data must be message digest generated by some hash functions.
///
///
/// ECDSA algorithm, signature is in DER x9.62 encoding, input data must be message digest created by SHA1 algorithm.
///
///
/// ECDSA algorithm, signature is in DER x9.62 encoding, input data must be message digest created by SHA224 algorithm.
///
///
/// ECDSA algorithm, signature is in DER x9.62 encoding, input data must be message digest created by SHA256 algorithm.
///
///
/// ECDSA algorithm, signature is in DER x9.62 encoding, input data must be message digest created by SHA384 algorithm.
///
///
/// ECDSA algorithm, signature is in DER x9.62 encoding, input data must be message digest created by SHA512 algorithm.
///
///
/// ECDSA algorithm, signature is in DER x9.62 encoding, SHA-1 digest is generated by called function automatically from input data of any size.
///
///
/// ECDSA algorithm, signature is in DER x9.62 encoding, SHA-224 digest is generated by called function automatically from input data of any size.
///
///
/// ECDSA algorithm, signature is in DER x9.62 encoding, SHA-256 digest is generated by called function automatically from input data of any size.
///
///
/// ECDSA algorithm, signature is in DER x9.62 encoding, SHA-384 digest is generated by called function automatically from input data of any size.
///
///
/// ECDSA algorithm, signature is in DER x9.62 encoding, SHA-512 digest is generated by called function automatically from input data of any size.
///
///
/// ECDSA algorithm, signature is concatenated r and s, big endian, input data must be message digest generated by some hash functions.
///
///
/// ECDSA algorithm, signature is concatenated r and s, big endian, input data must be message digest created by SHA1 algorithm.
///
///
/// ECDSA algorithm, signature is concatenated r and s, big endian, input data must be message digest created by SHA224 algorithm.
///
///
/// ECDSA algorithm, signature is concatenated r and s, big endian, input data must be message digest created by SHA256 algorithm.
///
///
/// ECDSA algorithm, signature is concatenated r and s, big endian, input data must be message digest created by SHA384 algorithm.
///
///
/// ECDSA algorithm, signature is concatenated r and s, big endian, input data must be message digest created by SHA512 algorithm.
///
///
/// ECDSA algorithm, signature is concatenated r and s, big endian, SHA-1 digest is generated by called function automatically from input data of any size.
///
///
/// ECDSA algorithm, signature is concatenated r and s, big endian, SHA-224 digest is generated by called function automatically from input data of any size.
///
///
/// ECDSA algorithm, signature is concatenated r and s, big endian, SHA-256 digest is generated by called function automatically from input data of any size.
///
///
/// ECDSA algorithm, signature is concatenated r and s, big endian, SHA-384 digest is generated by called function automatically from input data of any size.
///
///
/// ECDSA algorithm, signature is concatenated r and s, big endian, SHA-512 digest is generated by called function automatically from input data of any size.
///
///
/// ECDSA algorithm, signature is concatenated r and s, big endian, input data must be message digest generated by some hash function.
/// This is deprecated algorithm, replaced by kSecKeyAlgorithmECDSASignatureDigestRFC4754
///
///
/// Raw RSA encryption or decryption, size of data must match RSA key modulus size.  Note that direct
/// use of this algorithm without padding is cryptographically very weak, it is important to always introduce
/// some kind of padding.  Input data size must be less or equal to the key block size and returned block has always
/// the same size as block size, as returned by SecKeyGetBlockSize().
///
///
/// RSA encryption or decryption, data is padded using PKCS#1 padding scheme.  This algorithm should be used only for
/// backward compatibility with existing protocols and data. New implementations should choose cryptographically
/// stronger algorithm instead (see kSecKeyAlgorithmRSAEncryptionOAEP).  Input data must be at most
/// "key block size - 11" bytes long and returned block has always the same size as block size, as returned
/// by SecKeyGetBlockSize().
///
///
/// RSA encryption or decryption, data is padded using OAEP padding scheme internally using SHA1. Input data must be at most
/// "key block size - 42" bytes long and returned block has always the same size as block size, as returned
/// by SecKeyGetBlockSize().  Use kSecKeyAlgorithmRSAEncryptionOAEPSHA1AESGCM to be able to encrypt and decrypt arbitrary long data.
///
///
/// RSA encryption or decryption, data is padded using OAEP padding scheme internally using SHA224. Input data must be at most
/// "key block size - 58" bytes long and returned block has always the same size as block size, as returned
/// by SecKeyGetBlockSize().  Use kSecKeyAlgorithmRSAEncryptionOAEPSHA224AESGCM to be able to encrypt and decrypt arbitrary long data.
///
///
/// RSA encryption or decryption, data is padded using OAEP padding scheme internally using SHA256. Input data must be at most
/// "key block size - 66" bytes long and returned block has always the same size as block size, as returned
/// by SecKeyGetBlockSize().  Use kSecKeyAlgorithmRSAEncryptionOAEPSHA256AESGCM to be able to encrypt and decrypt arbitrary long data.
///
///
/// RSA encryption or decryption, data is padded using OAEP padding scheme internally using SHA384. Input data must be at most
/// "key block size - 98" bytes long and returned block has always the same size as block size, as returned
/// by SecKeyGetBlockSize().  Use kSecKeyAlgorithmRSAEncryptionOAEPSHA384AESGCM to be able to encrypt and decrypt arbitrary long data.
///
///
/// RSA encryption or decryption, data is padded using OAEP padding scheme internally using SHA512. Input data must be at most
/// "key block size - 130" bytes long and returned block has always the same size as block size, as returned
/// by SecKeyGetBlockSize().  Use kSecKeyAlgorithmRSAEncryptionOAEPSHA512AESGCM to be able to encrypt and decrypt arbitrary long data.
///
///
/// Randomly generated AES session key is encrypted by RSA with OAEP padding.  User data are encrypted using session key in GCM
/// mode with all-zero 16 bytes long IV (initialization vector).  Finally 16 byte AES-GCM tag is appended to ciphertext.
/// 256bit AES key is used if RSA key is 4096bit or bigger, otherwise 128bit AES key is used.  Raw public key data is used
/// as authentication data for AES-GCM encryption.
///
///
/// Randomly generated AES session key is encrypted by RSA with OAEP padding.  User data are encrypted using session key in GCM
/// mode with all-zero 16 bytes long IV (initialization vector).  Finally 16 byte AES-GCM tag is appended to ciphertext.
/// 256bit AES key is used if RSA key is 4096bit or bigger, otherwise 128bit AES key is used.  Raw public key data is used
/// as authentication data for AES-GCM encryption.
///
///
/// Randomly generated AES session key is encrypted by RSA with OAEP padding.  User data are encrypted using session key in GCM
/// mode with all-zero 16 bytes long IV (initialization vector).  Finally 16 byte AES-GCM tag is appended to ciphertext.
/// 256bit AES key is used if RSA key is 4096bit or bigger, otherwise 128bit AES key is used.  Raw public key data is used
/// as authentication data for AES-GCM encryption.
///
///
/// Randomly generated AES session key is encrypted by RSA with OAEP padding.  User data are encrypted using session key in GCM
/// mode with all-zero 16 bytes long IV (initialization vector).  Finally 16 byte AES-GCM tag is appended to ciphertext.
/// 256bit AES key is used if RSA key is 4096bit or bigger, otherwise 128bit AES key is used.  Raw public key data is used
/// as authentication data for AES-GCM encryption.
///
///
/// Randomly generated AES session key is encrypted by RSA with OAEP padding.  User data are encrypted using session key in GCM
/// mode with all-zero 16 bytes long IV (initialization vector).  Finally 16 byte AES-GCM tag is appended to ciphertext.
/// 256bit AES key is used if RSA key is 4096bit or bigger, otherwise 128bit AES key is used.  Raw public key data is used
/// as authentication data for AES-GCM encryption.
///
///
/// Legacy ECIES encryption or decryption, use kSecKeyAlgorithmECIESEncryptionStandardVariableIVX963SHA256AESGCM in new code.
/// Encryption is done using AES-GCM with key negotiated by kSecKeyAlgorithmECDHKeyExchangeStandardX963SHA1.  AES Key size
/// is 128bit for EC keys
/// <
/// =256bit and 256bit for bigger EC keys. Ephemeral public key data is used as sharedInfo for KDF.
/// AES-GCM uses 16 bytes long TAG and all-zero 16 byte long IV (initialization vector).
///
///
/// Legacy ECIES encryption or decryption, use kSecKeyAlgorithmECIESEncryptionStandardVariableIVX963SHA224AESGCM in new code.
/// Encryption is done using AES-GCM with key negotiated by kSecKeyAlgorithmECDHKeyExchangeStandardX963SHA224.  AES Key size
/// is 128bit for EC keys
/// <
/// =256bit and 256bit for bigger EC keys. Ephemeral public key data is used as sharedInfo for KDF.
/// AES-GCM uses 16 bytes long TAG and all-zero 16 byte long IV (initialization vector).
///
///
/// Legacy ECIES encryption or decryption, use kSecKeyAlgorithmECIESEncryptionStandardVariableIVX963SHA256AESGCM in new code.
/// Encryption is done using AES-GCM with key negotiated by kSecKeyAlgorithmECDHKeyExchangeStandardX963SHA256.  AES Key size
/// is 128bit for EC keys
/// <
/// =256bit and 256bit for bigger EC keys. Ephemeral public key data is used as sharedInfo for KDF.
/// AES-GCM uses 16 bytes long TAG and all-zero 16 byte long IV (initialization vector).
///
///
/// Legacy ECIES encryption or decryption, use kSecKeyAlgorithmECIESEncryptionStandardVariableIVX963SHA384AESGCM in new code.
/// Encryption is done using AES-GCM with key negotiated by kSecKeyAlgorithmECDHKeyExchangeStandardX963SHA384.  AES Key size
/// is 128bit for EC keys
/// <
/// =256bit and 256bit for bigger EC keys. Ephemeral public key data is used as sharedInfo for KDF.
/// AES-GCM uses 16 bytes long TAG and all-zero 16 byte long IV (initialization vector).
///
///
/// Legacy ECIES encryption or decryption, use kSecKeyAlgorithmECIESEncryptionStandardVariableIVX963SHA512AESGCM in new code.
/// Encryption is done using AES-GCM with key negotiated by kSecKeyAlgorithmECDHKeyExchangeStandardX963SHA512.  AES Key size
/// is 128bit for EC keys
/// <
/// =256bit and 256bit for bigger EC keys. Ephemeral public key data is used as sharedInfo for KDF.
/// AES-GCM uses 16 bytes long TAG and all-zero 16 byte long IV (initialization vector).
///
///
/// Legacy ECIES encryption or decryption, use kSecKeyAlgorithmECIESEncryptionCofactorVariableIVX963SHA256AESGCM in new code.
/// Encryption is done using AES-GCM with key negotiated by kSecKeyAlgorithmECDHKeyExchangeCofactorX963SHA1.  AES Key size
/// is 128bit for EC keys
/// <
/// =256bit and 256bit for bigger EC keys. Ephemeral public key data is used as sharedInfo for KDF.
/// AES-GCM uses 16 bytes long TAG and all-zero 16 byte long IV (initialization vector).
///
///
/// Legacy ECIES encryption or decryption, use kSecKeyAlgorithmECIESEncryptionCofactorVariableIVX963SHA224AESGCM in new code.
/// Encryption is done using AES-GCM with key negotiated by kSecKeyAlgorithmECDHKeyExchangeCofactorX963SHA224.  AES Key size
/// is 128bit for EC keys
/// <
/// =256bit and 256bit for bigger EC keys. Ephemeral public key data is used as sharedInfo for KDF.
/// AES-GCM uses 16 bytes long TAG and all-zero 16 byte long IV (initialization vector).
///
///
/// Legacy ECIES encryption or decryption, use kSecKeyAlgorithmECIESEncryptionCofactorVariableIVX963SHA256AESGCM in new code.
/// Encryption is done using AES-GCM with key negotiated by kSecKeyAlgorithmECDHKeyExchangeCofactorX963SHA256.  AES Key size
/// is 128bit for EC keys
/// <
/// =256bit and 256bit for bigger EC keys. Ephemeral public key data is used as sharedInfo for KDF.
/// AES-GCM uses 16 bytes long TAG and all-zero 16 byte long IV (initialization vector).
///
///
/// Legacy ECIES encryption or decryption, use kSecKeyAlgorithmECIESEncryptionCofactorVariableIVX963SHA384AESGCM in new code.
/// Encryption is done using AES-GCM with key negotiated by kSecKeyAlgorithmECDHKeyExchangeCofactorX963SHA384.  AES Key size
/// is 128bit for EC keys
/// <
/// =256bit and 256bit for bigger EC keys. Ephemeral public key data is used as sharedInfo for KDF.
/// AES-GCM uses 16 bytes long TAG and all-zero 16 byte long IV (initialization vector).
///
///
/// Legacy ECIES encryption or decryption, use kSecKeyAlgorithmECIESEncryptionCofactorVariableIVX963SHA512AESGCM in new code.
/// Encryption is done using AES-GCM with key negotiated by kSecKeyAlgorithmECDHKeyExchangeCofactorX963SHA512.  AES Key size
/// is 128bit for EC keys
/// <
/// =256bit and 256bit for bigger EC keys. Ephemeral public key data is used as sharedInfo for KDF.
/// AES-GCM uses 16 bytes long TAG and all-zero 16 byte long IV (initialization vector).
///
///
/// ECIES encryption or decryption.  This algorithm does not limit the size of the message to be encrypted or decrypted.
/// Encryption is done using AES-GCM with key negotiated by kSecKeyAlgorithmECDHKeyExchangeStandardX963SHA224.  AES Key size
/// is 128bit for EC keys
/// <
/// =256bit and 256bit for bigger EC keys. Ephemeral public key data is used as sharedInfo for KDF.
/// AES-GCM uses 16 bytes long TAG, AES key is first half of KDF output and 16 byte long IV (initialization vector) is second half
/// of KDF output.
///
///
/// ECIES encryption or decryption.  This algorithm does not limit the size of the message to be encrypted or decrypted.
/// Encryption is done using AES-GCM with key negotiated by kSecKeyAlgorithmECDHKeyExchangeStandardX963SHA256.  AES Key size
/// is 128bit for EC keys
/// <
/// =256bit and 256bit for bigger EC keys. Ephemeral public key data is used as sharedInfo for KDF.
/// AES-GCM uses 16 bytes long TAG, AES key is first half of KDF output and 16 byte long IV (initialization vector) is second half
/// of KDF output.
///
///
/// ECIES encryption or decryption.  This algorithm does not limit the size of the message to be encrypted or decrypted.
/// Encryption is done using AES-GCM with key negotiated by kSecKeyAlgorithmECDHKeyExchangeStandardX963SHA384.  AES Key size
/// is 128bit for EC keys
/// <
/// =256bit and 256bit for bigger EC keys. Ephemeral public key data is used as sharedInfo for KDF.
/// AES-GCM uses 16 bytes long TAG, AES key is first half of KDF output and 16 byte long IV (initialization vector) is second half
/// of KDF output.
///
///
/// ECIES encryption or decryption.  This algorithm does not limit the size of the message to be encrypted or decrypted.
/// Encryption is done using AES-GCM with key negotiated by kSecKeyAlgorithmECDHKeyExchangeStandardX963SHA512.  AES Key size
/// is 128bit for EC keys
/// <
/// =256bit and 256bit for bigger EC keys. Ephemeral public key data is used as sharedInfo for KDF.
/// AES-GCM uses 16 bytes long TAG, AES key is first half of KDF output and 16 byte long IV (initialization vector) is second half
/// of KDF output.
///
///
/// ECIES encryption or decryption.  This algorithm does not limit the size of the message to be encrypted or decrypted.
/// Encryption is done using AES-GCM with key negotiated by kSecKeyAlgorithmECDHKeyExchangeCofactorX963SHA224.  AES Key size
/// is 128bit for EC keys
/// <
/// =256bit and 256bit for bigger EC keys. Ephemeral public key data is used as sharedInfo for KDF.
/// AES-GCM uses 16 bytes long TAG, AES key is first half of KDF output and 16 byte long IV (initialization vector) is second half
/// of KDF output.
///
///
/// ECIES encryption or decryption.  This algorithm does not limit the size of the message to be encrypted or decrypted.
/// Encryption is done using AES-GCM with key negotiated by kSecKeyAlgorithmECDHKeyExchangeCofactorX963SHA256.  AES Key size
/// is 128bit for EC keys
/// <
/// =256bit and 256bit for bigger EC keys. Ephemeral public key data is used as sharedInfo for KDF.
/// AES-GCM uses 16 bytes long TAG, AES key is first half of KDF output and 16 byte long IV (initialization vector) is second half
/// of KDF output.
///
///
/// ECIES encryption or decryption.  This algorithm does not limit the size of the message to be encrypted or decrypted.
/// Encryption is done using AES-GCM with key negotiated by kSecKeyAlgorithmECDHKeyExchangeCofactorX963SHA384.  AES Key size
/// is 128bit for EC keys
/// <
/// =256bit and 256bit for bigger EC keys. Ephemeral public key data is used as sharedInfo for KDF.
/// AES-GCM uses 16 bytes long TAG, AES key is first half of KDF output and 16 byte long IV (initialization vector) is second half
/// of KDF output.
///
///
/// ECIES encryption or decryption.  This algorithm does not limit the size of the message to be encrypted or decrypted.
/// Encryption is done using AES-GCM with key negotiated by kSecKeyAlgorithmECDHKeyExchangeCofactorX963SHA512.  AES Key size
/// is 128bit for EC keys
/// <
/// =256bit and 256bit for bigger EC keys. Ephemeral public key data is used as sharedInfo for KDF.
/// AES-GCM uses 16 bytes long TAG, AES key is first half of KDF output and 16 byte long IV (initialization vector) is second half
/// of KDF output.
///
///
/// Compute shared secret using ECDH cofactor algorithm, suitable only for kSecAttrKeyTypeECSECPrimeRandom keys.
/// This algorithm does not accept any parameters, length of output raw shared secret is given by the length of the key.
///
///
/// Compute shared secret using ECDH cofactor algorithm, suitable only for kSecAttrKeyTypeECSECPrimeRandom keys
/// and apply ANSI X9.63 KDF with SHA1 as hashing function.  Requires kSecKeyKeyExchangeParameterRequestedSize and allows
/// kSecKeyKeyExchangeParameterSharedInfo parameters to be used.
///
///
/// Compute shared secret using ECDH cofactor algorithm, suitable only for kSecAttrKeyTypeECSECPrimeRandom keys
/// and apply ANSI X9.63 KDF with SHA224 as hashing function.  Requires kSecKeyKeyExchangeParameterRequestedSize and allows
/// kSecKeyKeyExchangeParameterSharedInfo parameters to be used.
///
///
/// Compute shared secret using ECDH cofactor algorithm, suitable only for kSecAttrKeyTypeECSECPrimeRandom keys
/// and apply ANSI X9.63 KDF with SHA256 as hashing function.  Requires kSecKeyKeyExchangeParameterRequestedSize and allows
/// kSecKeyKeyExchangeParameterSharedInfo parameters to be used.
///
///
/// Compute shared secret using ECDH cofactor algorithm, suitable only for kSecAttrKeyTypeECSECPrimeRandom keys
/// and apply ANSI X9.63 KDF with SHA384 as hashing function.  Requires kSecKeyKeyExchangeParameterRequestedSize and allows
/// kSecKeyKeyExchangeParameterSharedInfo parameters to be used.
///
///
/// Compute shared secret using ECDH cofactor algorithm, suitable only for kSecAttrKeyTypeECSECPrimeRandom keys
/// and apply ANSI X9.63 KDF with SHA512 as hashing function.  Requires kSecKeyKeyExchangeParameterRequestedSize and allows
/// kSecKeyKeyExchangeParameterSharedInfo parameters to be used.
///
///
/// Compute shared secret using ECDH algorithm without cofactor, suitable only for kSecAttrKeyTypeECSECPrimeRandom keys.
/// This algorithm does not accept any parameters, length of output raw shared secret is given by the length of the key.
///
///
/// Compute shared secret using ECDH algorithm without cofactor, suitable only for kSecAttrKeyTypeECSECPrimeRandom keys
/// and apply ANSI X9.63 KDF with SHA1 as hashing function.  Requires kSecKeyKeyExchangeParameterRequestedSize and allows
/// kSecKeyKeyExchangeParameterSharedInfo parameters to be used.
///
///
/// Compute shared secret using ECDH algorithm without cofactor, suitable only for kSecAttrKeyTypeECSECPrimeRandom keys
/// and apply ANSI X9.63 KDF with SHA224 as hashing function.  Requires kSecKeyKeyExchangeParameterRequestedSize and allows
/// kSecKeyKeyExchangeParameterSharedInfo parameters to be used.
///
///
/// Compute shared secret using ECDH algorithm without cofactor, suitable only for kSecAttrKeyTypeECSECPrimeRandom keys
/// and apply ANSI X9.63 KDF with SHA256 as hashing function.  Requires kSecKeyKeyExchangeParameterRequestedSize and allows
/// kSecKeyKeyExchangeParameterSharedInfo parameters to be used.
///
///
/// Compute shared secret using ECDH algorithm without cofactor, suitable only for kSecAttrKeyTypeECSECPrimeRandom keys
/// and apply ANSI X9.63 KDF with SHA384 as hashing function.  Requires kSecKeyKeyExchangeParameterRequestedSize and allows
/// kSecKeyKeyExchangeParameterSharedInfo parameters to be used.
///
///
/// Compute shared secret using ECDH algorithm without cofactor, suitable only for kSecAttrKeyTypeECSECPrimeRandom keys
/// and apply ANSI X9.63 KDF with SHA512 as hashing function.  Requires kSecKeyKeyExchangeParameterRequestedSize and allows
/// kSecKeyKeyExchangeParameterSharedInfo parameters to be used.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/security/seckeyalgorithm?language=objc)
// NS_TYPED_ENUM
pub type SecKeyAlgorithm = CFString;

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmrsasignatureraw?language=objc)
    pub static kSecKeyAlgorithmRSASignatureRaw: &'static SecKeyAlgorithm;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmrsasignaturedigestpkcs1v15raw?language=objc)
    pub static kSecKeyAlgorithmRSASignatureDigestPKCS1v15Raw: &'static SecKeyAlgorithm;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmrsasignaturedigestpkcs1v15sha1?language=objc)
    pub static kSecKeyAlgorithmRSASignatureDigestPKCS1v15SHA1: &'static SecKeyAlgorithm;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmrsasignaturedigestpkcs1v15sha224?language=objc)
    pub static kSecKeyAlgorithmRSASignatureDigestPKCS1v15SHA224: &'static SecKeyAlgorithm;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmrsasignaturedigestpkcs1v15sha256?language=objc)
    pub static kSecKeyAlgorithmRSASignatureDigestPKCS1v15SHA256: &'static SecKeyAlgorithm;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmrsasignaturedigestpkcs1v15sha384?language=objc)
    pub static kSecKeyAlgorithmRSASignatureDigestPKCS1v15SHA384: &'static SecKeyAlgorithm;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmrsasignaturedigestpkcs1v15sha512?language=objc)
    pub static kSecKeyAlgorithmRSASignatureDigestPKCS1v15SHA512: &'static SecKeyAlgorithm;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmrsasignaturemessagepkcs1v15sha1?language=objc)
    pub static kSecKeyAlgorithmRSASignatureMessagePKCS1v15SHA1: &'static SecKeyAlgorithm;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmrsasignaturemessagepkcs1v15sha224?language=objc)
    pub static kSecKeyAlgorithmRSASignatureMessagePKCS1v15SHA224: &'static SecKeyAlgorithm;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmrsasignaturemessagepkcs1v15sha256?language=objc)
    pub static kSecKeyAlgorithmRSASignatureMessagePKCS1v15SHA256: &'static SecKeyAlgorithm;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmrsasignaturemessagepkcs1v15sha384?language=objc)
    pub static kSecKeyAlgorithmRSASignatureMessagePKCS1v15SHA384: &'static SecKeyAlgorithm;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmrsasignaturemessagepkcs1v15sha512?language=objc)
    pub static kSecKeyAlgorithmRSASignatureMessagePKCS1v15SHA512: &'static SecKeyAlgorithm;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmrsasignaturedigestpsssha1?language=objc)
    pub static kSecKeyAlgorithmRSASignatureDigestPSSSHA1: &'static SecKeyAlgorithm;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmrsasignaturedigestpsssha224?language=objc)
    pub static kSecKeyAlgorithmRSASignatureDigestPSSSHA224: &'static SecKeyAlgorithm;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmrsasignaturedigestpsssha256?language=objc)
    pub static kSecKeyAlgorithmRSASignatureDigestPSSSHA256: &'static SecKeyAlgorithm;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmrsasignaturedigestpsssha384?language=objc)
    pub static kSecKeyAlgorithmRSASignatureDigestPSSSHA384: &'static SecKeyAlgorithm;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmrsasignaturedigestpsssha512?language=objc)
    pub static kSecKeyAlgorithmRSASignatureDigestPSSSHA512: &'static SecKeyAlgorithm;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmrsasignaturemessagepsssha1?language=objc)
    pub static kSecKeyAlgorithmRSASignatureMessagePSSSHA1: &'static SecKeyAlgorithm;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmrsasignaturemessagepsssha224?language=objc)
    pub static kSecKeyAlgorithmRSASignatureMessagePSSSHA224: &'static SecKeyAlgorithm;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmrsasignaturemessagepsssha256?language=objc)
    pub static kSecKeyAlgorithmRSASignatureMessagePSSSHA256: &'static SecKeyAlgorithm;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmrsasignaturemessagepsssha384?language=objc)
    pub static kSecKeyAlgorithmRSASignatureMessagePSSSHA384: &'static SecKeyAlgorithm;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmrsasignaturemessagepsssha512?language=objc)
    pub static kSecKeyAlgorithmRSASignatureMessagePSSSHA512: &'static SecKeyAlgorithm;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmecdsasignaturedigestx962?language=objc)
    pub static kSecKeyAlgorithmECDSASignatureDigestX962: &'static SecKeyAlgorithm;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmecdsasignaturedigestx962sha1?language=objc)
    pub static kSecKeyAlgorithmECDSASignatureDigestX962SHA1: &'static SecKeyAlgorithm;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmecdsasignaturedigestx962sha224?language=objc)
    pub static kSecKeyAlgorithmECDSASignatureDigestX962SHA224: &'static SecKeyAlgorithm;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmecdsasignaturedigestx962sha256?language=objc)
    pub static kSecKeyAlgorithmECDSASignatureDigestX962SHA256: &'static SecKeyAlgorithm;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmecdsasignaturedigestx962sha384?language=objc)
    pub static kSecKeyAlgorithmECDSASignatureDigestX962SHA384: &'static SecKeyAlgorithm;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmecdsasignaturedigestx962sha512?language=objc)
    pub static kSecKeyAlgorithmECDSASignatureDigestX962SHA512: &'static SecKeyAlgorithm;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmecdsasignaturemessagex962sha1?language=objc)
    pub static kSecKeyAlgorithmECDSASignatureMessageX962SHA1: &'static SecKeyAlgorithm;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmecdsasignaturemessagex962sha224?language=objc)
    pub static kSecKeyAlgorithmECDSASignatureMessageX962SHA224: &'static SecKeyAlgorithm;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmecdsasignaturemessagex962sha256?language=objc)
    pub static kSecKeyAlgorithmECDSASignatureMessageX962SHA256: &'static SecKeyAlgorithm;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmecdsasignaturemessagex962sha384?language=objc)
    pub static kSecKeyAlgorithmECDSASignatureMessageX962SHA384: &'static SecKeyAlgorithm;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmecdsasignaturemessagex962sha512?language=objc)
    pub static kSecKeyAlgorithmECDSASignatureMessageX962SHA512: &'static SecKeyAlgorithm;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmecdsasignaturedigestrfc4754?language=objc)
    pub static kSecKeyAlgorithmECDSASignatureDigestRFC4754: &'static SecKeyAlgorithm;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmecdsasignaturedigestrfc4754sha1?language=objc)
    pub static kSecKeyAlgorithmECDSASignatureDigestRFC4754SHA1: &'static SecKeyAlgorithm;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmecdsasignaturedigestrfc4754sha224?language=objc)
    pub static kSecKeyAlgorithmECDSASignatureDigestRFC4754SHA224: &'static SecKeyAlgorithm;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmecdsasignaturedigestrfc4754sha256?language=objc)
    pub static kSecKeyAlgorithmECDSASignatureDigestRFC4754SHA256: &'static SecKeyAlgorithm;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmecdsasignaturedigestrfc4754sha384?language=objc)
    pub static kSecKeyAlgorithmECDSASignatureDigestRFC4754SHA384: &'static SecKeyAlgorithm;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmecdsasignaturedigestrfc4754sha512?language=objc)
    pub static kSecKeyAlgorithmECDSASignatureDigestRFC4754SHA512: &'static SecKeyAlgorithm;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmecdsasignaturemessagerfc4754sha1?language=objc)
    pub static kSecKeyAlgorithmECDSASignatureMessageRFC4754SHA1: &'static SecKeyAlgorithm;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmecdsasignaturemessagerfc4754sha224?language=objc)
    pub static kSecKeyAlgorithmECDSASignatureMessageRFC4754SHA224: &'static SecKeyAlgorithm;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmecdsasignaturemessagerfc4754sha256?language=objc)
    pub static kSecKeyAlgorithmECDSASignatureMessageRFC4754SHA256: &'static SecKeyAlgorithm;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmecdsasignaturemessagerfc4754sha384?language=objc)
    pub static kSecKeyAlgorithmECDSASignatureMessageRFC4754SHA384: &'static SecKeyAlgorithm;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmecdsasignaturemessagerfc4754sha512?language=objc)
    pub static kSecKeyAlgorithmECDSASignatureMessageRFC4754SHA512: &'static SecKeyAlgorithm;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmecdsasignaturerfc4754?language=objc)
    #[deprecated]
    pub static kSecKeyAlgorithmECDSASignatureRFC4754: &'static SecKeyAlgorithm;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmrsaencryptionraw?language=objc)
    pub static kSecKeyAlgorithmRSAEncryptionRaw: &'static SecKeyAlgorithm;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmrsaencryptionpkcs1?language=objc)
    pub static kSecKeyAlgorithmRSAEncryptionPKCS1: &'static SecKeyAlgorithm;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmrsaencryptionoaepsha1?language=objc)
    pub static kSecKeyAlgorithmRSAEncryptionOAEPSHA1: &'static SecKeyAlgorithm;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmrsaencryptionoaepsha224?language=objc)
    pub static kSecKeyAlgorithmRSAEncryptionOAEPSHA224: &'static SecKeyAlgorithm;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmrsaencryptionoaepsha256?language=objc)
    pub static kSecKeyAlgorithmRSAEncryptionOAEPSHA256: &'static SecKeyAlgorithm;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmrsaencryptionoaepsha384?language=objc)
    pub static kSecKeyAlgorithmRSAEncryptionOAEPSHA384: &'static SecKeyAlgorithm;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmrsaencryptionoaepsha512?language=objc)
    pub static kSecKeyAlgorithmRSAEncryptionOAEPSHA512: &'static SecKeyAlgorithm;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmrsaencryptionoaepsha1aesgcm?language=objc)
    pub static kSecKeyAlgorithmRSAEncryptionOAEPSHA1AESGCM: &'static SecKeyAlgorithm;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmrsaencryptionoaepsha224aesgcm?language=objc)
    pub static kSecKeyAlgorithmRSAEncryptionOAEPSHA224AESGCM: &'static SecKeyAlgorithm;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmrsaencryptionoaepsha256aesgcm?language=objc)
    pub static kSecKeyAlgorithmRSAEncryptionOAEPSHA256AESGCM: &'static SecKeyAlgorithm;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmrsaencryptionoaepsha384aesgcm?language=objc)
    pub static kSecKeyAlgorithmRSAEncryptionOAEPSHA384AESGCM: &'static SecKeyAlgorithm;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmrsaencryptionoaepsha512aesgcm?language=objc)
    pub static kSecKeyAlgorithmRSAEncryptionOAEPSHA512AESGCM: &'static SecKeyAlgorithm;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmeciesencryptionstandardx963sha1aesgcm?language=objc)
    pub static kSecKeyAlgorithmECIESEncryptionStandardX963SHA1AESGCM: &'static SecKeyAlgorithm;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmeciesencryptionstandardx963sha224aesgcm?language=objc)
    pub static kSecKeyAlgorithmECIESEncryptionStandardX963SHA224AESGCM: &'static SecKeyAlgorithm;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmeciesencryptionstandardx963sha256aesgcm?language=objc)
    pub static kSecKeyAlgorithmECIESEncryptionStandardX963SHA256AESGCM: &'static SecKeyAlgorithm;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmeciesencryptionstandardx963sha384aesgcm?language=objc)
    pub static kSecKeyAlgorithmECIESEncryptionStandardX963SHA384AESGCM: &'static SecKeyAlgorithm;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmeciesencryptionstandardx963sha512aesgcm?language=objc)
    pub static kSecKeyAlgorithmECIESEncryptionStandardX963SHA512AESGCM: &'static SecKeyAlgorithm;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmeciesencryptioncofactorx963sha1aesgcm?language=objc)
    pub static kSecKeyAlgorithmECIESEncryptionCofactorX963SHA1AESGCM: &'static SecKeyAlgorithm;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmeciesencryptioncofactorx963sha224aesgcm?language=objc)
    pub static kSecKeyAlgorithmECIESEncryptionCofactorX963SHA224AESGCM: &'static SecKeyAlgorithm;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmeciesencryptioncofactorx963sha256aesgcm?language=objc)
    pub static kSecKeyAlgorithmECIESEncryptionCofactorX963SHA256AESGCM: &'static SecKeyAlgorithm;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmeciesencryptioncofactorx963sha384aesgcm?language=objc)
    pub static kSecKeyAlgorithmECIESEncryptionCofactorX963SHA384AESGCM: &'static SecKeyAlgorithm;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmeciesencryptioncofactorx963sha512aesgcm?language=objc)
    pub static kSecKeyAlgorithmECIESEncryptionCofactorX963SHA512AESGCM: &'static SecKeyAlgorithm;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmeciesencryptionstandardvariableivx963sha224aesgcm?language=objc)
    pub static kSecKeyAlgorithmECIESEncryptionStandardVariableIVX963SHA224AESGCM:
        &'static SecKeyAlgorithm;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmeciesencryptionstandardvariableivx963sha256aesgcm?language=objc)
    pub static kSecKeyAlgorithmECIESEncryptionStandardVariableIVX963SHA256AESGCM:
        &'static SecKeyAlgorithm;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmeciesencryptionstandardvariableivx963sha384aesgcm?language=objc)
    pub static kSecKeyAlgorithmECIESEncryptionStandardVariableIVX963SHA384AESGCM:
        &'static SecKeyAlgorithm;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmeciesencryptionstandardvariableivx963sha512aesgcm?language=objc)
    pub static kSecKeyAlgorithmECIESEncryptionStandardVariableIVX963SHA512AESGCM:
        &'static SecKeyAlgorithm;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmeciesencryptioncofactorvariableivx963sha224aesgcm?language=objc)
    pub static kSecKeyAlgorithmECIESEncryptionCofactorVariableIVX963SHA224AESGCM:
        &'static SecKeyAlgorithm;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmeciesencryptioncofactorvariableivx963sha256aesgcm?language=objc)
    pub static kSecKeyAlgorithmECIESEncryptionCofactorVariableIVX963SHA256AESGCM:
        &'static SecKeyAlgorithm;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmeciesencryptioncofactorvariableivx963sha384aesgcm?language=objc)
    pub static kSecKeyAlgorithmECIESEncryptionCofactorVariableIVX963SHA384AESGCM:
        &'static SecKeyAlgorithm;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmeciesencryptioncofactorvariableivx963sha512aesgcm?language=objc)
    pub static kSecKeyAlgorithmECIESEncryptionCofactorVariableIVX963SHA512AESGCM:
        &'static SecKeyAlgorithm;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmecdhkeyexchangestandard?language=objc)
    pub static kSecKeyAlgorithmECDHKeyExchangeStandard: &'static SecKeyAlgorithm;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmecdhkeyexchangestandardx963sha1?language=objc)
    pub static kSecKeyAlgorithmECDHKeyExchangeStandardX963SHA1: &'static SecKeyAlgorithm;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmecdhkeyexchangestandardx963sha224?language=objc)
    pub static kSecKeyAlgorithmECDHKeyExchangeStandardX963SHA224: &'static SecKeyAlgorithm;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmecdhkeyexchangestandardx963sha256?language=objc)
    pub static kSecKeyAlgorithmECDHKeyExchangeStandardX963SHA256: &'static SecKeyAlgorithm;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmecdhkeyexchangestandardx963sha384?language=objc)
    pub static kSecKeyAlgorithmECDHKeyExchangeStandardX963SHA384: &'static SecKeyAlgorithm;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmecdhkeyexchangestandardx963sha512?language=objc)
    pub static kSecKeyAlgorithmECDHKeyExchangeStandardX963SHA512: &'static SecKeyAlgorithm;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmecdhkeyexchangecofactor?language=objc)
    pub static kSecKeyAlgorithmECDHKeyExchangeCofactor: &'static SecKeyAlgorithm;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmecdhkeyexchangecofactorx963sha1?language=objc)
    pub static kSecKeyAlgorithmECDHKeyExchangeCofactorX963SHA1: &'static SecKeyAlgorithm;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmecdhkeyexchangecofactorx963sha224?language=objc)
    pub static kSecKeyAlgorithmECDHKeyExchangeCofactorX963SHA224: &'static SecKeyAlgorithm;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmecdhkeyexchangecofactorx963sha256?language=objc)
    pub static kSecKeyAlgorithmECDHKeyExchangeCofactorX963SHA256: &'static SecKeyAlgorithm;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmecdhkeyexchangecofactorx963sha384?language=objc)
    pub static kSecKeyAlgorithmECDHKeyExchangeCofactorX963SHA384: &'static SecKeyAlgorithm;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmecdhkeyexchangecofactorx963sha512?language=objc)
    pub static kSecKeyAlgorithmECDHKeyExchangeCofactorX963SHA512: &'static SecKeyAlgorithm;
}

#[cfg(feature = "SecBase")]
impl SecKey {
    /// Given a private key and data to sign, generate a digital signature.
    ///
    /// Parameter `key`: Private key with which to sign.
    ///
    /// Parameter `algorithm`: One of SecKeyAlgorithm constants suitable to generate signature with this key.
    ///
    /// Parameter `dataToSign`: The data to be signed, typically the digest of the actual data.
    ///
    /// Parameter `error`: On error, will be populated with an error object describing the failure.
    /// See "Security Error Codes" (SecBase.h).
    ///
    /// Returns: The signature over dataToSign represented as a CFData, or NULL on failure.
    ///
    /// Computes digital signature using specified key over input data.  The operation algorithm
    /// further defines the exact format of input data, operation to be performed and output signature.
    ///
    /// # Safety
    ///
    /// `error` must be a valid pointer or null.
    #[doc(alias = "SecKeyCreateSignature")]
    #[cfg(feature = "SecBase")]
    #[inline]
    pub unsafe fn signature(
        &self,
        algorithm: &SecKeyAlgorithm,
        data_to_sign: &CFData,
        error: *mut *mut CFError,
    ) -> Option<CFRetained<CFData>> {
        extern "C-unwind" {
            fn SecKeyCreateSignature(
                key: &SecKey,
                algorithm: &SecKeyAlgorithm,
                data_to_sign: &CFData,
                error: *mut *mut CFError,
            ) -> Option<NonNull<CFData>>;
        }
        let ret = unsafe { SecKeyCreateSignature(self, algorithm, data_to_sign, error) };
        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
    }

    /// Given a public key, data which has been signed, and a signature, verify the signature.
    ///
    /// Parameter `key`: Public key with which to verify the signature.
    ///
    /// Parameter `algorithm`: One of SecKeyAlgorithm constants suitable to verify signature with this key.
    ///
    /// Parameter `signedData`: The data over which sig is being verified, typically the digest of the actual data.
    ///
    /// Parameter `signature`: The signature to verify.
    ///
    /// Parameter `error`: On error, will be populated with an error object describing the failure.
    /// See "Security Error Codes" (SecBase.h).
    ///
    /// Returns: True if the signature was valid, False otherwise.
    ///
    /// Verifies digital signature operation using specified key and signed data.  The operation algorithm
    /// further defines the exact format of input data, signature and operation to be performed.
    ///
    /// # Safety
    ///
    /// `error` must be a valid pointer or null.
    #[doc(alias = "SecKeyVerifySignature")]
    #[cfg(feature = "SecBase")]
    #[inline]
    pub unsafe fn verify_signature(
        &self,
        algorithm: &SecKeyAlgorithm,
        signed_data: &CFData,
        signature: &CFData,
        error: *mut *mut CFError,
    ) -> bool {
        extern "C-unwind" {
            fn SecKeyVerifySignature(
                key: &SecKey,
                algorithm: &SecKeyAlgorithm,
                signed_data: &CFData,
                signature: &CFData,
                error: *mut *mut CFError,
            ) -> Boolean;
        }
        let ret = unsafe { SecKeyVerifySignature(self, algorithm, signed_data, signature, error) };
        ret != 0
    }

    /// Encrypt a block of plaintext.
    ///
    /// Parameter `key`: Public key with which to encrypt the data.
    ///
    /// Parameter `algorithm`: One of SecKeyAlgorithm constants suitable to perform encryption with this key.
    ///
    /// Parameter `plaintext`: The data to encrypt. The length and format of the data must conform to chosen algorithm,
    /// typically be less or equal to the value returned by SecKeyGetBlockSize().
    ///
    /// Parameter `error`: On error, will be populated with an error object describing the failure.
    /// See "Security Error Codes" (SecBase.h).
    ///
    /// Returns: The ciphertext represented as a CFData, or NULL on failure.
    ///
    /// Encrypts plaintext data using specified key.  The exact type of the operation including the format
    /// of input and output data is specified by encryption algorithm.
    ///
    /// # Safety
    ///
    /// `error` must be a valid pointer or null.
    #[doc(alias = "SecKeyCreateEncryptedData")]
    #[cfg(feature = "SecBase")]
    #[inline]
    pub unsafe fn encrypted_data(
        &self,
        algorithm: &SecKeyAlgorithm,
        plaintext: &CFData,
        error: *mut *mut CFError,
    ) -> Option<CFRetained<CFData>> {
        extern "C-unwind" {
            fn SecKeyCreateEncryptedData(
                key: &SecKey,
                algorithm: &SecKeyAlgorithm,
                plaintext: &CFData,
                error: *mut *mut CFError,
            ) -> Option<NonNull<CFData>>;
        }
        let ret = unsafe { SecKeyCreateEncryptedData(self, algorithm, plaintext, error) };
        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
    }

    /// Decrypt a block of ciphertext.
    ///
    /// Parameter `key`: Private key with which to decrypt the data.
    ///
    /// Parameter `algorithm`: One of SecKeyAlgorithm constants suitable to perform decryption with this key.
    ///
    /// Parameter `ciphertext`: The data to decrypt. The length and format of the data must conform to chosen algorithm,
    /// typically be less or equal to the value returned by SecKeyGetBlockSize().
    ///
    /// Parameter `error`: On error, will be populated with an error object describing the failure.
    /// See "Security Error Codes" (SecBase.h).
    ///
    /// Returns: The plaintext represented as a CFData, or NULL on failure.
    ///
    /// Decrypts ciphertext data using specified key.  The exact type of the operation including the format
    /// of input and output data is specified by decryption algorithm.
    ///
    /// # Safety
    ///
    /// `error` must be a valid pointer or null.
    #[doc(alias = "SecKeyCreateDecryptedData")]
    #[cfg(feature = "SecBase")]
    #[inline]
    pub unsafe fn decrypted_data(
        &self,
        algorithm: &SecKeyAlgorithm,
        ciphertext: &CFData,
        error: *mut *mut CFError,
    ) -> Option<CFRetained<CFData>> {
        extern "C-unwind" {
            fn SecKeyCreateDecryptedData(
                key: &SecKey,
                algorithm: &SecKeyAlgorithm,
                ciphertext: &CFData,
                error: *mut *mut CFError,
            ) -> Option<NonNull<CFData>>;
        }
        let ret = unsafe { SecKeyCreateDecryptedData(self, algorithm, ciphertext, error) };
        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
    }
}

/// for KDF (key derivation function).
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/security/seckeykeyexchangeparameter?language=objc)
// NS_TYPED_ENUM
pub type SecKeyKeyExchangeParameter = CFString;

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeykeyexchangeparameterrequestedsize?language=objc)
    pub static kSecKeyKeyExchangeParameterRequestedSize: &'static SecKeyKeyExchangeParameter;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeykeyexchangeparametersharedinfo?language=objc)
    pub static kSecKeyKeyExchangeParameterSharedInfo: &'static SecKeyKeyExchangeParameter;
}

#[cfg(feature = "SecBase")]
impl SecKey {
    /// Perform Diffie-Hellman style of key exchange operation, optionally with additional key-derivation steps.
    ///
    /// Parameter `algorithm`: One of SecKeyAlgorithm constants suitable to perform this operation.
    ///
    /// Parameter `publicKey`: Remote party's public key.
    ///
    /// Parameter `parameters`: Dictionary with parameters, see SecKeyKeyExchangeParameter constants.  Used algorithm
    /// determines the set of required and optional parameters to be used.
    ///
    /// Parameter `error`: Pointer to an error object on failure.
    /// See "Security Error Codes" (SecBase.h).
    ///
    /// Returns: Result of key exchange operation as a CFDataRef, or NULL on failure.
    ///
    /// # Safety
    ///
    /// - `parameters` generics must be of the correct type.
    /// - `error` must be a valid pointer or null.
    #[doc(alias = "SecKeyCopyKeyExchangeResult")]
    #[cfg(feature = "SecBase")]
    #[inline]
    pub unsafe fn key_exchange_result(
        &self,
        algorithm: &SecKeyAlgorithm,
        public_key: &SecKey,
        parameters: &CFDictionary,
        error: *mut *mut CFError,
    ) -> Option<CFRetained<CFData>> {
        extern "C-unwind" {
            fn SecKeyCopyKeyExchangeResult(
                private_key: &SecKey,
                algorithm: &SecKeyAlgorithm,
                public_key: &SecKey,
                parameters: &CFDictionary,
                error: *mut *mut CFError,
            ) -> Option<NonNull<CFData>>;
        }
        let ret =
            unsafe { SecKeyCopyKeyExchangeResult(self, algorithm, public_key, parameters, error) };
        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
    }
}

/// Defines types of cryptographic operations available with SecKey instance.
///
///
/// Represents SecKeyCreateSignature()
///
///
/// Represents SecKeyVerifySignature()
///
///
/// Represents SecKeyCreateEncryptedData()
///
///
/// Represents SecKeyCreateDecryptedData()
///
///
/// Represents SecKeyCopyKeyExchangeResult()
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/security/seckeyoperationtype?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct SecKeyOperationType(pub CFIndex);
impl SecKeyOperationType {
    #[doc(alias = "kSecKeyOperationTypeSign")]
    pub const Sign: Self = Self(0);
    #[doc(alias = "kSecKeyOperationTypeVerify")]
    pub const Verify: Self = Self(1);
    #[doc(alias = "kSecKeyOperationTypeEncrypt")]
    pub const Encrypt: Self = Self(2);
    #[doc(alias = "kSecKeyOperationTypeDecrypt")]
    pub const Decrypt: Self = Self(3);
    #[doc(alias = "kSecKeyOperationTypeKeyExchange")]
    pub const KeyExchange: Self = Self(4);
}

#[cfg(feature = "objc2")]
unsafe impl Encode for SecKeyOperationType {
    const ENCODING: Encoding = CFIndex::ENCODING;
}

#[cfg(feature = "objc2")]
unsafe impl RefEncode for SecKeyOperationType {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

#[cfg(feature = "SecBase")]
impl SecKey {
    /// Checks whether key supports specified algorithm for specified operation.
    ///
    /// Parameter `key`: Key to query
    ///
    /// Parameter `operation`: Operation type for which the key is queried
    ///
    /// Parameter `algorithm`: Algorithm which is queried
    ///
    /// Returns: True if key supports specified algorithm for specified operation, False otherwise.
    #[doc(alias = "SecKeyIsAlgorithmSupported")]
    #[cfg(feature = "SecBase")]
    #[inline]
    pub unsafe fn is_algorithm_supported(
        &self,
        operation: SecKeyOperationType,
        algorithm: &SecKeyAlgorithm,
    ) -> bool {
        extern "C-unwind" {
            fn SecKeyIsAlgorithmSupported(
                key: &SecKey,
                operation: SecKeyOperationType,
                algorithm: &SecKeyAlgorithm,
            ) -> Boolean;
        }
        let ret = unsafe { SecKeyIsAlgorithmSupported(self, operation, algorithm) };
        ret != 0
    }
}

extern "C-unwind" {
    #[cfg(all(feature = "SecBase", feature = "cssmconfig", feature = "cssmtype"))]
    #[deprecated = "renamed to `SecKey::create_pair`"]
    pub fn SecKeyCreatePair(
        keychain_ref: Option<&SecKeychain>,
        algorithm: CSSM_ALGORITHMS,
        key_size_in_bits: uint32,
        context_handle: CSSM_CC_HANDLE,
        public_key_usage: CSSM_KEYUSE,
        public_key_attr: uint32,
        private_key_usage: CSSM_KEYUSE,
        private_key_attr: uint32,
        initial_access: Option<&SecAccess>,
        public_key: *mut *mut SecKey,
        private_key: *mut *mut SecKey,
    ) -> OSStatus;
}

extern "C-unwind" {
    #[cfg(all(feature = "SecBase", feature = "cssmconfig", feature = "cssmtype"))]
    #[deprecated = "renamed to `SecKey::generate`"]
    pub fn SecKeyGenerate(
        keychain_ref: Option<&SecKeychain>,
        algorithm: CSSM_ALGORITHMS,
        key_size_in_bits: uint32,
        context_handle: CSSM_CC_HANDLE,
        key_usage: CSSM_KEYUSE,
        key_attr: uint32,
        initial_access: Option<&SecAccess>,
        key_ref: *mut *mut SecKey,
    ) -> OSStatus;
}

extern "C-unwind" {
    #[cfg(all(
        feature = "SecAsn1Types",
        feature = "SecBase",
        feature = "cssmconfig",
        feature = "cssmtype"
    ))]
    #[deprecated = "renamed to `SecKey::cssm_key`"]
    pub fn SecKeyGetCSSMKey(key: &SecKey, cssm_key: NonNull<*const CSSM_KEY>) -> OSStatus;
}

extern "C-unwind" {
    #[cfg(all(feature = "SecBase", feature = "cssmconfig", feature = "cssmtype"))]
    #[deprecated = "renamed to `SecKey::csp_handle`"]
    pub fn SecKeyGetCSPHandle(key_ref: &SecKey, csp_handle: NonNull<CSSM_CSP_HANDLE>) -> OSStatus;
}

extern "C-unwind" {
    #[cfg(all(
        feature = "SecAsn1Types",
        feature = "SecBase",
        feature = "cssmconfig",
        feature = "cssmtype"
    ))]
    #[deprecated = "renamed to `SecKey::credentials`"]
    pub fn SecKeyGetCredentials(
        key_ref: &SecKey,
        operation: CSSM_ACL_AUTHORIZATION_TAG,
        credential_type: SecCredentialType,
        out_credentials: NonNull<*const CSSM_ACCESS_CREDENTIALS>,
    ) -> OSStatus;
}

#[cfg(feature = "SecBase")]
#[deprecated = "renamed to `SecKey::generate_symmetric`"]
#[inline]
pub unsafe extern "C-unwind" fn SecKeyGenerateSymmetric(
    parameters: &CFDictionary,
    error: *mut *mut CFError,
) -> Option<CFRetained<SecKey>> {
    extern "C-unwind" {
        fn SecKeyGenerateSymmetric(
            parameters: &CFDictionary,
            error: *mut *mut CFError,
        ) -> Option<NonNull<SecKey>>;
    }
    let ret = unsafe { SecKeyGenerateSymmetric(parameters, error) };
    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}

#[cfg(feature = "SecBase")]
#[deprecated = "renamed to `SecKey::from_data`"]
#[inline]
pub unsafe extern "C-unwind" fn SecKeyCreateFromData(
    parameters: &CFDictionary,
    key_data: &CFData,
    error: *mut *mut CFError,
) -> Option<CFRetained<SecKey>> {
    extern "C-unwind" {
        fn SecKeyCreateFromData(
            parameters: &CFDictionary,
            key_data: &CFData,
            error: *mut *mut CFError,
        ) -> Option<NonNull<SecKey>>;
    }
    let ret = unsafe { SecKeyCreateFromData(parameters, key_data, error) };
    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}

#[cfg(feature = "SecBase")]
#[deprecated = "renamed to `SecKey::derive_from_password`"]
#[inline]
pub unsafe extern "C-unwind" fn SecKeyDeriveFromPassword(
    password: &CFString,
    parameters: &CFDictionary,
    error: *mut *mut CFError,
) -> Option<CFRetained<SecKey>> {
    extern "C-unwind" {
        fn SecKeyDeriveFromPassword(
            password: &CFString,
            parameters: &CFDictionary,
            error: *mut *mut CFError,
        ) -> Option<NonNull<SecKey>>;
    }
    let ret = unsafe { SecKeyDeriveFromPassword(password, parameters, error) };
    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}

#[cfg(feature = "SecBase")]
#[deprecated = "renamed to `SecKey::wrap_symmetric`"]
#[inline]
pub unsafe extern "C-unwind" fn SecKeyWrapSymmetric(
    key_to_wrap: &SecKey,
    wrapping_key: &SecKey,
    parameters: &CFDictionary,
    error: *mut *mut CFError,
) -> Option<CFRetained<CFData>> {
    extern "C-unwind" {
        fn SecKeyWrapSymmetric(
            key_to_wrap: &SecKey,
            wrapping_key: &SecKey,
            parameters: &CFDictionary,
            error: *mut *mut CFError,
        ) -> Option<NonNull<CFData>>;
    }
    let ret = unsafe { SecKeyWrapSymmetric(key_to_wrap, wrapping_key, parameters, error) };
    ret.map(|ret| unsafe { CFRetained::retain(ret) })
}

#[cfg(feature = "SecBase")]
#[deprecated = "renamed to `SecKey::unwrap_symmetric`"]
#[inline]
pub unsafe extern "C-unwind" fn SecKeyUnwrapSymmetric(
    key_to_unwrap: NonNull<*const CFData>,
    unwrapping_key: &SecKey,
    parameters: &CFDictionary,
    error: *mut *mut CFError,
) -> Option<CFRetained<SecKey>> {
    extern "C-unwind" {
        fn SecKeyUnwrapSymmetric(
            key_to_unwrap: NonNull<*const CFData>,
            unwrapping_key: &SecKey,
            parameters: &CFDictionary,
            error: *mut *mut CFError,
        ) -> Option<NonNull<SecKey>>;
    }
    let ret = unsafe { SecKeyUnwrapSymmetric(key_to_unwrap, unwrapping_key, parameters, error) };
    ret.map(|ret| unsafe { CFRetained::retain(ret) })
}

extern "C-unwind" {
    #[cfg(feature = "SecBase")]
    #[deprecated = "renamed to `SecKey::generate_pair`"]
    pub fn SecKeyGeneratePair(
        parameters: &CFDictionary,
        public_key: *mut *mut SecKey,
        private_key: *mut *mut SecKey,
    ) -> OSStatus;
}

#[cfg(feature = "SecBase")]
#[deprecated = "renamed to `SecKey::new_random_key`"]
#[inline]
pub unsafe extern "C-unwind" fn SecKeyCreateRandomKey(
    parameters: &CFDictionary,
    error: *mut *mut CFError,
) -> Option<CFRetained<SecKey>> {
    extern "C-unwind" {
        fn SecKeyCreateRandomKey(
            parameters: &CFDictionary,
            error: *mut *mut CFError,
        ) -> Option<NonNull<SecKey>>;
    }
    let ret = unsafe { SecKeyCreateRandomKey(parameters, error) };
    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}

#[cfg(feature = "SecBase")]
#[deprecated = "renamed to `SecKey::with_data`"]
#[inline]
pub unsafe extern "C-unwind" fn SecKeyCreateWithData(
    key_data: &CFData,
    attributes: &CFDictionary,
    error: *mut *mut CFError,
) -> Option<CFRetained<SecKey>> {
    extern "C-unwind" {
        fn SecKeyCreateWithData(
            key_data: &CFData,
            attributes: &CFDictionary,
            error: *mut *mut CFError,
        ) -> Option<NonNull<SecKey>>;
    }
    let ret = unsafe { SecKeyCreateWithData(key_data, attributes, error) };
    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}

extern "C-unwind" {
    #[cfg(feature = "SecBase")]
    #[deprecated = "renamed to `SecKey::block_size`"]
    pub fn SecKeyGetBlockSize(key: &SecKey) -> usize;
}

#[cfg(feature = "SecBase")]
#[deprecated = "renamed to `SecKey::external_representation`"]
#[inline]
pub unsafe extern "C-unwind" fn SecKeyCopyExternalRepresentation(
    key: &SecKey,
    error: *mut *mut CFError,
) -> Option<CFRetained<CFData>> {
    extern "C-unwind" {
        fn SecKeyCopyExternalRepresentation(
            key: &SecKey,
            error: *mut *mut CFError,
        ) -> Option<NonNull<CFData>>;
    }
    let ret = unsafe { SecKeyCopyExternalRepresentation(key, error) };
    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}

#[cfg(feature = "SecBase")]
#[deprecated = "renamed to `SecKey::attributes`"]
#[inline]
pub unsafe extern "C-unwind" fn SecKeyCopyAttributes(
    key: &SecKey,
) -> Option<CFRetained<CFDictionary>> {
    extern "C-unwind" {
        fn SecKeyCopyAttributes(key: &SecKey) -> Option<NonNull<CFDictionary>>;
    }
    let ret = unsafe { SecKeyCopyAttributes(key) };
    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}

#[cfg(feature = "SecBase")]
#[deprecated = "renamed to `SecKey::public_key`"]
#[inline]
pub unsafe extern "C-unwind" fn SecKeyCopyPublicKey(key: &SecKey) -> Option<CFRetained<SecKey>> {
    extern "C-unwind" {
        fn SecKeyCopyPublicKey(key: &SecKey) -> Option<NonNull<SecKey>>;
    }
    let ret = unsafe { SecKeyCopyPublicKey(key) };
    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}

#[cfg(feature = "SecBase")]
#[deprecated = "renamed to `SecKey::signature`"]
#[inline]
pub unsafe extern "C-unwind" fn SecKeyCreateSignature(
    key: &SecKey,
    algorithm: &SecKeyAlgorithm,
    data_to_sign: &CFData,
    error: *mut *mut CFError,
) -> Option<CFRetained<CFData>> {
    extern "C-unwind" {
        fn SecKeyCreateSignature(
            key: &SecKey,
            algorithm: &SecKeyAlgorithm,
            data_to_sign: &CFData,
            error: *mut *mut CFError,
        ) -> Option<NonNull<CFData>>;
    }
    let ret = unsafe { SecKeyCreateSignature(key, algorithm, data_to_sign, error) };
    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}

#[cfg(feature = "SecBase")]
#[deprecated = "renamed to `SecKey::verify_signature`"]
#[inline]
pub unsafe extern "C-unwind" fn SecKeyVerifySignature(
    key: &SecKey,
    algorithm: &SecKeyAlgorithm,
    signed_data: &CFData,
    signature: &CFData,
    error: *mut *mut CFError,
) -> bool {
    extern "C-unwind" {
        fn SecKeyVerifySignature(
            key: &SecKey,
            algorithm: &SecKeyAlgorithm,
            signed_data: &CFData,
            signature: &CFData,
            error: *mut *mut CFError,
        ) -> Boolean;
    }
    let ret = unsafe { SecKeyVerifySignature(key, algorithm, signed_data, signature, error) };
    ret != 0
}

#[cfg(feature = "SecBase")]
#[deprecated = "renamed to `SecKey::encrypted_data`"]
#[inline]
pub unsafe extern "C-unwind" fn SecKeyCreateEncryptedData(
    key: &SecKey,
    algorithm: &SecKeyAlgorithm,
    plaintext: &CFData,
    error: *mut *mut CFError,
) -> Option<CFRetained<CFData>> {
    extern "C-unwind" {
        fn SecKeyCreateEncryptedData(
            key: &SecKey,
            algorithm: &SecKeyAlgorithm,
            plaintext: &CFData,
            error: *mut *mut CFError,
        ) -> Option<NonNull<CFData>>;
    }
    let ret = unsafe { SecKeyCreateEncryptedData(key, algorithm, plaintext, error) };
    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}

#[cfg(feature = "SecBase")]
#[deprecated = "renamed to `SecKey::decrypted_data`"]
#[inline]
pub unsafe extern "C-unwind" fn SecKeyCreateDecryptedData(
    key: &SecKey,
    algorithm: &SecKeyAlgorithm,
    ciphertext: &CFData,
    error: *mut *mut CFError,
) -> Option<CFRetained<CFData>> {
    extern "C-unwind" {
        fn SecKeyCreateDecryptedData(
            key: &SecKey,
            algorithm: &SecKeyAlgorithm,
            ciphertext: &CFData,
            error: *mut *mut CFError,
        ) -> Option<NonNull<CFData>>;
    }
    let ret = unsafe { SecKeyCreateDecryptedData(key, algorithm, ciphertext, error) };
    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}

#[cfg(feature = "SecBase")]
#[deprecated = "renamed to `SecKey::key_exchange_result`"]
#[inline]
pub unsafe extern "C-unwind" fn SecKeyCopyKeyExchangeResult(
    private_key: &SecKey,
    algorithm: &SecKeyAlgorithm,
    public_key: &SecKey,
    parameters: &CFDictionary,
    error: *mut *mut CFError,
) -> Option<CFRetained<CFData>> {
    extern "C-unwind" {
        fn SecKeyCopyKeyExchangeResult(
            private_key: &SecKey,
            algorithm: &SecKeyAlgorithm,
            public_key: &SecKey,
            parameters: &CFDictionary,
            error: *mut *mut CFError,
        ) -> Option<NonNull<CFData>>;
    }
    let ret = unsafe {
        SecKeyCopyKeyExchangeResult(private_key, algorithm, public_key, parameters, error)
    };
    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}

#[cfg(feature = "SecBase")]
#[deprecated = "renamed to `SecKey::is_algorithm_supported`"]
#[inline]
pub unsafe extern "C-unwind" fn SecKeyIsAlgorithmSupported(
    key: &SecKey,
    operation: SecKeyOperationType,
    algorithm: &SecKeyAlgorithm,
) -> bool {
    extern "C-unwind" {
        fn SecKeyIsAlgorithmSupported(
            key: &SecKey,
            operation: SecKeyOperationType,
            algorithm: &SecKeyAlgorithm,
        ) -> Boolean;
    }
    let ret = unsafe { SecKeyIsAlgorithmSupported(key, operation, algorithm) };
    ret != 0
}