summaryrefslogtreecommitdiffhomepage
path: root/ios/MullvadVPN/KeychainError.swift
blob: f006175827ac289c1458654ee8e8e95ba105f26b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
//
//  KeychainError.swift
//  MullvadVPN
//
//  Created by pronebird on 02/10/2019.
//  Copyright © 2019 Mullvad VPN AB. All rights reserved.
//

import Foundation
import Security

struct KeychainError: Error, LocalizedError {
    let code: OSStatus

    var errorDescription: String? {
        return SecCopyErrorMessageString(code, nil) as String?
    }
}

extension KeychainError {

    static let duplicateItem = KeychainError(code: errSecDuplicateItem)
    static let itemNotFound = KeychainError(code: errSecItemNotFound)

    static func ~= (lhs: KeychainError, rhs: Error) -> Bool {
        guard let rhsError = rhs as? KeychainError else { return false }
        return lhs.code == rhsError.code
    }
}