Skip to content
This repository has been archived by the owner on Jun 20, 2023. It is now read-only.

Commit

Permalink
Implement checking of certificates against blocklist
Browse files Browse the repository at this point in the history
  • Loading branch information
nickguendling committed Nov 5, 2021
1 parent 42fc02e commit 5b9d2ac
Showing 1 changed file with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,30 @@ final class HealthCertificate: Codable, Equatable, Comparable, RecycleBinIdentif
validityState == .valid || type == .test && (validityState == .expiringSoon || validityState == .expired)
}

var uniqueCertificateIdentifierChunks: [String] {
uniqueCertificateIdentifier
.dropPrefix("URN:UVCI:")
.components(separatedBy: CharacterSet(charactersIn: "/#:"))
}

func isBlocked(by blockedIdentifierChunks: [SAP_Internal_V2_DGCBlockedUVCIChunk]) -> Bool {
blockedIdentifierChunks.contains {
/// Skip if at least on index would be out of bounds
guard $0.indices.allSatisfy({ $0 < uniqueCertificateIdentifierChunks.count }) else {
return false
}

let blockedChunks = $0.indices
.map { uniqueCertificateIdentifierChunks[Int($0)] }
.joined(separator: "/")

let hash = ENAHasher.sha256(blockedChunks)
let hashData = Data(base64Encoded: hash)

return hashData == $0.hash
}
}

// MARK: - Private

private var sortDate: Date? {
Expand Down

0 comments on commit 5b9d2ac

Please sign in to comment.