Skip to content

Commit

Permalink
new type of information for wallet app and verifier (#88)
Browse files Browse the repository at this point in the history
* new version of info sections

* check if issCode is empty

Co-authored-by: Alexandr Chernyy <pingus.nikalex@gmail.com>
  • Loading branch information
alexchornyi and pingus-nikalex authored Jul 21, 2021
1 parent ede637f commit 689a6e3
Show file tree
Hide file tree
Showing 7 changed files with 277 additions and 45 deletions.
5 changes: 5 additions & 0 deletions Localization/SwiftDGC/en.xcloc/Localized Contents/en.xliff
Original file line number Diff line number Diff line change
Expand Up @@ -1473,6 +1473,11 @@
<target>Test Issuer</target>
<note/>
</trans-unit>
<trans-unit id="test.type" xml:space="preserve">
<source>Type of Test</source>
<target>Type of Test</target>
<note/>
</trans-unit>
<trans-unit id="test.man.344" xml:space="preserve">
<source>SD BIOSENSOR Inc, STANDARD F COVID-19 Ag FIA</source>
<target>SD BIOSENSOR Inc, STANDARD F COVID-19 Ag FIA</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
"test.man.1278" = "Xiamen Boson Biotech Co. Ltd, Rapid SARS-CoV-2 Antigen Test Card";
"test.man.1343" = "Zhejiang Orient Gene Biotech, Coronavirus Ag Rapid Test Cassette (Swab)";
"test.man.unknown" = "Unknown";
"test.type" = "Type of Test";

"disease.840539006" = "COVID-19";
"disease.unknown" = "Unknown";
Expand Down
225 changes: 180 additions & 45 deletions Sources/Models/HCert.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ enum AttributeKey: String {
case recoveryStatements
}

public enum AppType: Int {
case verifier
case wallet
}

public enum HCertType: String {
case test
case vaccine
Expand Down Expand Up @@ -124,6 +129,8 @@ public struct HCert {
"HC1:"
]

public var appType: AppType = .verifier

static func parsePrefix(_ payloadString: String) -> String {
var payloadString = payloadString
Self.supportedPrefixes.forEach({ prefix in
Expand All @@ -143,7 +150,7 @@ public struct HCert {
return foundPrefix
}

public init?(from payload: String, errors: ParseErrors? = nil) {
public init?(from payload: String, errors: ParseErrors? = nil, applicationType: AppType = .verifier) {

let payload = payload
if Self.checkCH1PreffixExist(payload) {
Expand All @@ -154,6 +161,7 @@ public struct HCert {
fullPayloadString = fullPayloadString + payload
payloadString = payload
}
appType = applicationType

guard
let compressed = try? payloadString.fromBase45()
Expand Down Expand Up @@ -194,7 +202,7 @@ public struct HCert {
return nil
}
findValidity()
makeSections()
makeSections(for: appType)

#if os(iOS)
if Self.config.prefetchAllCodes {
Expand All @@ -221,7 +229,7 @@ public struct HCert {
}

//
public mutating func makeSectionForRuleError(infoSections: InfoSection) {
public mutating func makeSectionForRuleError(infoSections: InfoSection, for appType: AppType) {
info.removeAll()
info = isValid ? [] : [
InfoSection(header: l10n("header.validity-errors"), content: validityFailures.joined(separator: " "))
Expand All @@ -233,6 +241,64 @@ public struct HCert {
)
] + personIdentifiers
info += [infoSections]
switch appType {
case .verifier:
makeSectionsForVerifier(includeInvalidSection: false)
case .wallet:
switch type {
case .vaccine:
makeSectionsForVaccine(includeInvalidSection: false)
break
case .test:
makeSectionsForTest()
break
case .recovery:
makeSectionsForRecovery(includeInvalidSection: false)
break
default:
makeSectionsForVerifier(includeInvalidSection: false)
}
break
}
}

//

mutating func makeSections(for appType: AppType) {
info.removeAll()
switch appType {
case .verifier:
makeSectionsForVerifier()
case .wallet:
switch type {
case .vaccine:
makeSectionsForVaccine()
break
case .test:
makeSectionsForTest()
break
case .recovery:
makeSectionsForRecovery()
break
default:
makeSectionsForVerifier()
}
break
}
}

mutating func makeSectionsForVerifier(includeInvalidSection: Bool = true) {
info = isValid && includeInvalidSection ? [] : [
InfoSection(header: l10n("header.validity-errors"), content: validityFailures.joined(separator: " "))
]
if includeInvalidSection {
info += [
InfoSection(
header: l10n("header.cert-type"),
content: certTypeString
)
] + personIdentifiers
}
if let last = get(.lastNameStandardized).string {
info += [
InfoSection(
Expand Down Expand Up @@ -265,38 +331,35 @@ public struct HCert {
}
info += statement == nil ? [] : statement.info
info += [
// Certificate expiration date
// InfoSection(
// header: l10n("header.expires-at"),
// content: exp.dateTimeStringUtc
// ),
InfoSection(
header: l10n("header.uvci"),
content: uvci,
style: .fixedWidthFont,
isPrivate: true
)
]
info += [
InfoSection(
header: l10n("issuer.country"),
content: l10n("country.\(issCode.uppercased())")
)
]
if issCode.count > 0 {
info += [
InfoSection(
header: l10n("issuer.country"),
content: l10n("country.\(issCode.uppercased())")
)
]
}
}

//

mutating func makeSections() {
info = isValid ? [] : [
mutating func makeSectionsForVaccine(includeInvalidSection: Bool = true) {
info = isValid && includeInvalidSection ? [] : [
InfoSection(header: l10n("header.validity-errors"), content: validityFailures.joined(separator: " "))
]
info += [
InfoSection(
header: l10n("header.cert-type"),
content: certTypeString
)
] + personIdentifiers
if includeInvalidSection {
info += [
InfoSection(
header: l10n("header.cert-type"),
content: certTypeString
)
] + personIdentifiers
}
if let last = get(.lastNameStandardized).string {
info += [
InfoSection(
Expand All @@ -319,35 +382,107 @@ public struct HCert {
)
]
}
if let date = get(.dateOfBirth).string {
info += statement == nil ? [] : statement.walletInfo
if issCode.count > 0 {
info += [
InfoSection(
header: l10n("header.dob"),
content: date
header: l10n("issuer.country"),
content: l10n("country.\(issCode.uppercased())")
)
]
}
info += statement == nil ? [] : statement.info
info += [
// Certificate expiration date
// InfoSection(
// header: l10n("header.expires-at"),
// content: exp.dateTimeStringUtc
// ),
InfoSection(
header: l10n("header.uvci"),
content: uvci,
style: .fixedWidthFont,
isPrivate: true
)
}

mutating func makeSectionsForTest(includeInvalidSection: Bool = true) {
info = isValid && includeInvalidSection ? [] : [
InfoSection(header: l10n("header.validity-errors"), content: validityFailures.joined(separator: " "))
]
info += [
InfoSection(
header: l10n("issuer.country"),
content: l10n("country.\(issCode.uppercased())")
)
if includeInvalidSection {
info += [
InfoSection(
header: l10n("header.cert-type"),
content: certTypeString
)
] + personIdentifiers
}
if let last = get(.lastNameStandardized).string {
info += [
InfoSection(
header: l10n("header.std-fn"),
content: last.replacingOccurrences(
of: "<",
with: String.zeroWidthSpace + "<" + String.zeroWidthSpace),
style: .fixedWidthFont
)
]
}
if let first = get(.firstNameStandardized).string {
info += [
InfoSection(
header: l10n("header.std-gn"),
content: first.replacingOccurrences(
of: "<",
with: String.zeroWidthSpace + "<" + String.zeroWidthSpace),
style: .fixedWidthFont
)
]
}
info += statement == nil ? [] : statement.walletInfo
if issCode.count > 0 {
info += [
InfoSection(
header: l10n("issuer.country"),
content: l10n("country.\(issCode.uppercased())")
)
]
}
}

mutating func makeSectionsForRecovery(includeInvalidSection: Bool = true) {
info = isValid && includeInvalidSection ? [] : [
InfoSection(header: l10n("header.validity-errors"), content: validityFailures.joined(separator: " "))
]
if includeInvalidSection {
info += [
InfoSection(
header: l10n("header.cert-type"),
content: certTypeString
)
] + personIdentifiers
}
if let last = get(.lastNameStandardized).string {
info += [
InfoSection(
header: l10n("header.std-fn"),
content: last.replacingOccurrences(
of: "<",
with: String.zeroWidthSpace + "<" + String.zeroWidthSpace),
style: .fixedWidthFont
)
]
}
if let first = get(.firstNameStandardized).string {
info += [
InfoSection(
header: l10n("header.std-gn"),
content: first.replacingOccurrences(
of: "<",
with: String.zeroWidthSpace + "<" + String.zeroWidthSpace),
style: .fixedWidthFont
)
]
}
info += statement == nil ? [] : statement.walletInfo
if issCode.count > 0 {
info += [
InfoSection(
header: l10n("issuer.country"),
content: l10n("country.\(issCode.uppercased())")
)
]
}
}


func get(_ attribute: AttributeKey) -> JSON {
var object = body
Expand Down
21 changes: 21 additions & 0 deletions Sources/Models/RecoveryEntry.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,27 @@ struct RecoveryEntry: HCertEntry {
]
}

var walletInfo: [InfoSection] {
[
InfoSection(header: l10n("recovery.valid-from"), content: validFrom.localDateString),
InfoSection(header: l10n("recovery.valid-until"), content: validUntil.localDateString),
InfoSection(
header: l10n("recovery.disease"),
content: l10n("disease." + diseaseTargeted, or: "\(l10n("disease.unknown")): \(diseaseTargeted)")
),
InfoSection(
header: l10n("recovery.country"),
content: country(for: countryCode),
isPrivate: true
),
InfoSection(
header: l10n("recovery.issuer"),
content: issuer,
isPrivate: true
)
]
}

var validityFailures: [String] {
var fail = [String]()
if validFrom > HCert.clock {
Expand Down
30 changes: 30 additions & 0 deletions Sources/Models/TestEntry.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,36 @@ struct TestEntry: HCertEntry {
]
}

var walletInfo: [InfoSection] {
[
InfoSection(
header: l10n("test.test-result"),
content: resultNegative ? l10n("test.result.negative") : l10n("test.result.positive")
),
InfoSection(header: l10n("test.sample-date-time"), content: sampleTime.dateTimeStringUtc),
InfoSection(header: l10n("test.type"), content: type),
InfoSection(
header: l10n("test.disease"),
content: l10n("disease." + diseaseTargeted, or: "\(l10n("disease.unknown")): \(diseaseTargeted)")
),
InfoSection(
header: l10n("test.center"),
content: testCenter,
isPrivate: true
),
InfoSection(
header: l10n("test.country"),
content: country(for: countryCode),
isPrivate: true
),
InfoSection(
header: l10n("test.issuer"),
content: issuer,
isPrivate: true
)
]
}

var validityFailures: [String] {
var fail = [String]()
if !resultNegative {
Expand Down
Loading

0 comments on commit 689a6e3

Please sign in to comment.