summaryrefslogtreecommitdiffhomepage
path: root/ios/MullvadVPN/Keychain/KeychainError.swift
blob: 4758d08b66639dbe16b62fcc5f552f614c7663b9 (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
30
31
32
//
//  KeychainError.swift
//  MullvadVPN
//
//  Created by pronebird on 02/10/2019.
//  Copyright © 2019 Mullvad VPN AB. All rights reserved.
//

import Foundation
import Security

extension Keychain {
    struct Error: Swift.Error, LocalizedError {
        let code: OSStatus

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


extension Keychain.Error {

    static let duplicateItem = Keychain.Error(code: errSecDuplicateItem)
    static let itemNotFound = Keychain.Error(code: errSecItemNotFound)

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