From d63991309dbf6ad43cd1bc53f48190a7fa2056b3 Mon Sep 17 00:00:00 2001 From: Fabian Boemer Date: Mon, 26 Aug 2024 11:35:28 -0700 Subject: [PATCH] Adds PNNS API protos (#75) --- ...homomorphic_encryption_api_v1_api.pb.swift | 653 ------------------ ...ryption_api_v1_api_evaluation_key.pb.swift | 286 ++++++++ ...morphic_encryption_api_v1_api_pir.pb.swift | 447 ++++++++++++ .../PnnsProtocol.swift | 31 +- .../ConversionApi.swift | 51 ++ .../ConversionPnns.swift | 9 + ...ryption_api_v1_api_evaluation_key.pb.swift | 286 ++++++++ ...orphic_encryption_api_v1_api_pnns.pb.swift | 376 ++++++++++ Utilities/generate-protobuf-files.sh | 11 +- swift-homomorphic-encryption-protobuf | 2 +- 10 files changed, 1488 insertions(+), 664 deletions(-) create mode 100644 Sources/PrivateInformationRetrievalProtobuf/generated/apple_swift_homomorphic_encryption_api_v1_api_evaluation_key.pb.swift create mode 100644 Sources/PrivateInformationRetrievalProtobuf/generated/apple_swift_homomorphic_encryption_api_v1_api_pir.pb.swift create mode 100644 Sources/PrivateNearestNeighborsSearchProtobuf/ConversionApi.swift create mode 100644 Sources/PrivateNearestNeighborsSearchProtobuf/generated/apple_swift_homomorphic_encryption_api_v1_api_evaluation_key.pb.swift create mode 100644 Sources/PrivateNearestNeighborsSearchProtobuf/generated/apple_swift_homomorphic_encryption_api_v1_api_pnns.pb.swift diff --git a/Sources/PrivateInformationRetrievalProtobuf/generated/apple_swift_homomorphic_encryption_api_v1_api.pb.swift b/Sources/PrivateInformationRetrievalProtobuf/generated/apple_swift_homomorphic_encryption_api_v1_api.pb.swift index 0d978cb4..49fe920f 100644 --- a/Sources/PrivateInformationRetrievalProtobuf/generated/apple_swift_homomorphic_encryption_api_v1_api.pb.swift +++ b/Sources/PrivateInformationRetrievalProtobuf/generated/apple_swift_homomorphic_encryption_api_v1_api.pb.swift @@ -24,8 +24,6 @@ import Foundation import SwiftProtobuf -import HomomorphicEncryptionProtobuf - // If the compiler emits an error on this type, it is because this file // was generated by a version of the `protoc` Swift plug-in that is // incompatible with the version of SwiftProtobuf to which you are linking. @@ -36,97 +34,6 @@ fileprivate struct _GeneratedWithProtocGenSwiftVersion: SwiftProtobuf.ProtobufAP typealias Version = _2 } -/// Evaluation key metadata. -public struct Apple_SwiftHomomorphicEncryption_Api_V1_EvaluationKeyMetadata: @unchecked Sendable { - // SwiftProtobuf.Message conformance is added in an extension below. See the - // `Message` and `Message+*Additions` files in the SwiftProtobuf library for - // methods supported on all messages. - - /// Timestamp of the (secret) key generation, seconds from Unix epoch. - public var timestamp: UInt64 = 0 - - /// Key identifier (SHA256 of `EvaluationKeyConfig`). - public var identifier: Data = Data() - - public var unknownFields = SwiftProtobuf.UnknownStorage() - - public init() {} -} - -/// Status of the evaluation key. -public struct Apple_SwiftHomomorphicEncryption_Api_V1_KeyStatus: Sendable { - // SwiftProtobuf.Message conformance is added in an extension below. See the - // `Message` and `Message+*Additions` files in the SwiftProtobuf library for - // methods supported on all messages. - - /// When was this key last updated (seconds from Unix epoch), 0 when key is missing. - public var timestamp: UInt64 = 0 - - /// Configuration for the key. - public var keyConfig: HomomorphicEncryptionProtobuf.Apple_SwiftHomomorphicEncryption_V1_EvaluationKeyConfig { - get {return _keyConfig ?? HomomorphicEncryptionProtobuf.Apple_SwiftHomomorphicEncryption_V1_EvaluationKeyConfig()} - set {_keyConfig = newValue} - } - /// Returns true if `keyConfig` has been explicitly set. - public var hasKeyConfig: Bool {return self._keyConfig != nil} - /// Clears the value of `keyConfig`. Subsequent reads from it will return its default value. - public mutating func clearKeyConfig() {self._keyConfig = nil} - - public var unknownFields = SwiftProtobuf.UnknownStorage() - - public init() {} - - fileprivate var _keyConfig: HomomorphicEncryptionProtobuf.Apple_SwiftHomomorphicEncryption_V1_EvaluationKeyConfig? = nil -} - -/// Container for multiple evaluation keys. -public struct Apple_SwiftHomomorphicEncryption_Api_V1_EvaluationKeys: Sendable { - // SwiftProtobuf.Message conformance is added in an extension below. See the - // `Message` and `Message+*Additions` files in the SwiftProtobuf library for - // methods supported on all messages. - - /// Evaluation keys. - public var keys: [Apple_SwiftHomomorphicEncryption_Api_V1_EvaluationKey] = [] - - public var unknownFields = SwiftProtobuf.UnknownStorage() - - public init() {} -} - -/// Evaluation key upload. -public struct Apple_SwiftHomomorphicEncryption_Api_V1_EvaluationKey: Sendable { - // SwiftProtobuf.Message conformance is added in an extension below. See the - // `Message` and `Message+*Additions` files in the SwiftProtobuf library for - // methods supported on all messages. - - /// Metadata for the key. - public var metadata: Apple_SwiftHomomorphicEncryption_Api_V1_EvaluationKeyMetadata { - get {return _metadata ?? Apple_SwiftHomomorphicEncryption_Api_V1_EvaluationKeyMetadata()} - set {_metadata = newValue} - } - /// Returns true if `metadata` has been explicitly set. - public var hasMetadata: Bool {return self._metadata != nil} - /// Clears the value of `metadata`. Subsequent reads from it will return its default value. - public mutating func clearMetadata() {self._metadata = nil} - - /// Evaluation key. - public var evaluationKey: HomomorphicEncryptionProtobuf.Apple_SwiftHomomorphicEncryption_V1_SerializedEvaluationKey { - get {return _evaluationKey ?? HomomorphicEncryptionProtobuf.Apple_SwiftHomomorphicEncryption_V1_SerializedEvaluationKey()} - set {_evaluationKey = newValue} - } - /// Returns true if `evaluationKey` has been explicitly set. - public var hasEvaluationKey: Bool {return self._evaluationKey != nil} - /// Clears the value of `evaluationKey`. Subsequent reads from it will return its default value. - public mutating func clearEvaluationKey() {self._evaluationKey = nil} - - public var unknownFields = SwiftProtobuf.UnknownStorage() - - public init() {} - - fileprivate var _metadata: Apple_SwiftHomomorphicEncryption_Api_V1_EvaluationKeyMetadata? = nil - fileprivate var _evaluationKey: HomomorphicEncryptionProtobuf.Apple_SwiftHomomorphicEncryption_V1_SerializedEvaluationKey? = nil -} - /// Request for server side configurations. public struct Apple_SwiftHomomorphicEncryption_Api_V1_ConfigRequest: Sendable { // SwiftProtobuf.Message conformance is added in an extension below. See the @@ -283,340 +190,10 @@ public struct Apple_SwiftHomomorphicEncryption_Api_V1_Response: Sendable { public init() {} } -/// Configuration for one shard of the PIR database. -public struct Apple_SwiftHomomorphicEncryption_Api_V1_PIRShardConfig: Sendable { - // SwiftProtobuf.Message conformance is added in an extension below. See the - // `Message` and `Message+*Additions` files in the SwiftProtobuf library for - // methods supported on all messages. - - /// Number of entries in the shard. - public var numEntries: UInt64 = 0 - - /// Size in bytes of entries in the shard. - public var entrySize: UInt64 = 0 - - /// Dimensions that make up the hypercube. - public var dimensions: [UInt64] = [] - - /// Unique identifier for the shard. - public var shardID: String { - get {return _shardID ?? String()} - set {_shardID = newValue} - } - /// Returns true if `shardID` has been explicitly set. - public var hasShardID: Bool {return self._shardID != nil} - /// Clears the value of `shardID`. Subsequent reads from it will return its default value. - public mutating func clearShardID() {self._shardID = nil} - - /// Whether to compress vectorized PIR response. - public var compressVectorizedPirResponse: Bool { - get {return _compressVectorizedPirResponse ?? false} - set {_compressVectorizedPirResponse = newValue} - } - /// Returns true if `compressVectorizedPirResponse` has been explicitly set. - public var hasCompressVectorizedPirResponse: Bool {return self._compressVectorizedPirResponse != nil} - /// Clears the value of `compressVectorizedPirResponse`. Subsequent reads from it will return its default value. - public mutating func clearCompressVectorizedPirResponse() {self._compressVectorizedPirResponse = nil} - - /// The additional "batching" introduced in vectorized pir to accommodate large entry size. - public var vectorizedPirInternalBatchingSize: UInt64 { - get {return _vectorizedPirInternalBatchingSize ?? 0} - set {_vectorizedPirInternalBatchingSize = newValue} - } - /// Returns true if `vectorizedPirInternalBatchingSize` has been explicitly set. - public var hasVectorizedPirInternalBatchingSize: Bool {return self._vectorizedPirInternalBatchingSize != nil} - /// Clears the value of `vectorizedPirInternalBatchingSize`. Subsequent reads from it will return its default value. - public mutating func clearVectorizedPirInternalBatchingSize() {self._vectorizedPirInternalBatchingSize = nil} - - public var unknownFields = SwiftProtobuf.UnknownStorage() - - public init() {} - - fileprivate var _shardID: String? = nil - fileprivate var _compressVectorizedPirResponse: Bool? = nil - fileprivate var _vectorizedPirInternalBatchingSize: UInt64? = nil -} - -/// Configuration for one PIR usecase. -public struct Apple_SwiftHomomorphicEncryption_Api_V1_PIRConfig: @unchecked Sendable { - // SwiftProtobuf.Message conformance is added in an extension below. See the - // `Message` and `Message+*Additions` files in the SwiftProtobuf library for - // methods supported on all messages. - - /// Encryption parameters. - public var encryptionParameters: HomomorphicEncryptionProtobuf.Apple_SwiftHomomorphicEncryption_V1_EncryptionParameters { - get {return _encryptionParameters ?? HomomorphicEncryptionProtobuf.Apple_SwiftHomomorphicEncryption_V1_EncryptionParameters()} - set {_encryptionParameters = newValue} - } - /// Returns true if `encryptionParameters` has been explicitly set. - public var hasEncryptionParameters: Bool {return self._encryptionParameters != nil} - /// Clears the value of `encryptionParameters`. Subsequent reads from it will return its default value. - public mutating func clearEncryptionParameters() {self._encryptionParameters = nil} - - /// Configuration for each shard. - public var shardConfigs: [Apple_SwiftHomomorphicEncryption_Api_V1_PIRShardConfig] = [] - - /// Parameters specific to KeywordPIR. - public var keywordPirParams: Apple_SwiftHomomorphicEncryption_Pir_V1_KeywordPirParameters { - get {return _keywordPirParams ?? Apple_SwiftHomomorphicEncryption_Pir_V1_KeywordPirParameters()} - set {_keywordPirParams = newValue} - } - /// Returns true if `keywordPirParams` has been explicitly set. - public var hasKeywordPirParams: Bool {return self._keywordPirParams != nil} - /// Clears the value of `keywordPirParams`. Subsequent reads from it will return its default value. - public mutating func clearKeywordPirParams() {self._keywordPirParams = nil} - - /// Server-side PIR algorithm. - public var algorithm: Apple_SwiftHomomorphicEncryption_Pir_V1_PirAlgorithm = .aclsPir - - /// Maximum number of queries allowed in a single request. - public var batchSize: UInt64 = 0 - - /// Hash of EvaluationKeyConfig. - public var evaluationKeyConfigHash: Data = Data() - - public var unknownFields = SwiftProtobuf.UnknownStorage() - - public init() {} - - fileprivate var _encryptionParameters: HomomorphicEncryptionProtobuf.Apple_SwiftHomomorphicEncryption_V1_EncryptionParameters? = nil - fileprivate var _keywordPirParams: Apple_SwiftHomomorphicEncryption_Pir_V1_KeywordPirParameters? = nil -} - -/// PIR Request. -public struct Apple_SwiftHomomorphicEncryption_Api_V1_PIRRequest: @unchecked Sendable { - // SwiftProtobuf.Message conformance is added in an extension below. See the - // `Message` and `Message+*Additions` files in the SwiftProtobuf library for - // methods supported on all messages. - - /// Shard index where this request should be routed. Can be overridden by shard_id. - public var shardIndex: UInt32 = 0 - - /// Encrypted query. - public var query: Apple_SwiftHomomorphicEncryption_Pir_V1_EncryptedIndices { - get {return _query ?? Apple_SwiftHomomorphicEncryption_Pir_V1_EncryptedIndices()} - set {_query = newValue} - } - /// Returns true if `query` has been explicitly set. - public var hasQuery: Bool {return self._query != nil} - /// Clears the value of `query`. Subsequent reads from it will return its default value. - public mutating func clearQuery() {self._query = nil} - - /// Evaluation key metadata. - public var evaluationKeyMetadata: Apple_SwiftHomomorphicEncryption_Api_V1_EvaluationKeyMetadata { - get {return _evaluationKeyMetadata ?? Apple_SwiftHomomorphicEncryption_Api_V1_EvaluationKeyMetadata()} - set {_evaluationKeyMetadata = newValue} - } - /// Returns true if `evaluationKeyMetadata` has been explicitly set. - public var hasEvaluationKeyMetadata: Bool {return self._evaluationKeyMetadata != nil} - /// Clears the value of `evaluationKeyMetadata`. Subsequent reads from it will return its default value. - public mutating func clearEvaluationKeyMetadata() {self._evaluationKeyMetadata = nil} - - /// Hash of the `PIRConfig` used to construct the query. - public var configurationHash: Data = Data() - - /// If set, route request to a shard with this `shard_id` instead of `shard_index`. - public var shardID: String { - get {return _shardID ?? String()} - set {_shardID = newValue} - } - /// Returns true if `shardID` has been explicitly set. - public var hasShardID: Bool {return self._shardID != nil} - /// Clears the value of `shardID`. Subsequent reads from it will return its default value. - public mutating func clearShardID() {self._shardID = nil} - - /// If set, evaluation key to query with. Will override evaluation key stored server-side. - public var evaluationKey: Apple_SwiftHomomorphicEncryption_Api_V1_EvaluationKey { - get {return _evaluationKey ?? Apple_SwiftHomomorphicEncryption_Api_V1_EvaluationKey()} - set {_evaluationKey = newValue} - } - /// Returns true if `evaluationKey` has been explicitly set. - public var hasEvaluationKey: Bool {return self._evaluationKey != nil} - /// Clears the value of `evaluationKey`. Subsequent reads from it will return its default value. - public mutating func clearEvaluationKey() {self._evaluationKey = nil} - - public var unknownFields = SwiftProtobuf.UnknownStorage() - - public init() {} - - fileprivate var _query: Apple_SwiftHomomorphicEncryption_Pir_V1_EncryptedIndices? = nil - fileprivate var _evaluationKeyMetadata: Apple_SwiftHomomorphicEncryption_Api_V1_EvaluationKeyMetadata? = nil - fileprivate var _shardID: String? = nil - fileprivate var _evaluationKey: Apple_SwiftHomomorphicEncryption_Api_V1_EvaluationKey? = nil -} - -/// PIR Response. -public struct Apple_SwiftHomomorphicEncryption_Api_V1_PIRResponse: Sendable { - // SwiftProtobuf.Message conformance is added in an extension below. See the - // `Message` and `Message+*Additions` files in the SwiftProtobuf library for - // methods supported on all messages. - - /// Encrypted replies, each of which is a ciphertext vector. - public var replies: [HomomorphicEncryptionProtobuf.Apple_SwiftHomomorphicEncryption_V1_SerializedCiphertextVec] = [] - - public var unknownFields = SwiftProtobuf.UnknownStorage() - - public init() {} -} - // MARK: - Code below here is support for the SwiftProtobuf runtime. fileprivate let _protobuf_package = "apple.swift_homomorphic_encryption.api.v1" -extension Apple_SwiftHomomorphicEncryption_Api_V1_EvaluationKeyMetadata: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { - public static let protoMessageName: String = _protobuf_package + ".EvaluationKeyMetadata" - public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ - 1: .same(proto: "timestamp"), - 2: .same(proto: "identifier"), - ] - - public mutating func decodeMessage(decoder: inout D) throws { - while let fieldNumber = try decoder.nextFieldNumber() { - // The use of inline closures is to circumvent an issue where the compiler - // allocates stack space for every case branch when no optimizations are - // enabled. https://github.com/apple/swift-protobuf/issues/1034 - switch fieldNumber { - case 1: try { try decoder.decodeSingularUInt64Field(value: &self.timestamp) }() - case 2: try { try decoder.decodeSingularBytesField(value: &self.identifier) }() - default: break - } - } - } - - public func traverse(visitor: inout V) throws { - if self.timestamp != 0 { - try visitor.visitSingularUInt64Field(value: self.timestamp, fieldNumber: 1) - } - if !self.identifier.isEmpty { - try visitor.visitSingularBytesField(value: self.identifier, fieldNumber: 2) - } - try unknownFields.traverse(visitor: &visitor) - } - - public static func ==(lhs: Apple_SwiftHomomorphicEncryption_Api_V1_EvaluationKeyMetadata, rhs: Apple_SwiftHomomorphicEncryption_Api_V1_EvaluationKeyMetadata) -> Bool { - if lhs.timestamp != rhs.timestamp {return false} - if lhs.identifier != rhs.identifier {return false} - if lhs.unknownFields != rhs.unknownFields {return false} - return true - } -} - -extension Apple_SwiftHomomorphicEncryption_Api_V1_KeyStatus: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { - public static let protoMessageName: String = _protobuf_package + ".KeyStatus" - public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ - 1: .same(proto: "timestamp"), - 2: .standard(proto: "key_config"), - ] - - public mutating func decodeMessage(decoder: inout D) throws { - while let fieldNumber = try decoder.nextFieldNumber() { - // The use of inline closures is to circumvent an issue where the compiler - // allocates stack space for every case branch when no optimizations are - // enabled. https://github.com/apple/swift-protobuf/issues/1034 - switch fieldNumber { - case 1: try { try decoder.decodeSingularUInt64Field(value: &self.timestamp) }() - case 2: try { try decoder.decodeSingularMessageField(value: &self._keyConfig) }() - default: break - } - } - } - - public func traverse(visitor: inout V) throws { - // The use of inline closures is to circumvent an issue where the compiler - // allocates stack space for every if/case branch local when no optimizations - // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and - // https://github.com/apple/swift-protobuf/issues/1182 - if self.timestamp != 0 { - try visitor.visitSingularUInt64Field(value: self.timestamp, fieldNumber: 1) - } - try { if let v = self._keyConfig { - try visitor.visitSingularMessageField(value: v, fieldNumber: 2) - } }() - try unknownFields.traverse(visitor: &visitor) - } - - public static func ==(lhs: Apple_SwiftHomomorphicEncryption_Api_V1_KeyStatus, rhs: Apple_SwiftHomomorphicEncryption_Api_V1_KeyStatus) -> Bool { - if lhs.timestamp != rhs.timestamp {return false} - if lhs._keyConfig != rhs._keyConfig {return false} - if lhs.unknownFields != rhs.unknownFields {return false} - return true - } -} - -extension Apple_SwiftHomomorphicEncryption_Api_V1_EvaluationKeys: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { - public static let protoMessageName: String = _protobuf_package + ".EvaluationKeys" - public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ - 1: .same(proto: "keys"), - ] - - public mutating func decodeMessage(decoder: inout D) throws { - while let fieldNumber = try decoder.nextFieldNumber() { - // The use of inline closures is to circumvent an issue where the compiler - // allocates stack space for every case branch when no optimizations are - // enabled. https://github.com/apple/swift-protobuf/issues/1034 - switch fieldNumber { - case 1: try { try decoder.decodeRepeatedMessageField(value: &self.keys) }() - default: break - } - } - } - - public func traverse(visitor: inout V) throws { - if !self.keys.isEmpty { - try visitor.visitRepeatedMessageField(value: self.keys, fieldNumber: 1) - } - try unknownFields.traverse(visitor: &visitor) - } - - public static func ==(lhs: Apple_SwiftHomomorphicEncryption_Api_V1_EvaluationKeys, rhs: Apple_SwiftHomomorphicEncryption_Api_V1_EvaluationKeys) -> Bool { - if lhs.keys != rhs.keys {return false} - if lhs.unknownFields != rhs.unknownFields {return false} - return true - } -} - -extension Apple_SwiftHomomorphicEncryption_Api_V1_EvaluationKey: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { - public static let protoMessageName: String = _protobuf_package + ".EvaluationKey" - public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ - 1: .same(proto: "metadata"), - 2: .standard(proto: "evaluation_key"), - ] - - public mutating func decodeMessage(decoder: inout D) throws { - while let fieldNumber = try decoder.nextFieldNumber() { - // The use of inline closures is to circumvent an issue where the compiler - // allocates stack space for every case branch when no optimizations are - // enabled. https://github.com/apple/swift-protobuf/issues/1034 - switch fieldNumber { - case 1: try { try decoder.decodeSingularMessageField(value: &self._metadata) }() - case 2: try { try decoder.decodeSingularMessageField(value: &self._evaluationKey) }() - default: break - } - } - } - - public func traverse(visitor: inout V) throws { - // The use of inline closures is to circumvent an issue where the compiler - // allocates stack space for every if/case branch local when no optimizations - // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and - // https://github.com/apple/swift-protobuf/issues/1182 - try { if let v = self._metadata { - try visitor.visitSingularMessageField(value: v, fieldNumber: 1) - } }() - try { if let v = self._evaluationKey { - try visitor.visitSingularMessageField(value: v, fieldNumber: 2) - } }() - try unknownFields.traverse(visitor: &visitor) - } - - public static func ==(lhs: Apple_SwiftHomomorphicEncryption_Api_V1_EvaluationKey, rhs: Apple_SwiftHomomorphicEncryption_Api_V1_EvaluationKey) -> Bool { - if lhs._metadata != rhs._metadata {return false} - if lhs._evaluationKey != rhs._evaluationKey {return false} - if lhs.unknownFields != rhs.unknownFields {return false} - return true - } -} - extension Apple_SwiftHomomorphicEncryption_Api_V1_ConfigRequest: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { public static let protoMessageName: String = _protobuf_package + ".ConfigRequest" public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ @@ -906,233 +483,3 @@ extension Apple_SwiftHomomorphicEncryption_Api_V1_Response: SwiftProtobuf.Messag return true } } - -extension Apple_SwiftHomomorphicEncryption_Api_V1_PIRShardConfig: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { - public static let protoMessageName: String = _protobuf_package + ".PIRShardConfig" - public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ - 1: .standard(proto: "num_entries"), - 2: .standard(proto: "entry_size"), - 3: .same(proto: "dimensions"), - 4: .standard(proto: "shard_id"), - 5: .standard(proto: "compress_vectorized_pir_response"), - 6: .standard(proto: "vectorized_pir_internal_batching_size"), - ] - - public mutating func decodeMessage(decoder: inout D) throws { - while let fieldNumber = try decoder.nextFieldNumber() { - // The use of inline closures is to circumvent an issue where the compiler - // allocates stack space for every case branch when no optimizations are - // enabled. https://github.com/apple/swift-protobuf/issues/1034 - switch fieldNumber { - case 1: try { try decoder.decodeSingularUInt64Field(value: &self.numEntries) }() - case 2: try { try decoder.decodeSingularUInt64Field(value: &self.entrySize) }() - case 3: try { try decoder.decodeRepeatedUInt64Field(value: &self.dimensions) }() - case 4: try { try decoder.decodeSingularStringField(value: &self._shardID) }() - case 5: try { try decoder.decodeSingularBoolField(value: &self._compressVectorizedPirResponse) }() - case 6: try { try decoder.decodeSingularUInt64Field(value: &self._vectorizedPirInternalBatchingSize) }() - default: break - } - } - } - - public func traverse(visitor: inout V) throws { - // The use of inline closures is to circumvent an issue where the compiler - // allocates stack space for every if/case branch local when no optimizations - // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and - // https://github.com/apple/swift-protobuf/issues/1182 - if self.numEntries != 0 { - try visitor.visitSingularUInt64Field(value: self.numEntries, fieldNumber: 1) - } - if self.entrySize != 0 { - try visitor.visitSingularUInt64Field(value: self.entrySize, fieldNumber: 2) - } - if !self.dimensions.isEmpty { - try visitor.visitPackedUInt64Field(value: self.dimensions, fieldNumber: 3) - } - try { if let v = self._shardID { - try visitor.visitSingularStringField(value: v, fieldNumber: 4) - } }() - try { if let v = self._compressVectorizedPirResponse { - try visitor.visitSingularBoolField(value: v, fieldNumber: 5) - } }() - try { if let v = self._vectorizedPirInternalBatchingSize { - try visitor.visitSingularUInt64Field(value: v, fieldNumber: 6) - } }() - try unknownFields.traverse(visitor: &visitor) - } - - public static func ==(lhs: Apple_SwiftHomomorphicEncryption_Api_V1_PIRShardConfig, rhs: Apple_SwiftHomomorphicEncryption_Api_V1_PIRShardConfig) -> Bool { - if lhs.numEntries != rhs.numEntries {return false} - if lhs.entrySize != rhs.entrySize {return false} - if lhs.dimensions != rhs.dimensions {return false} - if lhs._shardID != rhs._shardID {return false} - if lhs._compressVectorizedPirResponse != rhs._compressVectorizedPirResponse {return false} - if lhs._vectorizedPirInternalBatchingSize != rhs._vectorizedPirInternalBatchingSize {return false} - if lhs.unknownFields != rhs.unknownFields {return false} - return true - } -} - -extension Apple_SwiftHomomorphicEncryption_Api_V1_PIRConfig: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { - public static let protoMessageName: String = _protobuf_package + ".PIRConfig" - public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ - 1: .standard(proto: "encryption_parameters"), - 2: .standard(proto: "shard_configs"), - 3: .standard(proto: "keyword_pir_params"), - 4: .same(proto: "algorithm"), - 5: .standard(proto: "batch_size"), - 6: .standard(proto: "evaluation_key_config_hash"), - ] - - public mutating func decodeMessage(decoder: inout D) throws { - while let fieldNumber = try decoder.nextFieldNumber() { - // The use of inline closures is to circumvent an issue where the compiler - // allocates stack space for every case branch when no optimizations are - // enabled. https://github.com/apple/swift-protobuf/issues/1034 - switch fieldNumber { - case 1: try { try decoder.decodeSingularMessageField(value: &self._encryptionParameters) }() - case 2: try { try decoder.decodeRepeatedMessageField(value: &self.shardConfigs) }() - case 3: try { try decoder.decodeSingularMessageField(value: &self._keywordPirParams) }() - case 4: try { try decoder.decodeSingularEnumField(value: &self.algorithm) }() - case 5: try { try decoder.decodeSingularUInt64Field(value: &self.batchSize) }() - case 6: try { try decoder.decodeSingularBytesField(value: &self.evaluationKeyConfigHash) }() - default: break - } - } - } - - public func traverse(visitor: inout V) throws { - // The use of inline closures is to circumvent an issue where the compiler - // allocates stack space for every if/case branch local when no optimizations - // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and - // https://github.com/apple/swift-protobuf/issues/1182 - try { if let v = self._encryptionParameters { - try visitor.visitSingularMessageField(value: v, fieldNumber: 1) - } }() - if !self.shardConfigs.isEmpty { - try visitor.visitRepeatedMessageField(value: self.shardConfigs, fieldNumber: 2) - } - try { if let v = self._keywordPirParams { - try visitor.visitSingularMessageField(value: v, fieldNumber: 3) - } }() - if self.algorithm != .aclsPir { - try visitor.visitSingularEnumField(value: self.algorithm, fieldNumber: 4) - } - if self.batchSize != 0 { - try visitor.visitSingularUInt64Field(value: self.batchSize, fieldNumber: 5) - } - if !self.evaluationKeyConfigHash.isEmpty { - try visitor.visitSingularBytesField(value: self.evaluationKeyConfigHash, fieldNumber: 6) - } - try unknownFields.traverse(visitor: &visitor) - } - - public static func ==(lhs: Apple_SwiftHomomorphicEncryption_Api_V1_PIRConfig, rhs: Apple_SwiftHomomorphicEncryption_Api_V1_PIRConfig) -> Bool { - if lhs._encryptionParameters != rhs._encryptionParameters {return false} - if lhs.shardConfigs != rhs.shardConfigs {return false} - if lhs._keywordPirParams != rhs._keywordPirParams {return false} - if lhs.algorithm != rhs.algorithm {return false} - if lhs.batchSize != rhs.batchSize {return false} - if lhs.evaluationKeyConfigHash != rhs.evaluationKeyConfigHash {return false} - if lhs.unknownFields != rhs.unknownFields {return false} - return true - } -} - -extension Apple_SwiftHomomorphicEncryption_Api_V1_PIRRequest: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { - public static let protoMessageName: String = _protobuf_package + ".PIRRequest" - public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ - 1: .standard(proto: "shard_index"), - 2: .same(proto: "query"), - 3: .standard(proto: "evaluation_key_metadata"), - 4: .standard(proto: "configuration_hash"), - 5: .standard(proto: "shard_id"), - 6: .standard(proto: "evaluation_key"), - ] - - public mutating func decodeMessage(decoder: inout D) throws { - while let fieldNumber = try decoder.nextFieldNumber() { - // The use of inline closures is to circumvent an issue where the compiler - // allocates stack space for every case branch when no optimizations are - // enabled. https://github.com/apple/swift-protobuf/issues/1034 - switch fieldNumber { - case 1: try { try decoder.decodeSingularUInt32Field(value: &self.shardIndex) }() - case 2: try { try decoder.decodeSingularMessageField(value: &self._query) }() - case 3: try { try decoder.decodeSingularMessageField(value: &self._evaluationKeyMetadata) }() - case 4: try { try decoder.decodeSingularBytesField(value: &self.configurationHash) }() - case 5: try { try decoder.decodeSingularStringField(value: &self._shardID) }() - case 6: try { try decoder.decodeSingularMessageField(value: &self._evaluationKey) }() - default: break - } - } - } - - public func traverse(visitor: inout V) throws { - // The use of inline closures is to circumvent an issue where the compiler - // allocates stack space for every if/case branch local when no optimizations - // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and - // https://github.com/apple/swift-protobuf/issues/1182 - if self.shardIndex != 0 { - try visitor.visitSingularUInt32Field(value: self.shardIndex, fieldNumber: 1) - } - try { if let v = self._query { - try visitor.visitSingularMessageField(value: v, fieldNumber: 2) - } }() - try { if let v = self._evaluationKeyMetadata { - try visitor.visitSingularMessageField(value: v, fieldNumber: 3) - } }() - if !self.configurationHash.isEmpty { - try visitor.visitSingularBytesField(value: self.configurationHash, fieldNumber: 4) - } - try { if let v = self._shardID { - try visitor.visitSingularStringField(value: v, fieldNumber: 5) - } }() - try { if let v = self._evaluationKey { - try visitor.visitSingularMessageField(value: v, fieldNumber: 6) - } }() - try unknownFields.traverse(visitor: &visitor) - } - - public static func ==(lhs: Apple_SwiftHomomorphicEncryption_Api_V1_PIRRequest, rhs: Apple_SwiftHomomorphicEncryption_Api_V1_PIRRequest) -> Bool { - if lhs.shardIndex != rhs.shardIndex {return false} - if lhs._query != rhs._query {return false} - if lhs._evaluationKeyMetadata != rhs._evaluationKeyMetadata {return false} - if lhs.configurationHash != rhs.configurationHash {return false} - if lhs._shardID != rhs._shardID {return false} - if lhs._evaluationKey != rhs._evaluationKey {return false} - if lhs.unknownFields != rhs.unknownFields {return false} - return true - } -} - -extension Apple_SwiftHomomorphicEncryption_Api_V1_PIRResponse: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { - public static let protoMessageName: String = _protobuf_package + ".PIRResponse" - public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ - 1: .same(proto: "replies"), - ] - - public mutating func decodeMessage(decoder: inout D) throws { - while let fieldNumber = try decoder.nextFieldNumber() { - // The use of inline closures is to circumvent an issue where the compiler - // allocates stack space for every case branch when no optimizations are - // enabled. https://github.com/apple/swift-protobuf/issues/1034 - switch fieldNumber { - case 1: try { try decoder.decodeRepeatedMessageField(value: &self.replies) }() - default: break - } - } - } - - public func traverse(visitor: inout V) throws { - if !self.replies.isEmpty { - try visitor.visitRepeatedMessageField(value: self.replies, fieldNumber: 1) - } - try unknownFields.traverse(visitor: &visitor) - } - - public static func ==(lhs: Apple_SwiftHomomorphicEncryption_Api_V1_PIRResponse, rhs: Apple_SwiftHomomorphicEncryption_Api_V1_PIRResponse) -> Bool { - if lhs.replies != rhs.replies {return false} - if lhs.unknownFields != rhs.unknownFields {return false} - return true - } -} diff --git a/Sources/PrivateInformationRetrievalProtobuf/generated/apple_swift_homomorphic_encryption_api_v1_api_evaluation_key.pb.swift b/Sources/PrivateInformationRetrievalProtobuf/generated/apple_swift_homomorphic_encryption_api_v1_api_evaluation_key.pb.swift new file mode 100644 index 00000000..63d88421 --- /dev/null +++ b/Sources/PrivateInformationRetrievalProtobuf/generated/apple_swift_homomorphic_encryption_api_v1_api_evaluation_key.pb.swift @@ -0,0 +1,286 @@ +// DO NOT EDIT. +// swift-format-ignore-file +// +// Generated by the Swift generator plugin for the protocol buffer compiler. +// Source: apple/swift_homomorphic_encryption/api/v1/api_evaluation_key.proto +// +// For information on using the generated types, please see the documentation: +// https://github.com/apple/swift-protobuf/ + +// Copyright 2024 Apple Inc. and the Swift Homomorphic Encryption project authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import Foundation +import SwiftProtobuf + +import HomomorphicEncryptionProtobuf + +// If the compiler emits an error on this type, it is because this file +// was generated by a version of the `protoc` Swift plug-in that is +// incompatible with the version of SwiftProtobuf to which you are linking. +// Please ensure that you are building against the same version of the API +// that was used to generate this file. +fileprivate struct _GeneratedWithProtocGenSwiftVersion: SwiftProtobuf.ProtobufAPIVersionCheck { + struct _2: SwiftProtobuf.ProtobufAPIVersion_2 {} + typealias Version = _2 +} + +/// Evaluation key metadata. +public struct Apple_SwiftHomomorphicEncryption_Api_V1_EvaluationKeyMetadata: @unchecked Sendable { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + /// Timestamp of the (secret) key generation, seconds from Unix epoch. + public var timestamp: UInt64 = 0 + + /// Key identifier (SHA256 of `EvaluationKeyConfig`). + public var identifier: Data = Data() + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} +} + +/// Status of the evaluation key. +public struct Apple_SwiftHomomorphicEncryption_Api_V1_KeyStatus: Sendable { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + /// When was this key last updated (seconds from Unix epoch), 0 when key is missing. + public var timestamp: UInt64 = 0 + + /// Configuration for the key. + public var keyConfig: HomomorphicEncryptionProtobuf.Apple_SwiftHomomorphicEncryption_V1_EvaluationKeyConfig { + get {return _keyConfig ?? HomomorphicEncryptionProtobuf.Apple_SwiftHomomorphicEncryption_V1_EvaluationKeyConfig()} + set {_keyConfig = newValue} + } + /// Returns true if `keyConfig` has been explicitly set. + public var hasKeyConfig: Bool {return self._keyConfig != nil} + /// Clears the value of `keyConfig`. Subsequent reads from it will return its default value. + public mutating func clearKeyConfig() {self._keyConfig = nil} + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} + + fileprivate var _keyConfig: HomomorphicEncryptionProtobuf.Apple_SwiftHomomorphicEncryption_V1_EvaluationKeyConfig? = nil +} + +/// Container for multiple evaluation keys. +public struct Apple_SwiftHomomorphicEncryption_Api_V1_EvaluationKeys: Sendable { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + /// Evaluation keys. + public var keys: [Apple_SwiftHomomorphicEncryption_Api_V1_EvaluationKey] = [] + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} +} + +/// Evaluation key upload. +public struct Apple_SwiftHomomorphicEncryption_Api_V1_EvaluationKey: Sendable { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + /// Metadata for the key. + public var metadata: Apple_SwiftHomomorphicEncryption_Api_V1_EvaluationKeyMetadata { + get {return _metadata ?? Apple_SwiftHomomorphicEncryption_Api_V1_EvaluationKeyMetadata()} + set {_metadata = newValue} + } + /// Returns true if `metadata` has been explicitly set. + public var hasMetadata: Bool {return self._metadata != nil} + /// Clears the value of `metadata`. Subsequent reads from it will return its default value. + public mutating func clearMetadata() {self._metadata = nil} + + /// Evaluation key. + public var evaluationKey: HomomorphicEncryptionProtobuf.Apple_SwiftHomomorphicEncryption_V1_SerializedEvaluationKey { + get {return _evaluationKey ?? HomomorphicEncryptionProtobuf.Apple_SwiftHomomorphicEncryption_V1_SerializedEvaluationKey()} + set {_evaluationKey = newValue} + } + /// Returns true if `evaluationKey` has been explicitly set. + public var hasEvaluationKey: Bool {return self._evaluationKey != nil} + /// Clears the value of `evaluationKey`. Subsequent reads from it will return its default value. + public mutating func clearEvaluationKey() {self._evaluationKey = nil} + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} + + fileprivate var _metadata: Apple_SwiftHomomorphicEncryption_Api_V1_EvaluationKeyMetadata? = nil + fileprivate var _evaluationKey: HomomorphicEncryptionProtobuf.Apple_SwiftHomomorphicEncryption_V1_SerializedEvaluationKey? = nil +} + +// MARK: - Code below here is support for the SwiftProtobuf runtime. + +fileprivate let _protobuf_package = "apple.swift_homomorphic_encryption.api.v1" + +extension Apple_SwiftHomomorphicEncryption_Api_V1_EvaluationKeyMetadata: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".EvaluationKeyMetadata" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "timestamp"), + 2: .same(proto: "identifier"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularUInt64Field(value: &self.timestamp) }() + case 2: try { try decoder.decodeSingularBytesField(value: &self.identifier) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + if self.timestamp != 0 { + try visitor.visitSingularUInt64Field(value: self.timestamp, fieldNumber: 1) + } + if !self.identifier.isEmpty { + try visitor.visitSingularBytesField(value: self.identifier, fieldNumber: 2) + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Apple_SwiftHomomorphicEncryption_Api_V1_EvaluationKeyMetadata, rhs: Apple_SwiftHomomorphicEncryption_Api_V1_EvaluationKeyMetadata) -> Bool { + if lhs.timestamp != rhs.timestamp {return false} + if lhs.identifier != rhs.identifier {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Apple_SwiftHomomorphicEncryption_Api_V1_KeyStatus: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".KeyStatus" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "timestamp"), + 2: .standard(proto: "key_config"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularUInt64Field(value: &self.timestamp) }() + case 2: try { try decoder.decodeSingularMessageField(value: &self._keyConfig) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every if/case branch local when no optimizations + // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and + // https://github.com/apple/swift-protobuf/issues/1182 + if self.timestamp != 0 { + try visitor.visitSingularUInt64Field(value: self.timestamp, fieldNumber: 1) + } + try { if let v = self._keyConfig { + try visitor.visitSingularMessageField(value: v, fieldNumber: 2) + } }() + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Apple_SwiftHomomorphicEncryption_Api_V1_KeyStatus, rhs: Apple_SwiftHomomorphicEncryption_Api_V1_KeyStatus) -> Bool { + if lhs.timestamp != rhs.timestamp {return false} + if lhs._keyConfig != rhs._keyConfig {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Apple_SwiftHomomorphicEncryption_Api_V1_EvaluationKeys: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".EvaluationKeys" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "keys"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeRepeatedMessageField(value: &self.keys) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + if !self.keys.isEmpty { + try visitor.visitRepeatedMessageField(value: self.keys, fieldNumber: 1) + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Apple_SwiftHomomorphicEncryption_Api_V1_EvaluationKeys, rhs: Apple_SwiftHomomorphicEncryption_Api_V1_EvaluationKeys) -> Bool { + if lhs.keys != rhs.keys {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Apple_SwiftHomomorphicEncryption_Api_V1_EvaluationKey: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".EvaluationKey" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "metadata"), + 2: .standard(proto: "evaluation_key"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularMessageField(value: &self._metadata) }() + case 2: try { try decoder.decodeSingularMessageField(value: &self._evaluationKey) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every if/case branch local when no optimizations + // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and + // https://github.com/apple/swift-protobuf/issues/1182 + try { if let v = self._metadata { + try visitor.visitSingularMessageField(value: v, fieldNumber: 1) + } }() + try { if let v = self._evaluationKey { + try visitor.visitSingularMessageField(value: v, fieldNumber: 2) + } }() + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Apple_SwiftHomomorphicEncryption_Api_V1_EvaluationKey, rhs: Apple_SwiftHomomorphicEncryption_Api_V1_EvaluationKey) -> Bool { + if lhs._metadata != rhs._metadata {return false} + if lhs._evaluationKey != rhs._evaluationKey {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} diff --git a/Sources/PrivateInformationRetrievalProtobuf/generated/apple_swift_homomorphic_encryption_api_v1_api_pir.pb.swift b/Sources/PrivateInformationRetrievalProtobuf/generated/apple_swift_homomorphic_encryption_api_v1_api_pir.pb.swift new file mode 100644 index 00000000..0766f2f9 --- /dev/null +++ b/Sources/PrivateInformationRetrievalProtobuf/generated/apple_swift_homomorphic_encryption_api_v1_api_pir.pb.swift @@ -0,0 +1,447 @@ +// DO NOT EDIT. +// swift-format-ignore-file +// +// Generated by the Swift generator plugin for the protocol buffer compiler. +// Source: apple/swift_homomorphic_encryption/api/v1/api_pir.proto +// +// For information on using the generated types, please see the documentation: +// https://github.com/apple/swift-protobuf/ + +// Copyright 2024 Apple Inc. and the Swift Homomorphic Encryption project authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import Foundation +import SwiftProtobuf + +import HomomorphicEncryptionProtobuf + +// If the compiler emits an error on this type, it is because this file +// was generated by a version of the `protoc` Swift plug-in that is +// incompatible with the version of SwiftProtobuf to which you are linking. +// Please ensure that you are building against the same version of the API +// that was used to generate this file. +fileprivate struct _GeneratedWithProtocGenSwiftVersion: SwiftProtobuf.ProtobufAPIVersionCheck { + struct _2: SwiftProtobuf.ProtobufAPIVersion_2 {} + typealias Version = _2 +} + +/// Configuration for one shard of the PIR database. +public struct Apple_SwiftHomomorphicEncryption_Api_V1_PIRShardConfig: Sendable { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + /// Number of entries in the shard. + public var numEntries: UInt64 = 0 + + /// Size in bytes of entries in the shard. + public var entrySize: UInt64 = 0 + + /// Dimensions that make up the hypercube. + public var dimensions: [UInt64] = [] + + /// Unique identifier for the shard. + public var shardID: String { + get {return _shardID ?? String()} + set {_shardID = newValue} + } + /// Returns true if `shardID` has been explicitly set. + public var hasShardID: Bool {return self._shardID != nil} + /// Clears the value of `shardID`. Subsequent reads from it will return its default value. + public mutating func clearShardID() {self._shardID = nil} + + /// Whether to compress vectorized PIR response. + public var compressVectorizedPirResponse: Bool { + get {return _compressVectorizedPirResponse ?? false} + set {_compressVectorizedPirResponse = newValue} + } + /// Returns true if `compressVectorizedPirResponse` has been explicitly set. + public var hasCompressVectorizedPirResponse: Bool {return self._compressVectorizedPirResponse != nil} + /// Clears the value of `compressVectorizedPirResponse`. Subsequent reads from it will return its default value. + public mutating func clearCompressVectorizedPirResponse() {self._compressVectorizedPirResponse = nil} + + /// The additional "batching" introduced in vectorized pir to accommodate large entry size. + public var vectorizedPirInternalBatchingSize: UInt64 { + get {return _vectorizedPirInternalBatchingSize ?? 0} + set {_vectorizedPirInternalBatchingSize = newValue} + } + /// Returns true if `vectorizedPirInternalBatchingSize` has been explicitly set. + public var hasVectorizedPirInternalBatchingSize: Bool {return self._vectorizedPirInternalBatchingSize != nil} + /// Clears the value of `vectorizedPirInternalBatchingSize`. Subsequent reads from it will return its default value. + public mutating func clearVectorizedPirInternalBatchingSize() {self._vectorizedPirInternalBatchingSize = nil} + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} + + fileprivate var _shardID: String? = nil + fileprivate var _compressVectorizedPirResponse: Bool? = nil + fileprivate var _vectorizedPirInternalBatchingSize: UInt64? = nil +} + +/// Configuration for one PIR usecase. +public struct Apple_SwiftHomomorphicEncryption_Api_V1_PIRConfig: @unchecked Sendable { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + /// Encryption parameters. + public var encryptionParameters: HomomorphicEncryptionProtobuf.Apple_SwiftHomomorphicEncryption_V1_EncryptionParameters { + get {return _encryptionParameters ?? HomomorphicEncryptionProtobuf.Apple_SwiftHomomorphicEncryption_V1_EncryptionParameters()} + set {_encryptionParameters = newValue} + } + /// Returns true if `encryptionParameters` has been explicitly set. + public var hasEncryptionParameters: Bool {return self._encryptionParameters != nil} + /// Clears the value of `encryptionParameters`. Subsequent reads from it will return its default value. + public mutating func clearEncryptionParameters() {self._encryptionParameters = nil} + + /// Configuration for each shard. + public var shardConfigs: [Apple_SwiftHomomorphicEncryption_Api_V1_PIRShardConfig] = [] + + /// Parameters specific to KeywordPIR. + public var keywordPirParams: Apple_SwiftHomomorphicEncryption_Pir_V1_KeywordPirParameters { + get {return _keywordPirParams ?? Apple_SwiftHomomorphicEncryption_Pir_V1_KeywordPirParameters()} + set {_keywordPirParams = newValue} + } + /// Returns true if `keywordPirParams` has been explicitly set. + public var hasKeywordPirParams: Bool {return self._keywordPirParams != nil} + /// Clears the value of `keywordPirParams`. Subsequent reads from it will return its default value. + public mutating func clearKeywordPirParams() {self._keywordPirParams = nil} + + /// Server-side PIR algorithm. + public var algorithm: Apple_SwiftHomomorphicEncryption_Pir_V1_PirAlgorithm = .aclsPir + + /// Maximum number of queries allowed in a single request. + public var batchSize: UInt64 = 0 + + /// Hash of EvaluationKeyConfig. + public var evaluationKeyConfigHash: Data = Data() + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} + + fileprivate var _encryptionParameters: HomomorphicEncryptionProtobuf.Apple_SwiftHomomorphicEncryption_V1_EncryptionParameters? = nil + fileprivate var _keywordPirParams: Apple_SwiftHomomorphicEncryption_Pir_V1_KeywordPirParameters? = nil +} + +/// PIR Request. +public struct Apple_SwiftHomomorphicEncryption_Api_V1_PIRRequest: @unchecked Sendable { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + /// Shard index where this request should be routed. Can be overridden by shard_id. + public var shardIndex: UInt32 = 0 + + /// Encrypted query. + public var query: Apple_SwiftHomomorphicEncryption_Pir_V1_EncryptedIndices { + get {return _query ?? Apple_SwiftHomomorphicEncryption_Pir_V1_EncryptedIndices()} + set {_query = newValue} + } + /// Returns true if `query` has been explicitly set. + public var hasQuery: Bool {return self._query != nil} + /// Clears the value of `query`. Subsequent reads from it will return its default value. + public mutating func clearQuery() {self._query = nil} + + /// Evaluation key metadata. + public var evaluationKeyMetadata: Apple_SwiftHomomorphicEncryption_Api_V1_EvaluationKeyMetadata { + get {return _evaluationKeyMetadata ?? Apple_SwiftHomomorphicEncryption_Api_V1_EvaluationKeyMetadata()} + set {_evaluationKeyMetadata = newValue} + } + /// Returns true if `evaluationKeyMetadata` has been explicitly set. + public var hasEvaluationKeyMetadata: Bool {return self._evaluationKeyMetadata != nil} + /// Clears the value of `evaluationKeyMetadata`. Subsequent reads from it will return its default value. + public mutating func clearEvaluationKeyMetadata() {self._evaluationKeyMetadata = nil} + + /// Hash of the `PIRConfig` used to construct the query. + public var configurationHash: Data = Data() + + /// If set, route request to a shard with this `shard_id` instead of `shard_index`. + public var shardID: String { + get {return _shardID ?? String()} + set {_shardID = newValue} + } + /// Returns true if `shardID` has been explicitly set. + public var hasShardID: Bool {return self._shardID != nil} + /// Clears the value of `shardID`. Subsequent reads from it will return its default value. + public mutating func clearShardID() {self._shardID = nil} + + /// If set, evaluation key to query with. Will override evaluation key stored server-side. + public var evaluationKey: Apple_SwiftHomomorphicEncryption_Api_V1_EvaluationKey { + get {return _evaluationKey ?? Apple_SwiftHomomorphicEncryption_Api_V1_EvaluationKey()} + set {_evaluationKey = newValue} + } + /// Returns true if `evaluationKey` has been explicitly set. + public var hasEvaluationKey: Bool {return self._evaluationKey != nil} + /// Clears the value of `evaluationKey`. Subsequent reads from it will return its default value. + public mutating func clearEvaluationKey() {self._evaluationKey = nil} + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} + + fileprivate var _query: Apple_SwiftHomomorphicEncryption_Pir_V1_EncryptedIndices? = nil + fileprivate var _evaluationKeyMetadata: Apple_SwiftHomomorphicEncryption_Api_V1_EvaluationKeyMetadata? = nil + fileprivate var _shardID: String? = nil + fileprivate var _evaluationKey: Apple_SwiftHomomorphicEncryption_Api_V1_EvaluationKey? = nil +} + +/// PIR Response. +public struct Apple_SwiftHomomorphicEncryption_Api_V1_PIRResponse: Sendable { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + /// Encrypted replies, each of which is a ciphertext vector. + public var replies: [HomomorphicEncryptionProtobuf.Apple_SwiftHomomorphicEncryption_V1_SerializedCiphertextVec] = [] + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} +} + +// MARK: - Code below here is support for the SwiftProtobuf runtime. + +fileprivate let _protobuf_package = "apple.swift_homomorphic_encryption.api.v1" + +extension Apple_SwiftHomomorphicEncryption_Api_V1_PIRShardConfig: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".PIRShardConfig" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .standard(proto: "num_entries"), + 2: .standard(proto: "entry_size"), + 3: .same(proto: "dimensions"), + 4: .standard(proto: "shard_id"), + 5: .standard(proto: "compress_vectorized_pir_response"), + 6: .standard(proto: "vectorized_pir_internal_batching_size"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularUInt64Field(value: &self.numEntries) }() + case 2: try { try decoder.decodeSingularUInt64Field(value: &self.entrySize) }() + case 3: try { try decoder.decodeRepeatedUInt64Field(value: &self.dimensions) }() + case 4: try { try decoder.decodeSingularStringField(value: &self._shardID) }() + case 5: try { try decoder.decodeSingularBoolField(value: &self._compressVectorizedPirResponse) }() + case 6: try { try decoder.decodeSingularUInt64Field(value: &self._vectorizedPirInternalBatchingSize) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every if/case branch local when no optimizations + // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and + // https://github.com/apple/swift-protobuf/issues/1182 + if self.numEntries != 0 { + try visitor.visitSingularUInt64Field(value: self.numEntries, fieldNumber: 1) + } + if self.entrySize != 0 { + try visitor.visitSingularUInt64Field(value: self.entrySize, fieldNumber: 2) + } + if !self.dimensions.isEmpty { + try visitor.visitPackedUInt64Field(value: self.dimensions, fieldNumber: 3) + } + try { if let v = self._shardID { + try visitor.visitSingularStringField(value: v, fieldNumber: 4) + } }() + try { if let v = self._compressVectorizedPirResponse { + try visitor.visitSingularBoolField(value: v, fieldNumber: 5) + } }() + try { if let v = self._vectorizedPirInternalBatchingSize { + try visitor.visitSingularUInt64Field(value: v, fieldNumber: 6) + } }() + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Apple_SwiftHomomorphicEncryption_Api_V1_PIRShardConfig, rhs: Apple_SwiftHomomorphicEncryption_Api_V1_PIRShardConfig) -> Bool { + if lhs.numEntries != rhs.numEntries {return false} + if lhs.entrySize != rhs.entrySize {return false} + if lhs.dimensions != rhs.dimensions {return false} + if lhs._shardID != rhs._shardID {return false} + if lhs._compressVectorizedPirResponse != rhs._compressVectorizedPirResponse {return false} + if lhs._vectorizedPirInternalBatchingSize != rhs._vectorizedPirInternalBatchingSize {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Apple_SwiftHomomorphicEncryption_Api_V1_PIRConfig: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".PIRConfig" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .standard(proto: "encryption_parameters"), + 2: .standard(proto: "shard_configs"), + 3: .standard(proto: "keyword_pir_params"), + 4: .same(proto: "algorithm"), + 5: .standard(proto: "batch_size"), + 6: .standard(proto: "evaluation_key_config_hash"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularMessageField(value: &self._encryptionParameters) }() + case 2: try { try decoder.decodeRepeatedMessageField(value: &self.shardConfigs) }() + case 3: try { try decoder.decodeSingularMessageField(value: &self._keywordPirParams) }() + case 4: try { try decoder.decodeSingularEnumField(value: &self.algorithm) }() + case 5: try { try decoder.decodeSingularUInt64Field(value: &self.batchSize) }() + case 6: try { try decoder.decodeSingularBytesField(value: &self.evaluationKeyConfigHash) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every if/case branch local when no optimizations + // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and + // https://github.com/apple/swift-protobuf/issues/1182 + try { if let v = self._encryptionParameters { + try visitor.visitSingularMessageField(value: v, fieldNumber: 1) + } }() + if !self.shardConfigs.isEmpty { + try visitor.visitRepeatedMessageField(value: self.shardConfigs, fieldNumber: 2) + } + try { if let v = self._keywordPirParams { + try visitor.visitSingularMessageField(value: v, fieldNumber: 3) + } }() + if self.algorithm != .aclsPir { + try visitor.visitSingularEnumField(value: self.algorithm, fieldNumber: 4) + } + if self.batchSize != 0 { + try visitor.visitSingularUInt64Field(value: self.batchSize, fieldNumber: 5) + } + if !self.evaluationKeyConfigHash.isEmpty { + try visitor.visitSingularBytesField(value: self.evaluationKeyConfigHash, fieldNumber: 6) + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Apple_SwiftHomomorphicEncryption_Api_V1_PIRConfig, rhs: Apple_SwiftHomomorphicEncryption_Api_V1_PIRConfig) -> Bool { + if lhs._encryptionParameters != rhs._encryptionParameters {return false} + if lhs.shardConfigs != rhs.shardConfigs {return false} + if lhs._keywordPirParams != rhs._keywordPirParams {return false} + if lhs.algorithm != rhs.algorithm {return false} + if lhs.batchSize != rhs.batchSize {return false} + if lhs.evaluationKeyConfigHash != rhs.evaluationKeyConfigHash {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Apple_SwiftHomomorphicEncryption_Api_V1_PIRRequest: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".PIRRequest" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .standard(proto: "shard_index"), + 2: .same(proto: "query"), + 3: .standard(proto: "evaluation_key_metadata"), + 4: .standard(proto: "configuration_hash"), + 5: .standard(proto: "shard_id"), + 6: .standard(proto: "evaluation_key"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularUInt32Field(value: &self.shardIndex) }() + case 2: try { try decoder.decodeSingularMessageField(value: &self._query) }() + case 3: try { try decoder.decodeSingularMessageField(value: &self._evaluationKeyMetadata) }() + case 4: try { try decoder.decodeSingularBytesField(value: &self.configurationHash) }() + case 5: try { try decoder.decodeSingularStringField(value: &self._shardID) }() + case 6: try { try decoder.decodeSingularMessageField(value: &self._evaluationKey) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every if/case branch local when no optimizations + // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and + // https://github.com/apple/swift-protobuf/issues/1182 + if self.shardIndex != 0 { + try visitor.visitSingularUInt32Field(value: self.shardIndex, fieldNumber: 1) + } + try { if let v = self._query { + try visitor.visitSingularMessageField(value: v, fieldNumber: 2) + } }() + try { if let v = self._evaluationKeyMetadata { + try visitor.visitSingularMessageField(value: v, fieldNumber: 3) + } }() + if !self.configurationHash.isEmpty { + try visitor.visitSingularBytesField(value: self.configurationHash, fieldNumber: 4) + } + try { if let v = self._shardID { + try visitor.visitSingularStringField(value: v, fieldNumber: 5) + } }() + try { if let v = self._evaluationKey { + try visitor.visitSingularMessageField(value: v, fieldNumber: 6) + } }() + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Apple_SwiftHomomorphicEncryption_Api_V1_PIRRequest, rhs: Apple_SwiftHomomorphicEncryption_Api_V1_PIRRequest) -> Bool { + if lhs.shardIndex != rhs.shardIndex {return false} + if lhs._query != rhs._query {return false} + if lhs._evaluationKeyMetadata != rhs._evaluationKeyMetadata {return false} + if lhs.configurationHash != rhs.configurationHash {return false} + if lhs._shardID != rhs._shardID {return false} + if lhs._evaluationKey != rhs._evaluationKey {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Apple_SwiftHomomorphicEncryption_Api_V1_PIRResponse: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".PIRResponse" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "replies"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeRepeatedMessageField(value: &self.replies) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + if !self.replies.isEmpty { + try visitor.visitRepeatedMessageField(value: self.replies, fieldNumber: 1) + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Apple_SwiftHomomorphicEncryption_Api_V1_PIRResponse, rhs: Apple_SwiftHomomorphicEncryption_Api_V1_PIRResponse) -> Bool { + if lhs.replies != rhs.replies {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} diff --git a/Sources/PrivateNearestNeighborsSearch/PnnsProtocol.swift b/Sources/PrivateNearestNeighborsSearch/PnnsProtocol.swift index f2d9d1af..fc4a54f4 100644 --- a/Sources/PrivateNearestNeighborsSearch/PnnsProtocol.swift +++ b/Sources/PrivateNearestNeighborsSearch/PnnsProtocol.swift @@ -15,19 +15,34 @@ import HomomorphicEncryption /// A nearest neighbor search query. -struct Query: Sendable { +public struct Query: Sendable { // Encrypted query; one matrix per plaintext CRT modulus - let ciphertextMatrices: [CiphertextMatrix] + public let ciphertextMatrices: [CiphertextMatrix] } /// A nearest neighbor search response. -struct Response: Sendable { +public struct Response: Sendable { // Encrypted response; one matrix per plaintext CRT modulus - let ciphertextMatrices: [CiphertextMatrix] - // A list of entry identifiers the server computed similarities for - let entryIds: [UInt64] - // Metadata for each entry in the database - let entryMetadatas: [[UInt8]] + public let ciphertextMatrices: [CiphertextMatrix] + // The entry identifiers the server computed distances for. + public let entryIds: [UInt64] + // Metadata for each entry the server computed distances for. + public let entryMetadatas: [[UInt8]] + + /// Creates a new ``Response``. + /// - Parameters: + /// - ciphertextMatrices: Ciphertext matrices. + /// - entryIds: An identifiers the server computed distances for. + /// - entryMetadatas: Metadata for each entry the server computed distances for. + public init( + ciphertextMatrices: [CiphertextMatrix], + entryIds: [UInt64], + entryMetadatas: [[UInt8]]) + { + self.ciphertextMatrices = ciphertextMatrices + self.entryIds = entryIds + self.entryMetadatas = entryMetadatas + } } /// Distances from one or more query vector to the database rows. diff --git a/Sources/PrivateNearestNeighborsSearchProtobuf/ConversionApi.swift b/Sources/PrivateNearestNeighborsSearchProtobuf/ConversionApi.swift new file mode 100644 index 00000000..cf1500b0 --- /dev/null +++ b/Sources/PrivateNearestNeighborsSearchProtobuf/ConversionApi.swift @@ -0,0 +1,51 @@ +// Copyright 2024 Apple Inc. and the Swift Homomorphic Encryption project authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import Foundation + +import HomomorphicEncryption +import HomomorphicEncryptionProtobuf +import PrivateNearestNeighborsSearch + +extension Apple_SwiftHomomorphicEncryption_Api_V1_PNNSShardResponse { + /// Converts the protobuf object to a native type. + /// - Parameter context: Context to associate with the native type. + /// - Returns: The converted native type. + /// - Throws: Error upon invalid protobuf object. + public func native(context: Context) throws -> Response { + let matrices: [CiphertextMatrix] = try reply.map { matrix in + let serialized: SerializedCiphertextMatrix = try matrix.native() + return try CiphertextMatrix(deserialize: serialized, context: context, moduliCount: 1) + } + return Response( + ciphertextMatrices: matrices, + entryIds: entryIds, + entryMetadatas: entryMetadatas.map { metadata in Array(metadata) }) + } +} + +extension Response { + /// Converts the native object into a protobuf object. + /// - Returns: The converted protobuf object. + /// - Throws: Error upon unsupported object. + public func proto() throws -> Apple_SwiftHomomorphicEncryption_Api_V1_PNNSShardResponse { + try Apple_SwiftHomomorphicEncryption_Api_V1_PNNSShardResponse.with { pnnsResponse in + pnnsResponse.reply = try ciphertextMatrices.map { matrix in + try matrix.serialize(forDecryption: true).proto() + } + pnnsResponse.entryIds = entryIds + pnnsResponse.entryMetadatas = entryMetadatas.map { bytes in Data(bytes) } + } + } +} diff --git a/Sources/PrivateNearestNeighborsSearchProtobuf/ConversionPnns.swift b/Sources/PrivateNearestNeighborsSearchProtobuf/ConversionPnns.swift index e9c7c1c4..b8f1f57d 100644 --- a/Sources/PrivateNearestNeighborsSearchProtobuf/ConversionPnns.swift +++ b/Sources/PrivateNearestNeighborsSearchProtobuf/ConversionPnns.swift @@ -302,3 +302,12 @@ extension SerializedProcessedDatabase { } } } + +extension Query { + /// Converts the native object into a protobuf object. + /// - Returns: The converted protobuf object. + /// - Throws: Error upon unsupported object. + public func proto() throws -> [Apple_SwiftHomomorphicEncryption_Pnns_V1_SerializedCiphertextMatrix] { + try ciphertextMatrices.map { matrix in try matrix.serialize().proto() } + } +} diff --git a/Sources/PrivateNearestNeighborsSearchProtobuf/generated/apple_swift_homomorphic_encryption_api_v1_api_evaluation_key.pb.swift b/Sources/PrivateNearestNeighborsSearchProtobuf/generated/apple_swift_homomorphic_encryption_api_v1_api_evaluation_key.pb.swift new file mode 100644 index 00000000..63d88421 --- /dev/null +++ b/Sources/PrivateNearestNeighborsSearchProtobuf/generated/apple_swift_homomorphic_encryption_api_v1_api_evaluation_key.pb.swift @@ -0,0 +1,286 @@ +// DO NOT EDIT. +// swift-format-ignore-file +// +// Generated by the Swift generator plugin for the protocol buffer compiler. +// Source: apple/swift_homomorphic_encryption/api/v1/api_evaluation_key.proto +// +// For information on using the generated types, please see the documentation: +// https://github.com/apple/swift-protobuf/ + +// Copyright 2024 Apple Inc. and the Swift Homomorphic Encryption project authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import Foundation +import SwiftProtobuf + +import HomomorphicEncryptionProtobuf + +// If the compiler emits an error on this type, it is because this file +// was generated by a version of the `protoc` Swift plug-in that is +// incompatible with the version of SwiftProtobuf to which you are linking. +// Please ensure that you are building against the same version of the API +// that was used to generate this file. +fileprivate struct _GeneratedWithProtocGenSwiftVersion: SwiftProtobuf.ProtobufAPIVersionCheck { + struct _2: SwiftProtobuf.ProtobufAPIVersion_2 {} + typealias Version = _2 +} + +/// Evaluation key metadata. +public struct Apple_SwiftHomomorphicEncryption_Api_V1_EvaluationKeyMetadata: @unchecked Sendable { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + /// Timestamp of the (secret) key generation, seconds from Unix epoch. + public var timestamp: UInt64 = 0 + + /// Key identifier (SHA256 of `EvaluationKeyConfig`). + public var identifier: Data = Data() + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} +} + +/// Status of the evaluation key. +public struct Apple_SwiftHomomorphicEncryption_Api_V1_KeyStatus: Sendable { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + /// When was this key last updated (seconds from Unix epoch), 0 when key is missing. + public var timestamp: UInt64 = 0 + + /// Configuration for the key. + public var keyConfig: HomomorphicEncryptionProtobuf.Apple_SwiftHomomorphicEncryption_V1_EvaluationKeyConfig { + get {return _keyConfig ?? HomomorphicEncryptionProtobuf.Apple_SwiftHomomorphicEncryption_V1_EvaluationKeyConfig()} + set {_keyConfig = newValue} + } + /// Returns true if `keyConfig` has been explicitly set. + public var hasKeyConfig: Bool {return self._keyConfig != nil} + /// Clears the value of `keyConfig`. Subsequent reads from it will return its default value. + public mutating func clearKeyConfig() {self._keyConfig = nil} + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} + + fileprivate var _keyConfig: HomomorphicEncryptionProtobuf.Apple_SwiftHomomorphicEncryption_V1_EvaluationKeyConfig? = nil +} + +/// Container for multiple evaluation keys. +public struct Apple_SwiftHomomorphicEncryption_Api_V1_EvaluationKeys: Sendable { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + /// Evaluation keys. + public var keys: [Apple_SwiftHomomorphicEncryption_Api_V1_EvaluationKey] = [] + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} +} + +/// Evaluation key upload. +public struct Apple_SwiftHomomorphicEncryption_Api_V1_EvaluationKey: Sendable { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + /// Metadata for the key. + public var metadata: Apple_SwiftHomomorphicEncryption_Api_V1_EvaluationKeyMetadata { + get {return _metadata ?? Apple_SwiftHomomorphicEncryption_Api_V1_EvaluationKeyMetadata()} + set {_metadata = newValue} + } + /// Returns true if `metadata` has been explicitly set. + public var hasMetadata: Bool {return self._metadata != nil} + /// Clears the value of `metadata`. Subsequent reads from it will return its default value. + public mutating func clearMetadata() {self._metadata = nil} + + /// Evaluation key. + public var evaluationKey: HomomorphicEncryptionProtobuf.Apple_SwiftHomomorphicEncryption_V1_SerializedEvaluationKey { + get {return _evaluationKey ?? HomomorphicEncryptionProtobuf.Apple_SwiftHomomorphicEncryption_V1_SerializedEvaluationKey()} + set {_evaluationKey = newValue} + } + /// Returns true if `evaluationKey` has been explicitly set. + public var hasEvaluationKey: Bool {return self._evaluationKey != nil} + /// Clears the value of `evaluationKey`. Subsequent reads from it will return its default value. + public mutating func clearEvaluationKey() {self._evaluationKey = nil} + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} + + fileprivate var _metadata: Apple_SwiftHomomorphicEncryption_Api_V1_EvaluationKeyMetadata? = nil + fileprivate var _evaluationKey: HomomorphicEncryptionProtobuf.Apple_SwiftHomomorphicEncryption_V1_SerializedEvaluationKey? = nil +} + +// MARK: - Code below here is support for the SwiftProtobuf runtime. + +fileprivate let _protobuf_package = "apple.swift_homomorphic_encryption.api.v1" + +extension Apple_SwiftHomomorphicEncryption_Api_V1_EvaluationKeyMetadata: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".EvaluationKeyMetadata" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "timestamp"), + 2: .same(proto: "identifier"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularUInt64Field(value: &self.timestamp) }() + case 2: try { try decoder.decodeSingularBytesField(value: &self.identifier) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + if self.timestamp != 0 { + try visitor.visitSingularUInt64Field(value: self.timestamp, fieldNumber: 1) + } + if !self.identifier.isEmpty { + try visitor.visitSingularBytesField(value: self.identifier, fieldNumber: 2) + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Apple_SwiftHomomorphicEncryption_Api_V1_EvaluationKeyMetadata, rhs: Apple_SwiftHomomorphicEncryption_Api_V1_EvaluationKeyMetadata) -> Bool { + if lhs.timestamp != rhs.timestamp {return false} + if lhs.identifier != rhs.identifier {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Apple_SwiftHomomorphicEncryption_Api_V1_KeyStatus: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".KeyStatus" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "timestamp"), + 2: .standard(proto: "key_config"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularUInt64Field(value: &self.timestamp) }() + case 2: try { try decoder.decodeSingularMessageField(value: &self._keyConfig) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every if/case branch local when no optimizations + // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and + // https://github.com/apple/swift-protobuf/issues/1182 + if self.timestamp != 0 { + try visitor.visitSingularUInt64Field(value: self.timestamp, fieldNumber: 1) + } + try { if let v = self._keyConfig { + try visitor.visitSingularMessageField(value: v, fieldNumber: 2) + } }() + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Apple_SwiftHomomorphicEncryption_Api_V1_KeyStatus, rhs: Apple_SwiftHomomorphicEncryption_Api_V1_KeyStatus) -> Bool { + if lhs.timestamp != rhs.timestamp {return false} + if lhs._keyConfig != rhs._keyConfig {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Apple_SwiftHomomorphicEncryption_Api_V1_EvaluationKeys: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".EvaluationKeys" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "keys"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeRepeatedMessageField(value: &self.keys) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + if !self.keys.isEmpty { + try visitor.visitRepeatedMessageField(value: self.keys, fieldNumber: 1) + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Apple_SwiftHomomorphicEncryption_Api_V1_EvaluationKeys, rhs: Apple_SwiftHomomorphicEncryption_Api_V1_EvaluationKeys) -> Bool { + if lhs.keys != rhs.keys {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Apple_SwiftHomomorphicEncryption_Api_V1_EvaluationKey: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".EvaluationKey" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "metadata"), + 2: .standard(proto: "evaluation_key"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularMessageField(value: &self._metadata) }() + case 2: try { try decoder.decodeSingularMessageField(value: &self._evaluationKey) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every if/case branch local when no optimizations + // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and + // https://github.com/apple/swift-protobuf/issues/1182 + try { if let v = self._metadata { + try visitor.visitSingularMessageField(value: v, fieldNumber: 1) + } }() + try { if let v = self._evaluationKey { + try visitor.visitSingularMessageField(value: v, fieldNumber: 2) + } }() + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Apple_SwiftHomomorphicEncryption_Api_V1_EvaluationKey, rhs: Apple_SwiftHomomorphicEncryption_Api_V1_EvaluationKey) -> Bool { + if lhs._metadata != rhs._metadata {return false} + if lhs._evaluationKey != rhs._evaluationKey {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} diff --git a/Sources/PrivateNearestNeighborsSearchProtobuf/generated/apple_swift_homomorphic_encryption_api_v1_api_pnns.pb.swift b/Sources/PrivateNearestNeighborsSearchProtobuf/generated/apple_swift_homomorphic_encryption_api_v1_api_pnns.pb.swift new file mode 100644 index 00000000..b2c88a82 --- /dev/null +++ b/Sources/PrivateNearestNeighborsSearchProtobuf/generated/apple_swift_homomorphic_encryption_api_v1_api_pnns.pb.swift @@ -0,0 +1,376 @@ +// DO NOT EDIT. +// swift-format-ignore-file +// +// Generated by the Swift generator plugin for the protocol buffer compiler. +// Source: apple/swift_homomorphic_encryption/api/v1/api_pnns.proto +// +// For information on using the generated types, please see the documentation: +// https://github.com/apple/swift-protobuf/ + +// Copyright 2024 Apple Inc. and the Swift Homomorphic Encryption project authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import Foundation +import SwiftProtobuf + +import HomomorphicEncryptionProtobuf + +// If the compiler emits an error on this type, it is because this file +// was generated by a version of the `protoc` Swift plug-in that is +// incompatible with the version of SwiftProtobuf to which you are linking. +// Please ensure that you are building against the same version of the API +// that was used to generate this file. +fileprivate struct _GeneratedWithProtocGenSwiftVersion: SwiftProtobuf.ProtobufAPIVersionCheck { + struct _2: SwiftProtobuf.ProtobufAPIVersion_2 {} + typealias Version = _2 +} + +/// Configuration for one PNNS usecase. +public struct Apple_SwiftHomomorphicEncryption_Api_V1_PNNSConfig: @unchecked Sendable { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + /// Encryption parameters. + public var encryptionParameters: HomomorphicEncryptionProtobuf.Apple_SwiftHomomorphicEncryption_V1_EncryptionParameters { + get {return _encryptionParameters ?? HomomorphicEncryptionProtobuf.Apple_SwiftHomomorphicEncryption_V1_EncryptionParameters()} + set {_encryptionParameters = newValue} + } + /// Returns true if `encryptionParameters` has been explicitly set. + public var hasEncryptionParameters: Bool {return self._encryptionParameters != nil} + /// Clears the value of `encryptionParameters`. Subsequent reads from it will return its default value. + public mutating func clearEncryptionParameters() {self._encryptionParameters = nil} + + /// Factor by which to scale floating-point entries to integers. + public var scalingFactor: UInt64 = 0 + + /// Plaintext packing for the query. + public var plaintextPacking: Apple_SwiftHomomorphicEncryption_Pnns_V1_MatrixPacking { + get {return _plaintextPacking ?? Apple_SwiftHomomorphicEncryption_Pnns_V1_MatrixPacking()} + set {_plaintextPacking = newValue} + } + /// Returns true if `plaintextPacking` has been explicitly set. + public var hasPlaintextPacking: Bool {return self._plaintextPacking != nil} + /// Clears the value of `plaintextPacking`. Subsequent reads from it will return its default value. + public mutating func clearPlaintextPacking() {self._plaintextPacking = nil} + + /// Number of entries in each vector. + public var vectorDimension: UInt32 = 0 + + /// Metric for similarity computation. + public var distanceMetric: Apple_SwiftHomomorphicEncryption_Pnns_V1_DistanceMetric = .cosineSimilarity + + /// hash of EvaluationKeyConfig. + public var evaluationKeyConfigHash: Data = Data() + + /// For plaintext CRT, the list of extra plaintext moduli. + /// The first plaintext modulus will be the one in `encryption_parameters`. + public var extraPlaintextModuli: [UInt64] = [] + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} + + fileprivate var _encryptionParameters: HomomorphicEncryptionProtobuf.Apple_SwiftHomomorphicEncryption_V1_EncryptionParameters? = nil + fileprivate var _plaintextPacking: Apple_SwiftHomomorphicEncryption_Pnns_V1_MatrixPacking? = nil +} + +/// PNNS Request +public struct Apple_SwiftHomomorphicEncryption_Api_V1_PNNSRequest: @unchecked Sendable { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + /// optionally, the shard indices where this request should be routed + public var shardIndices: [UInt32] = [] + + /// Encrypted query, one per plaintext CRT component + public var query: [Apple_SwiftHomomorphicEncryption_Pnns_V1_SerializedCiphertextMatrix] = [] + + /// Key metadata + public var evaluationKeyMetadata: Apple_SwiftHomomorphicEncryption_Api_V1_EvaluationKeyMetadata { + get {return _evaluationKeyMetadata ?? Apple_SwiftHomomorphicEncryption_Api_V1_EvaluationKeyMetadata()} + set {_evaluationKeyMetadata = newValue} + } + /// Returns true if `evaluationKeyMetadata` has been explicitly set. + public var hasEvaluationKeyMetadata: Bool {return self._evaluationKeyMetadata != nil} + /// Clears the value of `evaluationKeyMetadata`. Subsequent reads from it will return its default value. + public mutating func clearEvaluationKeyMetadata() {self._evaluationKeyMetadata = nil} + + /// Identifier for the PNNSConfig used to construct the query + public var configID: Data = Data() + + /// If set, evaluation key to query with. Will override evaluation key stored server-side + public var evaluationKey: Apple_SwiftHomomorphicEncryption_Api_V1_EvaluationKey { + get {return _evaluationKey ?? Apple_SwiftHomomorphicEncryption_Api_V1_EvaluationKey()} + set {_evaluationKey = newValue} + } + /// Returns true if `evaluationKey` has been explicitly set. + public var hasEvaluationKey: Bool {return self._evaluationKey != nil} + /// Clears the value of `evaluationKey`. Subsequent reads from it will return its default value. + public mutating func clearEvaluationKey() {self._evaluationKey = nil} + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} + + fileprivate var _evaluationKeyMetadata: Apple_SwiftHomomorphicEncryption_Api_V1_EvaluationKeyMetadata? = nil + fileprivate var _evaluationKey: Apple_SwiftHomomorphicEncryption_Api_V1_EvaluationKey? = nil +} + +/// PNNS Shard Response +public struct Apple_SwiftHomomorphicEncryption_Api_V1_PNNSShardResponse: @unchecked Sendable { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + /// Encrypted reply, one per plaintext CRT component + public var reply: [Apple_SwiftHomomorphicEncryption_Pnns_V1_SerializedCiphertextMatrix] = [] + + /// A list of entry identifiers the server computed similarities for + public var entryIds: [UInt64] = [] + + /// Metadata for each entry in the database + public var entryMetadatas: [Data] = [] + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} +} + +/// PNNS Response +public struct Apple_SwiftHomomorphicEncryption_Api_V1_PNNSResponse: Sendable { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + /// PNNS responses from shards + public var shardResponses: [Apple_SwiftHomomorphicEncryption_Api_V1_PNNSShardResponse] = [] + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} +} + +// MARK: - Code below here is support for the SwiftProtobuf runtime. + +fileprivate let _protobuf_package = "apple.swift_homomorphic_encryption.api.v1" + +extension Apple_SwiftHomomorphicEncryption_Api_V1_PNNSConfig: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".PNNSConfig" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .standard(proto: "encryption_parameters"), + 2: .standard(proto: "scaling_factor"), + 3: .standard(proto: "plaintext_packing"), + 4: .standard(proto: "vector_dimension"), + 5: .standard(proto: "distance_metric"), + 6: .standard(proto: "evaluation_key_config_hash"), + 7: .standard(proto: "extra_plaintext_moduli"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularMessageField(value: &self._encryptionParameters) }() + case 2: try { try decoder.decodeSingularUInt64Field(value: &self.scalingFactor) }() + case 3: try { try decoder.decodeSingularMessageField(value: &self._plaintextPacking) }() + case 4: try { try decoder.decodeSingularUInt32Field(value: &self.vectorDimension) }() + case 5: try { try decoder.decodeSingularEnumField(value: &self.distanceMetric) }() + case 6: try { try decoder.decodeSingularBytesField(value: &self.evaluationKeyConfigHash) }() + case 7: try { try decoder.decodeRepeatedUInt64Field(value: &self.extraPlaintextModuli) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every if/case branch local when no optimizations + // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and + // https://github.com/apple/swift-protobuf/issues/1182 + try { if let v = self._encryptionParameters { + try visitor.visitSingularMessageField(value: v, fieldNumber: 1) + } }() + if self.scalingFactor != 0 { + try visitor.visitSingularUInt64Field(value: self.scalingFactor, fieldNumber: 2) + } + try { if let v = self._plaintextPacking { + try visitor.visitSingularMessageField(value: v, fieldNumber: 3) + } }() + if self.vectorDimension != 0 { + try visitor.visitSingularUInt32Field(value: self.vectorDimension, fieldNumber: 4) + } + if self.distanceMetric != .cosineSimilarity { + try visitor.visitSingularEnumField(value: self.distanceMetric, fieldNumber: 5) + } + if !self.evaluationKeyConfigHash.isEmpty { + try visitor.visitSingularBytesField(value: self.evaluationKeyConfigHash, fieldNumber: 6) + } + if !self.extraPlaintextModuli.isEmpty { + try visitor.visitPackedUInt64Field(value: self.extraPlaintextModuli, fieldNumber: 7) + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Apple_SwiftHomomorphicEncryption_Api_V1_PNNSConfig, rhs: Apple_SwiftHomomorphicEncryption_Api_V1_PNNSConfig) -> Bool { + if lhs._encryptionParameters != rhs._encryptionParameters {return false} + if lhs.scalingFactor != rhs.scalingFactor {return false} + if lhs._plaintextPacking != rhs._plaintextPacking {return false} + if lhs.vectorDimension != rhs.vectorDimension {return false} + if lhs.distanceMetric != rhs.distanceMetric {return false} + if lhs.evaluationKeyConfigHash != rhs.evaluationKeyConfigHash {return false} + if lhs.extraPlaintextModuli != rhs.extraPlaintextModuli {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Apple_SwiftHomomorphicEncryption_Api_V1_PNNSRequest: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".PNNSRequest" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .standard(proto: "shard_indices"), + 2: .same(proto: "query"), + 3: .standard(proto: "evaluation_key_metadata"), + 4: .standard(proto: "config_id"), + 5: .standard(proto: "evaluation_key"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeRepeatedUInt32Field(value: &self.shardIndices) }() + case 2: try { try decoder.decodeRepeatedMessageField(value: &self.query) }() + case 3: try { try decoder.decodeSingularMessageField(value: &self._evaluationKeyMetadata) }() + case 4: try { try decoder.decodeSingularBytesField(value: &self.configID) }() + case 5: try { try decoder.decodeSingularMessageField(value: &self._evaluationKey) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every if/case branch local when no optimizations + // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and + // https://github.com/apple/swift-protobuf/issues/1182 + if !self.shardIndices.isEmpty { + try visitor.visitPackedUInt32Field(value: self.shardIndices, fieldNumber: 1) + } + if !self.query.isEmpty { + try visitor.visitRepeatedMessageField(value: self.query, fieldNumber: 2) + } + try { if let v = self._evaluationKeyMetadata { + try visitor.visitSingularMessageField(value: v, fieldNumber: 3) + } }() + if !self.configID.isEmpty { + try visitor.visitSingularBytesField(value: self.configID, fieldNumber: 4) + } + try { if let v = self._evaluationKey { + try visitor.visitSingularMessageField(value: v, fieldNumber: 5) + } }() + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Apple_SwiftHomomorphicEncryption_Api_V1_PNNSRequest, rhs: Apple_SwiftHomomorphicEncryption_Api_V1_PNNSRequest) -> Bool { + if lhs.shardIndices != rhs.shardIndices {return false} + if lhs.query != rhs.query {return false} + if lhs._evaluationKeyMetadata != rhs._evaluationKeyMetadata {return false} + if lhs.configID != rhs.configID {return false} + if lhs._evaluationKey != rhs._evaluationKey {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Apple_SwiftHomomorphicEncryption_Api_V1_PNNSShardResponse: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".PNNSShardResponse" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "reply"), + 2: .standard(proto: "entry_ids"), + 3: .standard(proto: "entry_metadatas"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeRepeatedMessageField(value: &self.reply) }() + case 2: try { try decoder.decodeRepeatedUInt64Field(value: &self.entryIds) }() + case 3: try { try decoder.decodeRepeatedBytesField(value: &self.entryMetadatas) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + if !self.reply.isEmpty { + try visitor.visitRepeatedMessageField(value: self.reply, fieldNumber: 1) + } + if !self.entryIds.isEmpty { + try visitor.visitPackedUInt64Field(value: self.entryIds, fieldNumber: 2) + } + if !self.entryMetadatas.isEmpty { + try visitor.visitRepeatedBytesField(value: self.entryMetadatas, fieldNumber: 3) + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Apple_SwiftHomomorphicEncryption_Api_V1_PNNSShardResponse, rhs: Apple_SwiftHomomorphicEncryption_Api_V1_PNNSShardResponse) -> Bool { + if lhs.reply != rhs.reply {return false} + if lhs.entryIds != rhs.entryIds {return false} + if lhs.entryMetadatas != rhs.entryMetadatas {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Apple_SwiftHomomorphicEncryption_Api_V1_PNNSResponse: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".PNNSResponse" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .standard(proto: "shard_responses"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeRepeatedMessageField(value: &self.shardResponses) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + if !self.shardResponses.isEmpty { + try visitor.visitRepeatedMessageField(value: self.shardResponses, fieldNumber: 1) + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Apple_SwiftHomomorphicEncryption_Api_V1_PNNSResponse, rhs: Apple_SwiftHomomorphicEncryption_Api_V1_PNNSResponse) -> Bool { + if lhs.shardResponses != rhs.shardResponses {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} diff --git a/Utilities/generate-protobuf-files.sh b/Utilities/generate-protobuf-files.sh index ecbbaac7..e1421120 100755 --- a/Utilities/generate-protobuf-files.sh +++ b/Utilities/generate-protobuf-files.sh @@ -13,7 +13,11 @@ find apple/swift_homomorphic_encryption/v1/ -name "*.proto" -exec protoc --swift echo "Removing PrivateInformationRetrievalProtobuf swift protobuf files" rm ../Sources/PrivateInformationRetrievalProtobuf/generated/*.pb.swift echo "Regenerating PrivateInformationRetrievalProtobuf swift protobuf files" -find apple/swift_homomorphic_encryption/pir/ apple/swift_homomorphic_encryption/api/ -name "*.proto" -exec protoc \ +find apple/swift_homomorphic_encryption/pir/ \ + apple/swift_homomorphic_encryption/api/v1/api.proto \ + apple/swift_homomorphic_encryption/api/v1/api_pir.proto \ + apple/swift_homomorphic_encryption/api/v1/api_evaluation_key.proto \ + -name "*.proto" -exec protoc \ --swift_opt=ProtoPathModuleMappings=../Sources/PrivateInformationRetrievalProtobuf/protobuf_module_mappings.txtpb \ --swift_opt=Visibility=Public \ --swift_opt=FileNaming=PathToUnderscores \ @@ -22,7 +26,10 @@ find apple/swift_homomorphic_encryption/pir/ apple/swift_homomorphic_encryption/ echo "Removing PrivateNearestNeighborsSearchProtobuf swift protobuf files" rm ../Sources/PrivateNearestNeighborsSearchProtobuf/generated/*.pb.swift echo "Regenerating PrivateNearestNeighborsSearchProtobuf swift protobuf files" -find apple/swift_homomorphic_encryption/pnns/ -name "*.proto" -exec protoc \ +find apple/swift_homomorphic_encryption/pnns/ \ + apple/swift_homomorphic_encryption/api/v1/api_pnns.proto \ + apple/swift_homomorphic_encryption/api/v1/api_evaluation_key.proto \ + -name "*.proto" -exec protoc \ --swift_opt=ProtoPathModuleMappings=../Sources/PrivateNearestNeighborsSearchProtobuf/protobuf_module_mappings.txtpb \ --swift_opt=Visibility=Public \ --swift_opt=FileNaming=PathToUnderscores \ diff --git a/swift-homomorphic-encryption-protobuf b/swift-homomorphic-encryption-protobuf index 9961dae8..99f53532 160000 --- a/swift-homomorphic-encryption-protobuf +++ b/swift-homomorphic-encryption-protobuf @@ -1 +1 @@ -Subproject commit 9961dae813dab98131e0d91f60aac4818460764e +Subproject commit 99f53532ab7ee4b22720dd4bdbef0b1a564435ac