From 28acea3cf0577c6defc14fc4d0cb57652cbf891c Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Fri, 3 Aug 2018 14:03:02 -0400 Subject: [PATCH] Respond to CR. --- Scripts/ProtoWrappers.py | 7 +- SignalServiceKit/protobuf/Fingerprint.proto | 4 + SignalServiceKit/protobuf/Provisioning.proto | 9 + SignalServiceKit/protobuf/SignalIOS.proto | 2 + .../protobuf/WebSocketResources.proto | 7 + .../src/Protos/Generated/Fingerprint.pb.swift | 5 +- .../Protos/Generated/FingerprintProto.swift | 58 +++--- .../Protos/Generated/Provisioning.pb.swift | 10 +- .../Protos/Generated/ProvisioningProto.swift | 174 +++++++++--------- .../src/Protos/Generated/SignalIOS.pb.swift | 2 + .../src/Protos/Generated/SignalIOSProto.swift | 38 ++-- .../src/Protos/Generated/WebSocketProto.swift | 135 +++++++------- .../Generated/WebSocketResources.pb.swift | 7 + 13 files changed, 256 insertions(+), 202 deletions(-) diff --git a/Scripts/ProtoWrappers.py b/Scripts/ProtoWrappers.py index 9c5d56113..83e91349b 100755 --- a/Scripts/ProtoWrappers.py +++ b/Scripts/ProtoWrappers.py @@ -19,6 +19,7 @@ def lowerCamlCaseForUnderscoredText(name): splits[0] = splits[0].lower() return ''.join(splits) + # The generated code for "Apple Swift Protos" suppresses # adjacent capital letters in lowerCamlCase. def lowerCamlCaseForUnderscoredText_wrapped(name): @@ -29,7 +30,11 @@ def lowerCamlCaseForUnderscoredText_wrapped(name): char = char.lower() chars.append(char) lastWasUpper = (char.upper() == char) - return ''.join(chars) + result = ''.join(chars) + if result.endswith('Id'): + result = result[:-2] + 'ID' + return result + class WriterContext: def __init__(self, proto_name, swift_name, parent=None): diff --git a/SignalServiceKit/protobuf/Fingerprint.proto b/SignalServiceKit/protobuf/Fingerprint.proto index 22a8e6541..1464c4b8d 100644 --- a/SignalServiceKit/protobuf/Fingerprint.proto +++ b/SignalServiceKit/protobuf/Fingerprint.proto @@ -9,12 +9,16 @@ option java_package = "org.whispersystems.libsignal.fingerprint"; option java_outer_classname = "FingerprintProtos"; message LogicalFingerprint { + // @required optional bytes identityData = 1; // optional bytes identifier = 2; } message LogicalFingerprints { + // @required optional uint32 version = 1; + // @required optional LogicalFingerprint localFingerprint = 2; + // @required optional LogicalFingerprint remoteFingerprint = 3; } diff --git a/SignalServiceKit/protobuf/Provisioning.proto b/SignalServiceKit/protobuf/Provisioning.proto index d295131c8..cd80a1d3f 100644 --- a/SignalServiceKit/protobuf/Provisioning.proto +++ b/SignalServiceKit/protobuf/Provisioning.proto @@ -14,16 +14,25 @@ option java_package = "org.whispersystems.signalservice.internal.push"; option java_outer_classname = "ProvisioningProtos"; message ProvisionEnvelope { + // @required optional bytes publicKey = 1; + // @required optional bytes body = 2; // Encrypted ProvisionMessage } message ProvisionMessage { + // @required optional bytes identityKeyPublic = 1; + // @required optional bytes identityKeyPrivate = 2; + // @required optional string number = 3; + // @required optional string provisioningCode = 4; + // @required optional string userAgent = 5; + // @required optional bytes profileKey = 6; + // @required optional bool readReceipts = 7; } diff --git a/SignalServiceKit/protobuf/SignalIOS.proto b/SignalServiceKit/protobuf/SignalIOS.proto index a8de17498..c71732a02 100644 --- a/SignalServiceKit/protobuf/SignalIOS.proto +++ b/SignalServiceKit/protobuf/SignalIOS.proto @@ -20,7 +20,9 @@ message BackupSnapshot { INTERACTION = 3; ATTACHMENT = 4; } + // @required optional Type type = 1; + // @required optional bytes entityData = 2; } diff --git a/SignalServiceKit/protobuf/WebSocketResources.proto b/SignalServiceKit/protobuf/WebSocketResources.proto index 1a4447061..bb354a746 100644 --- a/SignalServiceKit/protobuf/WebSocketResources.proto +++ b/SignalServiceKit/protobuf/WebSocketResources.proto @@ -15,18 +15,24 @@ option java_package = "org.whispersystems.signalservice.internal.websocket"; option java_outer_classname = "WebSocketProtos"; message WebSocketRequestMessage { + // @required optional string verb = 1; + // @required optional string path = 2; optional bytes body = 3; repeated string headers = 5; + // @required optional uint64 requestId = 4; } message WebSocketResponseMessage { + // @required optional uint64 requestId = 1; + // @required optional uint32 status = 2; optional string message = 3; repeated string headers = 5; + // @required optional bytes body = 4; } @@ -37,6 +43,7 @@ message WebSocketMessage { RESPONSE = 2; } + // @required optional Type type = 1; optional WebSocketRequestMessage request = 2; optional WebSocketResponseMessage response = 3; diff --git a/SignalServiceKit/src/Protos/Generated/Fingerprint.pb.swift b/SignalServiceKit/src/Protos/Generated/Fingerprint.pb.swift index 7357c3085..96304b197 100644 --- a/SignalServiceKit/src/Protos/Generated/Fingerprint.pb.swift +++ b/SignalServiceKit/src/Protos/Generated/Fingerprint.pb.swift @@ -27,7 +27,7 @@ struct FingerprintProtos_LogicalFingerprint { // `Message` and `Message+*Additions` files in the SwiftProtobuf library for // methods supported on all messages. - /// optional bytes identifier = 2; + /// @required var identityData: Data { get {return _identityData ?? SwiftProtobuf.Internal.emptyData} set {_identityData = newValue} @@ -49,6 +49,7 @@ struct FingerprintProtos_LogicalFingerprints { // `Message` and `Message+*Additions` files in the SwiftProtobuf library for // methods supported on all messages. + /// @required var version: UInt32 { get {return _storage._version ?? 0} set {_uniqueStorage()._version = newValue} @@ -58,6 +59,7 @@ struct FingerprintProtos_LogicalFingerprints { /// Clears the value of `version`. Subsequent reads from it will return its default value. mutating func clearVersion() {_storage._version = nil} + /// @required var localFingerprint: FingerprintProtos_LogicalFingerprint { get {return _storage._localFingerprint ?? FingerprintProtos_LogicalFingerprint()} set {_uniqueStorage()._localFingerprint = newValue} @@ -67,6 +69,7 @@ struct FingerprintProtos_LogicalFingerprints { /// Clears the value of `localFingerprint`. Subsequent reads from it will return its default value. mutating func clearLocalFingerprint() {_storage._localFingerprint = nil} + /// @required var remoteFingerprint: FingerprintProtos_LogicalFingerprint { get {return _storage._remoteFingerprint ?? FingerprintProtos_LogicalFingerprint()} set {_uniqueStorage()._remoteFingerprint = newValue} diff --git a/SignalServiceKit/src/Protos/Generated/FingerprintProto.swift b/SignalServiceKit/src/Protos/Generated/FingerprintProto.swift index 532567529..29a0aeda6 100644 --- a/SignalServiceKit/src/Protos/Generated/FingerprintProto.swift +++ b/SignalServiceKit/src/Protos/Generated/FingerprintProto.swift @@ -34,18 +34,12 @@ public enum FingerprintProtoError: Error { fileprivate let proto: FingerprintProtos_LogicalFingerprint - @objc public var identityData: Data? { - guard proto.hasIdentityData else { - return nil - } - return proto.identityData - } - @objc public var hasIdentityData: Bool { - return proto.hasIdentityData - } + @objc public let identityData: Data - private init(proto: FingerprintProtos_LogicalFingerprint) { + private init(proto: FingerprintProtos_LogicalFingerprint, + identityData: Data) { self.proto = proto + self.identityData = identityData } @objc @@ -59,11 +53,17 @@ public enum FingerprintProtoError: Error { } fileprivate class func parseProto(_ proto: FingerprintProtos_LogicalFingerprint) throws -> FingerprintProtoLogicalFingerprint { + guard proto.hasIdentityData else { + throw FingerprintProtoError.invalidProtobuf(description: "\(logTag) missing required field: identityData") + } + let identityData = proto.identityData + // MARK: - Begin Validation Logic for FingerprintProtoLogicalFingerprint - // MARK: - End Validation Logic for FingerprintProtoLogicalFingerprint - - let result = FingerprintProtoLogicalFingerprint(proto: proto) + let result = FingerprintProtoLogicalFingerprint(proto: proto, + identityData: identityData) return result } } @@ -100,20 +100,16 @@ public enum FingerprintProtoError: Error { fileprivate let proto: FingerprintProtos_LogicalFingerprints - @objc public let localFingerprint: FingerprintProtoLogicalFingerprint? - @objc public let remoteFingerprint: FingerprintProtoLogicalFingerprint? - - @objc public var version: UInt32 { - return proto.version - } - @objc public var hasVersion: Bool { - return proto.hasVersion - } + @objc public let version: UInt32 + @objc public let localFingerprint: FingerprintProtoLogicalFingerprint + @objc public let remoteFingerprint: FingerprintProtoLogicalFingerprint private init(proto: FingerprintProtos_LogicalFingerprints, - localFingerprint: FingerprintProtoLogicalFingerprint?, - remoteFingerprint: FingerprintProtoLogicalFingerprint?) { + version: UInt32, + localFingerprint: FingerprintProtoLogicalFingerprint, + remoteFingerprint: FingerprintProtoLogicalFingerprint) { self.proto = proto + self.version = version self.localFingerprint = localFingerprint self.remoteFingerprint = remoteFingerprint } @@ -129,21 +125,27 @@ public enum FingerprintProtoError: Error { } fileprivate class func parseProto(_ proto: FingerprintProtos_LogicalFingerprints) throws -> FingerprintProtoLogicalFingerprints { - var localFingerprint: FingerprintProtoLogicalFingerprint? = nil - if proto.hasLocalFingerprint { - localFingerprint = try FingerprintProtoLogicalFingerprint.parseProto(proto.localFingerprint) + guard proto.hasVersion else { + throw FingerprintProtoError.invalidProtobuf(description: "\(logTag) missing required field: version") } + let version = proto.version - var remoteFingerprint: FingerprintProtoLogicalFingerprint? = nil - if proto.hasRemoteFingerprint { - remoteFingerprint = try FingerprintProtoLogicalFingerprint.parseProto(proto.remoteFingerprint) + guard proto.hasLocalFingerprint else { + throw FingerprintProtoError.invalidProtobuf(description: "\(logTag) missing required field: localFingerprint") } + let localFingerprint = try FingerprintProtoLogicalFingerprint.parseProto(proto.localFingerprint) + + guard proto.hasRemoteFingerprint else { + throw FingerprintProtoError.invalidProtobuf(description: "\(logTag) missing required field: remoteFingerprint") + } + let remoteFingerprint = try FingerprintProtoLogicalFingerprint.parseProto(proto.remoteFingerprint) // MARK: - Begin Validation Logic for FingerprintProtoLogicalFingerprints - // MARK: - End Validation Logic for FingerprintProtoLogicalFingerprints - let result = FingerprintProtoLogicalFingerprints(proto: proto, + version: version, localFingerprint: localFingerprint, remoteFingerprint: remoteFingerprint) return result diff --git a/SignalServiceKit/src/Protos/Generated/Provisioning.pb.swift b/SignalServiceKit/src/Protos/Generated/Provisioning.pb.swift index 17eebcc3b..446b178e8 100644 --- a/SignalServiceKit/src/Protos/Generated/Provisioning.pb.swift +++ b/SignalServiceKit/src/Protos/Generated/Provisioning.pb.swift @@ -32,6 +32,7 @@ struct ProvisioningProtos_ProvisionEnvelope { // `Message` and `Message+*Additions` files in the SwiftProtobuf library for // methods supported on all messages. + /// @required var publicKey: Data { get {return _publicKey ?? SwiftProtobuf.Internal.emptyData} set {_publicKey = newValue} @@ -41,7 +42,7 @@ struct ProvisioningProtos_ProvisionEnvelope { /// Clears the value of `publicKey`. Subsequent reads from it will return its default value. mutating func clearPublicKey() {self._publicKey = nil} - /// Encrypted ProvisionMessage + /// @required var body: Data { get {return _body ?? SwiftProtobuf.Internal.emptyData} set {_body = newValue} @@ -64,6 +65,7 @@ struct ProvisioningProtos_ProvisionMessage { // `Message` and `Message+*Additions` files in the SwiftProtobuf library for // methods supported on all messages. + /// @required var identityKeyPublic: Data { get {return _identityKeyPublic ?? SwiftProtobuf.Internal.emptyData} set {_identityKeyPublic = newValue} @@ -73,6 +75,7 @@ struct ProvisioningProtos_ProvisionMessage { /// Clears the value of `identityKeyPublic`. Subsequent reads from it will return its default value. mutating func clearIdentityKeyPublic() {self._identityKeyPublic = nil} + /// @required var identityKeyPrivate: Data { get {return _identityKeyPrivate ?? SwiftProtobuf.Internal.emptyData} set {_identityKeyPrivate = newValue} @@ -82,6 +85,7 @@ struct ProvisioningProtos_ProvisionMessage { /// Clears the value of `identityKeyPrivate`. Subsequent reads from it will return its default value. mutating func clearIdentityKeyPrivate() {self._identityKeyPrivate = nil} + /// @required var number: String { get {return _number ?? String()} set {_number = newValue} @@ -91,6 +95,7 @@ struct ProvisioningProtos_ProvisionMessage { /// Clears the value of `number`. Subsequent reads from it will return its default value. mutating func clearNumber() {self._number = nil} + /// @required var provisioningCode: String { get {return _provisioningCode ?? String()} set {_provisioningCode = newValue} @@ -100,6 +105,7 @@ struct ProvisioningProtos_ProvisionMessage { /// Clears the value of `provisioningCode`. Subsequent reads from it will return its default value. mutating func clearProvisioningCode() {self._provisioningCode = nil} + /// @required var userAgent: String { get {return _userAgent ?? String()} set {_userAgent = newValue} @@ -109,6 +115,7 @@ struct ProvisioningProtos_ProvisionMessage { /// Clears the value of `userAgent`. Subsequent reads from it will return its default value. mutating func clearUserAgent() {self._userAgent = nil} + /// @required var profileKey: Data { get {return _profileKey ?? SwiftProtobuf.Internal.emptyData} set {_profileKey = newValue} @@ -118,6 +125,7 @@ struct ProvisioningProtos_ProvisionMessage { /// Clears the value of `profileKey`. Subsequent reads from it will return its default value. mutating func clearProfileKey() {self._profileKey = nil} + /// @required var readReceipts: Bool { get {return _readReceipts ?? false} set {_readReceipts = newValue} diff --git a/SignalServiceKit/src/Protos/Generated/ProvisioningProto.swift b/SignalServiceKit/src/Protos/Generated/ProvisioningProto.swift index 4ee0f76fc..783a90559 100644 --- a/SignalServiceKit/src/Protos/Generated/ProvisioningProto.swift +++ b/SignalServiceKit/src/Protos/Generated/ProvisioningProto.swift @@ -38,28 +38,15 @@ public enum ProvisioningProtoError: Error { fileprivate let proto: ProvisioningProtos_ProvisionEnvelope - @objc public var publicKey: Data? { - guard proto.hasPublicKey else { - return nil - } - return proto.publicKey - } - @objc public var hasPublicKey: Bool { - return proto.hasPublicKey - } + @objc public let publicKey: Data + @objc public let body: Data - @objc public var body: Data? { - guard proto.hasBody else { - return nil - } - return proto.body - } - @objc public var hasBody: Bool { - return proto.hasBody - } - - private init(proto: ProvisioningProtos_ProvisionEnvelope) { + private init(proto: ProvisioningProtos_ProvisionEnvelope, + publicKey: Data, + body: Data) { self.proto = proto + self.publicKey = publicKey + self.body = body } @objc @@ -73,11 +60,23 @@ public enum ProvisioningProtoError: Error { } fileprivate class func parseProto(_ proto: ProvisioningProtos_ProvisionEnvelope) throws -> ProvisioningProtoProvisionEnvelope { + guard proto.hasPublicKey else { + throw ProvisioningProtoError.invalidProtobuf(description: "\(logTag) missing required field: publicKey") + } + let publicKey = proto.publicKey + + guard proto.hasBody else { + throw ProvisioningProtoError.invalidProtobuf(description: "\(logTag) missing required field: body") + } + let body = proto.body + // MARK: - Begin Validation Logic for ProvisioningProtoProvisionEnvelope - // MARK: - End Validation Logic for ProvisioningProtoProvisionEnvelope - - let result = ProvisioningProtoProvisionEnvelope(proto: proto) + let result = ProvisioningProtoProvisionEnvelope(proto: proto, + publicKey: publicKey, + body: body) return result } } @@ -130,75 +129,30 @@ public enum ProvisioningProtoError: Error { fileprivate let proto: ProvisioningProtos_ProvisionMessage - @objc public var identityKeyPublic: Data? { - guard proto.hasIdentityKeyPublic else { - return nil - } - return proto.identityKeyPublic - } - @objc public var hasIdentityKeyPublic: Bool { - return proto.hasIdentityKeyPublic - } + @objc public let identityKeyPublic: Data + @objc public let identityKeyPrivate: Data + @objc public let number: String + @objc public let provisioningCode: String + @objc public let userAgent: String + @objc public let profileKey: Data + @objc public let readReceipts: Bool - @objc public var identityKeyPrivate: Data? { - guard proto.hasIdentityKeyPrivate else { - return nil - } - return proto.identityKeyPrivate - } - @objc public var hasIdentityKeyPrivate: Bool { - return proto.hasIdentityKeyPrivate - } - - @objc public var number: String? { - guard proto.hasNumber else { - return nil - } - return proto.number - } - @objc public var hasNumber: Bool { - return proto.hasNumber - } - - @objc public var provisioningCode: String? { - guard proto.hasProvisioningCode else { - return nil - } - return proto.provisioningCode - } - @objc public var hasProvisioningCode: Bool { - return proto.hasProvisioningCode - } - - @objc public var userAgent: String? { - guard proto.hasUserAgent else { - return nil - } - return proto.userAgent - } - @objc public var hasUserAgent: Bool { - return proto.hasUserAgent - } - - @objc public var profileKey: Data? { - guard proto.hasProfileKey else { - return nil - } - return proto.profileKey - } - @objc public var hasProfileKey: Bool { - return proto.hasProfileKey - } - - @objc public var readReceipts: Bool { - return proto.readReceipts - } - @objc public var hasReadReceipts: Bool { - return proto.hasReadReceipts - } - - private init(proto: ProvisioningProtos_ProvisionMessage) { + private init(proto: ProvisioningProtos_ProvisionMessage, + identityKeyPublic: Data, + identityKeyPrivate: Data, + number: String, + provisioningCode: String, + userAgent: String, + profileKey: Data, + readReceipts: Bool) { self.proto = proto + self.identityKeyPublic = identityKeyPublic + self.identityKeyPrivate = identityKeyPrivate + self.number = number + self.provisioningCode = provisioningCode + self.userAgent = userAgent + self.profileKey = profileKey + self.readReceipts = readReceipts } @objc @@ -212,11 +166,53 @@ public enum ProvisioningProtoError: Error { } fileprivate class func parseProto(_ proto: ProvisioningProtos_ProvisionMessage) throws -> ProvisioningProtoProvisionMessage { + guard proto.hasIdentityKeyPublic else { + throw ProvisioningProtoError.invalidProtobuf(description: "\(logTag) missing required field: identityKeyPublic") + } + let identityKeyPublic = proto.identityKeyPublic + + guard proto.hasIdentityKeyPrivate else { + throw ProvisioningProtoError.invalidProtobuf(description: "\(logTag) missing required field: identityKeyPrivate") + } + let identityKeyPrivate = proto.identityKeyPrivate + + guard proto.hasNumber else { + throw ProvisioningProtoError.invalidProtobuf(description: "\(logTag) missing required field: number") + } + let number = proto.number + + guard proto.hasProvisioningCode else { + throw ProvisioningProtoError.invalidProtobuf(description: "\(logTag) missing required field: provisioningCode") + } + let provisioningCode = proto.provisioningCode + + guard proto.hasUserAgent else { + throw ProvisioningProtoError.invalidProtobuf(description: "\(logTag) missing required field: userAgent") + } + let userAgent = proto.userAgent + + guard proto.hasProfileKey else { + throw ProvisioningProtoError.invalidProtobuf(description: "\(logTag) missing required field: profileKey") + } + let profileKey = proto.profileKey + + guard proto.hasReadReceipts else { + throw ProvisioningProtoError.invalidProtobuf(description: "\(logTag) missing required field: readReceipts") + } + let readReceipts = proto.readReceipts + // MARK: - Begin Validation Logic for ProvisioningProtoProvisionMessage - // MARK: - End Validation Logic for ProvisioningProtoProvisionMessage - - let result = ProvisioningProtoProvisionMessage(proto: proto) + let result = ProvisioningProtoProvisionMessage(proto: proto, + identityKeyPublic: identityKeyPublic, + identityKeyPrivate: identityKeyPrivate, + number: number, + provisioningCode: provisioningCode, + userAgent: userAgent, + profileKey: profileKey, + readReceipts: readReceipts) return result } } diff --git a/SignalServiceKit/src/Protos/Generated/SignalIOS.pb.swift b/SignalServiceKit/src/Protos/Generated/SignalIOS.pb.swift index 0ac4740f9..934a293d8 100644 --- a/SignalServiceKit/src/Protos/Generated/SignalIOS.pb.swift +++ b/SignalServiceKit/src/Protos/Generated/SignalIOS.pb.swift @@ -41,6 +41,7 @@ struct IOSProtos_BackupSnapshot { // `Message` and `Message+*Additions` files in the SwiftProtobuf library for // methods supported on all messages. + /// @required var type: IOSProtos_BackupSnapshot.BackupEntity.TypeEnum { get {return _type ?? .unknown} set {_type = newValue} @@ -50,6 +51,7 @@ struct IOSProtos_BackupSnapshot { /// Clears the value of `type`. Subsequent reads from it will return its default value. mutating func clearType() {self._type = nil} + /// @required var entityData: Data { get {return _entityData ?? SwiftProtobuf.Internal.emptyData} set {_entityData = newValue} diff --git a/SignalServiceKit/src/Protos/Generated/SignalIOSProto.swift b/SignalServiceKit/src/Protos/Generated/SignalIOSProto.swift index b5f6402d9..4fb4d6cce 100644 --- a/SignalServiceKit/src/Protos/Generated/SignalIOSProto.swift +++ b/SignalServiceKit/src/Protos/Generated/SignalIOSProto.swift @@ -68,25 +68,15 @@ public enum SignalIOSProtoError: Error { fileprivate let proto: IOSProtos_BackupSnapshot.BackupEntity - @objc public var type: SignalIOSProtoBackupSnapshotBackupEntityType { - return SignalIOSProtoBackupSnapshotBackupEntity.SignalIOSProtoBackupSnapshotBackupEntityTypeWrap(proto.type) - } - @objc public var hasType: Bool { - return proto.hasType - } + @objc public let type: SignalIOSProtoBackupSnapshotBackupEntityType + @objc public let entityData: Data - @objc public var entityData: Data? { - guard proto.hasEntityData else { - return nil - } - return proto.entityData - } - @objc public var hasEntityData: Bool { - return proto.hasEntityData - } - - private init(proto: IOSProtos_BackupSnapshot.BackupEntity) { + private init(proto: IOSProtos_BackupSnapshot.BackupEntity, + type: SignalIOSProtoBackupSnapshotBackupEntityType, + entityData: Data) { self.proto = proto + self.type = type + self.entityData = entityData } @objc @@ -100,11 +90,23 @@ public enum SignalIOSProtoError: Error { } fileprivate class func parseProto(_ proto: IOSProtos_BackupSnapshot.BackupEntity) throws -> SignalIOSProtoBackupSnapshotBackupEntity { + guard proto.hasType else { + throw SignalIOSProtoError.invalidProtobuf(description: "\(logTag) missing required field: type") + } + let type = SignalIOSProtoBackupSnapshotBackupEntityTypeWrap(proto.type) + + guard proto.hasEntityData else { + throw SignalIOSProtoError.invalidProtobuf(description: "\(logTag) missing required field: entityData") + } + let entityData = proto.entityData + // MARK: - Begin Validation Logic for SignalIOSProtoBackupSnapshotBackupEntity - // MARK: - End Validation Logic for SignalIOSProtoBackupSnapshotBackupEntity - - let result = SignalIOSProtoBackupSnapshotBackupEntity(proto: proto) + let result = SignalIOSProtoBackupSnapshotBackupEntity(proto: proto, + type: type, + entityData: entityData) return result } } diff --git a/SignalServiceKit/src/Protos/Generated/WebSocketProto.swift b/SignalServiceKit/src/Protos/Generated/WebSocketProto.swift index 1ad72bad8..1251e1555 100644 --- a/SignalServiceKit/src/Protos/Generated/WebSocketProto.swift +++ b/SignalServiceKit/src/Protos/Generated/WebSocketProto.swift @@ -40,8 +40,8 @@ public enum WebSocketProtoError: Error { proto.headers = items } - @objc public func setRequestId(_ valueParam: UInt64) { - proto.requestId = valueParam + @objc public func setRequestID(_ valueParam: UInt64) { + proto.requestID = valueParam } @objc public func build() throws -> WebSocketProtoWebSocketRequestMessage { @@ -52,25 +52,9 @@ public enum WebSocketProtoError: Error { fileprivate let proto: WebSocketProtos_WebSocketRequestMessage - @objc public var verb: String? { - guard proto.hasVerb else { - return nil - } - return proto.verb - } - @objc public var hasVerb: Bool { - return proto.hasVerb - } - - @objc public var path: String? { - guard proto.hasPath else { - return nil - } - return proto.path - } - @objc public var hasPath: Bool { - return proto.hasPath - } + @objc public let verb: String + @objc public let path: String + @objc public let requestID: UInt64 @objc public var body: Data? { guard proto.hasBody else { @@ -86,15 +70,14 @@ public enum WebSocketProtoError: Error { return proto.headers } - @objc public var requestId: UInt64 { - return proto.requestId - } - @objc public var hasRequestId: Bool { - return proto.hasRequestId - } - - private init(proto: WebSocketProtos_WebSocketRequestMessage) { + private init(proto: WebSocketProtos_WebSocketRequestMessage, + verb: String, + path: String, + requestID: UInt64) { self.proto = proto + self.verb = verb + self.path = path + self.requestID = requestID } @objc @@ -108,11 +91,29 @@ public enum WebSocketProtoError: Error { } fileprivate class func parseProto(_ proto: WebSocketProtos_WebSocketRequestMessage) throws -> WebSocketProtoWebSocketRequestMessage { + guard proto.hasVerb else { + throw WebSocketProtoError.invalidProtobuf(description: "\(logTag) missing required field: verb") + } + let verb = proto.verb + + guard proto.hasPath else { + throw WebSocketProtoError.invalidProtobuf(description: "\(logTag) missing required field: path") + } + let path = proto.path + + guard proto.hasRequestID else { + throw WebSocketProtoError.invalidProtobuf(description: "\(logTag) missing required field: requestID") + } + let requestID = proto.requestID + // MARK: - Begin Validation Logic for WebSocketProtoWebSocketRequestMessage - // MARK: - End Validation Logic for WebSocketProtoWebSocketRequestMessage - - let result = WebSocketProtoWebSocketRequestMessage(proto: proto) + let result = WebSocketProtoWebSocketRequestMessage(proto: proto, + verb: verb, + path: path, + requestID: requestID) return result } } @@ -129,8 +130,8 @@ public enum WebSocketProtoError: Error { @objc public override init() {} - @objc public func setRequestId(_ valueParam: UInt64) { - proto.requestId = valueParam + @objc public func setRequestID(_ valueParam: UInt64) { + proto.requestID = valueParam } @objc public func setStatus(_ valueParam: UInt32) { @@ -159,19 +160,9 @@ public enum WebSocketProtoError: Error { fileprivate let proto: WebSocketProtos_WebSocketResponseMessage - @objc public var requestId: UInt64 { - return proto.requestId - } - @objc public var hasRequestId: Bool { - return proto.hasRequestId - } - - @objc public var status: UInt32 { - return proto.status - } - @objc public var hasStatus: Bool { - return proto.hasStatus - } + @objc public let requestID: UInt64 + @objc public let status: UInt32 + @objc public let body: Data @objc public var message: String? { guard proto.hasMessage else { @@ -187,18 +178,14 @@ public enum WebSocketProtoError: Error { return proto.headers } - @objc public var body: Data? { - guard proto.hasBody else { - return nil - } - return proto.body - } - @objc public var hasBody: Bool { - return proto.hasBody - } - - private init(proto: WebSocketProtos_WebSocketResponseMessage) { + private init(proto: WebSocketProtos_WebSocketResponseMessage, + requestID: UInt64, + status: UInt32, + body: Data) { self.proto = proto + self.requestID = requestID + self.status = status + self.body = body } @objc @@ -212,11 +199,29 @@ public enum WebSocketProtoError: Error { } fileprivate class func parseProto(_ proto: WebSocketProtos_WebSocketResponseMessage) throws -> WebSocketProtoWebSocketResponseMessage { + guard proto.hasRequestID else { + throw WebSocketProtoError.invalidProtobuf(description: "\(logTag) missing required field: requestID") + } + let requestID = proto.requestID + + guard proto.hasStatus else { + throw WebSocketProtoError.invalidProtobuf(description: "\(logTag) missing required field: status") + } + let status = proto.status + + guard proto.hasBody else { + throw WebSocketProtoError.invalidProtobuf(description: "\(logTag) missing required field: body") + } + let body = proto.body + // MARK: - Begin Validation Logic for WebSocketProtoWebSocketResponseMessage - // MARK: - End Validation Logic for WebSocketProtoWebSocketResponseMessage - - let result = WebSocketProtoWebSocketResponseMessage(proto: proto) + let result = WebSocketProtoWebSocketResponseMessage(proto: proto, + requestID: requestID, + status: status, + body: body) return result } } @@ -277,20 +282,16 @@ public enum WebSocketProtoError: Error { fileprivate let proto: WebSocketProtos_WebSocketMessage + @objc public let type: WebSocketProtoWebSocketMessageType @objc public let request: WebSocketProtoWebSocketRequestMessage? @objc public let response: WebSocketProtoWebSocketResponseMessage? - @objc public var type: WebSocketProtoWebSocketMessageType { - return WebSocketProtoWebSocketMessage.WebSocketProtoWebSocketMessageTypeWrap(proto.type) - } - @objc public var hasType: Bool { - return proto.hasType - } - private init(proto: WebSocketProtos_WebSocketMessage, + type: WebSocketProtoWebSocketMessageType, request: WebSocketProtoWebSocketRequestMessage?, response: WebSocketProtoWebSocketResponseMessage?) { self.proto = proto + self.type = type self.request = request self.response = response } @@ -306,6 +307,11 @@ public enum WebSocketProtoError: Error { } fileprivate class func parseProto(_ proto: WebSocketProtos_WebSocketMessage) throws -> WebSocketProtoWebSocketMessage { + guard proto.hasType else { + throw WebSocketProtoError.invalidProtobuf(description: "\(logTag) missing required field: type") + } + let type = WebSocketProtoWebSocketMessageTypeWrap(proto.type) + var request: WebSocketProtoWebSocketRequestMessage? = nil if proto.hasRequest { request = try WebSocketProtoWebSocketRequestMessage.parseProto(proto.request) @@ -321,6 +327,7 @@ public enum WebSocketProtoError: Error { // MARK: - End Validation Logic for WebSocketProtoWebSocketMessage - let result = WebSocketProtoWebSocketMessage(proto: proto, + type: type, request: request, response: response) return result diff --git a/SignalServiceKit/src/Protos/Generated/WebSocketResources.pb.swift b/SignalServiceKit/src/Protos/Generated/WebSocketResources.pb.swift index b3a02d079..dde0f11fa 100644 --- a/SignalServiceKit/src/Protos/Generated/WebSocketResources.pb.swift +++ b/SignalServiceKit/src/Protos/Generated/WebSocketResources.pb.swift @@ -32,6 +32,7 @@ struct WebSocketProtos_WebSocketRequestMessage { // `Message` and `Message+*Additions` files in the SwiftProtobuf library for // methods supported on all messages. + /// @required var verb: String { get {return _verb ?? String()} set {_verb = newValue} @@ -41,6 +42,7 @@ struct WebSocketProtos_WebSocketRequestMessage { /// Clears the value of `verb`. Subsequent reads from it will return its default value. mutating func clearVerb() {self._verb = nil} + /// @required var path: String { get {return _path ?? String()} set {_path = newValue} @@ -61,6 +63,7 @@ struct WebSocketProtos_WebSocketRequestMessage { var headers: [String] = [] + /// @required var requestID: UInt64 { get {return _requestID ?? 0} set {_requestID = newValue} @@ -85,6 +88,7 @@ struct WebSocketProtos_WebSocketResponseMessage { // `Message` and `Message+*Additions` files in the SwiftProtobuf library for // methods supported on all messages. + /// @required var requestID: UInt64 { get {return _requestID ?? 0} set {_requestID = newValue} @@ -94,6 +98,7 @@ struct WebSocketProtos_WebSocketResponseMessage { /// Clears the value of `requestID`. Subsequent reads from it will return its default value. mutating func clearRequestID() {self._requestID = nil} + /// @required var status: UInt32 { get {return _status ?? 0} set {_status = newValue} @@ -114,6 +119,7 @@ struct WebSocketProtos_WebSocketResponseMessage { var headers: [String] = [] + /// @required var body: Data { get {return _body ?? SwiftProtobuf.Internal.emptyData} set {_body = newValue} @@ -138,6 +144,7 @@ struct WebSocketProtos_WebSocketMessage { // `Message` and `Message+*Additions` files in the SwiftProtobuf library for // methods supported on all messages. + /// @required var type: WebSocketProtos_WebSocketMessage.TypeEnum { get {return _storage._type ?? .unknown} set {_uniqueStorage()._type = newValue}