Skip to content

Commit b9884cb

Browse files
authored
Update to swiftlint 0.59.1 & SwiftFormat 0.56.4 (#223)
1 parent 70cd3cc commit b9884cb

File tree

7 files changed

+122
-122
lines changed

7 files changed

+122
-122
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ concurrency:
1414
cancel-in-progress: true
1515
# Keep versions in sync with README
1616
env:
17-
SWIFTLINT_VERSION: 0.58.2
18-
SWIFTFORMAT_VERSION: 0.55.5
17+
SWIFTLINT_VERSION: 0.59.1
18+
SWIFTFORMAT_VERSION: 0.56.4
1919
SWIFT_HOMOMORPHIC_ENCRYPTION_ENABLE_BENCHMARKING: 1
2020
jobs:
2121
soundness:

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,11 @@ We'd like this package to quickly embrace Swift language and toolchain improveme
153153
## Developing Swift Homomorphic Encryption
154154
### Dependencies
155155
Developing Swift Homomorphic Encryption requires:
156-
* [Nick Lockwood SwiftFormat](https://github.com/nicklockwood/SwiftFormat), 0.55.5
156+
* [Nick Lockwood SwiftFormat](https://github.com/nicklockwood/SwiftFormat), 0.56.4
157157
* [pre-commit](https://pre-commit.com)
158158
* [swift-format](https://github.com/swiftlang/swift-format), 600.0.0
159159
* [swift-protobuf](https://github.com/apple/swift-protobuf), 1.29.0
160-
* [SwiftLint](https://github.com/realm/SwiftLint), 0.58.2
160+
* [SwiftLint](https://github.com/realm/SwiftLint), 0.59.1
161161

162162
### Building
163163
You can build Swift Homomorphic Encryption either via Xcode or via command line in a terminal.

Snippets/HomomorphicEncryption/SerializationSnippet.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ extension SerializedCiphertext {
2828
/// from the size.
2929
func size() throws -> Int {
3030
let data = try proto().serializedData()
31-
return data.filter { byte in byte != 0 }.count
31+
return data.count { byte in byte != 0 }
3232
}
3333
}
3434

Sources/PrivateInformationRetrieval/HashBucket.swift

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2024 Apple Inc. and the Swift Homomorphic Encryption project authors
1+
// Copyright 2024-2025 Apple Inc. and the Swift Homomorphic Encryption project authors
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -24,17 +24,17 @@ public struct HashBucket: Equatable {
2424
/// One entry in the HashBucket.
2525
@usableFromInline
2626
struct HashBucketEntry: Equatable {
27-
/// Hash of the keyword.
28-
@usableFromInline let keywordHash: KeywordHash
29-
/// Value.
30-
@usableFromInline let value: HashBucketValue
31-
3227
/// Maximum size of the value.
3328
@usableFromInline static var maxValueSize: Int {
3429
// Constrained by serialization.
3530
Int(UInt16.max)
3631
}
3732

33+
/// Hash of the keyword.
34+
@usableFromInline let keywordHash: KeywordHash
35+
/// Value.
36+
@usableFromInline let value: HashBucketValue
37+
3838
@inlinable
3939
init(keywordHash: KeywordHash, value: HashBucketValue) {
4040
self.keywordHash = keywordHash
@@ -71,6 +71,20 @@ public struct HashBucket: Equatable {
7171
self.value = value
7272
}
7373

74+
/// Returns the number of bytes in a serialized ``HashBucket`` with `value`.
75+
@inlinable
76+
static func serializedSize(value: HashBucketValue) -> Int {
77+
serializedSize(valueSize: value.count)
78+
}
79+
80+
@inlinable
81+
static func serializedSize(valueSize: Int) -> Int {
82+
var size = MemoryLayout<KeywordHash>.size
83+
size += MemoryLayout<UInt16>.size // size of value in bytes
84+
size += valueSize // value itself
85+
return size
86+
}
87+
7488
@inlinable
7589
func serialize() throws -> [UInt8] {
7690
guard value.count <= Self.maxValueSize else {
@@ -86,20 +100,6 @@ public struct HashBucket: Equatable {
86100
data += value
87101
return data
88102
}
89-
90-
/// Returns the number of bytes in a serialized ``HashBucket`` with `value`.
91-
@inlinable
92-
static func serializedSize(value: HashBucketValue) -> Int {
93-
serializedSize(valueSize: value.count)
94-
}
95-
96-
@inlinable
97-
static func serializedSize(valueSize: Int) -> Int {
98-
var size = MemoryLayout<KeywordHash>.size
99-
size += MemoryLayout<UInt16>.size // size of value in bytes
100-
size += valueSize // value itself
101-
return size
102-
}
103103
}
104104

105105
/// Maximum number of slots in a bucket.

Sources/TestUtilities/PirUtilities/IndexPirTests.swift

Lines changed: 93 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,99 @@ import Testing
1919
extension PirTestUtils {
2020
/// IndexPir tests.
2121
public enum IndexPirTests {
22+
@inlinable
23+
static func indexPirTestForParameter<Server: IndexPirServer, Client: IndexPirClient>(
24+
server _: Server.Type,
25+
client _: Client.Type,
26+
for parameter: IndexPirParameter,
27+
with context: Context<Server.Scheme>) throws
28+
where Server.IndexPir == Client.IndexPir
29+
{
30+
let database = PirTestUtils.randomIndexPirDatabase(
31+
entryCount: parameter.entryCount,
32+
entrySizeInBytes: parameter.entrySizeInBytes)
33+
let processedDb = try Server.process(database: database, with: context, using: parameter)
34+
35+
let server = try Server(parameter: parameter, context: context, database: processedDb)
36+
let client = Client(parameter: parameter, context: context)
37+
38+
let secretKey = try context.generateSecretKey()
39+
let evaluationKey = try client.generateEvaluationKey(using: secretKey)
40+
41+
for _ in 0..<10 {
42+
var indices = Array(0..<parameter.batchSize)
43+
indices.shuffle()
44+
let batchSize = Int.random(in: 1...parameter.batchSize)
45+
let queryIndices = Array(indices.prefix(batchSize))
46+
let query = try client.generateQuery(at: queryIndices, using: secretKey)
47+
let response = try server.computeResponse(to: query, using: evaluationKey)
48+
if Server.Scheme.self != NoOpScheme.self {
49+
#expect(!response.isTransparent())
50+
}
51+
let decryptedResponse = try client.decrypt(response: response, at: queryIndices, using: secretKey)
52+
for index in queryIndices.indices {
53+
#expect(decryptedResponse[index] == database[queryIndices[index]])
54+
}
55+
}
56+
}
57+
58+
@inlinable
59+
static func indexPirTest<Server: IndexPirServer, Client: IndexPirClient>(server: Server.Type,
60+
client: Client.Type) throws
61+
where Server.IndexPir == Client.IndexPir
62+
{
63+
let configs = try [
64+
IndexPirConfig(entryCount: 100,
65+
entrySizeInBytes: 1,
66+
dimensionCount: 2,
67+
batchSize: 2,
68+
unevenDimensions: false,
69+
keyCompression: .noCompression),
70+
IndexPirConfig(entryCount: 100,
71+
entrySizeInBytes: 8,
72+
dimensionCount: 2,
73+
batchSize: 2,
74+
unevenDimensions: false,
75+
keyCompression: .noCompression),
76+
IndexPirConfig(entryCount: 100,
77+
entrySizeInBytes: 24,
78+
dimensionCount: 2,
79+
batchSize: 2,
80+
unevenDimensions: true,
81+
keyCompression: .noCompression),
82+
IndexPirConfig(entryCount: 100,
83+
entrySizeInBytes: 24,
84+
dimensionCount: 1,
85+
batchSize: 2,
86+
unevenDimensions: true,
87+
keyCompression: .noCompression),
88+
IndexPirConfig(entryCount: 100,
89+
entrySizeInBytes: 24,
90+
dimensionCount: 1,
91+
batchSize: 2,
92+
unevenDimensions: true,
93+
keyCompression: .hybridCompression),
94+
IndexPirConfig(entryCount: 100,
95+
entrySizeInBytes: 24,
96+
dimensionCount: 1,
97+
batchSize: 2,
98+
unevenDimensions: true,
99+
keyCompression: .maxCompression),
100+
]
101+
102+
let context: Context<Server.Scheme> = try TestUtils.getTestContext()
103+
for config in configs {
104+
let parameter = Server.generateParameter(config: config, with: context)
105+
try indexPirTestForParameter(server: server, client: client, for: parameter, with: context)
106+
}
107+
}
108+
109+
/// Testing indexPir.
110+
@inlinable
111+
public static func indexPir<Scheme: HeScheme>(scheme _: Scheme.Type) throws {
112+
try indexPirTest(server: MulPirServer<Scheme>.self, client: MulPirClient<Scheme>.self)
113+
}
114+
22115
/// Testing client configuration.
23116
@inlinable
24117
func generateParameter() throws {
@@ -118,98 +211,5 @@ extension PirTestUtils {
118211
#expect(parameter.evaluationKeyConfig == evalKeyConfig)
119212
}
120213
}
121-
122-
@inlinable
123-
static func indexPirTestForParameter<Server: IndexPirServer, Client: IndexPirClient>(
124-
server _: Server.Type,
125-
client _: Client.Type,
126-
for parameter: IndexPirParameter,
127-
with context: Context<Server.Scheme>) throws
128-
where Server.IndexPir == Client.IndexPir
129-
{
130-
let database = PirTestUtils.randomIndexPirDatabase(
131-
entryCount: parameter.entryCount,
132-
entrySizeInBytes: parameter.entrySizeInBytes)
133-
let processedDb = try Server.process(database: database, with: context, using: parameter)
134-
135-
let server = try Server(parameter: parameter, context: context, database: processedDb)
136-
let client = Client(parameter: parameter, context: context)
137-
138-
let secretKey = try context.generateSecretKey()
139-
let evaluationKey = try client.generateEvaluationKey(using: secretKey)
140-
141-
for _ in 0..<10 {
142-
var indices = Array(0..<parameter.batchSize)
143-
indices.shuffle()
144-
let batchSize = Int.random(in: 1...parameter.batchSize)
145-
let queryIndices = Array(indices.prefix(batchSize))
146-
let query = try client.generateQuery(at: queryIndices, using: secretKey)
147-
let response = try server.computeResponse(to: query, using: evaluationKey)
148-
if Server.Scheme.self != NoOpScheme.self {
149-
#expect(!response.isTransparent())
150-
}
151-
let decryptedResponse = try client.decrypt(response: response, at: queryIndices, using: secretKey)
152-
for index in queryIndices.indices {
153-
#expect(decryptedResponse[index] == database[queryIndices[index]])
154-
}
155-
}
156-
}
157-
158-
@inlinable
159-
static func indexPirTest<Server: IndexPirServer, Client: IndexPirClient>(server: Server.Type,
160-
client: Client.Type) throws
161-
where Server.IndexPir == Client.IndexPir
162-
{
163-
let configs = try [
164-
IndexPirConfig(entryCount: 100,
165-
entrySizeInBytes: 1,
166-
dimensionCount: 2,
167-
batchSize: 2,
168-
unevenDimensions: false,
169-
keyCompression: .noCompression),
170-
IndexPirConfig(entryCount: 100,
171-
entrySizeInBytes: 8,
172-
dimensionCount: 2,
173-
batchSize: 2,
174-
unevenDimensions: false,
175-
keyCompression: .noCompression),
176-
IndexPirConfig(entryCount: 100,
177-
entrySizeInBytes: 24,
178-
dimensionCount: 2,
179-
batchSize: 2,
180-
unevenDimensions: true,
181-
keyCompression: .noCompression),
182-
IndexPirConfig(entryCount: 100,
183-
entrySizeInBytes: 24,
184-
dimensionCount: 1,
185-
batchSize: 2,
186-
unevenDimensions: true,
187-
keyCompression: .noCompression),
188-
IndexPirConfig(entryCount: 100,
189-
entrySizeInBytes: 24,
190-
dimensionCount: 1,
191-
batchSize: 2,
192-
unevenDimensions: true,
193-
keyCompression: .hybridCompression),
194-
IndexPirConfig(entryCount: 100,
195-
entrySizeInBytes: 24,
196-
dimensionCount: 1,
197-
batchSize: 2,
198-
unevenDimensions: true,
199-
keyCompression: .maxCompression),
200-
]
201-
202-
let context: Context<Server.Scheme> = try TestUtils.getTestContext()
203-
for config in configs {
204-
let parameter = Server.generateParameter(config: config, with: context)
205-
try indexPirTestForParameter(server: server, client: client, for: parameter, with: context)
206-
}
207-
}
208-
209-
/// Testing indexPir.
210-
@inlinable
211-
public static func indexPir<Scheme: HeScheme>(scheme _: Scheme.Type) throws {
212-
try indexPirTest(server: MulPirServer<Scheme>.self, client: MulPirClient<Scheme>.self)
213-
}
214214
}
215215
}

Tests/HomomorphicEncryptionTests/HeAPITests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ struct HeAPITests {
8585
}
8686

8787
@Test
88-
func testNoOpScheme() async throws {
88+
func noOpScheme() async throws {
8989
let context: Context<NoOpScheme> = try TestUtils.getTestContext()
9090
try HeAPITestHelpers.schemeEncodeDecodeTest(context: context)
9191
try HeAPITestHelpers.schemeEncryptDecryptTest(context: context)
@@ -193,12 +193,12 @@ struct HeAPITests {
193193
}
194194

195195
@Test
196-
func testBfvUInt32() async throws {
196+
func bfvUInt32() async throws {
197197
try await runBfvTests(UInt32.self)
198198
}
199199

200200
@Test
201-
func testBfvUInt64() async throws {
201+
func bfvUInt64() async throws {
202202
try await runBfvTests(UInt64.self)
203203
}
204204
}

Tests/HomomorphicEncryptionTests/PolyRqTests/PolyContextTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ struct PolyContextTests {
6565
}
6666

6767
@Test
68-
func testInitChild() throws {
68+
func initChild() throws {
6969
let context1 = try PolyContext<UInt32>(degree: 4, moduli: [2])
7070
let context2 = try PolyContext<UInt32>(degree: 4, moduli: [2, 3])
7171
let context3 = try PolyContext<UInt32>(degree: 4, moduli: [2, 3, 5], child: context1)

0 commit comments

Comments
 (0)