mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
33 lines
1009 B
Swift
33 lines
1009 B
Swift
import Foundation
|
|
|
|
public struct SecureIdValueAccessContext: Equatable {
|
|
let secret: Data
|
|
let id: Int64
|
|
|
|
public static func ==(lhs: SecureIdValueAccessContext, rhs: SecureIdValueAccessContext) -> Bool {
|
|
if lhs.secret != rhs.secret {
|
|
return false
|
|
}
|
|
if lhs.id != rhs.id {
|
|
return false
|
|
}
|
|
return true
|
|
}
|
|
}
|
|
|
|
public func generateSecureIdValueEmptyAccessContext() -> SecureIdValueAccessContext? {
|
|
return SecureIdValueAccessContext(secret: Data(), id: 0)
|
|
}
|
|
|
|
public func generateSecureIdValueAccessContext() -> SecureIdValueAccessContext? {
|
|
guard let secret = generateSecureSecretData() else {
|
|
return nil
|
|
}
|
|
let secretHashData = sha512Digest(secret)
|
|
var secretHash: Int64 = 0
|
|
secretHashData.withUnsafeBytes { (bytes: UnsafePointer<Int8>) -> Void in
|
|
memcpy(&secretHash, bytes.advanced(by: secretHashData.count - 8), 8)
|
|
}
|
|
return SecureIdValueAccessContext(secret: secret, id: secretHash)
|
|
}
|