mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-23 22:55:00 +00:00
Refactoring
This commit is contained in:
@@ -4,10 +4,14 @@ func paddedSecureIdData(_ data: Data) -> Data {
|
||||
var paddingCount = Int(47 + arc4random_uniform(255 - 47))
|
||||
paddingCount -= ((data.count + paddingCount) % 16)
|
||||
var result = Data(count: paddingCount + data.count)
|
||||
result.withUnsafeMutableBytes { (bytes: UnsafeMutablePointer<UInt8>) -> Void in
|
||||
result.withUnsafeMutableBytes { rawBytes -> Void in
|
||||
let bytes = rawBytes.baseAddress!.assumingMemoryBound(to: UInt8.self)
|
||||
|
||||
bytes.advanced(by: 0).pointee = UInt8(paddingCount)
|
||||
arc4random_buf(bytes.advanced(by: 1), paddingCount - 1)
|
||||
data.withUnsafeBytes { (source: UnsafePointer<UInt8>) -> Void in
|
||||
data.withUnsafeBytes { rawSource -> Void in
|
||||
let source = rawSource.baseAddress!.assumingMemoryBound(to: UInt8.self)
|
||||
|
||||
memcpy(bytes.advanced(by: paddingCount), source, data.count)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user