Skip to content

Commit f95142d

Browse files
committed
PropertyWrappers/HexEncoded: Log a warning for uneven hex strings.
NOTE: This will be an error in future versions, so please adjust your input data.
1 parent 629195c commit f95142d

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

Sources/CornucopiaCore/PropertyWrappers/HexEncoded.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
//
22
// Cornucopia – (C) Dr. Lauer Information Technology
33
//
4+
private let logger = Cornucopia.Core.Logger()
5+
46
public extension Cornucopia.Core {
57

68
private static let Prefix = "0x"
@@ -101,6 +103,7 @@ public extension Cornucopia.Core {
101103
throw DecodingError.dataCorruptedError(in: container, debugDescription: "@HexEncodedBytes STRING contains an invalid character")
102104
}
103105
if string.count % 2 == 1 {
106+
logger.notice("HexEncodedBytes STRING \(string) has an odd length, inserting leading zero. This will be hard ERROR in future versions")
104107
string.insert("0", at: string.startIndex)
105108
}
106109
let chars = Array(string.utf8)
@@ -126,6 +129,7 @@ public extension Cornucopia.Core {
126129
throw DecodingError.dataCorruptedError(in: container, debugDescription: "@HexEncodedBytes STRING contains an invalid character")
127130
}
128131
if string.count % 2 == 1 {
132+
logger.notice("HexEncodedBytes STRING \(string) has an odd length, inserting leading zero. This will be hard ERROR in future versions")
129133
string.insert("0", at: string.startIndex)
130134
}
131135
let chars = Array(string.utf8)
@@ -179,6 +183,7 @@ public extension Cornucopia.Core {
179183
throw DecodingError.dataCorruptedError(in: container, debugDescription: "@HexEncodedBytes STRING contains an invalid character")
180184
}
181185
if string.count % 2 == 1 {
186+
logger.notice("HexEncodedBytes STRING \(string) has an odd length, inserting leading zero. This will be hard ERROR in future versions")
182187
string.insert("0", at: string.startIndex)
183188
}
184189
let uint32 = UInt32(string, radix: 16) ?? 0
@@ -221,6 +226,7 @@ public extension Cornucopia.Core {
221226
throw DecodingError.dataCorruptedError(in: container, debugDescription: "@HexEncodedBytes STRING contains an invalid character")
222227
}
223228
if string.count % 2 == 1 {
229+
logger.notice("HexEncodedBytes STRING \(string) has an odd length, inserting leading zero. This will be hard ERROR in future versions")
224230
string.insert("0", at: string.startIndex)
225231
}
226232
let value = T(string, radix: 16) ?? 0
@@ -264,6 +270,7 @@ public extension Cornucopia.Core {
264270
throw DecodingError.dataCorruptedError(in: container, debugDescription: "@HexEncodedBytes STRING contains an invalid character")
265271
}
266272
if string.count % 2 == 1 {
273+
logger.notice("HexEncodedBytes STRING \(string) has an odd length, inserting leading zero. This will be hard ERROR in future versions")
267274
string.insert("0", at: string.startIndex)
268275
}
269276
let value = T(string, radix: 16) ?? 0

0 commit comments

Comments
 (0)