• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

hyperledger / identus-edge-agent-sdk-swift / 10563970802

26 Aug 2024 05:03PM CUT coverage: 43.981%. Remained the same
10563970802

Pull #162

github

web-flow
Merge ec9fb33d5 into 7e2737c01
Pull Request #162: chore: update links in readme and contributing

5320 of 12096 relevant lines covered (43.98%)

101.49 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/EdgeAgentSDK/Domain/Sources/Models/KeyManagement/KeychainStorableKey.swift
1
import Foundation
2
import Security
3

4
/// Represents properties required for storing keys in a keychain.
5
public struct KeychainStorableKeyProperties {
6

7
    /// Represents the type of cryptographic key.
8
    public enum KeyType: String {
9
        case privateKey
10
        case publicKey
11
    }
12

13
    /// Represents the accessibility of the key in the keychain.
14
    public enum Accessability {
15

16
        /// Key is accessible after the first device unlock.
17
        /// - Parameter deviceOnly: A boolean indicating if the key is available only on the specific device.
18
        case firstUnlock(deviceOnly: Bool)
19

20
        /// Key is accessible as long as the device is unlocked.
21
        /// - Parameter deviceOnly: A boolean indicating if the key is available only on the specific device.
22
        case unlocked(deviceOnly: Bool)
23

24
        /// Key is accessible when a password is set.
25
        case passwordSet
26

27
        /// Indicates if the key is available only on the specific device.
28
        var deviceOnly: Bool {
×
29
            switch self {
×
30
            case .firstUnlock(let deviceOnly):
×
31
                return deviceOnly
×
32
            case .unlocked(let deviceOnly):
×
33
                return deviceOnly
×
34
            case .passwordSet:
×
35
                return true
×
36
            }
×
37
        }
×
38
    }
39

40
    /// Represents the cryptographic algorithm of the key.
41
    public enum KeyAlgorithm: String {
42
        /// RSA is an asymmetric algorithm used for both encryption and digital signatures.
43
        case rsa
44

45
        /// DSA (Digital Signature Algorithm) is primarily used for digital signatures.
46
        case dsa
47

48
        /// AES (Advanced Encryption Standard) is a symmetric encryption algorithm.
49
        case aes
50

51
        /// DES (Data Encryption Standard) is an older symmetric encryption algorithm that's considered insecure today.
52
        case des
53

54
        /// 3DES (Triple DES) is an enhancement of DES that applies the DES algorithm three times on each data block. It's represented as "3des" in the string.
55
        case _3des = "3des"
56

57
        /// RC4 is a symmetric stream cipher.
58
        case rc4
59

60
        /// RC2 is a symmetric block cipher.
61
        case rc2
62

63
        /// CAST is a family of symmetric encryption algorithms.
64
        case cast
65

66
        /// EC (Elliptic Curve) is used in asymmetric cryptography for encryption, digital signatures, and key agreement.
67
        case ec
68

69
        /// Represents a `kSecAttrKeyClassKey`. It's a key type that doesn't leverage the `SecKey` API for cryptographic operations. This can be thought of as a raw representation of a key, without being tied to specific cryptographic operations or algorithms.
70
        case rawKey
71

72
        /// A generic password representation, not associated with any specific cryptographic algorithm.
73
        case genericPassword
74
    }
75
}
76

77
/// Protocol defining a key that can be stored within the keychain.
78
///
79
/// This protocol extends the basic `StorableKey` interface to include properties specific to the keychain. It provides information about the cryptographic algorithm used (`type`), the key type (`keyClass`), accessibility restrictions (`accessibility`), and whether or not the key is synchronizable across the user's devices (`synchronizable`).
80
public protocol KeychainStorableKey: StorableKey {
81

82
    /// The cryptographic algorithm used by the key.
83
    ///
84
    /// This determines how the key is used for cryptographic operations. For example, the key could be based on the RSA algorithm, the AES algorithm, etc. This attribute is aligned with Apple's `kSecAttrKeyType`.
85
    var type: KeychainStorableKeyProperties.KeyAlgorithm { get }
86

87
    /// The class or type of the key.
88
    ///
89
    /// Specifies if the key is a public key, private key, or a symmetric key. This attribute helps determine how the key interacts within cryptographic operations.
90
    var keyClass: KeychainStorableKeyProperties.KeyType { get }
91

92
    /// The accessibility of the key within the keychain.
93
    ///
94
    /// Determines under which conditions the key can be accessed. This might restrict access to the key until the device has been unlocked for the first time or every time the device is unlocked, for instance. It provides a layer of security by defining when the key can be accessed.
95
    var accessiblity: KeychainStorableKeyProperties.Accessability? { get }
96

97
    /// Indicates if the key is synchronizable across devices using iCloud.
98
    ///
99
    /// If `true`, the key can be synchronized and made available on other devices signed into the same Apple ID. This is useful for shared secrets that need to be available across a user's devices. However, developers must be careful about what is synchronized to ensure user privacy and security.
100
    var synchronizable: Bool { get }
101
}
102

103
/// Extension of the `Key` protocol to provide additional functionality related to keychain storage.
104
public extension Key {
105
    /// A boolean value indicating whether the key can be stored in the keychain.
106
    var isKeychainStorable: Bool { self is KeychainStorableKey }
×
107

108
    /// Returns this key as a `KeychainStorableKey`, or `nil` if the key cannot be stored in the keychain.
109
    var keychainStorable: KeychainStorableKey? { self as? KeychainStorableKey }
×
110
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc