Skip to content

Commit

Permalink
Merge pull request #250 from DP-3T/develop
Browse files Browse the repository at this point in the history
Release 2.3.0
  • Loading branch information
UBaggeler authored Apr 30, 2021
2 parents 68dc79c + 357f7a1 commit 1a311c3
Show file tree
Hide file tree
Showing 15 changed files with 49 additions and 10 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog for DP3T-SDK iOS

## Version 2.3.0 (30.04.2021)
- expose oldest shared keydate when calling iWasExposed

## Version 2.2.0 (25.03.2021)
- Add support for international key exchange with parameter 'federationGateway'

Expand Down
2 changes: 1 addition & 1 deletion DP3TSDK.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Pod::Spec.new do |spec|

spec.name = "DP3TSDK"
spec.version = ENV['LIB_VERSION'] || '2.2.0'
spec.version = ENV['LIB_VERSION'] || '2.3.0'
spec.summary = "Open protocol for COVID-19 proximity tracing using Bluetooth Low Energy on mobile devices"

spec.description = <<-DESC
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ DP3T-SDK is available through [Cocoapods](https://cocoapods.org/)

```ruby

pod 'DP3TSDK', => '2.2.0'
pod 'DP3TSDK', => '2.3.0'

```

Expand Down
9 changes: 7 additions & 2 deletions Sources/DP3TSDK/DP3TSDK.swift
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ class DP3TSDK {
func iWasExposed(onset: Date,
authentication: ExposeeAuthMethod,
isFakeRequest: Bool = false,
callback: @escaping (Result<Void, DP3TTracingError>) -> Void) {
callback: @escaping (Result<DP3TTracing.IWasExposedResult, DP3TTracingError>) -> Void) {
log.trace()
if !isFakeRequest,
case .infected = state.infectionStatus {
Expand Down Expand Up @@ -299,6 +299,11 @@ class DP3TSDK {
withFederationGateway = nil
}

var oldestNonFakeKeyDate: Date? = nil
if !isFakeRequest {
oldestNonFakeKeyDate = Date(timeIntervalSince1970: Double(oldestRollingStartNumber) * 10 * .minute)
}

let model = ExposeeListModel(gaenKeys: mutableKeys,
withFederationGateway: withFederationGateway,
fake: isFakeRequest)
Expand All @@ -313,7 +318,7 @@ class DP3TSDK {
self.tracer.setEnabled(false, completionHandler: nil)
}

callback(.success(()))
callback(.success(.init(oldestKeyDate: oldestNonFakeKeyDate)))
case let .failure(error):
callback(.failure(.networkingError(error: error)))
}
Expand Down
9 changes: 7 additions & 2 deletions Sources/DP3TSDK/DP3TTracing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ private var instance: DP3TSDK!
/// DP3TTracing
public enum DP3TTracing {
/// The current version of the SDK
public static let frameworkVersion: String = "2.2.0"
public static let frameworkVersion: String = "2.3.0"

/// sets global parameter values which are used throughout the sdk
public static var parameters: DP3TParameters {
Expand Down Expand Up @@ -135,6 +135,11 @@ public enum DP3TTracing {
return instance.status
}


public struct IWasExposedResult {
public let oldestKeyDate: Date?
}

/// tell the SDK that the user was exposed
/// - Parameters:
/// - onset: Start date of the exposure
Expand All @@ -145,7 +150,7 @@ public enum DP3TTracing {
public static func iWasExposed(onset: Date,
authentication: ExposeeAuthMethod,
isFakeRequest: Bool = false,
callback: @escaping (Result<Void, DP3TTracingError>) -> Void) {
callback: @escaping (Result<IWasExposedResult, DP3TTracingError>) -> Void) {
instancePrecondition()
instance.iWasExposed(onset: onset,
authentication: authentication,
Expand Down
6 changes: 6 additions & 0 deletions Sources/DP3TSDK/Models/ExposeeListModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ struct CodableDiagnosisKey: Codable, Equatable {
let fake: UInt8
}

extension CodableDiagnosisKey {
var date: Date {
Date(timeIntervalSince1970: TimeInterval(rollingStartNumber) * TimeInterval.minute * 10)
}
}

/// Model of the exposed person
struct ExposeeListModel: Encodable {
/// Diagnosis keys
Expand Down
2 changes: 1 addition & 1 deletion Sources/DP3TSDK/Networking/ExposeeServiceClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class ExposeeServiceClient: ExposeeServiceClientProtocol {

private let jwtVerifier: DP3TJWTVerifier?

var federationGateway: FederationGateway
internal var federationGateway: FederationGateway

private let log = Logger(ExposeeServiceClient.self, category: "exposeeServiceClient")

Expand Down
17 changes: 14 additions & 3 deletions Tests/DP3TSDKTests/DP3TSDKTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ private class MockKeyProvider: DiagnosisKeysProvider {
}


@available(iOS 12.5, *)
class DP3TSDKTests: XCTestCase {

fileprivate var keychain: MockKeychain!
Expand Down Expand Up @@ -95,8 +96,18 @@ class DP3TSDKTests: XCTestCase {
XCTAssertEqual(sdk.status.infectionStatus, .healthy)

let exp = expectation(description: "infected")
keyProvider.keys = [ .init(keyData: Data(count: 16), rollingPeriod: 144, rollingStartNumber: DayDate().period, transmissionRiskLevel: 0, fake: 0) ]
let oldestDate = Date(timeIntervalSinceNow: -.day * 5)
keyProvider.keys = [
.init(keyData: Data(count: 16), rollingPeriod: 144, rollingStartNumber: DayDate(date: oldestDate.addingTimeInterval(.day)).period, transmissionRiskLevel: 0, fake: 0),
.init(keyData: Data(count: 16), rollingPeriod: 144, rollingStartNumber: DayDate(date: oldestDate).period, transmissionRiskLevel: 0, fake: 0),
.init(keyData: Data(count: 16), rollingPeriod: 144, rollingStartNumber: DayDate(date: oldestDate.addingTimeInterval(.day * 2)).period, transmissionRiskLevel: 0, fake: 0),
]
sdk.iWasExposed(onset: .init(timeIntervalSinceNow: -.day), authentication: .none) { (result) in
if case let Result.success(wrapper) = result {
XCTAssertEqual(wrapper.oldestKeyDate, DayDate(date: oldestDate).dayMin)
} else {
XCTFail()
}
exp.fulfill()
}
wait(for: [exp], timeout: 0.1)
Expand All @@ -107,8 +118,8 @@ class DP3TSDKTests: XCTestCase {
let rollingStartNumbers = Set(model!.gaenKeys.map(\.rollingStartNumber))
XCTAssertEqual(rollingStartNumbers.count, model!.gaenKeys.count)
var runningDate: Date?
for key in model!.gaenKeys {
let date = Date(timeIntervalSince1970: Double(key.rollingStartNumber) * 10 * .minute)
for key in model!.gaenKeys.sorted(by: { $0.date > $1.date }) {
let date = key.date
guard runningDate != nil else {
runningDate = date
continue
Expand Down
2 changes: 2 additions & 0 deletions Tests/DP3TSDKTests/DiagnosisKeysProviderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import Foundation
import XCTest
import ExposureNotification

@available(iOS 12.5, *)
class DiagnosisKeysProviderTests: XCTestCase {

var manager: MockENManager!
Expand Down Expand Up @@ -81,6 +82,7 @@ class DiagnosisKeysProviderTests: XCTestCase {

}

@available(iOS 12.5, *)
extension ENTemporaryExposureKey {
static func initialize(data: Data = Data(capacity: 16),
rollingPeriod: ENIntervalNumber = UInt32(TimeInterval.day / (.minute * 10)),
Expand Down
1 change: 1 addition & 0 deletions Tests/DP3TSDKTests/ExposureNotificationMatcherTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import Foundation
import XCTest
import ZIPFoundation

@available(iOS 12.5, *)
final class ExposureNotificationMatcherTests: XCTestCase {
var keychain = MockKeychain()

Expand Down
1 change: 1 addition & 0 deletions Tests/DP3TSDKTests/ExposureNotificationTracerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
@testable import DP3TSDK
import XCTest

@available(iOS 12.5, *)
class ExposureNotificationTracerTests: XCTestCase {

var manager: MockENManager!
Expand Down
1 change: 1 addition & 0 deletions Tests/DP3TSDKTests/ExposureWindowTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import XCTest
import ExposureNotification


@available(iOS 12.5, *)
class ExposureWindowTests: XCTestCase {
func testDayGroupingSingle(){
var windows: [MockWindow] = []
Expand Down
2 changes: 2 additions & 0 deletions Tests/DP3TSDKTests/Mocks/MockENManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import Foundation
import ExposureNotification

@available(iOS 12.5, *)
class MockENManager: ENManager {
var activateCallbacks: [ENErrorHandler] = []

Expand Down Expand Up @@ -108,6 +109,7 @@ class MockENManager: ENManager {
}
}

@available(iOS 12.5, *)
class MockSummary: ENExposureDetectionSummary {
override var attenuationDurations: [NSNumber] {
get {
Expand Down
1 change: 1 addition & 0 deletions Tests/DP3TSDKTests/Mocks/MockScanInstance.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import Foundation
import ExposureNotification

@available(iOS 12.5, *)
class MockScanInstance: ENScanInstance {

private var internalTypicalAttenuation: ENAttenuation
Expand Down
1 change: 1 addition & 0 deletions Tests/DP3TSDKTests/Mocks/MockWindow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import Foundation
import ExposureNotification

@available(iOS 12.5, *)
class MockWindow: ENExposureWindow {
private var internalDate: Date
private var internalScanInstances: [ENScanInstance]
Expand Down

0 comments on commit 1a311c3

Please sign in to comment.