@swiftbrowser/swift 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (393) hide show
  1. package/Package.swift +200 -9
  2. package/README.md +7 -9
  3. package/Sources/AVFoundation/AVFoundation.swift +131 -0
  4. package/Sources/AVFoundation/Asset.swift +487 -0
  5. package/Sources/AVFoundation/AudioSession.swift +144 -0
  6. package/Sources/AVFoundation/CMTime.swift +303 -0
  7. package/Sources/AVFoundation/Capture.swift +688 -0
  8. package/Sources/AVFoundation/Player.swift +749 -0
  9. package/Sources/AVFoundation/PlayerView.swift +117 -0
  10. package/Sources/AVKit/AVKit.swift +132 -0
  11. package/Sources/Accelerate/Accelerate.swift +122 -0
  12. package/Sources/AppIntents/AppIntents.swift +144 -0
  13. package/Sources/AppIntents/Parameters.swift +220 -0
  14. package/Sources/AppIntents/Shortcuts.swift +159 -0
  15. package/Sources/AudioToolbox/AudioToolbox.swift +55 -0
  16. package/Sources/AuthenticationServices/AuthenticationServices.swift +257 -0
  17. package/Sources/AuthenticationServices/Authorization.swift +251 -0
  18. package/Sources/Charts/Charts.swift +0 -4
  19. package/Sources/Combine/AnyCancellable.swift +65 -0
  20. package/Sources/Combine/AnyPublisher.swift +148 -0
  21. package/Sources/Combine/AnySubscriber.swift +230 -0
  22. package/Sources/Combine/Cancellable.swift +35 -0
  23. package/Sources/Combine/Codable.swift +29 -0
  24. package/Sources/Combine/CombineIdentifier.swift +45 -0
  25. package/Sources/Combine/Concurrency/ConcurrencyHelpers.swift +24 -0
  26. package/Sources/Combine/Concurrency/Future+Concurrency.swift +136 -0
  27. package/Sources/Combine/Concurrency/GENERATED-Publisher+Concurrency.swift +397 -0
  28. package/Sources/Combine/CurrentValueSubject.swift +252 -0
  29. package/Sources/Combine/CustomCombineIdentifierConvertible.swift +28 -0
  30. package/Sources/Combine/Future.swift +228 -0
  31. package/Sources/Combine/GENERATED-RootProtocols.swift +426 -0
  32. package/Sources/Combine/Helpers/ConduitBase.swift +40 -0
  33. package/Sources/Combine/Helpers/ConduitList.swift +59 -0
  34. package/Sources/Combine/Helpers/DebugHook.swift +177 -0
  35. package/Sources/Combine/Helpers/FilterProducer.swift +174 -0
  36. package/Sources/Combine/Helpers/Locking.swift +30 -0
  37. package/Sources/Combine/Helpers/PartialCompletion.swift +26 -0
  38. package/Sources/Combine/Helpers/ReduceProducer.swift +249 -0
  39. package/Sources/Combine/Helpers/SubjectSubscriber.swift +96 -0
  40. package/Sources/Combine/Helpers/SubscriberTap.swift +69 -0
  41. package/Sources/Combine/Helpers/SubscriptionStatus.swift +33 -0
  42. package/Sources/Combine/Helpers/SubscriptionTap.swift +33 -0
  43. package/Sources/Combine/Helpers/Utils.swift +30 -0
  44. package/Sources/Combine/Helpers/Violations.swift +33 -0
  45. package/Sources/Combine/ImmediateScheduler.swift +178 -0
  46. package/Sources/Combine/LICENSE +21 -0
  47. package/Sources/Combine/NotificationPublisher.swift +48 -0
  48. package/Sources/Combine/ObjectWillChange.swift +46 -0
  49. package/Sources/Combine/PassthroughSubject.swift +222 -0
  50. package/Sources/Combine/Publisher+Subscribe.swift +53 -0
  51. package/Sources/Combine/Publishers/Deferred.swift +48 -0
  52. package/Sources/Combine/Publishers/Empty.swift +54 -0
  53. package/Sources/Combine/Publishers/Fail.swift +42 -0
  54. package/Sources/Combine/Publishers/GENERATED-Publishers.Catch.swift +673 -0
  55. package/Sources/Combine/Publishers/GENERATED-Publishers.Encode.swift +388 -0
  56. package/Sources/Combine/Publishers/GENERATED-Publishers.MapKeyPath.swift +384 -0
  57. package/Sources/Combine/Publishers/Just.swift +313 -0
  58. package/Sources/Combine/Publishers/Optional.Publisher.swift +315 -0
  59. package/Sources/Combine/Publishers/Publishers.AllSatisfy.swift +217 -0
  60. package/Sources/Combine/Publishers/Publishers.AssertNoFailure.swift +158 -0
  61. package/Sources/Combine/Publishers/Publishers.Autoconnect.swift +193 -0
  62. package/Sources/Combine/Publishers/Publishers.Breakpoint.swift +231 -0
  63. package/Sources/Combine/Publishers/Publishers.Buffer.swift +356 -0
  64. package/Sources/Combine/Publishers/Publishers.Collect.swift +102 -0
  65. package/Sources/Combine/Publishers/Publishers.CollectByCount.swift +195 -0
  66. package/Sources/Combine/Publishers/Publishers.CompactMap.swift +241 -0
  67. package/Sources/Combine/Publishers/Publishers.Comparison.swift +371 -0
  68. package/Sources/Combine/Publishers/Publishers.Concatenate.swift +474 -0
  69. package/Sources/Combine/Publishers/Publishers.Contains.swift +293 -0
  70. package/Sources/Combine/Publishers/Publishers.Count.swift +87 -0
  71. package/Sources/Combine/Publishers/Publishers.Debounce.swift +332 -0
  72. package/Sources/Combine/Publishers/Publishers.Delay.swift +269 -0
  73. package/Sources/Combine/Publishers/Publishers.Drop.swift +155 -0
  74. package/Sources/Combine/Publishers/Publishers.DropUntilOutput.swift +283 -0
  75. package/Sources/Combine/Publishers/Publishers.DropWhile.swift +378 -0
  76. package/Sources/Combine/Publishers/Publishers.Filter.swift +248 -0
  77. package/Sources/Combine/Publishers/Publishers.First.swift +261 -0
  78. package/Sources/Combine/Publishers/Publishers.FlatMap.swift +533 -0
  79. package/Sources/Combine/Publishers/Publishers.HandleEvents.swift +260 -0
  80. package/Sources/Combine/Publishers/Publishers.IgnoreOutput.swift +109 -0
  81. package/Sources/Combine/Publishers/Publishers.Last.swift +252 -0
  82. package/Sources/Combine/Publishers/Publishers.MakeConnectable.swift +82 -0
  83. package/Sources/Combine/Publishers/Publishers.Map.swift +351 -0
  84. package/Sources/Combine/Publishers/Publishers.MapError.swift +140 -0
  85. package/Sources/Combine/Publishers/Publishers.MeasureInterval.swift +187 -0
  86. package/Sources/Combine/Publishers/Publishers.Multicast.swift +284 -0
  87. package/Sources/Combine/Publishers/Publishers.Output.swift +241 -0
  88. package/Sources/Combine/Publishers/Publishers.PrefixUntilOutput.swift +197 -0
  89. package/Sources/Combine/Publishers/Publishers.PrefixWhile.swift +176 -0
  90. package/Sources/Combine/Publishers/Publishers.Print.swift +206 -0
  91. package/Sources/Combine/Publishers/Publishers.ReceiveOn.swift +227 -0
  92. package/Sources/Combine/Publishers/Publishers.Reduce.swift +204 -0
  93. package/Sources/Combine/Publishers/Publishers.RemoveDuplicates.swift +264 -0
  94. package/Sources/Combine/Publishers/Publishers.ReplaceEmpty.swift +201 -0
  95. package/Sources/Combine/Publishers/Publishers.ReplaceError.swift +211 -0
  96. package/Sources/Combine/Publishers/Publishers.Retry.swift +274 -0
  97. package/Sources/Combine/Publishers/Publishers.Scan.swift +331 -0
  98. package/Sources/Combine/Publishers/Publishers.Sequence.swift +437 -0
  99. package/Sources/Combine/Publishers/Publishers.SetFailureType.swift +120 -0
  100. package/Sources/Combine/Publishers/Publishers.Share.swift +104 -0
  101. package/Sources/Combine/Publishers/Publishers.SubscribeOn.swift +197 -0
  102. package/Sources/Combine/Publishers/Publishers.SwitchToLatest.swift +444 -0
  103. package/Sources/Combine/Publishers/Publishers.Throttle.swift +359 -0
  104. package/Sources/Combine/Publishers/Publishers.Timeout.swift +301 -0
  105. package/Sources/Combine/Publishers/Publishers.Zip.swift +720 -0
  106. package/Sources/Combine/Publishers/Publishers.swift +13 -0
  107. package/Sources/Combine/Publishers/Record.swift +237 -0
  108. package/Sources/Combine/Publishers/Result.Publisher.swift +337 -0
  109. package/Sources/Combine/Result.swift +46 -0
  110. package/Sources/Combine/Scheduler.swift +89 -0
  111. package/Sources/Combine/Schedulers.swift +211 -0
  112. package/Sources/Combine/Subject+Void.swift +17 -0
  113. package/Sources/Combine/Subscriber+Void.swift +20 -0
  114. package/Sources/Combine/Subscribers/Subscribers.Assign.swift +175 -0
  115. package/Sources/Combine/Subscribers/Subscribers.Completion.swift +90 -0
  116. package/Sources/Combine/Subscribers/Subscribers.Demand.swift +476 -0
  117. package/Sources/Combine/Subscribers/Subscribers.Sink.swift +206 -0
  118. package/Sources/Combine/Subscribers/Subscribers.swift +9 -0
  119. package/Sources/Combine/Subscription.swift +22 -0
  120. package/Sources/Combine/Subscriptions.swift +42 -0
  121. package/Sources/Combine/SwiftUIObservation.swift +10 -0
  122. package/Sources/Combine/_Introspection.swift +107 -0
  123. package/Sources/CommonCrypto/CommonCrypto.swift +80 -0
  124. package/Sources/Compression/Compression.swift +365 -0
  125. package/Sources/Compression/Deflate.swift +407 -0
  126. package/Sources/Compression/Zlib.swift +179 -0
  127. package/Sources/CoreFoundationTypes/CoreFoundationTypes.swift +101 -0
  128. package/Sources/CoreGraphics/CoreGraphics.swift +411 -0
  129. package/Sources/CoreGraphics/ProjectionTransforms.swift +28 -0
  130. package/Sources/CoreHaptics/CoreHaptics.swift +399 -0
  131. package/Sources/CoreImage/CIColor.swift +41 -0
  132. package/Sources/CoreImage/CIContext.swift +31 -0
  133. package/Sources/CoreImage/CIDetector.swift +57 -0
  134. package/Sources/CoreImage/CIFilter.swift +243 -0
  135. package/Sources/CoreImage/CIFilterBuiltins.swift +136 -0
  136. package/Sources/CoreImage/CIImage.swift +162 -0
  137. package/Sources/CoreImage/QRCode.swift +393 -0
  138. package/Sources/CoreLocation/Coordinate.swift +30 -0
  139. package/Sources/CoreLocation/Location.swift +65 -0
  140. package/Sources/CoreML/Evaluation.swift +414 -0
  141. package/Sources/CoreML/FeatureValue.swift +266 -0
  142. package/Sources/CoreML/Model.swift +269 -0
  143. package/Sources/CoreML/MultiArray.swift +92 -0
  144. package/Sources/CoreML/Specification.swift +233 -0
  145. package/Sources/CoreText/CoreText.swift +64 -0
  146. package/Sources/CoreTransferable/CoreTransferable.swift +606 -0
  147. package/Sources/CryptoKit/ChaChaPoly.swift +258 -0
  148. package/Sources/CryptoKit/CryptoKit.swift +375 -0
  149. package/Sources/CryptoKit/Curve25519.swift +317 -0
  150. package/Sources/CryptoKit/P256.swift +321 -0
  151. package/Sources/FoundationBridge/AppStorage.swift +165 -0
  152. package/Sources/FoundationBridge/AssetResources.swift +90 -0
  153. package/Sources/FoundationBridge/AsyncBytes.swift +128 -0
  154. package/Sources/FoundationBridge/AsyncImage.swift +116 -0
  155. package/Sources/FoundationBridge/AttributedStrings.swift +16 -0
  156. package/Sources/{_FoundationCommon → FoundationBridge}/Bundle.swift +41 -4
  157. package/Sources/FoundationBridge/CombineExports.swift +8 -0
  158. package/Sources/FoundationBridge/CoreFoundation.swift +77 -0
  159. package/Sources/FoundationBridge/Dispatch.swift +458 -0
  160. package/Sources/FoundationBridge/EnvironmentFoundation.swift +41 -0
  161. package/Sources/FoundationBridge/FileImporter.swift +128 -0
  162. package/Sources/FoundationBridge/FileSystem.swift +68 -0
  163. package/Sources/FoundationBridge/FoundationBridge.swift +24 -72
  164. package/Sources/FoundationBridge/HostResolution.swift +31 -0
  165. package/Sources/FoundationBridge/ItemProvider.swift +655 -0
  166. package/Sources/FoundationBridge/KeyValueObserving.swift +138 -0
  167. package/Sources/FoundationBridge/Links.swift +127 -0
  168. package/Sources/FoundationBridge/ListFormatter.swift +32 -0
  169. package/Sources/FoundationBridge/Localization.swift +149 -0
  170. package/Sources/FoundationBridge/Locks.swift +50 -0
  171. package/Sources/FoundationBridge/Markdown.swift +527 -0
  172. package/Sources/FoundationBridge/MeasurementFormat.swift +95 -0
  173. package/Sources/FoundationBridge/NotificationCenter.swift +154 -0
  174. package/Sources/FoundationBridge/OpenURLHandlers.swift +60 -0
  175. package/Sources/FoundationBridge/Operation.swift +195 -0
  176. package/Sources/FoundationBridge/ProcessInfo.swift +32 -0
  177. package/Sources/FoundationBridge/RelativeDateTimeFormatter.swift +136 -0
  178. package/Sources/FoundationBridge/SceneStorage.swift +78 -0
  179. package/Sources/FoundationBridge/SecurityExports.swift +8 -0
  180. package/Sources/FoundationBridge/Selector.swift +226 -0
  181. package/Sources/FoundationBridge/StringComparators.swift +17 -0
  182. package/Sources/FoundationBridge/Table.swift +211 -0
  183. package/Sources/FoundationBridge/TextAttributes.swift +42 -0
  184. package/Sources/FoundationBridge/Timer.swift +6 -1
  185. package/Sources/FoundationBridge/URLSession.swift +718 -0
  186. package/Sources/{_FoundationCommon → FoundationBridge}/UserDefaults.swift +17 -4
  187. package/Sources/FoundationBridge/WebAuthRedirects.swift +227 -0
  188. package/Sources/FoundationBridge/WebSocket.swift +187 -0
  189. package/Sources/FoundationModels/FoundationModels.swift +1098 -0
  190. package/Sources/ImageIO/GIF.swift +72 -0
  191. package/Sources/ImageIO/ImageIO.swift +248 -0
  192. package/Sources/ImageIO/ImageTypes.swift +28 -0
  193. package/Sources/LinkPresentation/LinkPresentation.swift +249 -0
  194. package/Sources/LocalAuthentication/LAContext.swift +86 -0
  195. package/Sources/MapKit/Geometry.swift +223 -0
  196. package/Sources/MapKit/Map.swift +638 -0
  197. package/Sources/MapKit/MapView.swift +229 -0
  198. package/Sources/MobileCoreServices/MobileCoreServices.swift +28 -0
  199. package/Sources/NaturalLanguage/LanguageIdentifier.swift +317 -0
  200. package/Sources/NaturalLanguage/NaturalLanguage.swift +135 -0
  201. package/Sources/OSLog/OSLog.swift +6 -0
  202. package/Sources/Photos/Photos.swift +572 -0
  203. package/Sources/PhotosUI/PhotosPicker.swift +248 -0
  204. package/Sources/PhotosUI/PhotosPickerItem.swift +261 -0
  205. package/Sources/QuickLook/QuickLook.swift +168 -0
  206. package/Sources/SafariServices/SafariServices.swift +106 -0
  207. package/Sources/Security/Security.swift +332 -0
  208. package/Sources/StoreKit/AppStore.swift +207 -0
  209. package/Sources/StoreKit/Products.swift +280 -0
  210. package/Sources/StoreKit/RequestReview.swift +28 -0
  211. package/Sources/StoreKit/StoreKit1.swift +486 -0
  212. package/Sources/StoreKit/StoreViews.swift +428 -0
  213. package/Sources/StoreKit/Transactions.swift +197 -0
  214. package/Sources/SwiftData/Macros.swift +58 -0
  215. package/Sources/SwiftData/ModelActor.swift +38 -0
  216. package/Sources/SwiftData/ModelContainer.swift +129 -0
  217. package/Sources/SwiftData/ModelContext.swift +451 -0
  218. package/Sources/SwiftData/PersistentModel.swift +238 -0
  219. package/Sources/SwiftData/Properties.swift +261 -0
  220. package/Sources/SwiftData/Query.swift +256 -0
  221. package/Sources/SwiftData/Schema.swift +192 -0
  222. package/Sources/SwiftData/Store.swift +146 -0
  223. package/Sources/SwiftData/StringPredicates.swift +125 -0
  224. package/Sources/SwiftDataMacros/EntryMacro.swift +82 -0
  225. package/Sources/SwiftDataMacros/GenerableMacro.swift +183 -0
  226. package/Sources/SwiftDataMacros/ModelActorMacro.swift +46 -0
  227. package/Sources/SwiftDataMacros/ModelMacro.swift +260 -0
  228. package/Sources/SwiftDataMacros/Plugin.swift +18 -0
  229. package/Sources/SwiftDataMacros/PredicateMacro.swift +1244 -0
  230. package/Sources/SwiftUI/API/Accessibility.swift +55 -6
  231. package/Sources/SwiftUI/API/AccessibilityExtras.swift +33 -0
  232. package/Sources/SwiftUI/API/AccessibilityFocus.swift +63 -0
  233. package/Sources/SwiftUI/API/Alert.swift +1 -1
  234. package/Sources/SwiftUI/API/AlignmentGuides.swift +65 -0
  235. package/Sources/SwiftUI/API/Animation.swift +37 -5
  236. package/Sources/SwiftUI/API/App.swift +31 -1
  237. package/Sources/SwiftUI/API/BindingCollections.swift +35 -0
  238. package/Sources/SwiftUI/API/BindingForEach.swift +27 -0
  239. package/Sources/SwiftUI/API/Bitmaps.swift +254 -0
  240. package/Sources/SwiftUI/API/ButtonStyles.swift +96 -0
  241. package/Sources/SwiftUI/API/Canvas.swift +337 -0
  242. package/Sources/SwiftUI/API/Color.swift +104 -28
  243. package/Sources/SwiftUI/API/ColorEffects.swift +52 -0
  244. package/Sources/SwiftUI/API/ColorPickerAndLabeledContent.swift +138 -0
  245. package/Sources/SwiftUI/API/ColorSpaces.swift +161 -0
  246. package/Sources/SwiftUI/API/Commands.swift +106 -0
  247. package/Sources/SwiftUI/API/ContainerBackground.swift +28 -0
  248. package/Sources/SwiftUI/API/ContentShape.swift +33 -0
  249. package/Sources/SwiftUI/API/ContentSizeCategory.swift +35 -0
  250. package/Sources/SwiftUI/API/ContentUnavailable.swift +101 -0
  251. package/Sources/SwiftUI/API/Controls.swift +59 -27
  252. package/Sources/SwiftUI/API/CustomLayout.swift +49 -10
  253. package/Sources/SwiftUI/API/CustomToolbarContent.swift +46 -0
  254. package/Sources/SwiftUI/API/Decorations.swift +1 -1
  255. package/Sources/SwiftUI/API/EditMode.swift +25 -82
  256. package/Sources/SwiftUI/API/Effects.swift +105 -7
  257. package/Sources/SwiftUI/API/Entry.swift +8 -0
  258. package/Sources/SwiftUI/API/Environment.swift +93 -9
  259. package/Sources/SwiftUI/API/EnvironmentSendable.swift +6 -0
  260. package/Sources/SwiftUI/API/Focus.swift +11 -3
  261. package/Sources/SwiftUI/API/Gauge.swift +3 -2
  262. package/Sources/SwiftUI/API/GeometryEffects.swift +232 -0
  263. package/Sources/SwiftUI/API/GeometryReader.swift +13 -2
  264. package/Sources/SwiftUI/API/GestureState.swift +65 -0
  265. package/Sources/SwiftUI/API/Gestures.swift +1 -1
  266. package/Sources/SwiftUI/API/Glass.swift +127 -0
  267. package/Sources/SwiftUI/API/Grid.swift +1 -1
  268. package/Sources/SwiftUI/API/GroupBoxAndControlGroup.swift +130 -0
  269. package/Sources/SwiftUI/API/KeyPress.swift +54 -0
  270. package/Sources/SwiftUI/API/LabelStyle.swift +13 -6
  271. package/Sources/SwiftUI/API/Layout.swift +67 -12
  272. package/Sources/SwiftUI/API/LazyStacks.swift +49 -0
  273. package/Sources/SwiftUI/API/LegacyAlert.swift +97 -0
  274. package/Sources/SwiftUI/API/Lists.swift +61 -6
  275. package/Sources/SwiftUI/API/Menu.swift +8 -1
  276. package/Sources/SwiftUI/API/Modifiers.swift +80 -10
  277. package/Sources/SwiftUI/API/MoreModifiers.swift +100 -0
  278. package/Sources/SwiftUI/API/Namespace.swift +44 -0
  279. package/Sources/SwiftUI/API/Navigation.swift +24 -9
  280. package/Sources/SwiftUI/API/NavigationDestinationBindings.swift +55 -0
  281. package/Sources/SwiftUI/API/ObservableObject.swift +16 -2
  282. package/Sources/SwiftUI/API/Path.swift +543 -0
  283. package/Sources/SwiftUI/API/Phase8Controls.swift +48 -31
  284. package/Sources/SwiftUI/API/PhaseAnimator.swift +130 -0
  285. package/Sources/SwiftUI/API/Picker.swift +11 -2
  286. package/Sources/SwiftUI/API/PointerAndKeyboard.swift +77 -0
  287. package/Sources/SwiftUI/API/Popover.swift +41 -0
  288. package/Sources/SwiftUI/API/Preferences.swift +262 -0
  289. package/Sources/SwiftUI/API/Presentation.swift +17 -4
  290. package/Sources/SwiftUI/API/PresentationExtras.swift +60 -0
  291. package/Sources/SwiftUI/API/Primitives.swift +164 -37
  292. package/Sources/SwiftUI/API/Publishers.swift +4 -4
  293. package/Sources/SwiftUI/API/Redaction.swift +75 -0
  294. package/Sources/SwiftUI/API/RowActions.swift +3 -2
  295. package/Sources/SwiftUI/API/Scenes.swift +131 -0
  296. package/Sources/SwiftUI/API/ScrollModifiers.swift +132 -0
  297. package/Sources/SwiftUI/API/ScrollTargets.swift +3 -3
  298. package/Sources/SwiftUI/API/ScrollViewReader.swift +144 -0
  299. package/Sources/SwiftUI/API/SectionSupplements.swift +96 -0
  300. package/Sources/SwiftUI/API/Shape.swift +214 -0
  301. package/Sources/SwiftUI/API/ShapeStyle.swift +105 -7
  302. package/Sources/SwiftUI/API/ShapeTrim.swift +78 -0
  303. package/Sources/SwiftUI/API/Sharing.swift +193 -0
  304. package/Sources/SwiftUI/API/StackLayouts.swift +199 -0
  305. package/Sources/SwiftUI/API/State.swift +18 -1
  306. package/Sources/SwiftUI/API/StatusGaps.swift +121 -0
  307. package/Sources/SwiftUI/API/SymbolEffects.swift +203 -0
  308. package/Sources/SwiftUI/API/TabContent.swift +841 -0
  309. package/Sources/SwiftUI/API/Table.swift +382 -0
  310. package/Sources/SwiftUI/API/Tabs.swift +148 -4
  311. package/Sources/SwiftUI/API/Tasks.swift +2 -2
  312. package/Sources/SwiftUI/API/Text.swift +386 -0
  313. package/Sources/SwiftUI/API/TextDates.swift +61 -0
  314. package/Sources/SwiftUI/API/TextDecorations.swift +52 -0
  315. package/Sources/SwiftUI/API/TextFieldAxis.swift +103 -0
  316. package/Sources/SwiftUI/API/TextFieldCommit.swift +52 -0
  317. package/Sources/SwiftUI/API/Toolbar.swift +52 -16
  318. package/Sources/SwiftUI/API/Transfer.swift +145 -0
  319. package/Sources/SwiftUI/API/UnevenRoundedRectangle.swift +66 -0
  320. package/Sources/SwiftUI/API/Video.swift +64 -0
  321. package/Sources/SwiftUI/API/View.swift +10 -2
  322. package/Sources/SwiftUI/API/ViewModifier.swift +4 -1
  323. package/Sources/SwiftUI/API/VisualEffect.swift +74 -1
  324. package/Sources/SwiftUI/API/Windows.swift +25 -0
  325. package/Sources/SwiftUI/Charts/Axis.swift +7 -1
  326. package/Sources/SwiftUI/Charts/AxisFormatsAndRanges.swift +68 -0
  327. package/Sources/SwiftUI/Charts/Chart.swift +17 -3
  328. package/Sources/SwiftUI/Charts/ChartProxy.swift +57 -0
  329. package/Sources/SwiftUI/Localization/Localization.swift +498 -0
  330. package/Sources/SwiftUI/Localization/PluralRules.swift +127 -0
  331. package/Sources/SwiftUI/Runtime/Executor.swift +2 -0
  332. package/Sources/SwiftUI/Runtime/Exports.swift +37 -1
  333. package/Sources/SwiftUI/Runtime/ImageSource.swift +310 -0
  334. package/Sources/SwiftUI/Runtime/JSON.swift +76 -4
  335. package/Sources/SwiftUI/Runtime/LazyRows.swift +99 -0
  336. package/Sources/SwiftUI/Runtime/Measurements.swift +140 -0
  337. package/Sources/SwiftUI/Runtime/Ops.swift +58 -12
  338. package/Sources/SwiftUI/Runtime/Reconciler.swift +10 -1
  339. package/Sources/SwiftUI/Runtime/Replay.swift +382 -0
  340. package/Sources/SwiftUI/Runtime/Runtime.swift +977 -198
  341. package/Sources/SwiftUI/Runtime/Sameness.swift +152 -0
  342. package/Sources/SwiftUI/Runtime/ViewPath.swift +89 -0
  343. package/Sources/SwiftUI/Runtime/ViewTraits.swift +175 -0
  344. package/Sources/SwiftUI/Runtime/WebAuthHeadless.swift +49 -0
  345. package/Sources/Symbols/Symbols.swift +25 -0
  346. package/Sources/Translation/Translation.swift +423 -0
  347. package/Sources/UIKit/Activity.swift +213 -0
  348. package/Sources/UIKit/Alerts.swift +69 -0
  349. package/Sources/UIKit/AppDelegate.swift +222 -0
  350. package/Sources/UIKit/Appearance.swift +84 -0
  351. package/Sources/UIKit/ColorConversions.swift +70 -0
  352. package/Sources/UIKit/Controls.swift +225 -0
  353. package/Sources/UIKit/Device.swift +200 -0
  354. package/Sources/UIKit/Feedback.swift +65 -0
  355. package/Sources/UIKit/Font.swift +307 -0
  356. package/Sources/UIKit/Graphics.swift +204 -0
  357. package/Sources/UIKit/HostingController.swift +185 -0
  358. package/Sources/UIKit/Identity.swift +24 -0
  359. package/Sources/UIKit/Introspectable.swift +510 -0
  360. package/Sources/UIKit/Pasteboard.swift +363 -0
  361. package/Sources/UIKit/PhotoAlbum.swift +81 -0
  362. package/Sources/UIKit/RemoteNotifications.swift +15 -0
  363. package/Sources/UIKit/Representable.swift +288 -0
  364. package/Sources/UIKit/SafeArea.swift +12 -0
  365. package/Sources/UIKit/SceneDelegates.swift +132 -0
  366. package/Sources/UIKit/Scenes.swift +40 -0
  367. package/Sources/UIKit/ScrollView.swift +157 -0
  368. package/Sources/UIKit/ShortcutItems.swift +67 -0
  369. package/Sources/UIKit/SymbolConfiguration.swift +124 -0
  370. package/Sources/UIKit/TargetAction.swift +123 -0
  371. package/Sources/UIKit/TextPaste.swift +161 -0
  372. package/Sources/UIKit/TextView.swift +538 -0
  373. package/Sources/UIKit/UIKit.swift +292 -0
  374. package/Sources/UIKit/UIView.swift +855 -0
  375. package/Sources/UIKit/ViewTranslation.swift +311 -0
  376. package/Sources/UniformTypeIdentifiers/UTType.swift +196 -0
  377. package/Sources/UserNotifications/Content.swift +370 -0
  378. package/Sources/UserNotifications/NotificationCenter.swift +309 -0
  379. package/Sources/WeatherKit/WeatherKit.swift +228 -0
  380. package/Sources/WebKit/WebKit.swift +245 -0
  381. package/Sources/os/os.swift +376 -0
  382. package/Sources/zlib/zlib.swift +6 -0
  383. package/index.d.ts +1 -1
  384. package/index.mjs +2 -2
  385. package/manifest.d.mts +2 -0
  386. package/manifest.mjs +39 -0
  387. package/package.json +5 -3
  388. package/sync-sources.mjs +21 -7
  389. package/Sources/FoundationLite/Common.swift +0 -3
  390. package/Sources/FoundationLite/FoundationLite.swift +0 -171
  391. package/Sources/FoundationLite/Interaction.swift +0 -146
  392. package/Sources/FoundationLite/Timer.swift +0 -48
  393. package/Sources/_FoundationCommon/_FoundationCommon.swift +0 -10
@@ -0,0 +1,258 @@
1
+ // ChaCha20-Poly1305 (RFC 8439), CryptoKit's `ChaChaPoly`, with the
2
+ // `SymmetricKey` it takes, in plain Swift. A sealed box is the 12-byte
3
+ // nonce, the ciphertext and the 16-byte tag; `combined` joins them in that
4
+ // order, as CryptoKit does. Opening checks the tag before decrypting and
5
+ // fails with `CryptoKitError.authenticationFailure`.
6
+
7
+ import struct Foundation.Data
8
+ import protocol Foundation.ContiguousBytes
9
+ import protocol Foundation.DataProtocol
10
+
11
+ // MARK: - Symmetric keys
12
+
13
+ /// A key's size in bits.
14
+ public struct SymmetricKeySize: Sendable {
15
+ public let bitCount: Int
16
+
17
+ public init(bitCount: Int) {
18
+ precondition(bitCount > 0 && bitCount % 8 == 0, "a key's size is a positive number of bytes")
19
+ self.bitCount = bitCount
20
+ }
21
+
22
+ public static let bits128 = SymmetricKeySize(bitCount: 128)
23
+ public static let bits192 = SymmetricKeySize(bitCount: 192)
24
+ public static let bits256 = SymmetricKeySize(bitCount: 256)
25
+ }
26
+
27
+ /// A symmetric key: its bytes.
28
+ public struct SymmetricKey: ContiguousBytes, Sendable {
29
+ let bytes: [UInt8]
30
+
31
+ /// A new random key of `size`.
32
+ public init(size: SymmetricKeySize) {
33
+ var generator = SystemRandomNumberGenerator()
34
+ bytes = (0..<size.bitCount / 8).map { _ in UInt8.random(in: .min ... .max, using: &generator) }
35
+ }
36
+
37
+ public init<D: ContiguousBytes>(data: D) {
38
+ bytes = data.withUnsafeBytes { Array($0) }
39
+ }
40
+
41
+ public var bitCount: Int { bytes.count * 8 }
42
+
43
+ public func withUnsafeBytes<R>(_ body: (UnsafeRawBufferPointer) throws -> R) rethrows -> R {
44
+ try bytes.withUnsafeBytes(body)
45
+ }
46
+ }
47
+
48
+ // MARK: - ChaChaPoly
49
+
50
+ public enum ChaChaPoly {
51
+ /// A 12-byte nonce; a new one is random.
52
+ public struct Nonce: ContiguousBytes, Sequence, Sendable {
53
+ let bytes: [UInt8]
54
+
55
+ public init() {
56
+ var generator = SystemRandomNumberGenerator()
57
+ bytes = (0..<12).map { _ in UInt8.random(in: .min ... .max, using: &generator) }
58
+ }
59
+
60
+ public init<D: DataProtocol>(data: D) throws {
61
+ let bytes = Array(data)
62
+ guard bytes.count == 12 else { throw CryptoKitError.incorrectParameterSize }
63
+ self.bytes = bytes
64
+ }
65
+
66
+ public func makeIterator() -> Array<UInt8>.Iterator { bytes.makeIterator() }
67
+
68
+ public func withUnsafeBytes<R>(_ body: (UnsafeRawBufferPointer) throws -> R) rethrows -> R {
69
+ try bytes.withUnsafeBytes(body)
70
+ }
71
+ }
72
+
73
+ /// A message sealed with a key: nonce, ciphertext and tag.
74
+ public struct SealedBox: Sendable {
75
+ public let nonce: Nonce
76
+ public let ciphertext: Data
77
+ public let tag: Data
78
+
79
+ /// `nonce ‖ ciphertext ‖ tag`.
80
+ public var combined: Data { Data(nonce.bytes) + ciphertext + tag }
81
+
82
+ public init<D: DataProtocol>(combined data: D) throws {
83
+ let bytes = Array(data)
84
+ guard bytes.count >= 28 else { throw CryptoKitError.incorrectParameterSize }
85
+ nonce = try Nonce(data: bytes[0..<12])
86
+ ciphertext = Data(bytes[12..<(bytes.count - 16)])
87
+ tag = Data(bytes[(bytes.count - 16)...])
88
+ }
89
+
90
+ public init<C: DataProtocol, T: DataProtocol>(nonce: Nonce, ciphertext: C, tag: T) throws {
91
+ guard tag.count == 16 else { throw CryptoKitError.incorrectParameterSize }
92
+ self.nonce = nonce
93
+ self.ciphertext = Data(ciphertext)
94
+ self.tag = Data(tag)
95
+ }
96
+ }
97
+
98
+ public static func seal<Plaintext: DataProtocol>(_ message: Plaintext, using key: SymmetricKey, nonce: Nonce? = nil) throws -> SealedBox {
99
+ try seal(message, using: key, nonce: nonce, authenticating: [UInt8]())
100
+ }
101
+
102
+ public static func seal<Plaintext: DataProtocol, AuthenticatedData: DataProtocol>(
103
+ _ message: Plaintext, using key: SymmetricKey, nonce: Nonce? = nil, authenticating authenticatedData: AuthenticatedData
104
+ ) throws -> SealedBox {
105
+ guard key.bytes.count == 32 else { throw CryptoKitError.incorrectKeySize }
106
+ let nonce = nonce ?? Nonce()
107
+ let ciphertext = _ChaCha20.xor(Array(message), key: key.bytes, nonce: nonce.bytes, counter: 1)
108
+ let tag = _ChaCha20.tag(key: key.bytes, nonce: nonce.bytes, authenticatedData: Array(authenticatedData), ciphertext: ciphertext)
109
+ return try SealedBox(nonce: nonce, ciphertext: ciphertext, tag: tag)
110
+ }
111
+
112
+ public static func open(_ sealedBox: SealedBox, using key: SymmetricKey) throws -> Data {
113
+ try open(sealedBox, using: key, authenticating: [UInt8]())
114
+ }
115
+
116
+ public static func open<AuthenticatedData: DataProtocol>(
117
+ _ sealedBox: SealedBox, using key: SymmetricKey, authenticating authenticatedData: AuthenticatedData
118
+ ) throws -> Data {
119
+ guard key.bytes.count == 32 else { throw CryptoKitError.incorrectKeySize }
120
+ let ciphertext = Array(sealedBox.ciphertext)
121
+ let expected = _ChaCha20.tag(key: key.bytes, nonce: sealedBox.nonce.bytes, authenticatedData: Array(authenticatedData), ciphertext: ciphertext)
122
+ // Compared in full, whatever differs.
123
+ guard zip(expected, sealedBox.tag).reduce(UInt8(0), { $0 | ($1.0 ^ $1.1) }) == 0 else {
124
+ throw CryptoKitError.authenticationFailure
125
+ }
126
+ return Data(_ChaCha20.xor(ciphertext, key: key.bytes, nonce: sealedBox.nonce.bytes, counter: 1))
127
+ }
128
+ }
129
+
130
+ // MARK: - ChaCha20 and Poly1305
131
+
132
+ enum _ChaCha20 {
133
+ /// The 64-byte keystream block for `counter`.
134
+ static func block(key: [UInt8], nonce: [UInt8], counter: UInt32) -> [UInt8] {
135
+ func word(_ bytes: [UInt8], _ index: Int) -> UInt32 {
136
+ (0..<4).reduce(UInt32(0)) { $0 | UInt32(bytes[index * 4 + $1]) << (8 * $1) }
137
+ }
138
+ var state: [UInt32] = [0x6170_7865, 0x3320_646E, 0x7962_2D32, 0x6B20_6574]
139
+ state += (0..<8).map { word(key, $0) }
140
+ state.append(counter)
141
+ state += (0..<3).map { word(nonce, $0) }
142
+ var working = state
143
+ func quarterRound(_ a: Int, _ b: Int, _ c: Int, _ d: Int) {
144
+ working[a] &+= working[b]; working[d] ^= working[a]; working[d] = working[d].rotatedLeft(16)
145
+ working[c] &+= working[d]; working[b] ^= working[c]; working[b] = working[b].rotatedLeft(12)
146
+ working[a] &+= working[b]; working[d] ^= working[a]; working[d] = working[d].rotatedLeft(8)
147
+ working[c] &+= working[d]; working[b] ^= working[c]; working[b] = working[b].rotatedLeft(7)
148
+ }
149
+ for _ in 0..<10 {
150
+ quarterRound(0, 4, 8, 12); quarterRound(1, 5, 9, 13); quarterRound(2, 6, 10, 14); quarterRound(3, 7, 11, 15)
151
+ quarterRound(0, 5, 10, 15); quarterRound(1, 6, 11, 12); quarterRound(2, 7, 8, 13); quarterRound(3, 4, 9, 14)
152
+ }
153
+ return (0..<16).flatMap { i -> [UInt8] in
154
+ let value = working[i] &+ state[i]
155
+ return (0..<4).map { UInt8(truncatingIfNeeded: value >> (8 * $0)) }
156
+ }
157
+ }
158
+
159
+ /// `bytes` XORed with the keystream from block `counter` on.
160
+ static func xor(_ bytes: [UInt8], key: [UInt8], nonce: [UInt8], counter: UInt32) -> [UInt8] {
161
+ var output = bytes
162
+ var blockCounter = counter
163
+ var offset = 0
164
+ while offset < bytes.count {
165
+ let stream = block(key: key, nonce: nonce, counter: blockCounter)
166
+ for i in 0..<min(64, bytes.count - offset) { output[offset + i] ^= stream[i] }
167
+ offset += 64
168
+ blockCounter &+= 1
169
+ }
170
+ return output
171
+ }
172
+
173
+ /// The AEAD tag: Poly1305, keyed by block 0, over the padded authenticated
174
+ /// data and ciphertext and their lengths.
175
+ static func tag(key: [UInt8], nonce: [UInt8], authenticatedData: [UInt8], ciphertext: [UInt8]) -> [UInt8] {
176
+ let oneTimeKey = Array(block(key: key, nonce: nonce, counter: 0)[0..<32])
177
+ func padded(_ bytes: [UInt8]) -> [UInt8] { bytes + [UInt8](repeating: 0, count: (16 - bytes.count % 16) % 16) }
178
+ func length(_ count: Int) -> [UInt8] { (0..<8).map { UInt8(truncatingIfNeeded: UInt64(count) >> (8 * $0)) } }
179
+ let message = padded(authenticatedData) + padded(ciphertext) + length(authenticatedData.count) + length(ciphertext.count)
180
+ return _Poly1305.authenticate(message, key: oneTimeKey)
181
+ }
182
+ }
183
+
184
+ /// Poly1305 with five 26-bit limbs (as poly1305-donna's 32-bit form).
185
+ enum _Poly1305 {
186
+ static func authenticate(_ message: [UInt8], key: [UInt8]) -> [UInt8] {
187
+ func load32(_ bytes: [UInt8], _ index: Int) -> UInt32 {
188
+ (0..<4).reduce(UInt32(0)) { $0 | UInt32(bytes[index + $1]) << (8 * $1) }
189
+ }
190
+ let r0 = load32(key, 0) & 0x3FF_FFFF
191
+ let r1 = (load32(key, 3) >> 2) & 0x3FF_FF03
192
+ let r2 = (load32(key, 6) >> 4) & 0x3FF_C0FF
193
+ let r3 = (load32(key, 9) >> 6) & 0x3F0_3FFF
194
+ let r4 = (load32(key, 12) >> 8) & 0x00F_FFFF
195
+ let (s1, s2, s3, s4) = (r1 * 5, r2 * 5, r3 * 5, r4 * 5)
196
+ var (h0, h1, h2, h3, h4): (UInt32, UInt32, UInt32, UInt32, UInt32) = (0, 0, 0, 0, 0)
197
+
198
+ var offset = 0
199
+ while offset < message.count {
200
+ var block = [UInt8](repeating: 0, count: 17)
201
+ let count = min(16, message.count - offset)
202
+ for i in 0..<count { block[i] = message[offset + i] }
203
+ block[count] = 1
204
+ h0 &+= load32(block, 0) & 0x3FF_FFFF
205
+ h1 &+= (load32(block, 3) >> 2) & 0x3FF_FFFF
206
+ h2 &+= (load32(block, 6) >> 4) & 0x3FF_FFFF
207
+ h3 &+= (load32(block, 9) >> 6) & 0x3FF_FFFF
208
+ h4 &+= (load32(block, 12) >> 8) | (UInt32(block[16]) << 24)
209
+
210
+ func m(_ a: UInt32, _ b: UInt32) -> UInt64 { UInt64(a) * UInt64(b) }
211
+ let d0 = m(h0, r0) + m(h1, s4) + m(h2, s3) + m(h3, s2) + m(h4, s1)
212
+ var d1 = m(h0, r1) + m(h1, r0) + m(h2, s4) + m(h3, s3) + m(h4, s2)
213
+ var d2 = m(h0, r2) + m(h1, r1) + m(h2, r0) + m(h3, s4) + m(h4, s3)
214
+ var d3 = m(h0, r3) + m(h1, r2) + m(h2, r1) + m(h3, r0) + m(h4, s4)
215
+ var d4 = m(h0, r4) + m(h1, r3) + m(h2, r2) + m(h3, r1) + m(h4, r0)
216
+
217
+ var carry = d0 >> 26; h0 = UInt32(d0 & 0x3FF_FFFF)
218
+ d1 += carry; carry = d1 >> 26; h1 = UInt32(d1 & 0x3FF_FFFF)
219
+ d2 += carry; carry = d2 >> 26; h2 = UInt32(d2 & 0x3FF_FFFF)
220
+ d3 += carry; carry = d3 >> 26; h3 = UInt32(d3 & 0x3FF_FFFF)
221
+ d4 += carry; carry = d4 >> 26; h4 = UInt32(d4 & 0x3FF_FFFF)
222
+ h0 &+= UInt32(carry) &* 5; let c = h0 >> 26; h0 &= 0x3FF_FFFF
223
+ h1 &+= c
224
+ offset += 16
225
+ }
226
+
227
+ // Full carry, then h mod 2¹³⁰ − 5.
228
+ var c = h1 >> 26; h1 &= 0x3FF_FFFF
229
+ h2 &+= c; c = h2 >> 26; h2 &= 0x3FF_FFFF
230
+ h3 &+= c; c = h3 >> 26; h3 &= 0x3FF_FFFF
231
+ h4 &+= c; c = h4 >> 26; h4 &= 0x3FF_FFFF
232
+ h0 &+= c &* 5; c = h0 >> 26; h0 &= 0x3FF_FFFF
233
+ h1 &+= c
234
+
235
+ var g0 = h0 &+ 5; c = g0 >> 26; g0 &= 0x3FF_FFFF
236
+ var g1 = h1 &+ c; c = g1 >> 26; g1 &= 0x3FF_FFFF
237
+ var g2 = h2 &+ c; c = g2 >> 26; g2 &= 0x3FF_FFFF
238
+ var g3 = h3 &+ c; c = g3 >> 26; g3 &= 0x3FF_FFFF
239
+ let g4 = h4 &+ c &- (1 << 26)
240
+ // h − p when that is not negative.
241
+ if g4 >> 31 == 0 { (h0, h1, h2, h3, h4) = (g0, g1, g2, g3, g4) }
242
+
243
+ // h as 128 bits, plus s.
244
+ let w0 = h0 | h1 << 26
245
+ let w1 = h1 >> 6 | h2 << 20
246
+ let w2 = h2 >> 12 | h3 << 14
247
+ let w3 = h3 >> 18 | h4 << 8
248
+ var f = UInt64(w0) + UInt64(load32(key, 16)); let t0 = UInt32(truncatingIfNeeded: f)
249
+ f = UInt64(w1) + UInt64(load32(key, 20)) + (f >> 32); let t1 = UInt32(truncatingIfNeeded: f)
250
+ f = UInt64(w2) + UInt64(load32(key, 24)) + (f >> 32); let t2 = UInt32(truncatingIfNeeded: f)
251
+ f = UInt64(w3) + UInt64(load32(key, 28)) + (f >> 32); let t3 = UInt32(truncatingIfNeeded: f)
252
+ return [t0, t1, t2, t3].flatMap { word in (0..<4).map { UInt8(truncatingIfNeeded: word >> (8 * $0)) } }
253
+ }
254
+ }
255
+
256
+ extension UInt32 {
257
+ func rotatedLeft(_ count: UInt32) -> UInt32 { self << count | self >> (32 - count) }
258
+ }
@@ -0,0 +1,375 @@
1
+ // `import CryptoKit` for the browser: the hash functions (SHA-1, SHA-256,
2
+ // SHA-384, SHA-512 and MD5) in plain Swift, with CryptoKit's API, which is
3
+ // what packages use it for (cache file names, content digests). Keys,
4
+ // ciphers and signatures are not here: code that needs them is a compile
5
+ // error in the browser build.
6
+
7
+ import struct Foundation.Data
8
+
9
+ /// A hash function.
10
+ public protocol HashFunction: Sendable {
11
+ associatedtype Digest: CryptoKit.Digest
12
+ static var blockByteCount: Int { get }
13
+ init()
14
+ mutating func update(bufferPointer: UnsafeRawBufferPointer)
15
+ func finalize() -> Digest
16
+ }
17
+
18
+ extension HashFunction {
19
+ public mutating func update<D: DataProtocol>(data: D) {
20
+ let bytes = [UInt8](data)
21
+ bytes.withUnsafeBytes { update(bufferPointer: $0) }
22
+ }
23
+
24
+ public static func hash<D: DataProtocol>(data: D) -> Digest {
25
+ var hasher = Self()
26
+ hasher.update(data: data)
27
+ return hasher.finalize()
28
+ }
29
+ }
30
+
31
+ /// A hash's output: a sequence of bytes.
32
+ public protocol Digest: Hashable, Sequence, CustomStringConvertible, Sendable where Element == UInt8 {
33
+ static var byteCount: Int { get }
34
+ var bytes: [UInt8] { get }
35
+ }
36
+
37
+ extension Digest {
38
+ public func makeIterator() -> Array<UInt8>.Iterator { bytes.makeIterator() }
39
+ public func withUnsafeBytes<R>(_ body: (UnsafeRawBufferPointer) throws -> R) rethrows -> R { try bytes.withUnsafeBytes(body) }
40
+ public var description: String {
41
+ "\(Self.self): \(bytes.map { ($0 < 16 ? "0" : "") + String($0, radix: 16) }.joined())"
42
+ }
43
+ }
44
+
45
+ import protocol Foundation.DataProtocol
46
+
47
+ // MARK: - SHA-2
48
+
49
+ public struct SHA256Digest: Digest {
50
+ public static let byteCount = 32
51
+ public let bytes: [UInt8]
52
+ }
53
+
54
+ public struct SHA384Digest: Digest {
55
+ public static let byteCount = 48
56
+ public let bytes: [UInt8]
57
+ }
58
+
59
+ public struct SHA512Digest: Digest {
60
+ public static let byteCount = 64
61
+ public let bytes: [UInt8]
62
+ }
63
+
64
+ public struct SHA256: HashFunction {
65
+ public static let blockByteCount = 64
66
+ public static let byteCount = 32
67
+ var state = _SHA32(initial: [0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19])
68
+
69
+ public init() {}
70
+ public mutating func update(bufferPointer: UnsafeRawBufferPointer) { state.update(bufferPointer) }
71
+ public func finalize() -> SHA256Digest { SHA256Digest(bytes: state.finalize(words: 8)) }
72
+ }
73
+
74
+ public struct SHA384: HashFunction {
75
+ public static let blockByteCount = 128
76
+ public static let byteCount = 48
77
+ var state = _SHA64(initial: [0xcbbb9d5dc1059ed8, 0x629a292a367cd507, 0x9159015a3070dd17, 0x152fecd8f70e5939,
78
+ 0x67332667ffc00b31, 0x8eb44a8768581511, 0xdb0c2e0d64f98fa7, 0x47b5481dbefa4fa4])
79
+
80
+ public init() {}
81
+ public mutating func update(bufferPointer: UnsafeRawBufferPointer) { state.update(bufferPointer) }
82
+ public func finalize() -> SHA384Digest { SHA384Digest(bytes: state.finalize(words: 6)) }
83
+ }
84
+
85
+ public struct SHA512: HashFunction {
86
+ public static let blockByteCount = 128
87
+ public static let byteCount = 64
88
+ var state = _SHA64(initial: [0x6a09e667f3bcc908, 0xbb67ae8584caa73b, 0x3c6ef372fe94f82b, 0xa54ff53a5f1d36f1,
89
+ 0x510e527fade682d1, 0x9b05688c2b3e6c1f, 0x1f83d9abfb41bd6b, 0x5be0cd19137e2179])
90
+
91
+ public init() {}
92
+ public mutating func update(bufferPointer: UnsafeRawBufferPointer) { state.update(bufferPointer) }
93
+ public func finalize() -> SHA512Digest { SHA512Digest(bytes: state.finalize(words: 8)) }
94
+ }
95
+
96
+ /// The insecure hash functions, kept for compatibility (file names, checksums).
97
+ public enum Insecure {
98
+ public struct SHA1Digest: Digest {
99
+ public static let byteCount = 20
100
+ public let bytes: [UInt8]
101
+ }
102
+
103
+ public struct MD5Digest: Digest {
104
+ public static let byteCount = 16
105
+ public let bytes: [UInt8]
106
+ }
107
+
108
+ public struct SHA1: HashFunction {
109
+ public static let blockByteCount = 64
110
+ public static let byteCount = 20
111
+ var buffer = _Blocks(size: 64)
112
+ var h: [UInt32] = [0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0]
113
+
114
+ public init() {}
115
+
116
+ public mutating func update(bufferPointer: UnsafeRawBufferPointer) {
117
+ var h = self.h
118
+ buffer.append(bufferPointer) { block in Self.compress(&h, block) }
119
+ self.h = h
120
+ }
121
+
122
+ public func finalize() -> SHA1Digest {
123
+ var copy = self
124
+ var h = copy.h
125
+ copy.buffer.pad(lengthBytes: 8, bigEndian: true) { block in Self.compress(&h, block) }
126
+ return SHA1Digest(bytes: h.flatMap { _bigEndianBytes($0) })
127
+ }
128
+
129
+ static func compress(_ h: inout [UInt32], _ block: [UInt8]) {
130
+ var w = [UInt32](repeating: 0, count: 80)
131
+ for i in 0..<16 { w[i] = _word32(block, i * 4) }
132
+ for i in 16..<80 { w[i] = _rotl(w[i - 3] ^ w[i - 8] ^ w[i - 14] ^ w[i - 16], 1) }
133
+ var (a, b, c, d, e) = (h[0], h[1], h[2], h[3], h[4])
134
+ for i in 0..<80 {
135
+ let (f, k): (UInt32, UInt32) = switch i {
136
+ case 0..<20: ((b & c) | (~b & d), 0x5A827999)
137
+ case 20..<40: (b ^ c ^ d, 0x6ED9EBA1)
138
+ case 40..<60: ((b & c) | (b & d) | (c & d), 0x8F1BBCDC)
139
+ default: (b ^ c ^ d, 0xCA62C1D6)
140
+ }
141
+ let t = _rotl(a, 5) &+ f &+ e &+ k &+ w[i]
142
+ (e, d, c, b, a) = (d, c, _rotl(b, 30), a, t)
143
+ }
144
+ h[0] &+= a; h[1] &+= b; h[2] &+= c; h[3] &+= d; h[4] &+= e
145
+ }
146
+ }
147
+
148
+ public struct MD5: HashFunction {
149
+ public static let blockByteCount = 64
150
+ public static let byteCount = 16
151
+ var buffer = _Blocks(size: 64)
152
+ var h: [UInt32] = [0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476]
153
+
154
+ public init() {}
155
+
156
+ public mutating func update(bufferPointer: UnsafeRawBufferPointer) {
157
+ var h = self.h
158
+ buffer.append(bufferPointer) { block in Self.compress(&h, block) }
159
+ self.h = h
160
+ }
161
+
162
+ public func finalize() -> MD5Digest {
163
+ var copy = self
164
+ var h = copy.h
165
+ copy.buffer.pad(lengthBytes: 8, bigEndian: false) { block in Self.compress(&h, block) }
166
+ return MD5Digest(bytes: h.flatMap { word in (0..<4).map { UInt8(truncatingIfNeeded: word >> ($0 * 8)) } })
167
+ }
168
+
169
+ static let s: [UInt32] = [7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22,
170
+ 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20,
171
+ 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23,
172
+ 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21]
173
+ static let k: [UInt32] = (0..<64).map { UInt32(truncatingIfNeeded: Int64(abs(_sin(Double($0 + 1))) * 4294967296.0)) }
174
+
175
+ static func compress(_ h: inout [UInt32], _ block: [UInt8]) {
176
+ var m = [UInt32](repeating: 0, count: 16)
177
+ for i in 0..<16 {
178
+ m[i] = UInt32(block[i * 4]) | UInt32(block[i * 4 + 1]) << 8 | UInt32(block[i * 4 + 2]) << 16 | UInt32(block[i * 4 + 3]) << 24
179
+ }
180
+ var (a, b, c, d) = (h[0], h[1], h[2], h[3])
181
+ for i in 0..<64 {
182
+ var f: UInt32
183
+ let g: Int
184
+ switch i {
185
+ case 0..<16: f = (b & c) | (~b & d); g = i
186
+ case 16..<32: f = (d & b) | (~d & c); g = (5 * i + 1) % 16
187
+ case 32..<48: f = b ^ c ^ d; g = (3 * i + 5) % 16
188
+ default: f = c ^ (b | ~d); g = (7 * i) % 16
189
+ }
190
+ f = f &+ a &+ k[i] &+ m[g]
191
+ a = d; d = c; c = b
192
+ b = b &+ _rotl(f, s[i])
193
+ }
194
+ h[0] &+= a; h[1] &+= b; h[2] &+= c; h[3] &+= d
195
+ }
196
+ }
197
+ }
198
+
199
+ // MARK: - Internals
200
+
201
+ /// Buffers input into blocks, and pads the last one (Merkle–Damgård).
202
+ struct _Blocks: Sendable {
203
+ let size: Int
204
+ var pending: [UInt8] = []
205
+ var length: UInt64 = 0
206
+
207
+ init(size: Int) { self.size = size }
208
+
209
+ mutating func append(_ bytes: UnsafeRawBufferPointer, _ compress: ([UInt8]) -> Void) {
210
+ length &+= UInt64(bytes.count)
211
+ pending.append(contentsOf: bytes)
212
+ var start = 0
213
+ while pending.count - start >= size {
214
+ compress(Array(pending[start..<start + size]))
215
+ start += size
216
+ }
217
+ pending.removeFirst(start)
218
+ }
219
+
220
+ mutating func pad(lengthBytes: Int, bigEndian: Bool, _ compress: ([UInt8]) -> Void) {
221
+ let bits = length &* 8
222
+ var tail = pending + [0x80]
223
+ while (tail.count + lengthBytes) % size != 0 { tail.append(0) }
224
+ var lengthField = [UInt8](repeating: 0, count: lengthBytes)
225
+ for i in 0..<min(8, lengthBytes) {
226
+ let byte = UInt8(truncatingIfNeeded: bits >> (UInt64(i) * 8))
227
+ if bigEndian { lengthField[lengthBytes - 1 - i] = byte } else { lengthField[i] = byte }
228
+ }
229
+ tail += lengthField
230
+ var start = 0
231
+ while start < tail.count {
232
+ compress(Array(tail[start..<start + size]))
233
+ start += size
234
+ }
235
+ pending = []
236
+ }
237
+ }
238
+
239
+ /// SHA-224/256's state.
240
+ struct _SHA32: Sendable {
241
+ var buffer = _Blocks(size: 64)
242
+ var h: [UInt32]
243
+
244
+ init(initial: [UInt32]) { h = initial }
245
+
246
+ static let k: [UInt32] = [
247
+ 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
248
+ 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
249
+ 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
250
+ 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
251
+ 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
252
+ 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
253
+ 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
254
+ 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2,
255
+ ]
256
+
257
+ mutating func update(_ bytes: UnsafeRawBufferPointer) {
258
+ var h = self.h
259
+ buffer.append(bytes) { Self.compress(&h, $0) }
260
+ self.h = h
261
+ }
262
+
263
+ func finalize(words: Int) -> [UInt8] {
264
+ var copy = self
265
+ var h = copy.h
266
+ copy.buffer.pad(lengthBytes: 8, bigEndian: true) { Self.compress(&h, $0) }
267
+ return h.prefix(words).flatMap { _bigEndianBytes($0) }
268
+ }
269
+
270
+ static func compress(_ h: inout [UInt32], _ block: [UInt8]) {
271
+ var w = [UInt32](repeating: 0, count: 64)
272
+ for i in 0..<16 { w[i] = _word32(block, i * 4) }
273
+ for i in 16..<64 {
274
+ let s0 = _rotr(w[i - 15], 7) ^ _rotr(w[i - 15], 18) ^ (w[i - 15] >> 3)
275
+ let s1 = _rotr(w[i - 2], 17) ^ _rotr(w[i - 2], 19) ^ (w[i - 2] >> 10)
276
+ w[i] = w[i - 16] &+ s0 &+ w[i - 7] &+ s1
277
+ }
278
+ var (a, b, c, d, e, f, g, hh) = (h[0], h[1], h[2], h[3], h[4], h[5], h[6], h[7])
279
+ for i in 0..<64 {
280
+ let s1 = _rotr(e, 6) ^ _rotr(e, 11) ^ _rotr(e, 25)
281
+ let ch = (e & f) ^ (~e & g)
282
+ let t1 = hh &+ s1 &+ ch &+ k[i] &+ w[i]
283
+ let s0 = _rotr(a, 2) ^ _rotr(a, 13) ^ _rotr(a, 22)
284
+ let maj = (a & b) ^ (a & c) ^ (b & c)
285
+ let t2 = s0 &+ maj
286
+ (hh, g, f, e, d, c, b, a) = (g, f, e, d &+ t1, c, b, a, t1 &+ t2)
287
+ }
288
+ h[0] &+= a; h[1] &+= b; h[2] &+= c; h[3] &+= d; h[4] &+= e; h[5] &+= f; h[6] &+= g; h[7] &+= hh
289
+ }
290
+ }
291
+
292
+ /// SHA-384/512's state.
293
+ struct _SHA64: Sendable {
294
+ var buffer = _Blocks(size: 128)
295
+ var h: [UInt64]
296
+
297
+ init(initial: [UInt64]) { h = initial }
298
+
299
+ static let k: [UInt64] = [
300
+ 0x428a2f98d728ae22, 0x7137449123ef65cd, 0xb5c0fbcfec4d3b2f, 0xe9b5dba58189dbbc, 0x3956c25bf348b538, 0x59f111f1b605d019,
301
+ 0x923f82a4af194f9b, 0xab1c5ed5da6d8118, 0xd807aa98a3030242, 0x12835b0145706fbe, 0x243185be4ee4b28c, 0x550c7dc3d5ffb4e2,
302
+ 0x72be5d74f27b896f, 0x80deb1fe3b1696b1, 0x9bdc06a725c71235, 0xc19bf174cf692694, 0xe49b69c19ef14ad2, 0xefbe4786384f25e3,
303
+ 0x0fc19dc68b8cd5b5, 0x240ca1cc77ac9c65, 0x2de92c6f592b0275, 0x4a7484aa6ea6e483, 0x5cb0a9dcbd41fbd4, 0x76f988da831153b5,
304
+ 0x983e5152ee66dfab, 0xa831c66d2db43210, 0xb00327c898fb213f, 0xbf597fc7beef0ee4, 0xc6e00bf33da88fc2, 0xd5a79147930aa725,
305
+ 0x06ca6351e003826f, 0x142929670a0e6e70, 0x27b70a8546d22ffc, 0x2e1b21385c26c926, 0x4d2c6dfc5ac42aed, 0x53380d139d95b3df,
306
+ 0x650a73548baf63de, 0x766a0abb3c77b2a8, 0x81c2c92e47edaee6, 0x92722c851482353b, 0xa2bfe8a14cf10364, 0xa81a664bbc423001,
307
+ 0xc24b8b70d0f89791, 0xc76c51a30654be30, 0xd192e819d6ef5218, 0xd69906245565a910, 0xf40e35855771202a, 0x106aa07032bbd1b8,
308
+ 0x19a4c116b8d2d0c8, 0x1e376c085141ab53, 0x2748774cdf8eeb99, 0x34b0bcb5e19b48a8, 0x391c0cb3c5c95a63, 0x4ed8aa4ae3418acb,
309
+ 0x5b9cca4f7763e373, 0x682e6ff3d6b2b8a3, 0x748f82ee5defb2fc, 0x78a5636f43172f60, 0x84c87814a1f0ab72, 0x8cc702081a6439ec,
310
+ 0x90befffa23631e28, 0xa4506cebde82bde9, 0xbef9a3f7b2c67915, 0xc67178f2e372532b, 0xca273eceea26619c, 0xd186b8c721c0c207,
311
+ 0xeada7dd6cde0eb1e, 0xf57d4f7fee6ed178, 0x06f067aa72176fba, 0x0a637dc5a2c898a6, 0x113f9804bef90dae, 0x1b710b35131c471b,
312
+ 0x28db77f523047d84, 0x32caab7b40c72493, 0x3c9ebe0a15c9bebc, 0x431d67c49c100d4c, 0x4cc5d4becb3e42b6, 0x597f299cfc657e2a,
313
+ 0x5fcb6fab3ad6faec, 0x6c44198c4a475817,
314
+ ]
315
+
316
+ mutating func update(_ bytes: UnsafeRawBufferPointer) {
317
+ var h = self.h
318
+ buffer.append(bytes) { Self.compress(&h, $0) }
319
+ self.h = h
320
+ }
321
+
322
+ func finalize(words: Int) -> [UInt8] {
323
+ var copy = self
324
+ var h = copy.h
325
+ copy.buffer.pad(lengthBytes: 16, bigEndian: true) { Self.compress(&h, $0) }
326
+ return h.prefix(words).flatMap { word in (0..<8).reversed().map { UInt8(truncatingIfNeeded: word >> (UInt64($0) * 8)) } }
327
+ }
328
+
329
+ static func compress(_ h: inout [UInt64], _ block: [UInt8]) {
330
+ var w = [UInt64](repeating: 0, count: 80)
331
+ for i in 0..<16 {
332
+ w[i] = (0..<8).reduce(0) { $0 << 8 | UInt64(block[i * 8 + $1]) }
333
+ }
334
+ for i in 16..<80 {
335
+ let s0 = _rotr64(w[i - 15], 1) ^ _rotr64(w[i - 15], 8) ^ (w[i - 15] >> 7)
336
+ let s1 = _rotr64(w[i - 2], 19) ^ _rotr64(w[i - 2], 61) ^ (w[i - 2] >> 6)
337
+ w[i] = w[i - 16] &+ s0 &+ w[i - 7] &+ s1
338
+ }
339
+ var (a, b, c, d, e, f, g, hh) = (h[0], h[1], h[2], h[3], h[4], h[5], h[6], h[7])
340
+ for i in 0..<80 {
341
+ let s1 = _rotr64(e, 14) ^ _rotr64(e, 18) ^ _rotr64(e, 41)
342
+ let ch = (e & f) ^ (~e & g)
343
+ let t1 = hh &+ s1 &+ ch &+ k[i] &+ w[i]
344
+ let s0 = _rotr64(a, 28) ^ _rotr64(a, 34) ^ _rotr64(a, 39)
345
+ let maj = (a & b) ^ (a & c) ^ (b & c)
346
+ let t2 = s0 &+ maj
347
+ (hh, g, f, e, d, c, b, a) = (g, f, e, d &+ t1, c, b, a, t1 &+ t2)
348
+ }
349
+ h[0] &+= a; h[1] &+= b; h[2] &+= c; h[3] &+= d; h[4] &+= e; h[5] &+= f; h[6] &+= g; h[7] &+= hh
350
+ }
351
+ }
352
+
353
+ @inline(__always) func _rotl(_ x: UInt32, _ n: UInt32) -> UInt32 { (x << n) | (x >> (32 - n)) }
354
+ @inline(__always) func _rotr(_ x: UInt32, _ n: UInt32) -> UInt32 { (x >> n) | (x << (32 - n)) }
355
+ @inline(__always) func _rotr64(_ x: UInt64, _ n: UInt64) -> UInt64 { (x >> n) | (x << (64 - n)) }
356
+ @inline(__always) func _word32(_ b: [UInt8], _ i: Int) -> UInt32 {
357
+ UInt32(b[i]) << 24 | UInt32(b[i + 1]) << 16 | UInt32(b[i + 2]) << 8 | UInt32(b[i + 3])
358
+ }
359
+ func _bigEndianBytes(_ word: UInt32) -> [UInt8] {
360
+ [UInt8(word >> 24), UInt8(truncatingIfNeeded: word >> 16), UInt8(truncatingIfNeeded: word >> 8), UInt8(truncatingIfNeeded: word)]
361
+ }
362
+
363
+ /// `sin` for MD5's constants, without a libm dependency.
364
+ func _sin(_ x: Double) -> Double {
365
+ // Reduce to [-π, π], then a Taylor series (enough terms for 2⁻⁵³).
366
+ let twoPi = 6.283185307179586
367
+ var r = x - (x / twoPi).rounded() * twoPi
368
+ if r > .pi { r -= twoPi }
369
+ var term = r, sum = r
370
+ for n in 1..<20 {
371
+ term *= -r * r / Double((2 * n) * (2 * n + 1))
372
+ sum += term
373
+ }
374
+ return sum
375
+ }