22//
33// This source file is part of the Swift.org open source project
44//
5- // Copyright (c) 2023-2024 Apple Inc. and the Swift project authors
5+ // Copyright (c) 2023-2025 Apple Inc. and the Swift project authors
66// Licensed under Apache License v2.0 with Runtime Library Exception
77//
88// See https://swift.org/LICENSE.txt for license information
@@ -25,6 +25,56 @@ import WinSDK
2525import WASILibc
2626#endif
2727
28+ #if !FOUNDATION_FRAMEWORK
29+ extension Data {
30+
31+ @available ( macOS 10 . 10 , iOS 8 . 0 , watchOS 2 . 0 , tvOS 9 . 0 , * )
32+ public struct Base64EncodingOptions : OptionSet , Sendable {
33+ public let rawValue : UInt
34+
35+ public init ( rawValue: UInt ) {
36+ self . rawValue = rawValue
37+ }
38+ /// Set the maximum line length to 64 characters, after which a line ending is inserted.
39+ public static let lineLength64Characters = Base64EncodingOptions ( rawValue: 1 << 0 )
40+ /// Set the maximum line length to 76 characters, after which a line ending is inserted.
41+ public static let lineLength76Characters = Base64EncodingOptions ( rawValue: 1 << 1 )
42+ /// When a maximum line length is set, specify that the line ending to insert should include a carriage return.
43+ public static let endLineWithCarriageReturn = Base64EncodingOptions ( rawValue: 1 << 4 )
44+ /// When a maximum line length is set, specify that the line ending to insert should include a line feed.
45+ public static let endLineWithLineFeed = Base64EncodingOptions ( rawValue: 1 << 5 )
46+ }
47+
48+ @available ( macOS 10 . 10 , iOS 8 . 0 , watchOS 2 . 0 , tvOS 9 . 0 , * )
49+ public struct Base64DecodingOptions : OptionSet , Sendable {
50+ public let rawValue : UInt
51+
52+ public init ( rawValue: UInt ) {
53+ self . rawValue = rawValue
54+ }
55+ /// Modify the decoding algorithm so that it ignores unknown non-Base-64 bytes, including line ending characters.
56+ public static let ignoreUnknownCharacters = Base64DecodingOptions ( rawValue: 1 << 0 )
57+ }
58+ }
59+ #else
60+ @available ( macOS 10 . 10 , iOS 8 . 0 , watchOS 2 . 0 , tvOS 9 . 0 , * )
61+ extension Data {
62+ // These types are typealiased to the `NSData` options for framework builds only.
63+ public typealias Base64EncodingOptions = NSData . Base64EncodingOptions
64+ public typealias Base64DecodingOptions = NSData . Base64DecodingOptions
65+ }
66+ #endif //!FOUNDATION_FRAMEWORK
67+
68+ extension Data . Base64EncodingOptions {
69+ /// Use the base64url alphabet to encode the data
70+ @available ( FoundationPreview 6 . 3 , * )
71+ public static let base64URLAlphabet = Self ( rawValue: 1 << 6 )
72+
73+ /// Omit the `=` padding characters in the end of the base64 encoded result
74+ @available ( FoundationPreview 6 . 3 , * )
75+ public static let omitPaddingCharacter = Self ( rawValue: 1 << 7 )
76+ }
77+
2878@available ( macOS 10 . 10 , iOS 8 . 0 , watchOS 2 . 0 , tvOS 9 . 0 , * )
2979extension Data {
3080
0 commit comments