Skip to content

Commit 2418889

Browse files
authored
Hide Base64 (#159)
* Make base64 private * Switch to inlinable
1 parent 7eddf52 commit 2418889

File tree

1 file changed

+34
-18
lines changed

1 file changed

+34
-18
lines changed

Sources/APNSwift/Base64.swift

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -72,27 +72,35 @@
7272

7373
extension String {
7474
@inlinable
75-
public init<Buffer: Collection>(base64Encoding bytes: Buffer, options: Base64.EncodingOptions = [])
75+
internal init<Buffer: Collection>(base64Encoding bytes: Buffer, options: Base64.EncodingOptions = [])
7676
where Buffer.Element == UInt8 {
7777
self = Base64.encodeString(bytes: bytes, options: options)
7878
}
7979

80-
public func base64decoded(options: Base64.DecodingOptions = []) throws -> [UInt8] {
80+
internal func base64decoded(options: Base64.DecodingOptions = []) throws -> [UInt8] {
8181
try Base64.decode(string: self, options: options)
8282
}
8383
}
8484

85-
public enum Base64 {}
85+
@usableFromInline
86+
internal enum Base64 {}
8687

8788
// MARK: - Encoding -
8889

8990
extension Base64 {
90-
public struct EncodingOptions: OptionSet {
91-
public let rawValue: UInt
92-
public init(rawValue: UInt) { self.rawValue = rawValue }
91+
@usableFromInline
92+
internal struct EncodingOptions: OptionSet {
93+
@usableFromInline
94+
internal let rawValue: UInt
95+
96+
@inlinable
97+
internal init(rawValue: UInt) { self.rawValue = rawValue }
9398

94-
public static let base64UrlAlphabet = EncodingOptions(rawValue: UInt(1 << 0))
95-
public static let omitPaddingCharacter = EncodingOptions(rawValue: UInt(1 << 1))
99+
@usableFromInline
100+
internal static let base64UrlAlphabet = EncodingOptions(rawValue: UInt(1 << 0))
101+
102+
@usableFromInline
103+
internal static let omitPaddingCharacter = EncodingOptions(rawValue: UInt(1 << 1))
96104
}
97105

98106
@usableFromInline
@@ -423,7 +431,7 @@ extension Base64 {
423431
]
424432

425433
@inlinable
426-
public static func encodeBytes<Buffer: Collection>(bytes: Buffer, options: EncodingOptions = [])
434+
internal static func encodeBytes<Buffer: Collection>(bytes: Buffer, options: EncodingOptions = [])
427435
-> [UInt8] where Buffer.Element == UInt8 {
428436
let newCapacity = ((bytes.count + 2) / 3) * 4
429437

@@ -439,7 +447,7 @@ extension Base64 {
439447
}
440448

441449
@inlinable
442-
public static func encodeString<Buffer: Collection>(bytes: Buffer, options: EncodingOptions = [])
450+
internal static func encodeString<Buffer: Collection>(bytes: Buffer, options: EncodingOptions = [])
443451
-> String where Buffer.Element == UInt8 {
444452
let newCapacity = ((bytes.count + 2) / 3) * 4
445453

@@ -548,23 +556,31 @@ extension Base64 {
548556
// MARK: - Decoding -
549557

550558
extension Base64 {
551-
public struct DecodingOptions: OptionSet {
552-
public let rawValue: UInt
553-
public init(rawValue: UInt) { self.rawValue = rawValue }
559+
@usableFromInline
560+
internal struct DecodingOptions: OptionSet {
561+
@usableFromInline
562+
internal let rawValue: UInt
554563

555-
public static let base64UrlAlphabet = DecodingOptions(rawValue: UInt(1 << 0))
556-
public static let omitPaddingCharacter = DecodingOptions(rawValue: UInt(1 << 1))
564+
@inlinable
565+
internal init(rawValue: UInt) { self.rawValue = rawValue }
566+
567+
@usableFromInline
568+
internal static let base64UrlAlphabet = DecodingOptions(rawValue: UInt(1 << 0))
569+
570+
@usableFromInline
571+
internal static let omitPaddingCharacter = DecodingOptions(rawValue: UInt(1 << 1))
557572
}
558573

559-
public enum DecodingError: Error, Equatable {
574+
@usableFromInline
575+
internal enum DecodingError: Error, Equatable {
560576
case invalidLength
561577
case invalidCharacter(UInt8)
562578
case unexpectedPaddingCharacter
563579
case unexpectedEnd
564580
}
565581

566582
@inlinable
567-
public static func decode(string encoded: String, options: DecodingOptions = []) throws -> [UInt8] {
583+
internal static func decode(string encoded: String, options: DecodingOptions = []) throws -> [UInt8] {
568584
let decoded = try encoded.utf8.withContiguousStorageIfAvailable { characterPointer -> [UInt8] in
569585
guard characterPointer.count > 0 else {
570586
return []
@@ -589,7 +605,7 @@ extension Base64 {
589605
}
590606

591607
@inlinable
592-
public static func decode<Buffer: Collection>(bytes: Buffer, options: DecodingOptions = []) throws -> [UInt8]
608+
internal static func decode<Buffer: Collection>(bytes: Buffer, options: DecodingOptions = []) throws -> [UInt8]
593609
where Buffer.Element == UInt8 {
594610
guard bytes.count > 0 else {
595611
return []

0 commit comments

Comments
 (0)