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

input-output-hk / atala-prism-wallet-sdk-swift / 9466819027

11 Jun 2024 01:48PM UTC coverage: 40.328% (-0.5%) from 40.822%
9466819027

Pull #145

github

web-flow
Merge 1399bca59 into 8e68386ce
Pull Request #145: feat(pollux): add support for sd-jwt

76 of 394 new or added lines in 20 files covered. (19.29%)

2 existing lines in 2 files now uncovered.

4518 of 11203 relevant lines covered (40.33%)

16.34 hits per line

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

20.0
/EdgeAgentSDK/Domain/Sources/Models/MessageAttachment.swift
1
import Foundation
2

3
/// The `AttachmentData` protocol represents a generic attachment for a DIDComm `Message`. Any type that conforms to `AttachmentData` can be used as an attachment.
4
public protocol AttachmentData: Codable {}
5

6
/// The `AttachmentHeader` struct represents the header for a DIDComm attachment.
7
public struct AttachmentHeader: AttachmentData {
8
    /// The `children` value associated with the attachment.
9
    public let children: String
10

11
    /// Initializes a new `AttachmentHeader` object with the specified properties.
12
    /// - Parameter children: The `children` value associated with the attachment.
13
    public init(children: String) {
×
14
        self.children = children
×
15
    }
×
16
}
17

18
/// The `AttachmentJws` struct represents a DIDComm attachment containing a JWS (JSON Web Signature).
19
public struct AttachmentJws: AttachmentData {
20
    /// The header for the JWS attachment.
21
    public let header: AttachmentHeader
22

23
    /// The `protected` value associated with the JWS.
24
    public let protected: String
25

26
    /// The signature for the JWS.
27
    public let signature: String
28

29
    /// Initializes a new `AttachmentJws` object with the specified properties.
30
    /// - Parameters:
31
    ///   - header: The header for the JWS attachment.
32
    ///   - protected: The `protected` value associated with the JWS.
33
    ///   - signature: The signature for the JWS.
34
    public init(header: AttachmentHeader, protected: String, signature: String) {
×
35
        self.header = header
×
36
        self.protected = protected
×
37
        self.signature = signature
×
38
    }
×
39
}
40

41
/// The `AttachmentJwsData` struct represents a DIDComm attachment containing JWS data.
42
public struct AttachmentJwsData: AttachmentData {
43
    /// The base64-encoded data for the JWS.
44
    public let base64: String
45

46
    /// The `AttachmentJws` object containing the JWS data.
47
    public let jws: AttachmentJws
48

49
    /// Initializes a new `AttachmentJwsData` object with the specified properties.
50
    /// - Parameters:
51
    ///   - base64: The base64-encoded data for the JWS.
52
    ///   - jws: The `AttachmentJws` object containing the JWS data.
53
    public init(base64: String, jws: AttachmentJws) {
×
54
        self.base64 = base64
×
55
        self.jws = jws
×
56
    }
×
57
}
58

59
/// The `AttachmentBase64` struct represents a DIDComm attachment containing base64-encoded data.
60
public struct AttachmentBase64: AttachmentData {
61
    /// The base64-encoded data.
62
    public let base64: String
63

64
    /// Initializes a new `AttachmentBase64` object with the specified properties.
65
    /// - Parameter base64: The base64-encoded data.
66
    public init(base64: String) {
96✔
67
        self.base64 = base64
96✔
68
    }
96✔
69
    
70
    public func decoded() throws -> Data {
24✔
71
        guard let decode = Data(base64Encoded: base64) else {
24✔
UNCOV
72
            throw CommonError.invalidCoding(message: "Could not decode base64 message attchment")
×
73
        }
24✔
74
        return decode
24✔
75
    }
24✔
76
}
77

78
/// The `AttachmentLinkData` struct represents a DIDComm attachment containing a link to external data.
79
public struct AttachmentLinkData: AttachmentData {
80
    /// The links associated with the attachment.
81
    public let links: [String]
82

83
    /// The hash associated with the attachment.
84
    public let hash: String
85

86
    /// Initializes a new `AttachmentLinkData` object with the specified properties.
87
    /// - Parameters:
88
    ///   - links: The links associated with the attachment.
89
    ///   - hash: The hash associated with the attachment.
90
    public init(links: [String], hash: String) {
×
91
        self.links = links
×
92
        self.hash = hash
×
93
    }
×
94
}
95

96
/// The `AttachmentJsonData` struct represents a DIDComm attachment containing JSON data.
97
public struct AttachmentJsonData: AttachmentData {
98
    /// The JSON data associated with the attachment.
99
    public let data: Data
100

101
    /// Initializes a new `AttachmentJsonData` object with the specified properties.
102
    /// - Parameter data: The JSON data associated with the attachment.
103
    public init(data: Data) {
×
104
        self.data = data
×
105
    }
×
106
}
107

108
/// The `AttachmentDescriptor` struct represents metadata for a DIDComm attachment.
109
public struct AttachmentDescriptor {
110
    /// The ID associated with the attachment.
111
    public let id: String
112

113
    /// The media type associated with the attachment.
114
    public let mediaType: String?
115

116
    /// The data associated with the attachment.
117
    public let data: AttachmentData
118

119
    /// The filename associated with the attachment.
120
    public let filename: [String]?
121

122
    /// The format associated with the attachment.
123
    public let format: String?
124

125
    /// The last modification time associated with the attachment.
126
    public let lastmodTime: Date?
127

128
    /// The byte count associated with the attachment.
129
    public let byteCount: Int?
130

131
    /// The description associated with the attachment.
132
    public let description: String?
133

134
    /// Initializes a new `AttachmentDescriptor` object with the specified properties.
135
    /// - Parameters:
136
    ///   - id: The ID associated with the attachment.
137
    ///   - mediaType: The media type associated with the attachment.
138
    ///   - data: The data associated with the attachment.
139
    ///   - filename: The filename associated with the attachment.
140
    ///   - format: The format associated with the attachment.
141
    ///   - lastmodTime: The last modification time associated with the attachment.
142
    ///   - byteCount: The byte count associated with the attachment.
143
    ///   - description: The description associated with the attachment.
144
    public init(
145
        id: String = UUID().uuidString,
146
        mediaType: String? = nil,
147
        data: AttachmentData,
148
        filename: [String]? = nil,
149
        format: String? = nil,
150
        lastmodTime: Date? = nil,
151
        byteCount: Int? = nil,
152
        description: String? = nil
153
    ) {
96✔
154
        self.id = id
96✔
155
        self.mediaType = mediaType
96✔
156
        self.data = data
96✔
157
        self.filename = filename
96✔
158
        self.format = format
96✔
159
        self.lastmodTime = lastmodTime
96✔
160
        self.byteCount = byteCount
96✔
161
        self.description = description
96✔
162
    }
96✔
163
}
164

165
extension AttachmentDescriptor: Codable {
166
    
167
    enum CodingKeys: String, CodingKey {
168
        case id
169
        case mediaType
170
        case data
171
        case filename
172
        case format
173
        case lastmodTime
174
        case byteCount
175
        case description
176
    }
177
    
178
    public func encode(to encoder: Encoder) throws {
×
179
        var container = encoder.container(keyedBy: CodingKeys.self)
×
180
        try container.encode(id, forKey: .id)
×
181
        try container.encode(mediaType, forKey: .mediaType)
×
182
        try container.encode(data, forKey: .data)
×
183
        try container.encode(filename, forKey: .filename)
×
184
        try container.encode(format, forKey: .format)
×
185
        try container.encode(lastmodTime, forKey: .lastmodTime)
×
186
        try container.encode(byteCount, forKey: .byteCount)
×
187
        try container.encode(description, forKey: .description)
×
188
    }
×
189

190
    public init(from decoder: Decoder) throws {
×
191
        let container = try decoder.container(keyedBy: CodingKeys.self)
×
192
        let id = try container.decode(String.self, forKey: .id)
×
193
        let mediaType = try? container.decodeIfPresent(String.self, forKey: .mediaType)
×
194
        let filename = try? container.decodeIfPresent([String].self, forKey: .filename)
×
195
        let format = try? container.decodeIfPresent(String.self, forKey: .format)
×
196
        let lastmodTime = try? container.decodeIfPresent(Date.self, forKey: .lastmodTime)
×
197
        let byteCount = try? container.decodeIfPresent(Int.self, forKey: .byteCount)
×
198
        let description = try? container.decodeIfPresent(String.self, forKey: .description)
×
199
        let data: AttachmentData?
×
200
        if let attchData = try? container.decode(AttachmentBase64.self, forKey: .data) {
×
201
            data = attchData
×
202
        } else if let attchData = try? container.decode(AttachmentJws.self, forKey: .data) {
×
203
            data = attchData
×
204
        } else if let attchData = try? container.decode(AttachmentHeader.self, forKey: .data) {
×
205
            data = attchData
×
206
        } else if let attchData = try? container.decode(AttachmentJwsData.self, forKey: .data) {
×
207
            data = attchData
×
208
        } else if let attchData = try? container.decode(AttachmentJsonData.self, forKey: .data) {
×
209
            data = attchData
×
210
        } else if let attchData = try? container.decode(AttachmentLinkData.self, forKey: .data) {
×
211
            data = attchData
×
212
        } else { data = nil }
×
213
        
×
214
        guard let data else { throw CommonError.invalidCoding(
×
215
            message: """
×
216
Could not parse AttachmentData to any of the following: AttachmentBase64, AttachmentJws, AttachmentHeader, AttachmentJwsData, AttachmentJsonData, AttachmentLinkData
×
217
"""
×
218
        )}
×
219

×
220
        self.init(
×
221
            id: id,
×
222
            mediaType: mediaType,
×
223
            data: data,
×
224
            filename: filename,
×
225
            format: format,
×
226
            lastmodTime: lastmodTime,
×
227
            byteCount: byteCount,
×
228
            description: description
×
229
        )
×
230
    }
×
231
}
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