-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
485 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// 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 PrivateInformationRetrievalProtobuf | ||
import Util | ||
|
||
extension Platform { | ||
var supportsPirFixedShardConfig: Bool { | ||
switch osType { | ||
case .iOS: | ||
osVersion >= .init(major: 18, minor: 2) | ||
case .macOS: | ||
osVersion >= .init(major: 15, minor: 2) | ||
default: | ||
fatalError("Unsupported platform \(self)") | ||
} | ||
} | ||
} | ||
|
||
public extension Apple_SwiftHomomorphicEncryption_Api_Pir_V1_Config { | ||
/// Makes the configuration compatible with the given platform. | ||
/// - Parameter platform: Device platform. | ||
mutating func makeCompatible(with platform: Platform) { | ||
if !platform.supportsPirFixedShardConfig { | ||
// Check for PIRFixedShardConfig, introduced in iOS 18.2 | ||
switch pirConfig.pirShardConfigs.shardConfigs { | ||
case let .repeatedShardConfig(repeatedConfig): | ||
pirConfig.shardConfigs = Array( | ||
repeating: repeatedConfig.shardConfig, | ||
count: Int(repeatedConfig.shardCount)) | ||
pirConfig.clearPirShardConfigs() | ||
case .none: | ||
break | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// 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 HTTPTypes | ||
import Hummingbird | ||
import Util | ||
|
||
protocol PlatformRequestContext: RequestContext { | ||
var platform: Platform? { get set } | ||
} | ||
|
||
/// Middleware that extracts the platform from the 'User-Agent' header | ||
struct ExtractPlatformMiddleware<Context: PlatformRequestContext>: RouterMiddleware { | ||
func handle( | ||
_ input: Request, | ||
context: Context, | ||
next: (Request, Context) async throws -> Response) async throws -> Response | ||
{ | ||
var context = context | ||
guard let userAgent = input.headers[.userAgent] else { | ||
throw HTTPError(.badRequest, message: "Missing 'User-Agent' header") | ||
} | ||
context.platform = Platform(userAgent: userAgent) | ||
return try await next(input, context) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.