]> git.saurik.com Git - apple/security.git/blob - keychain/TrustedPeersHelper/Container_Peers.swift
Security-59754.80.3.tar.gz
[apple/security.git] / keychain / TrustedPeersHelper / Container_Peers.swift
1 import CloudKitCode
2 import CloudKitCodeProtobuf
3 import CoreData
4 import Foundation
5 import os
6 import Security
7 import SecurityFoundation
8
9 extension Container {
10 internal static func removingDuplicates(vouchers: Set<VoucherMO>) -> Set<VoucherMO> {
11 var unique: Set<VoucherMO> = Set()
12
13 for voucher in vouchers {
14 if !unique.contains(voucher) {
15 unique.insert(voucher)
16 }
17 }
18 return unique
19 }
20
21 internal static func onqueueRemoveDuplicateVouchersPerPeer(container: ContainerMO, moc: NSManagedObjectContext) {
22 var peersWithUniqueSetOfVouchers: Set<PeerMO> = Set()
23 let peers = container.peers as? Set<PeerMO> ?? Set()
24 for peer in peers {
25 let vouchers = peer.vouchers as? Set<VoucherMO> ?? Set()
26 let uniqueSet = Container.removingDuplicates(vouchers: vouchers)
27 for voucher in vouchers {
28 peer.removeFromVouchers(voucher)
29 }
30 for voucher in uniqueSet {
31 peer.addToVouchers(voucher)
32 }
33 peersWithUniqueSetOfVouchers.insert(peer)
34 }
35 for peer in peers {
36 container.removeFromPeers(peer)
37 }
38 for peer in peersWithUniqueSetOfVouchers {
39 container.addToPeers(peer)
40 }
41 }
42 }