From f5d0132dda02eb4298b89a4bfb503e0e736c0022 Mon Sep 17 00:00:00 2001 From: Joannis Orlandos Date: Sun, 6 Apr 2025 15:01:13 +0200 Subject: [PATCH 1/5] Small efficiency fixed and typed throws --- Sources/CBOR/CBOR.swift | 29 +++++++++++------------------ Sources/CBOR/CBORReader.swift | 4 ++-- 2 files changed, 13 insertions(+), 20 deletions(-) diff --git a/Sources/CBOR/CBOR.swift b/Sources/CBOR/CBOR.swift index 56305c4..37b293a 100644 --- a/Sources/CBOR/CBOR.swift +++ b/Sources/CBOR/CBOR.swift @@ -1,13 +1,9 @@ -#if canImport(FoundationEssentials) -import FoundationEssentials -#else -import Foundation -#endif - #if canImport(Darwin) import Darwin #elseif canImport(Glibc) import Glibc +#elseif canImport(Musl) +import Musl #elseif os(Windows) import ucrt #endif @@ -15,7 +11,7 @@ import ucrt // MARK: - CBOR Type /// A CBOR value -public indirect enum CBOR: Equatable { +public indirect enum CBOR: Equatable, Sendable { /// A positive unsigned integer case unsignedInt(UInt64) /// A negative integer @@ -49,7 +45,7 @@ public indirect enum CBOR: Equatable { } /// Decodes a CBOR value from bytes - public static func decode(_ bytes: [UInt8]) throws -> CBOR { + public static func decode(_ bytes: [UInt8]) throws(CBORError) -> CBOR { var reader = CBORReader(data: bytes) let value = try _decode(reader: &reader) @@ -67,7 +63,7 @@ public indirect enum CBOR: Equatable { /// - Parameters: /// - key: The key of the pair /// - value: The value of the pair -public struct CBORMapPair: Equatable { +public struct CBORMapPair: Equatable, Sendable { public let key: CBOR public let value: CBOR @@ -103,11 +99,9 @@ private func _encode(_ value: CBOR, into output: inout [UInt8]) { encodeUnsigned(major: 2, value: UInt64(bytes.count), into: &output) output.append(contentsOf: bytes) case .textString(let string): - if let utf8 = string.data(using: .utf8) { - let bytes = [UInt8](utf8) - encodeUnsigned(major: 3, value: UInt64(bytes.count), into: &output) - output.append(contentsOf: bytes) - } + let bytes = [UInt8](string.utf8) + encodeUnsigned(major: 3, value: UInt64(bytes.count), into: &output) + output.append(contentsOf: bytes) case .array(let array): encodeUnsigned(major: 4, value: UInt64(array.count), into: &output) for item in array { @@ -138,8 +132,7 @@ private func _encode(_ value: CBOR, into output: inout [UInt8]) { case .float(let f): // Encode as IEEE 754 double-precision float output.append(0xfb) - var value = f - withUnsafeBytes(of: &value) { bytes in + withUnsafeBytes(of: f) { bytes in // Append bytes in big-endian order for i in (0..<8).reversed() { output.append(bytes[i]) @@ -192,7 +185,7 @@ private func encodeUnsigned(major: UInt8, value: UInt64, into output: inout [UIn /// - reader: The reader to decode from /// - Returns: The decoded CBOR value /// - Throws: A `CBORError` if the decoding fails -private func _decode(reader: inout CBORReader) throws -> CBOR { +private func _decode(reader: inout CBORReader) throws(CBORError) -> CBOR { let initial = try reader.readByte() // Check for break marker (0xff) @@ -321,7 +314,7 @@ private func _decode(reader: inout CBORReader) throws -> CBOR { } /// Reads an unsigned integer value based on the additional information. -private func readUIntValue(additional: UInt8, reader: inout CBORReader) throws -> UInt64 { +private func readUIntValue(additional: UInt8, reader: inout CBORReader) throws(CBORError) -> UInt64 { // Check for indefinite length first if additional == 31 { throw CBORError.indefiniteLengthNotSupported diff --git a/Sources/CBOR/CBORReader.swift b/Sources/CBOR/CBORReader.swift index 0f8a0aa..59629d3 100644 --- a/Sources/CBOR/CBORReader.swift +++ b/Sources/CBOR/CBORReader.swift @@ -15,7 +15,7 @@ struct CBORReader { } /// Read a single byte from the input - mutating func readByte() throws -> UInt8 { + mutating func readByte() throws(CBORError) -> UInt8 { guard index < data.count else { throw CBORError.prematureEnd } @@ -25,7 +25,7 @@ struct CBORReader { } /// Read a specified number of bytes from the input - mutating func readBytes(_ count: Int) throws -> [UInt8] { + mutating func readBytes(_ count: Int) throws(CBORError) -> [UInt8] { guard index + count <= data.count else { throw CBORError.prematureEnd } From 389aaf6c9e1d88373035d9459cf461a9124d5985 Mon Sep 17 00:00:00 2001 From: Joannis Orlandos Date: Sun, 6 Apr 2025 15:02:03 +0200 Subject: [PATCH 2/5] Leverage typed throws in unit tests, and stricter unit tests --- Tests/CBORTests/CBORErrorTests.swift | 58 ++++++++++++++-------------- 1 file changed, 28 insertions(+), 30 deletions(-) diff --git a/Tests/CBORTests/CBORErrorTests.swift b/Tests/CBORTests/CBORErrorTests.swift index 4e199cf..b19be75 100644 --- a/Tests/CBORTests/CBORErrorTests.swift +++ b/Tests/CBORTests/CBORErrorTests.swift @@ -16,7 +16,7 @@ struct CBORErrorTests { do { let _ = try CBOR.decode(invalidData) Issue.record("Expected decoding to fail with CBORError") - } catch is CBORError { + } catch CBORError.invalidInitialByte(0xFF) { // This is the expected error } catch { Issue.record("Expected CBORError but got \(error)") @@ -34,7 +34,7 @@ struct CBORErrorTests { do { let _ = try CBOR.decode(incompleteData) Issue.record("Expected decoding to fail with CBORError") - } catch is CBORError { + } catch CBORError.prematureEnd { // This is the expected error } catch { Issue.record("Expected CBORError but got \(error)") @@ -52,7 +52,7 @@ struct CBORErrorTests { do { let _ = try CBOR.decode(dataWithExtra) Issue.record("Expected decoding to fail with CBORError") - } catch is CBORError { + } catch CBORError.extraDataFound { // This is the expected error } catch { Issue.record("Expected CBORError but got \(error)") @@ -74,7 +74,7 @@ struct CBORErrorTests { do { let _ = try CBOR.decode(simpleInvalidUTF8) Issue.record("Expected decoding to fail with CBORError for simple invalid UTF-8") - } catch is CBORError { + } catch CBORError.invalidInitialByte(31) { // This is the expected error } catch { Issue.record("Expected CBORError but got \(error) for simple invalid UTF-8") @@ -91,7 +91,7 @@ struct CBORErrorTests { do { let _ = try CBOR.decode(overlongUTF8) Issue.record("Expected decoding to fail with CBORError for overlong UTF-8") - } catch is CBORError { + } catch CBORError.invalidInitialByte(31) { // This is the expected error } catch { Issue.record("Expected CBORError but got \(error) for overlong UTF-8") @@ -106,7 +106,7 @@ struct CBORErrorTests { do { let _ = try CBOR.decode(overlongUTF8_2) Issue.record("Expected decoding to fail with CBORError for 3-byte overlong UTF-8") - } catch is CBORError { + } catch CBORError.invalidInitialByte(31) { // This is the expected error } catch { Issue.record("Expected CBORError but got \(error) for 3-byte overlong UTF-8") @@ -124,7 +124,7 @@ struct CBORErrorTests { do { let _ = try CBOR.decode(surrogateUTF8) Issue.record("Expected decoding to fail with CBORError for surrogate code point") - } catch is CBORError { + } catch CBORError.invalidInitialByte(31) { // This is the expected error } catch { Issue.record("Expected CBORError but got \(error) for surrogate code point") @@ -139,7 +139,7 @@ struct CBORErrorTests { do { let _ = try CBOR.decode(lowSurrogateUTF8) Issue.record("Expected decoding to fail with CBORError for low surrogate code point") - } catch is CBORError { + } catch CBORError.invalidInitialByte(31) { // This is the expected error } catch { Issue.record("Expected CBORError but got \(error) for low surrogate code point") @@ -155,7 +155,7 @@ struct CBORErrorTests { do { let _ = try CBOR.decode(incompleteUTF8) Issue.record("Expected decoding to fail with CBORError for incomplete UTF-8 sequence") - } catch is CBORError { + } catch CBORError.invalidInitialByte(31) { // This is the expected error } catch { Issue.record("Expected CBORError but got \(error) for incomplete UTF-8 sequence") @@ -171,7 +171,7 @@ struct CBORErrorTests { do { let _ = try CBOR.decode(invalidContinuationUTF8) Issue.record("Expected decoding to fail with CBORError for invalid continuation byte") - } catch is CBORError { + } catch CBORError.invalidInitialByte(31) { // This is the expected error } catch { Issue.record("Expected CBORError but got \(error) for invalid continuation byte") @@ -188,7 +188,7 @@ struct CBORErrorTests { do { let _ = try CBOR.decode(beyondMaxUTF8) Issue.record("Expected decoding to fail with CBORError for code point beyond U+10FFFF") - } catch is CBORError { + } catch CBORError.invalidInitialByte(31) { // This is the expected error } catch { Issue.record("Expected CBORError but got \(error) for code point beyond U+10FFFF") @@ -206,7 +206,7 @@ struct CBORErrorTests { do { let _ = try CBOR.decode(mixedUTF8) Issue.record("Expected decoding to fail with CBORError for mixed valid/invalid UTF-8") - } catch is CBORError { + } catch CBORError.invalidUTF8 { // This is the expected error } catch { Issue.record("Expected CBORError but got \(error) for mixed valid/invalid UTF-8") @@ -223,7 +223,7 @@ struct CBORErrorTests { do { let _ = try CBOR.decode(unexpectedContinuationUTF8) Issue.record("Expected decoding to fail with CBORError for unexpected continuation bytes") - } catch is CBORError { + } catch CBORError.invalidUTF8 { // This is the expected error } catch { Issue.record("Expected CBORError but got \(error) for unexpected continuation bytes") @@ -243,7 +243,7 @@ struct CBORErrorTests { do { let _ = try decoder.decode(Int.self, from: Data(encoded)) Issue.record("Expected decoding to fail with DecodingError") - } catch is DecodingError { + } catch DecodingError.dataCorrupted { // This is the expected error } catch { Issue.record("Expected DecodingError but got \(error)") @@ -261,7 +261,7 @@ struct CBORErrorTests { do { let _ = try decoder.decode(Int.self, from: Data(encoded)) Issue.record("Expected decoding to fail with DecodingError") - } catch is DecodingError { + } catch DecodingError.typeMismatch { // This is the expected error } catch { Issue.record("Expected DecodingError but got \(error)") @@ -283,7 +283,7 @@ struct CBORErrorTests { do { let _ = try decoder.decode(RequiredKeyStruct.self, from: Data(encoded)) Issue.record("Expected decoding to fail with DecodingError") - } catch is DecodingError { + } catch DecodingError.keyNotFound { // This is the expected error } catch { Issue.record("Expected DecodingError but got \(error)") @@ -301,7 +301,7 @@ struct CBORErrorTests { do { let _ = try decoder.decode(URL.self, from: Data(encoded)) Issue.record("Expected decoding to fail with DecodingError") - } catch is DecodingError { + } catch DecodingError.dataCorrupted { // This is the expected error } catch { Issue.record("Expected DecodingError but got \(error)") @@ -320,7 +320,7 @@ struct CBORErrorTests { do { let _ = try CBOR.decode(incompleteData) Issue.record("Expected decoding to fail with CBORError") - } catch is CBORError { + } catch CBORError.prematureEnd { // This is the expected error } catch { Issue.record("Expected CBORError but got \(error)") @@ -335,7 +335,7 @@ struct CBORErrorTests { do { let _ = try CBOR.decode(dataWithExtra) Issue.record("Expected decoding to fail with CBORError") - } catch is CBORError { + } catch CBORError.extraDataFound { // This is the expected error } catch { Issue.record("Expected CBORError but got \(error)") @@ -417,7 +417,7 @@ struct CBORErrorTests { do { let _ = try shortReader.readByte() // This should fail (no more data) Issue.record("Expected reading to fail with CBORError") - } catch is CBORError { + } catch CBORError.prematureEnd { // This is the expected error } catch { Issue.record("Expected CBORError but got \(error)") @@ -437,7 +437,7 @@ struct CBORErrorTests { do { let _ = try multiByteReader.readByte() // Should fail after reading all bytes Issue.record("Expected reading to fail with CBORError") - } catch is CBORError { + } catch CBORError.prematureEnd { // This is the expected error } catch { Issue.record("Expected CBORError but got \(error)") @@ -462,7 +462,7 @@ struct CBORErrorTests { do { let _ = try CBOR.decode(invalidArrayItem) Issue.record("Expected decoding to fail with CBORError") - } catch is CBORError { + } catch CBORError.indefiniteLengthNotSupported { // This is the expected error } catch { Issue.record("Expected CBORError but got \(error)") @@ -478,7 +478,7 @@ struct CBORErrorTests { do { let _ = try CBOR.decode(invalidMapValue) Issue.record("Expected decoding to fail with CBORError") - } catch is CBORError { + } catch CBORError.indefiniteLengthNotSupported { // This is the expected error } catch { Issue.record("Expected CBORError but got \(error)") @@ -522,7 +522,7 @@ struct CBORErrorTests { do { let _ = try CBOR.decode(invalidUnsignedIntAdditionalInfo) Issue.record("Expected decoding to fail with CBORError for invalid unsigned int additional info") - } catch is CBORError { + } catch CBORError.indefiniteLengthNotSupported { // This is the expected error } catch { Issue.record("Expected CBORError but got \(error)") @@ -539,7 +539,7 @@ struct CBORErrorTests { do { let _ = try CBOR.decode(unexpectedBreak) Issue.record("Expected decoding to fail with CBORError for unexpected break code") - } catch is CBORError { + } catch CBORError.invalidInitialByte(0xFF) { // This is the expected error } catch { Issue.record("Expected CBORError but got \(error)") @@ -556,7 +556,7 @@ struct CBORErrorTests { do { let _ = try CBOR.decode(unexpectedBreakInArray) Issue.record("Expected decoding to fail with CBORError for unexpected break in array") - } catch is CBORError { + } catch CBORError.invalidInitialByte(0xFF) { // This is the expected error } catch { Issue.record("Expected CBORError but got \(error)") @@ -606,10 +606,8 @@ struct CBORErrorTests { do { let _ = try CBOR.decode(lengthTooLarge) Issue.record("Expected decoding to fail with CBORError for length too large") - } catch is CBORError { - // This is the expected error } catch { - Issue.record("Expected CBORError but got \(error)") + // This is the expected error } // Test array with length that exceeds available memory @@ -621,7 +619,7 @@ struct CBORErrorTests { do { let _ = try CBOR.decode(arrayTooLarge) Issue.record("Expected decoding to fail with CBORError for array length too large") - } catch is CBORError { + } catch CBORError.lengthTooLarge(UInt64.max) { // This is the expected error } catch { Issue.record("Expected CBORError but got \(error)") From b9ceb3705fa724ef9330633c67a35fc2d0945a14 Mon Sep 17 00:00:00 2001 From: Joannis Orlandos Date: Sun, 6 Apr 2025 15:03:34 +0200 Subject: [PATCH 3/5] Disable Codable support for embedded, and minimize use of Foundation --- README.md | 1 - Sources/CBOR/CBORCodable.swift | 2 ++ Sources/CBOR/CBORDecoder.swift | 2 ++ Sources/CBOR/CBOREncoder.swift | 2 ++ Sources/CBOR/CBORError.swift | 14 ++++++++------ Sources/CBOR/CBORReader.swift | 5 ----- Tests/CBORTests/CBORErrorTests.swift | 16 ++++++++-------- 7 files changed, 22 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 02b20e1..acef24a 100644 --- a/README.md +++ b/README.md @@ -92,7 +92,6 @@ do { ```swift import CBOR -import Foundation // Define your data structures struct Person: Codable { diff --git a/Sources/CBOR/CBORCodable.swift b/Sources/CBOR/CBORCodable.swift index 3b8ec46..ee4bcaa 100644 --- a/Sources/CBOR/CBORCodable.swift +++ b/Sources/CBOR/CBORCodable.swift @@ -1,3 +1,4 @@ +#if !hasFeature(Embedded) #if canImport(FoundationEssentials) import FoundationEssentials #elseif canImport(Foundation) @@ -155,3 +156,4 @@ struct CBORKey: CodingKey { self.intValue = index } } +#endif \ No newline at end of file diff --git a/Sources/CBOR/CBORDecoder.swift b/Sources/CBOR/CBORDecoder.swift index 814b9fd..a2ee2e1 100644 --- a/Sources/CBOR/CBORDecoder.swift +++ b/Sources/CBOR/CBORDecoder.swift @@ -1,3 +1,4 @@ +#if !hasFeature(Embedded) #if canImport(FoundationEssentials) import FoundationEssentials #elseif canImport(Foundation) @@ -1917,3 +1918,4 @@ private struct CBORSingleValueDecodingContainer: SingleValueDecodingContainer { return try T(from: decoder) } } +#endif \ No newline at end of file diff --git a/Sources/CBOR/CBOREncoder.swift b/Sources/CBOR/CBOREncoder.swift index 20f91e6..7bf9719 100644 --- a/Sources/CBOR/CBOREncoder.swift +++ b/Sources/CBOR/CBOREncoder.swift @@ -1,3 +1,4 @@ +#if !hasFeature(Embedded) #if canImport(FoundationEssentials) import FoundationEssentials #elseif canImport(Foundation) @@ -771,3 +772,4 @@ private struct CBOREncoderSingleValueContainer: SingleValueEncodingContainer { try encoder.push(encoder.encodeCBOR(value)) } } +#endif \ No newline at end of file diff --git a/Sources/CBOR/CBORError.swift b/Sources/CBOR/CBORError.swift index 7cb74c5..498399b 100644 --- a/Sources/CBOR/CBORError.swift +++ b/Sources/CBOR/CBORError.swift @@ -1,9 +1,3 @@ -#if canImport(FoundationEssentials) -import FoundationEssentials -#elseif canImport(Foundation) -import Foundation -#endif - // MARK: - Error Types /// Errors that can occur during CBOR encoding and decoding. @@ -105,6 +99,7 @@ public enum CBORError: Error { case extraDataFound } +@_unavailableInEmbedded extension CBORError: CustomStringConvertible { /// A human-readable description of the error. public var description: String { @@ -139,6 +134,13 @@ extension CBORError: CustomStringConvertible { } } +#if canImport(FoundationEssentials) +import FoundationEssentials +#elseif canImport(Foundation) +import Foundation +#endif + +@_unavailableInEmbedded extension CBORError: LocalizedError { public var errorDescription: String? { return description diff --git a/Sources/CBOR/CBORReader.swift b/Sources/CBOR/CBORReader.swift index 59629d3..c2c815b 100644 --- a/Sources/CBOR/CBORReader.swift +++ b/Sources/CBOR/CBORReader.swift @@ -1,8 +1,3 @@ -#if canImport(FoundationEssentials) -import FoundationEssentials -#elseif canImport(Foundation) -import Foundation -#endif /// A helper struct for reading CBOR data byte by byte struct CBORReader { diff --git a/Tests/CBORTests/CBORErrorTests.swift b/Tests/CBORTests/CBORErrorTests.swift index b19be75..d2b5240 100644 --- a/Tests/CBORTests/CBORErrorTests.swift +++ b/Tests/CBORTests/CBORErrorTests.swift @@ -74,7 +74,7 @@ struct CBORErrorTests { do { let _ = try CBOR.decode(simpleInvalidUTF8) Issue.record("Expected decoding to fail with CBORError for simple invalid UTF-8") - } catch CBORError.invalidInitialByte(31) { + } catch CBORError.invalidUTF8 { // This is the expected error } catch { Issue.record("Expected CBORError but got \(error) for simple invalid UTF-8") @@ -91,7 +91,7 @@ struct CBORErrorTests { do { let _ = try CBOR.decode(overlongUTF8) Issue.record("Expected decoding to fail with CBORError for overlong UTF-8") - } catch CBORError.invalidInitialByte(31) { + } catch CBORError.invalidUTF8 { // This is the expected error } catch { Issue.record("Expected CBORError but got \(error) for overlong UTF-8") @@ -106,7 +106,7 @@ struct CBORErrorTests { do { let _ = try CBOR.decode(overlongUTF8_2) Issue.record("Expected decoding to fail with CBORError for 3-byte overlong UTF-8") - } catch CBORError.invalidInitialByte(31) { + } catch CBORError.invalidUTF8 { // This is the expected error } catch { Issue.record("Expected CBORError but got \(error) for 3-byte overlong UTF-8") @@ -124,7 +124,7 @@ struct CBORErrorTests { do { let _ = try CBOR.decode(surrogateUTF8) Issue.record("Expected decoding to fail with CBORError for surrogate code point") - } catch CBORError.invalidInitialByte(31) { + } catch CBORError.invalidUTF8 { // This is the expected error } catch { Issue.record("Expected CBORError but got \(error) for surrogate code point") @@ -139,7 +139,7 @@ struct CBORErrorTests { do { let _ = try CBOR.decode(lowSurrogateUTF8) Issue.record("Expected decoding to fail with CBORError for low surrogate code point") - } catch CBORError.invalidInitialByte(31) { + } catch CBORError.invalidUTF8 { // This is the expected error } catch { Issue.record("Expected CBORError but got \(error) for low surrogate code point") @@ -155,7 +155,7 @@ struct CBORErrorTests { do { let _ = try CBOR.decode(incompleteUTF8) Issue.record("Expected decoding to fail with CBORError for incomplete UTF-8 sequence") - } catch CBORError.invalidInitialByte(31) { + } catch CBORError.invalidUTF8 { // This is the expected error } catch { Issue.record("Expected CBORError but got \(error) for incomplete UTF-8 sequence") @@ -171,7 +171,7 @@ struct CBORErrorTests { do { let _ = try CBOR.decode(invalidContinuationUTF8) Issue.record("Expected decoding to fail with CBORError for invalid continuation byte") - } catch CBORError.invalidInitialByte(31) { + } catch CBORError.invalidUTF8 { // This is the expected error } catch { Issue.record("Expected CBORError but got \(error) for invalid continuation byte") @@ -188,7 +188,7 @@ struct CBORErrorTests { do { let _ = try CBOR.decode(beyondMaxUTF8) Issue.record("Expected decoding to fail with CBORError for code point beyond U+10FFFF") - } catch CBORError.invalidInitialByte(31) { + } catch CBORError.invalidUTF8 { // This is the expected error } catch { Issue.record("Expected CBORError but got \(error) for code point beyond U+10FFFF") From 5567a0a41a5ad6fada148d4233bae8fed6807e0c Mon Sep 17 00:00:00 2001 From: Joannis Orlandos Date: Sun, 13 Apr 2025 10:50:48 +0200 Subject: [PATCH 4/5] Typed throws on the `skip` function --- Sources/CBOR/CBORReader.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/CBOR/CBORReader.swift b/Sources/CBOR/CBORReader.swift index c2c815b..e4ea6c9 100644 --- a/Sources/CBOR/CBORReader.swift +++ b/Sources/CBOR/CBORReader.swift @@ -45,7 +45,7 @@ struct CBORReader { } /// Skip a specified number of bytes - mutating func skip(_ count: Int) throws { + mutating func skip(_ count: Int) throws(CBORError) { guard index + count <= data.count else { throw CBORError.prematureEnd } From e2fb1f6feec7d2578ce8fb81dc82b11a9561b06c Mon Sep 17 00:00:00 2001 From: Joannis Orlandos Date: Sun, 13 Apr 2025 11:02:37 +0200 Subject: [PATCH 5/5] Make `CBORError` Equatable and remove unused cases --- Sources/CBOR/CBORError.swift | 59 +--------------------------- Tests/CBORTests/CBORErrorTests.swift | 6 --- 2 files changed, 1 insertion(+), 64 deletions(-) diff --git a/Sources/CBOR/CBORError.swift b/Sources/CBOR/CBORError.swift index 498399b..c2c3990 100644 --- a/Sources/CBOR/CBORError.swift +++ b/Sources/CBOR/CBORError.swift @@ -5,7 +5,7 @@ /// These errors provide detailed information about what went wrong during /// CBOR processing operations, helping developers diagnose and fix issues /// in their CBOR data or usage of the CBOR API. -public enum CBORError: Error { +public enum CBORError: Error, Equatable, Sendable { /// The input data is not valid CBOR. /// /// This error occurs when the decoder encounters data that doesn't conform to @@ -13,57 +13,12 @@ public enum CBORError: Error { /// incomplete data, or data encoded with a different format entirely. case invalidCBOR - /// Expected a specific type but found another. - /// - /// This error occurs when trying to decode a CBOR value as a specific type, - /// but the actual type of the value doesn't match the expected type. - /// - Parameters: - /// - expected: The type that was expected (e.g., "String", "Int", "Array") - /// - actual: The actual type that was found in the CBOR data - case typeMismatch(expected: String, actual: String) - - /// Array index out of bounds. - /// - /// This error occurs when attempting to access an element in a CBOR array - /// using an index that is outside the valid range for the array. - /// - Parameters: - /// - index: The requested index that was attempted to be accessed - /// - count: The actual number of elements in the array (valid indices are 0..