mirror of
https://github.com/apple/swift-http-structured-headers
synced 2026-11-24 04:37:50 +00:00
Integer serialization fix for 32 bit platform compatibility (#52)
Motivation: [RFC 9651](https://www.ietf.org/rfc/rfc9651.html) permits serializing an integer in the range of -999,999,999,999,999 to 999,999,999,999,999 inclusive ([Section 4.1.4-2.1.1](https://www.ietf.org/rfc/rfc9651.html#section-4.1.4-2.1.1)). As `RFC9651BareItem` takes values `integer` or `date` with an associated value of type `Int`, that range is implicitly more constrained on 32-bit platforms to a subset range of `Int32.min` to `Int32.max` inclusive. Modifications: - Adjust `RFC9651BareItem` to take values `integer` or `date` with an associated value of type `Int64` instead, which is sufficient for the permitted range. Result: Compatibility for the Integer and Date Structured Types on 32-bit platforms.
This commit is contained in:
1 parent
be84570e9f
commit
1a14678249
4 files changed
+15
-15
No files matched your search
@@ -313,7 +313,7 @@ extension _StructuredFieldEncoder: SingleValueEncodingContainer {
|
||||
}
|
||||
|
||||
func encode(_ data: Date) throws {
|
||||
let date = Int(data.timeIntervalSince1970)
|
||||
let date = Int64(data.timeIntervalSince1970)
|
||||
try self.currentStackEntry.storage.insertBareItem(.date(date))
|
||||
}
|
||||
|
||||
@@ -371,7 +371,7 @@ extension _StructuredFieldEncoder: SingleValueEncodingContainer {
|
||||
}
|
||||
|
||||
private func _encodeFixedWidthInteger<T: FixedWidthInteger>(_ value: T) throws {
|
||||
guard let base = Int(exactly: value) else {
|
||||
guard let base = Int64(exactly: value) else {
|
||||
throw StructuredHeaderError.integerOutOfRange
|
||||
}
|
||||
try self.currentStackEntry.storage.insertBareItem(.integer(base))
|
||||
@@ -483,7 +483,7 @@ extension _StructuredFieldEncoder {
|
||||
}
|
||||
|
||||
func append(_ value: Date) throws {
|
||||
let date = Int(value.timeIntervalSince1970)
|
||||
let date = Int64(value.timeIntervalSince1970)
|
||||
try self.currentStackEntry.storage.appendBareItem(.date(date))
|
||||
}
|
||||
|
||||
@@ -562,7 +562,7 @@ extension _StructuredFieldEncoder {
|
||||
}
|
||||
|
||||
private func _appendFixedWidthInteger<T: FixedWidthInteger>(_ value: T) throws {
|
||||
guard let base = Int(exactly: value) else {
|
||||
guard let base = Int64(exactly: value) else {
|
||||
throw StructuredHeaderError.integerOutOfRange
|
||||
}
|
||||
try self.currentStackEntry.storage.appendBareItem(.integer(base))
|
||||
@@ -667,7 +667,7 @@ extension _StructuredFieldEncoder {
|
||||
|
||||
func encode(_ value: Date, forKey key: String) throws {
|
||||
let key = self.sanitizeKey(key)
|
||||
let date = Int(value.timeIntervalSince1970)
|
||||
let date = Int64(value.timeIntervalSince1970)
|
||||
try self.currentStackEntry.storage.insertBareItem(.date(date), atKey: key)
|
||||
}
|
||||
|
||||
@@ -789,7 +789,7 @@ extension _StructuredFieldEncoder {
|
||||
}
|
||||
|
||||
private func _encodeFixedWidthInteger<T: FixedWidthInteger>(_ value: T, forKey key: String) throws {
|
||||
guard let base = Int(exactly: value) else {
|
||||
guard let base = Int64(exactly: value) else {
|
||||
throw StructuredHeaderError.integerOutOfRange
|
||||
}
|
||||
try self.currentStackEntry.storage.insertBareItem(.integer(base), atKey: key)
|
||||
|
||||
Reference in new issue
Block a user