Code generate Swift wrappers for protocol buffers.

pull/1/head
Matthew Chen 7 years ago
parent e45a6d5bed
commit f814157a9e

@ -109,7 +109,7 @@ class BaseContext(object):
def derive_swift_name(self): def derive_swift_name(self):
names = self.inherited_proto_names() names = self.inherited_proto_names()
return self.args.wrapper_prefix + '_'.join(names) return self.args.wrapper_prefix + ''.join(names)
def derive_wrapped_swift_name(self): def derive_wrapped_swift_name(self):
names = self.inherited_proto_names() names = self.inherited_proto_names()
@ -275,6 +275,11 @@ class FileContext(BaseContext):
import Foundation import Foundation
''') ''')
writer.extend('''
// WARNING: This code is generated. Only edit within the markers.
'''.strip())
writer.newline()
writer.invalid_protobuf_error_name = '%sError' % self.args.wrapper_prefix writer.invalid_protobuf_error_name = '%sError' % self.args.wrapper_prefix
writer.extend((''' writer.extend(('''
public enum %s: Error { public enum %s: Error {
@ -329,6 +334,9 @@ class MessageContext(BaseContext):
child.prepare() child.prepare()
def generate(self, writer): def generate(self, writer):
for child in self.messages:
child.generate(writer)
writer.add('// MARK: - %s' % self.swift_name) writer.add('// MARK: - %s' % self.swift_name)
writer.newline() writer.newline()
@ -337,7 +345,7 @@ class MessageContext(BaseContext):
writer.push_context(self.proto_name, self.swift_name) writer.push_context(self.proto_name, self.swift_name)
for child in self.children(): for child in self.enums:
child.generate(writer) child.generate(writer)
# Prepare fields # Prepare fields
@ -431,6 +439,7 @@ public func serializedData() throws -> Data {
writer.newline() writer.newline()
# Preserve existing validation logic. # Preserve existing validation logic.
if self.swift_name in args.validation_map:
validation_block = args.validation_map[self.swift_name] validation_block = args.validation_map[self.swift_name]
if validation_block: if validation_block:
writer.add_raw(validation_block) writer.add_raw(validation_block)
@ -577,10 +586,8 @@ class EnumContext(BaseContext):
writer.add('private class func %sWrap(_ value: %s) -> %s {' % ( self.swift_name, wrapped_swift_name, self.swift_name, ) ) writer.add('private class func %sWrap(_ value: %s) -> %s {' % ( self.swift_name, wrapped_swift_name, self.swift_name, ) )
writer.push_indent() writer.push_indent()
writer.add('switch value {') writer.add('switch value {')
writer.push_indent()
for case_name, case_index in self.case_pairs(): for case_name, case_index in self.case_pairs():
writer.add('case .%s: return .%s' % (case_name, case_name,)) writer.add('case .%s: return .%s' % (case_name, case_name,))
writer.pop_indent()
writer.add('}') writer.add('}')
writer.pop_indent() writer.pop_indent()
writer.add('}') writer.add('}')
@ -588,10 +595,8 @@ class EnumContext(BaseContext):
writer.add('private class func %sUnwrap(_ value: %s) -> %s {' % ( self.swift_name, self.swift_name, wrapped_swift_name, ) ) writer.add('private class func %sUnwrap(_ value: %s) -> %s {' % ( self.swift_name, self.swift_name, wrapped_swift_name, ) )
writer.push_indent() writer.push_indent()
writer.add('switch value {') writer.add('switch value {')
writer.push_indent()
for case_name, case_index in self.case_pairs(): for case_name, case_index in self.case_pairs():
writer.add('case .%s: return .%s' % (case_name, case_name,)) writer.add('case .%s: return .%s' % (case_name, case_name,))
writer.pop_indent()
writer.add('}') writer.add('}')
writer.pop_indent() writer.pop_indent()
writer.add('}') writer.add('}')

@ -38,7 +38,7 @@ public class MessageFetcherJob: NSObject {
Logger.info("\(self.logTag) fetching messages via REST.") Logger.info("\(self.logTag) fetching messages via REST.")
let promise = self.fetchUndeliveredMessages().then { (envelopes: [SSKEnvelope], more: Bool) -> Promise<Void> in let promise = self.fetchUndeliveredMessages().then { (envelopes: [SSKProtoEnvelope], more: Bool) -> Promise<Void> in
for envelope in envelopes { for envelope in envelopes {
Logger.info("\(self.logTag) received envelope.") Logger.info("\(self.logTag) received envelope.")
do { do {
@ -85,7 +85,7 @@ public class MessageFetcherJob: NSObject {
timer = nil timer = nil
} }
private func parseMessagesResponse(responseObject: Any?) -> (envelopes: [SSKEnvelope], more: Bool)? { private func parseMessagesResponse(responseObject: Any?) -> (envelopes: [SSKProtoEnvelope], more: Bool)? {
guard let responseObject = responseObject else { guard let responseObject = responseObject else {
Logger.error("\(self.logTag) response object was surpringly nil") Logger.error("\(self.logTag) response object was surpringly nil")
return nil return nil
@ -110,7 +110,7 @@ public class MessageFetcherJob: NSObject {
} }
}() }()
let envelopes: [SSKEnvelope] = messageDicts.compactMap { buildEnvelope(messageDict: $0) } let envelopes: [SSKProtoEnvelope] = messageDicts.compactMap { buildEnvelope(messageDict: $0) }
return ( return (
envelopes: envelopes, envelopes: envelopes,
@ -118,12 +118,12 @@ public class MessageFetcherJob: NSObject {
) )
} }
private func buildEnvelope(messageDict: [String: Any]) -> SSKEnvelope? { private func buildEnvelope(messageDict: [String: Any]) -> SSKProtoEnvelope? {
do { do {
let params = ParamParser(dictionary: messageDict) let params = ParamParser(dictionary: messageDict)
let typeInt: Int32 = try params.required(key: "type") let typeInt: Int32 = try params.required(key: "type")
guard let type: SSKEnvelope.SSKEnvelopeType = SSKEnvelope.SSKEnvelopeType(rawValue: typeInt) else { guard let type: SSKProtoEnvelope.SSKProtoEnvelopeType = SSKProtoEnvelope.SSKProtoEnvelopeType(rawValue: typeInt) else {
Logger.error("\(self.logTag) `typeInt` was invalid: \(typeInt)") Logger.error("\(self.logTag) `typeInt` was invalid: \(typeInt)")
throw ParamParser.ParseError.invalidFormat("type") throw ParamParser.ParseError.invalidFormat("type")
} }
@ -134,14 +134,14 @@ public class MessageFetcherJob: NSObject {
let legacyMessage: Data? = try params.optionalBase64EncodedData(key: "message") let legacyMessage: Data? = try params.optionalBase64EncodedData(key: "message")
let content: Data? = try params.optionalBase64EncodedData(key: "content") let content: Data? = try params.optionalBase64EncodedData(key: "content")
return SSKEnvelope(timestamp: UInt64(timestamp), source: source, sourceDevice: sourceDevice, type: type, content: content, legacyMessage: legacyMessage) return SSKProtoEnvelope(type: type, relay: nil, source: source, timestamp: UInt64(timestamp), sourceDevice: sourceDevice, legacyMessage: legacyMessage, content: content)
} catch { } catch {
owsFail("\(self.logTag) in \(#function) error building envelope: \(error)") owsFail("\(self.logTag) in \(#function) error building envelope: \(error)")
return nil return nil
} }
} }
private func fetchUndeliveredMessages() -> Promise<(envelopes: [SSKEnvelope], more: Bool)> { private func fetchUndeliveredMessages() -> Promise<(envelopes: [SSKProtoEnvelope], more: Bool)> {
return Promise { fulfill, reject in return Promise { fulfill, reject in
let request = OWSRequestFactory.getMessagesRequest() let request = OWSRequestFactory.getMessagesRequest()
self.networkManager.makeRequest( self.networkManager.makeRequest(
@ -165,8 +165,12 @@ public class MessageFetcherJob: NSObject {
} }
} }
private func acknowledgeDelivery(envelope: SSKEnvelope) { private func acknowledgeDelivery(envelope: SSKProtoEnvelope) {
let request = OWSRequestFactory.acknowledgeMessageDeliveryRequest(withSource: envelope.source, timestamp: envelope.timestamp) guard let source = envelope.source else {
Logger.error("\(self.logTag) envelope missing source.")
return
}
let request = OWSRequestFactory.acknowledgeMessageDeliveryRequest(withSource: source, timestamp: envelope.timestamp)
self.networkManager.makeRequest(request, self.networkManager.makeRequest(request,
success: { (_: URLSessionDataTask?, _: Any?) -> Void in success: { (_: URLSessionDataTask?, _: Any?) -> Void in
Logger.debug("\(self.logTag) acknowledged delivery for message at timestamp: \(envelope.timestamp)") Logger.debug("\(self.logTag) acknowledged delivery for message at timestamp: \(envelope.timestamp)")

@ -3372,7 +3372,7 @@ typedef OWSContact * (^OWSContactBlock)(YapDatabaseReadWriteTransaction *transac
completion:nil]; completion:nil];
} }
+ (SSKEnvelope *)createEnvelopeForThread:(TSThread *)thread + (SSKProtoEnvelope *)createEnvelopeForThread:(TSThread *)thread
{ {
OWSAssert(thread); OWSAssert(thread);
@ -3390,13 +3390,14 @@ typedef OWSContact * (^OWSContactBlock)(YapDatabaseReadWriteTransaction *transac
} }
}(); }();
SSKEnvelope *envelope = [[SSKEnvelope alloc] initWithTimestamp:timestamp
SSKProtoEnvelope *envelope = [[SSKProtoEnvelope alloc] initWithType:SSKProtoEnvelopeTypeCiphertext
relay:nil
source:source source:source
timestamp:timestamp
sourceDevice:1 sourceDevice:1
type:SSKEnvelopeTypeCiphertext legacyMessage:nil
content:nil content:nil];
legacyMessage:nil];
return envelope; return envelope;
} }
@ -3886,15 +3887,16 @@ typedef OWSContact * (^OWSContactBlock)(YapDatabaseReadWriteTransaction *transac
uint64_t timestamp = [NSDate ows_millisecondTimeStamp]; uint64_t timestamp = [NSDate ows_millisecondTimeStamp];
NSString *source = recipientId; NSString *source = recipientId;
uint32_t sourceDevice = 1; uint32_t sourceDevice = 1;
SSKEnvelopeType envelopeType = SSKEnvelopeTypeCiphertext; SSKProtoEnvelopeType envelopeType = SSKProtoEnvelopeTypeCiphertext;
NSData *content = plaintextData; NSData *content = plaintextData;
SSKEnvelope *envelope = [[SSKEnvelope alloc] initWithTimestamp:timestamp SSKProtoEnvelope *envelope = [[SSKProtoEnvelope alloc] initWithType:envelopeType
relay:nil
source:source source:source
timestamp:timestamp
sourceDevice:sourceDevice sourceDevice:sourceDevice
type:envelopeType legacyMessage:nil
content:content content:content];
legacyMessage:nil];
NSError *error; NSError *error;
NSData *_Nullable envelopeData = [envelope serializedDataAndReturnError:&error]; NSData *_Nullable envelopeData = [envelope serializedDataAndReturnError:&error];

@ -7,7 +7,7 @@ import XCTest
import SignalServiceKit import SignalServiceKit
import SwiftProtobuf import SwiftProtobuf
class SSKEnvelopeTest: XCTestCase { class SSKProtoEnvelopeTest: XCTestCase {
override func setUp() { override func setUp() {
super.setUp() super.setUp()
@ -21,12 +21,12 @@ class SSKEnvelopeTest: XCTestCase {
func testParse_EmptyData() { func testParse_EmptyData() {
let data = Data() let data = Data()
XCTAssertThrowsError(try SSKEnvelope(serializedData: data)) XCTAssertThrowsError(try SSKProtoEnvelope(serializedData: data))
} }
func testParse_UnparseableData() { func testParse_UnparseableData() {
let data = "asdf".data(using: .utf8)! let data = "asdf".data(using: .utf8)!
XCTAssertThrowsError(try SSKEnvelope(serializedData: data)) { error in XCTAssertThrowsError(try SSKProtoEnvelope(serializedData: data)) { error in
XCTAssert(error is SwiftProtobuf.BinaryDecodingError) XCTAssert(error is SwiftProtobuf.BinaryDecodingError)
} }
} }
@ -42,7 +42,7 @@ class SSKEnvelopeTest: XCTestCase {
let encodedData = "CAESDCsxNTU1MTIzMTIzNCjKm4WazSw4AQ==" let encodedData = "CAESDCsxNTU1MTIzMTIzNCjKm4WazSw4AQ=="
let data = Data(base64Encoded: encodedData)! let data = Data(base64Encoded: encodedData)!
XCTAssertNoThrow(try SSKEnvelope(serializedData: data)) XCTAssertNoThrow(try SSKProtoEnvelope(serializedData: data))
} }
func testParse_invalidData() { func testParse_invalidData() {
@ -56,9 +56,9 @@ class SSKEnvelopeTest: XCTestCase {
let encodedData = "EgwrMTU1NTEyMzEyMzQojdmOms0sOAE=" let encodedData = "EgwrMTU1NTEyMzEyMzQojdmOms0sOAE="
let data = Data(base64Encoded: encodedData)! let data = Data(base64Encoded: encodedData)!
XCTAssertThrowsError(try SSKEnvelope(serializedData: data)) { (error) -> Void in XCTAssertThrowsError(try SSKProtoEnvelope(serializedData: data)) { (error) -> Void in
switch error { switch error {
case SSKEnvelope.EnvelopeError.invalidProtobuf: case SSKProtoEnvelope.EnvelopeError.invalidProtobuf:
break break
default: default:
XCTFail("unexpected error: \(error)") XCTFail("unexpected error: \(error)")

@ -7,7 +7,7 @@
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
@class SSKEnvelope; @class SSKProtoEnvelope;
typedef NS_ENUM(int32_t, TSErrorMessageType) { typedef NS_ENUM(int32_t, TSErrorMessageType) {
TSErrorMessageNoSession, TSErrorMessageNoSession,
@ -55,18 +55,18 @@ typedef NS_ENUM(int32_t, TSErrorMessageType) {
inThread:(nullable TSThread *)thread inThread:(nullable TSThread *)thread
failedMessageType:(TSErrorMessageType)errorMessageType; failedMessageType:(TSErrorMessageType)errorMessageType;
+ (instancetype)corruptedMessageWithEnvelope:(SSKEnvelope *)envelope + (instancetype)corruptedMessageWithEnvelope:(SSKProtoEnvelope *)envelope
withTransaction:(YapDatabaseReadWriteTransaction *)transaction; withTransaction:(YapDatabaseReadWriteTransaction *)transaction;
+ (instancetype)corruptedMessageInUnknownThread; + (instancetype)corruptedMessageInUnknownThread;
+ (instancetype)invalidVersionWithEnvelope:(SSKEnvelope *)envelope + (instancetype)invalidVersionWithEnvelope:(SSKProtoEnvelope *)envelope
withTransaction:(YapDatabaseReadWriteTransaction *)transaction; withTransaction:(YapDatabaseReadWriteTransaction *)transaction;
+ (instancetype)invalidKeyExceptionWithEnvelope:(SSKEnvelope *)envelope + (instancetype)invalidKeyExceptionWithEnvelope:(SSKProtoEnvelope *)envelope
withTransaction:(YapDatabaseReadWriteTransaction *)transaction; withTransaction:(YapDatabaseReadWriteTransaction *)transaction;
+ (instancetype)missingSessionWithEnvelope:(SSKEnvelope *)envelope + (instancetype)missingSessionWithEnvelope:(SSKProtoEnvelope *)envelope
withTransaction:(YapDatabaseReadWriteTransaction *)transaction; withTransaction:(YapDatabaseReadWriteTransaction *)transaction;
+ (instancetype)nonblockingIdentityChangeInThread:(TSThread *)thread recipientId:(NSString *)recipientId; + (instancetype)nonblockingIdentityChangeInThread:(TSThread *)thread recipientId:(NSString *)recipientId;

@ -84,7 +84,7 @@ NSUInteger TSErrorMessageSchemaVersion = 1;
return [self initWithTimestamp:timestamp inThread:thread failedMessageType:errorMessageType recipientId:nil]; return [self initWithTimestamp:timestamp inThread:thread failedMessageType:errorMessageType recipientId:nil];
} }
- (instancetype)initWithEnvelope:(SSKEnvelope *)envelope - (instancetype)initWithEnvelope:(SSKProtoEnvelope *)envelope
withTransaction:(YapDatabaseReadWriteTransaction *)transaction withTransaction:(YapDatabaseReadWriteTransaction *)transaction
failedMessageType:(TSErrorMessageType)errorMessageType failedMessageType:(TSErrorMessageType)errorMessageType
{ {
@ -146,7 +146,7 @@ NSUInteger TSErrorMessageSchemaVersion = 1;
} }
} }
+ (instancetype)corruptedMessageWithEnvelope:(SSKEnvelope *)envelope + (instancetype)corruptedMessageWithEnvelope:(SSKProtoEnvelope *)envelope
withTransaction:(YapDatabaseReadWriteTransaction *)transaction withTransaction:(YapDatabaseReadWriteTransaction *)transaction
{ {
return [[self alloc] initWithEnvelope:envelope return [[self alloc] initWithEnvelope:envelope
@ -159,7 +159,7 @@ NSUInteger TSErrorMessageSchemaVersion = 1;
return [[self alloc] initWithFailedMessageType:TSErrorMessageInvalidMessage]; return [[self alloc] initWithFailedMessageType:TSErrorMessageInvalidMessage];
} }
+ (instancetype)invalidVersionWithEnvelope:(SSKEnvelope *)envelope + (instancetype)invalidVersionWithEnvelope:(SSKProtoEnvelope *)envelope
withTransaction:(YapDatabaseReadWriteTransaction *)transaction withTransaction:(YapDatabaseReadWriteTransaction *)transaction
{ {
return [[self alloc] initWithEnvelope:envelope return [[self alloc] initWithEnvelope:envelope
@ -167,7 +167,7 @@ NSUInteger TSErrorMessageSchemaVersion = 1;
failedMessageType:TSErrorMessageInvalidVersion]; failedMessageType:TSErrorMessageInvalidVersion];
} }
+ (instancetype)invalidKeyExceptionWithEnvelope:(SSKEnvelope *)envelope + (instancetype)invalidKeyExceptionWithEnvelope:(SSKProtoEnvelope *)envelope
withTransaction:(YapDatabaseReadWriteTransaction *)transaction withTransaction:(YapDatabaseReadWriteTransaction *)transaction
{ {
return [[self alloc] initWithEnvelope:envelope return [[self alloc] initWithEnvelope:envelope
@ -175,7 +175,7 @@ NSUInteger TSErrorMessageSchemaVersion = 1;
failedMessageType:TSErrorMessageInvalidKeyException]; failedMessageType:TSErrorMessageInvalidKeyException];
} }
+ (instancetype)missingSessionWithEnvelope:(SSKEnvelope *)envelope + (instancetype)missingSessionWithEnvelope:(SSKProtoEnvelope *)envelope
withTransaction:(YapDatabaseReadWriteTransaction *)transaction withTransaction:(YapDatabaseReadWriteTransaction *)transaction
{ {
return return

@ -6,13 +6,13 @@
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
@class SSKEnvelope; @class SSKProtoEnvelope;
// DEPRECATED - we no longer create new instances of this class (as of mid-2017); However, existing instances may // DEPRECATED - we no longer create new instances of this class (as of mid-2017); However, existing instances may
// exist, so we should keep this class around to honor their old behavior. // exist, so we should keep this class around to honor their old behavior.
@interface TSInvalidIdentityKeyReceivingErrorMessage : TSInvalidIdentityKeyErrorMessage @interface TSInvalidIdentityKeyReceivingErrorMessage : TSInvalidIdentityKeyErrorMessage
+ (nullable instancetype)untrustedKeyWithEnvelope:(SSKEnvelope *)envelope + (nullable instancetype)untrustedKeyWithEnvelope:(SSKProtoEnvelope *)envelope
withTransaction:(YapDatabaseReadWriteTransaction *)transaction; withTransaction:(YapDatabaseReadWriteTransaction *)transaction;
@end @end

@ -28,12 +28,12 @@ NS_ASSUME_NONNULL_BEGIN
@implementation TSInvalidIdentityKeyReceivingErrorMessage { @implementation TSInvalidIdentityKeyReceivingErrorMessage {
// Not using a property declaration in order to exclude from DB serialization // Not using a property declaration in order to exclude from DB serialization
SSKEnvelope *_Nullable _envelope; SSKProtoEnvelope *_Nullable _envelope;
} }
@synthesize envelopeData = _envelopeData; @synthesize envelopeData = _envelopeData;
+ (nullable instancetype)untrustedKeyWithEnvelope:(SSKEnvelope *)envelope + (nullable instancetype)untrustedKeyWithEnvelope:(SSKProtoEnvelope *)envelope
withTransaction:(YapDatabaseReadWriteTransaction *)transaction withTransaction:(YapDatabaseReadWriteTransaction *)transaction
{ {
TSContactThread *contactThread = TSContactThread *contactThread =
@ -47,7 +47,7 @@ NS_ASSUME_NONNULL_BEGIN
- (nullable instancetype)initForUnknownIdentityKeyWithTimestamp:(uint64_t)timestamp - (nullable instancetype)initForUnknownIdentityKeyWithTimestamp:(uint64_t)timestamp
inThread:(TSThread *)thread inThread:(TSThread *)thread
incomingEnvelope:(SSKEnvelope *)envelope incomingEnvelope:(SSKProtoEnvelope *)envelope
{ {
self = [self initWithTimestamp:timestamp inThread:thread failedMessageType:TSErrorMessageWrongTrustedIdentityKey]; self = [self initWithTimestamp:timestamp inThread:thread failedMessageType:TSErrorMessageWrongTrustedIdentityKey];
if (!self) { if (!self) {
@ -66,11 +66,11 @@ NS_ASSUME_NONNULL_BEGIN
return self; return self;
} }
- (nullable SSKEnvelope *)envelope - (nullable SSKProtoEnvelope *)envelope
{ {
if (!_envelope) { if (!_envelope) {
NSError *error; NSError *error;
SSKEnvelope *_Nullable envelope = [[SSKEnvelope alloc] initWithSerializedData:self.envelopeData error:&error]; SSKProtoEnvelope *_Nullable envelope = [SSKProtoEnvelope parseData:self.envelopeData error:&error];
if (error || envelope == nil) { if (error || envelope == nil) {
OWSProdLogAndFail(@"%@ Could not parse proto: %@", self.logTag, error); OWSProdLogAndFail(@"%@ Could not parse proto: %@", self.logTag, error);
} else { } else {
@ -118,7 +118,7 @@ NS_ASSUME_NONNULL_BEGIN
return nil; return nil;
} }
if (self.envelope.type != SSKEnvelopeTypePrekeyBundle) { if (self.envelope.type != SSKProtoEnvelopeTypePrekeyBundle) {
DDLogError(@"Refusing to attempt key extraction from an envelope which isn't a prekey bundle"); DDLogError(@"Refusing to attempt key extraction from an envelope which isn't a prekey bundle");
return nil; return nil;
} }

@ -5,7 +5,7 @@
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
@class OWSStorage; @class OWSStorage;
@class SSKEnvelope; @class SSKProtoEnvelope;
@class YapDatabaseReadWriteTransaction; @class YapDatabaseReadWriteTransaction;
// This class is used to write incoming (decrypted, unprocessed) // This class is used to write incoming (decrypted, unprocessed)

@ -40,7 +40,7 @@ NS_ASSUME_NONNULL_BEGIN
- (nullable instancetype)initWithCoder:(NSCoder *)coder NS_DESIGNATED_INITIALIZER; - (nullable instancetype)initWithCoder:(NSCoder *)coder NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithUniqueId:(NSString *_Nullable)uniqueId NS_UNAVAILABLE; - (instancetype)initWithUniqueId:(NSString *_Nullable)uniqueId NS_UNAVAILABLE;
@property (nonatomic, readonly, nullable) SSKEnvelope *envelope; @property (nonatomic, readonly, nullable) SSKProtoEnvelope *envelope;
@end @end
@ -74,13 +74,13 @@ NS_ASSUME_NONNULL_BEGIN
return [super initWithCoder:coder]; return [super initWithCoder:coder];
} }
- (nullable SSKEnvelope *)envelope - (nullable SSKProtoEnvelope *)envelope
{ {
NSError *error; NSError *error;
SSKEnvelope *_Nullable result = [[SSKEnvelope alloc] initWithSerializedData:self.envelopeData error:&error]; SSKProtoEnvelope *_Nullable result = [SSKProtoEnvelope parseData:self.envelopeData error:&error];
if (error) { if (error) {
OWSProdLogAndFail(@"%@ paring SSKEnvelope failed with error: %@", self.logTag, error); OWSProdLogAndFail(@"%@ paring SSKProtoEnvelope failed with error: %@", self.logTag, error);
return nil; return nil;
} }
@ -396,7 +396,7 @@ NSString *const OWSMessageContentJobFinderExtensionGroup = @"OWSMessageContentJo
}; };
@try { @try {
SSKEnvelope *_Nullable envelope = job.envelope; SSKProtoEnvelope *_Nullable envelope = job.envelope;
if (!envelope) { if (!envelope) {
reportFailure(transaction); reportFailure(transaction);
} else { } else {

@ -6,7 +6,7 @@
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
@class SSKEnvelope; @class SSKProtoEnvelope;
@class YapDatabaseReadWriteTransaction; @class YapDatabaseReadWriteTransaction;
typedef void (^DecryptSuccessBlock)(NSData *_Nullable plaintextData, YapDatabaseReadWriteTransaction *transaction); typedef void (^DecryptSuccessBlock)(NSData *_Nullable plaintextData, YapDatabaseReadWriteTransaction *transaction);
@ -22,7 +22,7 @@ typedef void (^DecryptFailureBlock)(void);
// //
// Exactly one of successBlock & failureBlock will be called, // Exactly one of successBlock & failureBlock will be called,
// once. // once.
- (void)decryptEnvelope:(SSKEnvelope *)envelope - (void)decryptEnvelope:(SSKProtoEnvelope *)envelope
successBlock:(DecryptSuccessBlock)successBlock successBlock:(DecryptSuccessBlock)successBlock
failureBlock:(DecryptFailureBlock)failureBlock; failureBlock:(DecryptFailureBlock)failureBlock;

@ -81,7 +81,7 @@ NS_ASSUME_NONNULL_BEGIN
#pragma mark - Blocking #pragma mark - Blocking
- (BOOL)isEnvelopeBlocked:(SSKEnvelope *)envelope - (BOOL)isEnvelopeBlocked:(SSKProtoEnvelope *)envelope
{ {
OWSAssert(envelope); OWSAssert(envelope);
@ -90,7 +90,7 @@ NS_ASSUME_NONNULL_BEGIN
#pragma mark - Decryption #pragma mark - Decryption
- (void)decryptEnvelope:(SSKEnvelope *)envelope - (void)decryptEnvelope:(SSKProtoEnvelope *)envelope
successBlock:(DecryptSuccessBlock)successBlockParameter successBlock:(DecryptSuccessBlock)successBlockParameter
failureBlock:(DecryptFailureBlock)failureBlockParameter failureBlock:(DecryptFailureBlock)failureBlockParameter
{ {
@ -129,7 +129,7 @@ NS_ASSUME_NONNULL_BEGIN
} }
switch (envelope.type) { switch (envelope.type) {
case SSKEnvelopeTypeCiphertext: { case SSKProtoEnvelopeTypeCiphertext: {
[self decryptSecureMessage:envelope [self decryptSecureMessage:envelope
successBlock:^(NSData *_Nullable plaintextData, YapDatabaseReadWriteTransaction *transaction) { successBlock:^(NSData *_Nullable plaintextData, YapDatabaseReadWriteTransaction *transaction) {
DDLogDebug(@"%@ decrypted secure message.", self.logTag); DDLogDebug(@"%@ decrypted secure message.", self.logTag);
@ -146,7 +146,7 @@ NS_ASSUME_NONNULL_BEGIN
// Return to avoid double-acknowledging. // Return to avoid double-acknowledging.
return; return;
} }
case SSKEnvelopeTypePrekeyBundle: { case SSKProtoEnvelopeTypePrekeyBundle: {
[self decryptPreKeyBundle:envelope [self decryptPreKeyBundle:envelope
successBlock:^(NSData *_Nullable plaintextData, YapDatabaseReadWriteTransaction *transaction) { successBlock:^(NSData *_Nullable plaintextData, YapDatabaseReadWriteTransaction *transaction) {
DDLogDebug(@"%@ decrypted pre-key whisper message", self.logTag); DDLogDebug(@"%@ decrypted pre-key whisper message", self.logTag);
@ -165,9 +165,9 @@ NS_ASSUME_NONNULL_BEGIN
return; return;
} }
// These message types don't have a payload to decrypt. // These message types don't have a payload to decrypt.
case SSKEnvelopeTypeReceipt: case SSKProtoEnvelopeTypeReceipt:
case SSKEnvelopeTypeKeyExchange: case SSKProtoEnvelopeTypeKeyExchange:
case SSKEnvelopeTypeUnknown: { case SSKProtoEnvelopeTypeUnknown: {
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) { [self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
successBlock(nil, transaction); successBlock(nil, transaction);
}]; }];
@ -193,7 +193,7 @@ NS_ASSUME_NONNULL_BEGIN
failureBlock(); failureBlock();
} }
- (void)decryptSecureMessage:(SSKEnvelope *)envelope - (void)decryptSecureMessage:(SSKProtoEnvelope *)envelope
successBlock:(DecryptSuccessBlock)successBlock successBlock:(DecryptSuccessBlock)successBlock
failureBlock:(void (^)(NSError *_Nullable error))failureBlock failureBlock:(void (^)(NSError *_Nullable error))failureBlock
{ {
@ -210,7 +210,7 @@ NS_ASSUME_NONNULL_BEGIN
failureBlock:failureBlock]; failureBlock:failureBlock];
} }
- (void)decryptPreKeyBundle:(SSKEnvelope *)envelope - (void)decryptPreKeyBundle:(SSKProtoEnvelope *)envelope
successBlock:(DecryptSuccessBlock)successBlock successBlock:(DecryptSuccessBlock)successBlock
failureBlock:(void (^)(NSError *_Nullable error))failureBlock failureBlock:(void (^)(NSError *_Nullable error))failureBlock
{ {
@ -230,7 +230,7 @@ NS_ASSUME_NONNULL_BEGIN
failureBlock:failureBlock]; failureBlock:failureBlock];
} }
- (void)decryptEnvelope:(SSKEnvelope *)envelope - (void)decryptEnvelope:(SSKProtoEnvelope *)envelope
cipherTypeName:(NSString *)cipherTypeName cipherTypeName:(NSString *)cipherTypeName
cipherMessageBlock:(id<CipherMessage> (^_Nonnull)(NSData *))cipherMessageBlock cipherMessageBlock:(id<CipherMessage> (^_Nonnull)(NSData *))cipherMessageBlock
successBlock:(DecryptSuccessBlock)successBlock successBlock:(DecryptSuccessBlock)successBlock
@ -279,7 +279,7 @@ NS_ASSUME_NONNULL_BEGIN
}]; }];
} }
- (void)processException:(NSException *)exception envelope:(SSKEnvelope *)envelope - (void)processException:(NSException *)exception envelope:(SSKProtoEnvelope *)envelope
{ {
DDLogError(@"%@ Got exception: %@ of type: %@ with reason: %@", DDLogError(@"%@ Got exception: %@ of type: %@ with reason: %@",
self.logTag, self.logTag,
@ -326,7 +326,7 @@ NS_ASSUME_NONNULL_BEGIN
} }
- (void)notifyUserForErrorMessage:(TSErrorMessage *)errorMessage - (void)notifyUserForErrorMessage:(TSErrorMessage *)errorMessage
envelope:(SSKEnvelope *)envelope envelope:(SSKProtoEnvelope *)envelope
transaction:(YapDatabaseReadWriteTransaction *)transaction transaction:(YapDatabaseReadWriteTransaction *)transaction
{ {
TSThread *contactThread = [TSContactThread getOrCreateThreadWithContactId:envelope.source transaction:transaction]; TSThread *contactThread = [TSContactThread getOrCreateThreadWithContactId:envelope.source transaction:transaction];

@ -6,14 +6,14 @@ NS_ASSUME_NONNULL_BEGIN
@class OWSSignalServiceProtosContent; @class OWSSignalServiceProtosContent;
@class OWSSignalServiceProtosDataMessage; @class OWSSignalServiceProtosDataMessage;
@class SSKEnvelope; @class SSKProtoEnvelope;
NSString *envelopeAddress(SSKEnvelope *envelope); NSString *envelopeAddress(SSKProtoEnvelope *envelope);
@interface OWSMessageHandler : NSObject @interface OWSMessageHandler : NSObject
- (NSString *)descriptionForEnvelopeType:(SSKEnvelope *)envelope; - (NSString *)descriptionForEnvelopeType:(SSKProtoEnvelope *)envelope;
- (NSString *)descriptionForEnvelope:(SSKEnvelope *)envelope; - (NSString *)descriptionForEnvelope:(SSKProtoEnvelope *)envelope;
- (NSString *)descriptionForContent:(OWSSignalServiceProtosContent *)content; - (NSString *)descriptionForContent:(OWSSignalServiceProtosContent *)content;
- (NSString *)descriptionForDataMessage:(OWSSignalServiceProtosDataMessage *)dataMessage; - (NSString *)descriptionForDataMessage:(OWSSignalServiceProtosDataMessage *)dataMessage;

@ -9,31 +9,31 @@
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
// used in log formatting // used in log formatting
NSString *envelopeAddress(SSKEnvelope *envelope) NSString *envelopeAddress(SSKProtoEnvelope *envelope)
{ {
return [NSString stringWithFormat:@"%@.%d", envelope.source, (unsigned int)envelope.sourceDevice]; return [NSString stringWithFormat:@"%@.%d", envelope.source, (unsigned int)envelope.sourceDevice];
} }
@implementation OWSMessageHandler @implementation OWSMessageHandler
- (NSString *)descriptionForEnvelopeType:(SSKEnvelope *)envelope - (NSString *)descriptionForEnvelopeType:(SSKProtoEnvelope *)envelope
{ {
OWSAssert(envelope != nil); OWSAssert(envelope != nil);
switch (envelope.type) { switch (envelope.type) {
case SSKEnvelopeTypeReceipt: case SSKProtoEnvelopeTypeReceipt:
return @"DeliveryReceipt"; return @"DeliveryReceipt";
case SSKEnvelopeTypeUnknown: case SSKProtoEnvelopeTypeUnknown:
// Shouldn't happen // Shouldn't happen
OWSProdFail([OWSAnalyticsEvents messageManagerErrorEnvelopeTypeUnknown]); OWSProdFail([OWSAnalyticsEvents messageManagerErrorEnvelopeTypeUnknown]);
return @"Unknown"; return @"Unknown";
case SSKEnvelopeTypeCiphertext: case SSKProtoEnvelopeTypeCiphertext:
return @"SignalEncryptedMessage"; return @"SignalEncryptedMessage";
case SSKEnvelopeTypeKeyExchange: case SSKProtoEnvelopeTypeKeyExchange:
// Unsupported // Unsupported
OWSProdFail([OWSAnalyticsEvents messageManagerErrorEnvelopeTypeKeyExchange]); OWSProdFail([OWSAnalyticsEvents messageManagerErrorEnvelopeTypeKeyExchange]);
return @"KeyExchange"; return @"KeyExchange";
case SSKEnvelopeTypePrekeyBundle: case SSKProtoEnvelopeTypePrekeyBundle:
return @"PreKeyEncryptedMessage"; return @"PreKeyEncryptedMessage";
default: default:
// Shouldn't happen // Shouldn't happen
@ -42,7 +42,7 @@ NSString *envelopeAddress(SSKEnvelope *envelope)
} }
} }
- (NSString *)descriptionForEnvelope:(SSKEnvelope *)envelope - (NSString *)descriptionForEnvelope:(SSKProtoEnvelope *)envelope
{ {
OWSAssert(envelope != nil); OWSAssert(envelope != nil);

@ -6,7 +6,7 @@
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
@class SSKEnvelope; @class SSKProtoEnvelope;
@class TSThread; @class TSThread;
@class YapDatabaseReadWriteTransaction; @class YapDatabaseReadWriteTransaction;
@ -16,7 +16,7 @@ NS_ASSUME_NONNULL_BEGIN
+ (instancetype)sharedManager; + (instancetype)sharedManager;
// processEnvelope: can be called from any thread. // processEnvelope: can be called from any thread.
- (void)processEnvelope:(SSKEnvelope *)envelope - (void)processEnvelope:(SSKProtoEnvelope *)envelope
plaintextData:(NSData *_Nullable)plaintextData plaintextData:(NSData *_Nullable)plaintextData
transaction:(YapDatabaseReadWriteTransaction *)transaction; transaction:(YapDatabaseReadWriteTransaction *)transaction;

@ -158,7 +158,7 @@ NS_ASSUME_NONNULL_BEGIN
#pragma mark - Blocking #pragma mark - Blocking
- (BOOL)isEnvelopeBlocked:(SSKEnvelope *)envelope - (BOOL)isEnvelopeBlocked:(SSKProtoEnvelope *)envelope
{ {
OWSAssert(envelope); OWSAssert(envelope);
@ -167,7 +167,7 @@ NS_ASSUME_NONNULL_BEGIN
#pragma mark - message handling #pragma mark - message handling
- (void)processEnvelope:(SSKEnvelope *)envelope - (void)processEnvelope:(SSKProtoEnvelope *)envelope
plaintextData:(NSData *_Nullable)plaintextData plaintextData:(NSData *_Nullable)plaintextData
transaction:(YapDatabaseReadWriteTransaction *)transaction transaction:(YapDatabaseReadWriteTransaction *)transaction
{ {
@ -189,8 +189,8 @@ NS_ASSUME_NONNULL_BEGIN
OWSAssert(![self isEnvelopeBlocked:envelope]); OWSAssert(![self isEnvelopeBlocked:envelope]);
switch (envelope.type) { switch (envelope.type) {
case SSKEnvelopeTypeCiphertext: case SSKProtoEnvelopeTypeCiphertext:
case SSKEnvelopeTypePrekeyBundle: case SSKProtoEnvelopeTypePrekeyBundle:
if (plaintextData) { if (plaintextData) {
[self handleEnvelope:envelope plaintextData:plaintextData transaction:transaction]; [self handleEnvelope:envelope plaintextData:plaintextData transaction:transaction];
} else { } else {
@ -198,15 +198,15 @@ NS_ASSUME_NONNULL_BEGIN
@"%@ missing decrypted data for envelope: %@", self.logTag, [self descriptionForEnvelope:envelope]); @"%@ missing decrypted data for envelope: %@", self.logTag, [self descriptionForEnvelope:envelope]);
} }
break; break;
case SSKEnvelopeTypeReceipt: case SSKProtoEnvelopeTypeReceipt:
OWSAssert(!plaintextData); OWSAssert(!plaintextData);
[self handleDeliveryReceipt:envelope transaction:transaction]; [self handleDeliveryReceipt:envelope transaction:transaction];
break; break;
// Other messages are just dismissed for now. // Other messages are just dismissed for now.
case SSKEnvelopeTypeKeyExchange: case SSKProtoEnvelopeTypeKeyExchange:
DDLogWarn(@"Received Key Exchange Message, not supported"); DDLogWarn(@"Received Key Exchange Message, not supported");
break; break;
case SSKEnvelopeTypeUnknown: case SSKProtoEnvelopeTypeUnknown:
DDLogWarn(@"Received an unknown message type"); DDLogWarn(@"Received an unknown message type");
break; break;
default: default:
@ -215,8 +215,7 @@ NS_ASSUME_NONNULL_BEGIN
} }
} }
- (void)handleDeliveryReceipt:(SSKEnvelope *)envelope - (void)handleDeliveryReceipt:(SSKProtoEnvelope *)envelope transaction:(YapDatabaseReadWriteTransaction *)transaction
transaction:(YapDatabaseReadWriteTransaction *)transaction
{ {
OWSAssert(envelope); OWSAssert(envelope);
OWSAssert(transaction); OWSAssert(transaction);
@ -272,7 +271,7 @@ NS_ASSUME_NONNULL_BEGIN
} }
} }
- (void)handleEnvelope:(SSKEnvelope *)envelope - (void)handleEnvelope:(SSKProtoEnvelope *)envelope
plaintextData:(NSData *)plaintextData plaintextData:(NSData *)plaintextData
transaction:(YapDatabaseReadWriteTransaction *)transaction transaction:(YapDatabaseReadWriteTransaction *)transaction
{ {
@ -326,7 +325,7 @@ NS_ASSUME_NONNULL_BEGIN
} }
} }
- (void)handleIncomingEnvelope:(SSKEnvelope *)envelope - (void)handleIncomingEnvelope:(SSKProtoEnvelope *)envelope
withDataMessage:(OWSSignalServiceProtosDataMessage *)dataMessage withDataMessage:(OWSSignalServiceProtosDataMessage *)dataMessage
transaction:(YapDatabaseReadWriteTransaction *)transaction transaction:(YapDatabaseReadWriteTransaction *)transaction
{ {
@ -395,7 +394,7 @@ NS_ASSUME_NONNULL_BEGIN
} }
- (void)sendGroupInfoRequest:(NSData *)groupId - (void)sendGroupInfoRequest:(NSData *)groupId
envelope:(SSKEnvelope *)envelope envelope:(SSKProtoEnvelope *)envelope
transaction:(YapDatabaseReadWriteTransaction *)transaction transaction:(YapDatabaseReadWriteTransaction *)transaction
{ {
OWSAssert(groupId.length > 0); OWSAssert(groupId.length > 0);
@ -429,7 +428,7 @@ NS_ASSUME_NONNULL_BEGIN
return [TextSecureKitEnv sharedEnv].profileManager; return [TextSecureKitEnv sharedEnv].profileManager;
} }
- (void)handleIncomingEnvelope:(SSKEnvelope *)envelope - (void)handleIncomingEnvelope:(SSKProtoEnvelope *)envelope
withReceiptMessage:(OWSSignalServiceProtosReceiptMessage *)receiptMessage withReceiptMessage:(OWSSignalServiceProtosReceiptMessage *)receiptMessage
transaction:(YapDatabaseReadWriteTransaction *)transaction transaction:(YapDatabaseReadWriteTransaction *)transaction
{ {
@ -464,7 +463,7 @@ NS_ASSUME_NONNULL_BEGIN
} }
} }
- (void)handleIncomingEnvelope:(SSKEnvelope *)envelope - (void)handleIncomingEnvelope:(SSKProtoEnvelope *)envelope
withCallMessage:(OWSSignalServiceProtosCallMessage *)callMessage withCallMessage:(OWSSignalServiceProtosCallMessage *)callMessage
{ {
OWSAssert(envelope); OWSAssert(envelope);
@ -499,7 +498,7 @@ NS_ASSUME_NONNULL_BEGIN
}); });
} }
- (void)handleReceivedGroupAvatarUpdateWithEnvelope:(SSKEnvelope *)envelope - (void)handleReceivedGroupAvatarUpdateWithEnvelope:(SSKProtoEnvelope *)envelope
dataMessage:(OWSSignalServiceProtosDataMessage *)dataMessage dataMessage:(OWSSignalServiceProtosDataMessage *)dataMessage
transaction:(YapDatabaseReadWriteTransaction *)transaction transaction:(YapDatabaseReadWriteTransaction *)transaction
{ {
@ -537,7 +536,7 @@ NS_ASSUME_NONNULL_BEGIN
}]; }];
} }
- (void)handleReceivedMediaWithEnvelope:(SSKEnvelope *)envelope - (void)handleReceivedMediaWithEnvelope:(SSKProtoEnvelope *)envelope
dataMessage:(OWSSignalServiceProtosDataMessage *)dataMessage dataMessage:(OWSSignalServiceProtosDataMessage *)dataMessage
transaction:(YapDatabaseReadWriteTransaction *)transaction transaction:(YapDatabaseReadWriteTransaction *)transaction
{ {
@ -585,7 +584,7 @@ NS_ASSUME_NONNULL_BEGIN
}]; }];
} }
- (void)handleIncomingEnvelope:(SSKEnvelope *)envelope - (void)handleIncomingEnvelope:(SSKProtoEnvelope *)envelope
withSyncMessage:(OWSSignalServiceProtosSyncMessage *)syncMessage withSyncMessage:(OWSSignalServiceProtosSyncMessage *)syncMessage
transaction:(YapDatabaseReadWriteTransaction *)transaction transaction:(YapDatabaseReadWriteTransaction *)transaction
{ {
@ -720,7 +719,7 @@ NS_ASSUME_NONNULL_BEGIN
} }
} }
- (void)handleEndSessionMessageWithEnvelope:(SSKEnvelope *)envelope - (void)handleEndSessionMessageWithEnvelope:(SSKProtoEnvelope *)envelope
dataMessage:(OWSSignalServiceProtosDataMessage *)dataMessage dataMessage:(OWSSignalServiceProtosDataMessage *)dataMessage
transaction:(YapDatabaseReadWriteTransaction *)transaction transaction:(YapDatabaseReadWriteTransaction *)transaction
{ {
@ -737,7 +736,7 @@ NS_ASSUME_NONNULL_BEGIN
[self.primaryStorage deleteAllSessionsForContact:envelope.source protocolContext:transaction]; [self.primaryStorage deleteAllSessionsForContact:envelope.source protocolContext:transaction];
} }
- (void)handleExpirationTimerUpdateMessageWithEnvelope:(SSKEnvelope *)envelope - (void)handleExpirationTimerUpdateMessageWithEnvelope:(SSKProtoEnvelope *)envelope
dataMessage:(OWSSignalServiceProtosDataMessage *)dataMessage dataMessage:(OWSSignalServiceProtosDataMessage *)dataMessage
transaction:(YapDatabaseReadWriteTransaction *)transaction transaction:(YapDatabaseReadWriteTransaction *)transaction
{ {
@ -780,7 +779,7 @@ NS_ASSUME_NONNULL_BEGIN
[message saveWithTransaction:transaction]; [message saveWithTransaction:transaction];
} }
- (void)handleProfileKeyMessageWithEnvelope:(SSKEnvelope *)envelope - (void)handleProfileKeyMessageWithEnvelope:(SSKProtoEnvelope *)envelope
dataMessage:(OWSSignalServiceProtosDataMessage *)dataMessage dataMessage:(OWSSignalServiceProtosDataMessage *)dataMessage
{ {
OWSAssert(envelope); OWSAssert(envelope);
@ -805,7 +804,7 @@ NS_ASSUME_NONNULL_BEGIN
[profileManager setProfileKeyData:profileKey forRecipientId:recipientId]; [profileManager setProfileKeyData:profileKey forRecipientId:recipientId];
} }
- (void)handleReceivedTextMessageWithEnvelope:(SSKEnvelope *)envelope - (void)handleReceivedTextMessageWithEnvelope:(SSKProtoEnvelope *)envelope
dataMessage:(OWSSignalServiceProtosDataMessage *)dataMessage dataMessage:(OWSSignalServiceProtosDataMessage *)dataMessage
transaction:(YapDatabaseReadWriteTransaction *)transaction transaction:(YapDatabaseReadWriteTransaction *)transaction
{ {
@ -845,7 +844,7 @@ NS_ASSUME_NONNULL_BEGIN
} }
} }
- (void)handleGroupInfoRequest:(SSKEnvelope *)envelope - (void)handleGroupInfoRequest:(SSKProtoEnvelope *)envelope
dataMessage:(OWSSignalServiceProtosDataMessage *)dataMessage dataMessage:(OWSSignalServiceProtosDataMessage *)dataMessage
transaction:(YapDatabaseReadWriteTransaction *)transaction transaction:(YapDatabaseReadWriteTransaction *)transaction
{ {
@ -901,7 +900,7 @@ NS_ASSUME_NONNULL_BEGIN
[self sendGroupUpdateForThread:gThread message:message]; [self sendGroupUpdateForThread:gThread message:message];
} }
- (TSIncomingMessage *_Nullable)handleReceivedEnvelope:(SSKEnvelope *)envelope - (TSIncomingMessage *_Nullable)handleReceivedEnvelope:(SSKProtoEnvelope *)envelope
withDataMessage:(OWSSignalServiceProtosDataMessage *)dataMessage withDataMessage:(OWSSignalServiceProtosDataMessage *)dataMessage
attachmentIds:(NSArray<NSString *> *)attachmentIds attachmentIds:(NSArray<NSString *> *)attachmentIds
transaction:(YapDatabaseReadWriteTransaction *)transaction transaction:(YapDatabaseReadWriteTransaction *)transaction
@ -1083,7 +1082,7 @@ NS_ASSUME_NONNULL_BEGIN
- (void)finalizeIncomingMessage:(TSIncomingMessage *)incomingMessage - (void)finalizeIncomingMessage:(TSIncomingMessage *)incomingMessage
thread:(TSThread *)thread thread:(TSThread *)thread
envelope:(SSKEnvelope *)envelope envelope:(SSKProtoEnvelope *)envelope
transaction:(YapDatabaseReadWriteTransaction *)transaction transaction:(YapDatabaseReadWriteTransaction *)transaction
{ {
OWSAssert(thread); OWSAssert(thread);
@ -1203,7 +1202,7 @@ NS_ASSUME_NONNULL_BEGIN
* Group or Contact thread for message, creating a new contact thread if necessary, * Group or Contact thread for message, creating a new contact thread if necessary,
* but never creating a new group thread. * but never creating a new group thread.
*/ */
- (nullable TSThread *)threadForEnvelope:(SSKEnvelope *)envelope - (nullable TSThread *)threadForEnvelope:(SSKProtoEnvelope *)envelope
dataMessage:(OWSSignalServiceProtosDataMessage *)dataMessage dataMessage:(OWSSignalServiceProtosDataMessage *)dataMessage
transaction:(YapDatabaseReadWriteTransaction *)transaction transaction:(YapDatabaseReadWriteTransaction *)transaction
{ {

@ -31,7 +31,7 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, readonly) NSDate *createdAt; @property (nonatomic, readonly) NSDate *createdAt;
@property (nonatomic, readonly) NSData *envelopeData; @property (nonatomic, readonly) NSData *envelopeData;
@property (nonatomic, readonly, nullable) SSKEnvelope *envelopeProto; @property (nonatomic, readonly, nullable) SSKProtoEnvelope *envelopeProto;
- (instancetype)initWithEnvelopeData:(NSData *)envelopeData NS_DESIGNATED_INITIALIZER; - (instancetype)initWithEnvelopeData:(NSData *)envelopeData NS_DESIGNATED_INITIALIZER;
- (nullable instancetype)initWithCoder:(NSCoder *)coder NS_DESIGNATED_INITIALIZER; - (nullable instancetype)initWithCoder:(NSCoder *)coder NS_DESIGNATED_INITIALIZER;
@ -68,10 +68,10 @@ NS_ASSUME_NONNULL_BEGIN
return [super initWithCoder:coder]; return [super initWithCoder:coder];
} }
- (nullable SSKEnvelope *)envelopeProto - (nullable SSKProtoEnvelope *)envelopeProto
{ {
NSError *error; NSError *error;
SSKEnvelope *_Nullable envelope = [[SSKEnvelope alloc] initWithSerializedData:self.envelopeData error:&error]; SSKProtoEnvelope *_Nullable envelope = [SSKProtoEnvelope parseData:self.envelopeData error:&error];
if (error || envelope == nil) { if (error || envelope == nil) {
OWSFail(@"%@ failed to parase envelope with error: %@", self.logTag, error); OWSFail(@"%@ failed to parase envelope with error: %@", self.logTag, error);
return nil; return nil;
@ -327,7 +327,7 @@ NSString *const OWSMessageDecryptJobFinderExtensionGroup = @"OWSMessageProcessin
AssertOnDispatchQueue(self.serialQueue); AssertOnDispatchQueue(self.serialQueue);
OWSAssert(job); OWSAssert(job);
SSKEnvelope *_Nullable envelope = nil; SSKProtoEnvelope *_Nullable envelope = nil;
@try { @try {
envelope = job.envelopeProto; envelope = job.envelopeProto;
} @catch (NSException *exception) { } @catch (NSException *exception) {

File diff suppressed because it is too large Load Diff

@ -1,149 +0,0 @@
//
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
import Foundation
@objc
public class SSKEnvelope: NSObject {
public enum EnvelopeError: Error {
case invalidProtobuf(description: String)
}
@objc
public enum SSKEnvelopeType: Int32 {
case unknown = 0
case ciphertext = 1
case keyExchange = 2
case prekeyBundle = 3
case receipt = 5
}
@objc
public let timestamp: UInt64
@objc
public let source: String
@objc
public let sourceDevice: UInt32
@objc
public let type: SSKEnvelopeType
@objc
public let relay: String?
@objc
public let content: Data?
@objc
public let legacyMessage: Data?
@objc
public init(timestamp: UInt64, source: String, sourceDevice: UInt32, type: SSKEnvelopeType, content: Data?, legacyMessage: Data?) {
self.source = source
self.type = type
self.timestamp = timestamp
self.sourceDevice = sourceDevice
self.relay = nil
self.content = content
self.legacyMessage = legacyMessage
}
@objc
public init(serializedData: Data) throws {
let proto: SignalServiceProtos_Envelope = try SignalServiceProtos_Envelope(serializedData: serializedData)
guard proto.hasSource else {
throw EnvelopeError.invalidProtobuf(description: "missing required field: source")
}
self.source = proto.source
guard proto.hasType else {
throw EnvelopeError.invalidProtobuf(description: "missing required field: type")
}
self.type = {
switch proto.type {
case .unknown:
return .unknown
case .ciphertext:
return .ciphertext
case .keyExchange:
return .keyExchange
case .prekeyBundle:
return .prekeyBundle
case .receipt:
return .receipt
}
}()
guard proto.hasTimestamp else {
throw EnvelopeError.invalidProtobuf(description: "missing required field: timestamp")
}
self.timestamp = proto.timestamp
guard proto.hasSourceDevice else {
throw EnvelopeError.invalidProtobuf(description: "missing required field: sourceDevice")
}
self.sourceDevice = proto.sourceDevice
if proto.hasContent {
self.content = proto.content
} else {
self.content = nil
}
if proto.hasLegacyMessage {
self.legacyMessage = proto.legacyMessage
} else {
self.legacyMessage = nil
}
if proto.relay.count > 0 {
self.relay = proto.relay
} else {
relay = nil
}
}
@objc
public func serializedData() throws -> Data {
return try self.asProtobuf.serializedData()
}
private var asProtobuf: SignalServiceProtos_Envelope {
let proto = SignalServiceProtos_Envelope.with { (builder) in
builder.source = self.source
builder.type = {
switch self.type {
case .unknown:
return .unknown
case .ciphertext:
return .ciphertext
case .keyExchange:
return .keyExchange
case .prekeyBundle:
return .prekeyBundle
case .receipt:
return .receipt
}
}()
builder.timestamp = self.timestamp
builder.sourceDevice = self.sourceDevice
if let relay = self.relay {
builder.relay = relay
}
if let content = self.content {
builder.content = content
}
}
return proto
}
}
Loading…
Cancel
Save