Skip to content

Commit

Permalink
Allow multiple keys per kid. (eu-digital-green-certificates#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
yspreen authored May 13, 2021
1 parent 9dd70db commit 04bf2f0
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions DGCAVerifier/Models/LocalData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import SwiftDGC
struct LocalData: Codable {
static var sharedInstance = LocalData()

var encodedPublicKeys = [String: String]()
var encodedPublicKeys = [String: [String]]()
var resumeToken: String?
var lastFetchRaw: Date?
var lastFetch: Date {
Expand All @@ -47,7 +47,11 @@ struct LocalData: Codable {
let kid = KID.from(encodedPublicKey)
let kidStr = KID.string(from: kid)

encodedPublicKeys[kidStr] = encodedPublicKey
let list = encodedPublicKeys[kidStr] ?? []
if list.contains(encodedPublicKey) {
return
}
encodedPublicKeys[kidStr]?.append(encodedPublicKey)
}

static func set(resumeToken: String) {
Expand Down Expand Up @@ -75,8 +79,8 @@ struct LocalData: Codable {
}

class LocalDataDelegate: PublicKeyStorageDelegate {
func getEncodedPublicKey(for kidStr: String) -> String? {
LocalData.sharedInstance.encodedPublicKeys[kidStr]
func getEncodedPublicKeys(for kidStr: String) -> [String] {
LocalData.sharedInstance.encodedPublicKeys[kidStr] ?? []
}

static var instance = LocalDataDelegate()
Expand Down

0 comments on commit 04bf2f0

Please sign in to comment.