mirror of
https://github.com/apple/swift-crypto
synced 2026-11-29 05:14:21 +00:00
truncating for big contentLength (#119)
When contentLength is greater than 8 bits, i.e., greater than UInt8.max, the original implementation crashes. To work around this, use UInt8.init(truncatingIfNeeded:) to truncate only the lower 8 bits.
This commit is contained in:
1 parent
30b30ef3a1
commit
03399ef465
1 file changed
+1
-1
@@ -438,7 +438,7 @@ extension ASN1 {
|
||||
for shift in (0..<(lengthBytesNeeded - 1)).reversed() {
|
||||
// Shift and mask the integer.
|
||||
self.serializedBytes.formIndex(after: &writeIndex)
|
||||
self.serializedBytes[writeIndex] = UInt8((contentLength >> (shift * 8)) | 0x80 )
|
||||
self.serializedBytes[writeIndex] = UInt8(truncatingIfNeeded: (contentLength >> (shift * 8)) | 0x80 )
|
||||
}
|
||||
|
||||
assert(writeIndex == self.serializedBytes.index(lengthIndex, offsetBy: lengthBytesNeeded - 1))
|
||||
|
||||
Reference in new issue
Block a user