mirror of https://github.com/oxen-io/session-ios
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.3 KiB
Swift
40 lines
1.3 KiB
Swift
5 years ago
|
import SessionProtocolKit
|
||
|
import SessionUtilitiesKit
|
||
|
|
||
|
@objc(SNNullMessage)
|
||
|
public final class NullMessage : ControlMessage {
|
||
|
|
||
|
// MARK: Initialization
|
||
|
public override init() { super.init() }
|
||
|
|
||
|
// MARK: Coding
|
||
|
public required init?(coder: NSCoder) {
|
||
|
super.init(coder: coder)
|
||
|
}
|
||
|
|
||
|
public override func encode(with coder: NSCoder) {
|
||
|
super.encode(with: coder)
|
||
|
}
|
||
|
|
||
|
// MARK: Proto Conversion
|
||
|
public override class func fromProto(_ proto: SNProtoContent) -> NullMessage? {
|
||
|
guard proto.nullMessage != nil else { return nil }
|
||
|
return NullMessage()
|
||
|
}
|
||
|
|
||
|
public override func toProto() -> SNProtoContent? {
|
||
|
let nullMessageProto = SNProtoNullMessage.builder()
|
||
|
let paddingSize = UInt.random(in: 0..<512) // random(in:) uses the system's default random generator, which is cryptographically secure
|
||
|
let padding = Data.getSecureRandomData(ofSize: paddingSize)!
|
||
|
nullMessageProto.setPadding(padding)
|
||
|
let contentProto = SNProtoContent.builder()
|
||
|
do {
|
||
|
contentProto.setNullMessage(try nullMessageProto.build())
|
||
|
return try contentProto.build()
|
||
|
} catch {
|
||
|
SNLog("Couldn't construct null message proto from: \(self).")
|
||
|
return nil
|
||
|
}
|
||
|
}
|
||
|
}
|