mirror of https://github.com/oxen-io/session-ios
parent
99cd8fc27d
commit
35ee92f38f
@ -0,0 +1,19 @@
|
||||
//
|
||||
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
#import "TSOutgoingMessage.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@class OWSVerificationStateSyncMessage;
|
||||
@class TSContactThread;
|
||||
|
||||
@interface OWSOutgoingNullMessage : TSOutgoingMessage
|
||||
|
||||
- (instancetype)initWithContactThread:(TSContactThread *)contactThread
|
||||
verificationStateSyncMessage:(OWSVerificationStateSyncMessage *)verificationStateSyncMessage;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
@ -0,0 +1,67 @@
|
||||
//
|
||||
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
#import "OWSOutgoingNullMessage.h"
|
||||
#import "OWSSignalServiceProtos.pb.h"
|
||||
#import "Cryptography.h"
|
||||
#import "OWSVerificationStateSyncMessage.h"
|
||||
#import "NSDate+millisecondTimeStamp.h"
|
||||
#import "TSContactThread.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface OWSOutgoingNullMessage ()
|
||||
|
||||
@property (nonatomic, readonly) OWSVerificationStateSyncMessage *verificationStateSyncMessage;
|
||||
|
||||
@end
|
||||
|
||||
@implementation OWSOutgoingNullMessage
|
||||
|
||||
- (instancetype)initWithContactThread:(TSContactThread *)contactThread
|
||||
verificationStateSyncMessage:(OWSVerificationStateSyncMessage *)verificationStateSyncMessage
|
||||
{
|
||||
self = [super initWithTimestamp:[NSDate ows_millisecondTimeStamp]
|
||||
inThread:contactThread];
|
||||
if (!self) {
|
||||
return self;
|
||||
}
|
||||
|
||||
_verificationStateSyncMessage = verificationStateSyncMessage;
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
#pragma mark - override TSOutgoingMessage
|
||||
|
||||
- (NSData *)buildPlainTextData
|
||||
{
|
||||
OWSSignalServiceProtosContentBuilder *contentBuilder = [OWSSignalServiceProtosContentBuilder new];
|
||||
OWSSignalServiceProtosNullMessageBuilder *nullMessageBuilder = [OWSSignalServiceProtosNullMessageBuilder new];
|
||||
|
||||
// TODO padding size.
|
||||
NSUInteger contentLength = self.verificationStateSyncMessage.buildPlainTextData.length;
|
||||
contentLength -= self.verificationStateSyncMessage.paddingBytesLength;
|
||||
|
||||
OWSAssert(contentLength > 0)
|
||||
|
||||
// Add 1-512 bytes of random padding bytes.
|
||||
contentLength += arc4random_uniform(512) + 1;
|
||||
|
||||
nullMessageBuilder.padding = [Cryptography generateRandomBytes:contentLength];
|
||||
|
||||
contentBuilder.nullMessage = [nullMessageBuilder build];
|
||||
|
||||
return [contentBuilder build].data;
|
||||
}
|
||||
|
||||
- (void)saveWithTransaction:(YapDatabaseReadWriteTransaction *)transaction
|
||||
{
|
||||
// No-op as we don't want to actually display this as an outgoing message in our thread.
|
||||
return;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
Loading…
Reference in New Issue