Files
Morgan Pretty 5e384eb7fb Moved and renamed remaining API definitions
• Cleaned up API structures to be more consistent
• Moved OpenGroupAPI into SessionNetworkingKit
• Moved PushNotificationAPI into SessionNetworkingKit
• Renamed to OpenGroupAPI to SOGSAPI
2025-09-15 14:22:39 +10:00

42 lines
1.2 KiB
Swift

// Copyright © 2025 Rangeproof Pty Ltd. All rights reserved.
//
// stringlint:disable
import Foundation
import SessionUtil
import SessionUtilitiesKit
public extension Crypto.Generator {
static func plaintextWithPushNotificationPayload(
payload: Data,
encKey: Data
) -> Crypto.Generator<Data> {
return Crypto.Generator(
id: "plaintextWithPushNotificationPayload",
args: [payload, encKey]
) {
var cPayload: [UInt8] = Array(payload)
var cEncKey: [UInt8] = Array(encKey)
var maybePlaintext: UnsafeMutablePointer<UInt8>? = nil
var plaintextLen: Int = 0
guard
cEncKey.count == 32,
session_decrypt_push_notification(
&cPayload,
cPayload.count,
&cEncKey,
&maybePlaintext,
&plaintextLen
),
plaintextLen > 0,
let plaintext: Data = maybePlaintext.map({ Data(bytes: $0, count: plaintextLen) })
else { throw CryptoError.decryptionFailed }
free(UnsafeMutableRawPointer(mutating: maybePlaintext))
return plaintext
}
}
}