mirror of https://github.com/oxen-io/session-ios
Swift protos for Envelope
parent
e77b798aa7
commit
b860dce7f9
@ -1 +1 @@
|
||||
Subproject commit 4ede6c138ce6b5fd7279c9dcbbcece4018b03d57
|
||||
Subproject commit 2474b814b3108d9684effcdfe460c5ff42d3cbbe
|
@ -1,25 +1,22 @@
|
||||
# See README.md in this dir for prerequisite setup.
|
||||
|
||||
PROTOC=protoc \
|
||||
--plugin=/usr/local/bin/protoc-gen-objc \
|
||||
--proto_path="${HOME}/src/signal/protobuf-objc/src/compiler/" \
|
||||
--proto_path="${HOME}/src/signal/protobuf-objc/src/compiler/google/protobuf/" \
|
||||
--proto_path='./'
|
||||
|
||||
all: signal_service_proto provisioning_protos fingerprint_protos websocket_protos
|
||||
|
||||
signal_service_proto: OWSSignalServiceProtos.proto
|
||||
$(PROTOC) --objc_out=../src/Messages/ \
|
||||
$(PROTOC) --swift_out=../src/Protos/ \
|
||||
OWSSignalServiceProtos.proto
|
||||
|
||||
provisioning_protos: OWSProvisioningProtos.proto
|
||||
$(PROTOC) --objc_out=../src/Devices/ \
|
||||
$(PROTOC) --swift_out=../src/Protos/ \
|
||||
OWSProvisioningProtos.proto
|
||||
|
||||
fingerprint_protos: OWSFingerprintProtos.proto
|
||||
$(PROTOC) --objc_out=../src/Security/ \
|
||||
$(PROTOC) --swift_out=../src/Protos/ \
|
||||
OWSFingerprintProtos.proto
|
||||
|
||||
websocket_protos: WebSocketResources.proto
|
||||
$(PROTOC) --objc_out=../src/Network/WebSockets/ \
|
||||
$(PROTOC) --swift_out=../src/Protos/ \
|
||||
WebSocketResources.proto
|
||||
|
@ -1,38 +1,22 @@
|
||||
# SignalServiceKit Protobufs
|
||||
|
||||
These protobuf definitions are copied from Signal-Android, but modified
|
||||
to include a conventional ObjC classnames.
|
||||
|
||||
e.g.
|
||||
|
||||
import "objectivec-descriptor.proto";
|
||||
option (google.protobuf.objectivec_file_options).class_prefix = "OWSFingerprintProtos";
|
||||
to match some iOS conventions.
|
||||
|
||||
## Prequisites
|
||||
|
||||
Install protobuf 2.6, the objc plugin doesn't currently work with
|
||||
protobuf 3.0
|
||||
|
||||
brew install protobuf@2.6
|
||||
# Beware if you are depending on protobuf 3.0 elsewhere
|
||||
brew link --force protobuf@2.6
|
||||
Install Apple's `swift-protobuf` (*not* the similarly named `protobuf-swift`)
|
||||
|
||||
Install the objc plugin to $SignalServiceKitRoot/..
|
||||
brew install swift-protobuf
|
||||
|
||||
e.g. I have SignalServiceKit installed to ~/src/WhisperSystems/SignalServiceKit
|
||||
This should install an up to date protobuf package as a dependency. Note that
|
||||
since we use the legacy proto2 format, we need to specify this in our .proto
|
||||
files.
|
||||
|
||||
So I run
|
||||
|
||||
cd ~/src/WhisperSystems
|
||||
git clone https://github.com/alexeyxo/protobuf-objc
|
||||
|
||||
Follow the install instructions at https://github.com/alexeyxo/protobuf-objc
|
||||
syntax = "proto2";
|
||||
|
||||
## Building Protobuf
|
||||
|
||||
After changes are made to any proto, generate the ObjC classes by
|
||||
running:
|
||||
|
||||
cd ~/src/WhisperSystems/SignalServiceKit/protobuf
|
||||
make
|
||||
|
||||
|
@ -1,20 +1,15 @@
|
||||
//
|
||||
// TSInvalidIdentityKeyErrorMessage.h
|
||||
// Signal
|
||||
//
|
||||
// Created by Frederic Jacobs on 31/12/14.
|
||||
// Copyright (c) 2014 Open Whisper Systems. All rights reserved.
|
||||
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
#import "TSInvalidIdentityKeyErrorMessage.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
// 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.
|
||||
@interface TSInvalidIdentityKeyReceivingErrorMessage : TSInvalidIdentityKeyErrorMessage
|
||||
|
||||
+ (instancetype)untrustedKeyWithEnvelope:(OWSSignalServiceProtosEnvelope *)envelope
|
||||
withTransaction:(YapDatabaseReadWriteTransaction *)transaction;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,149 @@
|
||||
//
|
||||
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
@objc
|
||||
public class SSKEnvelope: NSObject {
|
||||
|
||||
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: SignalService_Envelope = try SignalService_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: SignalService_Envelope {
|
||||
var proto = SignalService_Envelope()
|
||||
|
||||
proto.source = self.source
|
||||
|
||||
proto.type = {
|
||||
switch self.type {
|
||||
case .unknown:
|
||||
return .unknown
|
||||
case .ciphertext:
|
||||
return .ciphertext
|
||||
case .keyExchange:
|
||||
return .keyExchange
|
||||
case .prekeyBundle:
|
||||
return .prekeyBundle
|
||||
case .receipt:
|
||||
return .receipt
|
||||
}
|
||||
}()
|
||||
|
||||
proto.timestamp = self.timestamp
|
||||
proto.sourceDevice = self.sourceDevice
|
||||
|
||||
if let relay = self.relay {
|
||||
proto.relay = relay
|
||||
}
|
||||
|
||||
if let content = self.content {
|
||||
proto.content = content
|
||||
}
|
||||
|
||||
return proto
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue