diff --git a/Sources/ExtrasBase64/Base32.swift b/Sources/ExtrasBase64/Base32.swift index d6c1982..0cbaf0e 100644 --- a/Sources/ExtrasBase64/Base32.swift +++ b/Sources/ExtrasBase64/Base32.swift @@ -30,8 +30,17 @@ public enum Base32 { public static let allowNullCharacters = DecodingOptions(rawValue: UInt(1 << 0)) } - public enum DecodingError: Swift.Error, Equatable { - case invalidCharacter + public struct DecodingError: Swift.Error, Equatable { + enum _Internal { + case invalidCharacter + } + + fileprivate let value: _Internal + init(_ value: _Internal) { + self.value = value + } + + public static var invalidCharacter: Self { .init(.invalidCharacter) } } /// Base32 Encode a buffer to an array of bytes diff --git a/Sources/ExtrasBase64/Base64.swift b/Sources/ExtrasBase64/Base64.swift index ba2a557..b75328b 100644 --- a/Sources/ExtrasBase64/Base64.swift +++ b/Sources/ExtrasBase64/Base64.swift @@ -334,11 +334,23 @@ extension Base64 { public static let omitPaddingCharacter = DecodingOptions(rawValue: UInt(1 << 1)) } - public enum DecodingError: Error, Equatable { - case invalidLength - case invalidCharacter(UInt8) - case unexpectedPaddingCharacter - case unexpectedEnd + public struct DecodingError: Error, Equatable { + fileprivate enum _Internal: Error, Equatable { + case invalidLength + case invalidCharacter(UInt8) + case unexpectedPaddingCharacter + case unexpectedEnd + } + + fileprivate let value: _Internal + fileprivate init(_ value: _Internal) { + self.value = value + } + + public static var invalidLength: Self { .init(.invalidLength) } + public static func invalidCharacter(_ character: UInt8) -> Self { .init(.invalidCharacter(character)) } + public static var unexpectedPaddingCharacter: Self { .init(.unexpectedPaddingCharacter) } + public static var unexpectedEnd: Self { .init(.unexpectedEnd) } } @inlinable