Skip to content

Commit 28c7f88

Browse files
authored
Merge pull request #1 from vmaraccini/whitespace-normalization
Whitespace normalization
2 parents 394b406 + a30c4ab commit 28c7f88

File tree

5 files changed

+70
-130
lines changed

5 files changed

+70
-130
lines changed

ASN1Decoder/ASN1Decoder.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,3 @@ FOUNDATION_EXPORT const unsigned char ASN1DecoderVersionString[];
1616

1717
// In this header, you should import all the public headers of your framework using statements like #import <ASN1Decoder/PublicHeader.h>
1818

19-

ASN1Decoder/ASN1Identifier.swift

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,13 @@ import Foundation
2525

2626

2727
public class ASN1Identifier : CustomStringConvertible {
28-
2928
public enum Class : UInt8 {
3029
case universal = 0x00
3130
case application = 0x40
3231
case contextSpecific = 0x80
3332
case `private` = 0xC0
3433
}
35-
34+
3635
public enum TagNumber: UInt8 {
3736
case endOfContent = 0x00
3837
case boolean = 0x01
@@ -64,15 +63,13 @@ public class ASN1Identifier : CustomStringConvertible {
6463
case characterString = 0x1D
6564
case bmpString = 0x1E
6665
}
67-
66+
6867
var rawValue: UInt8
69-
70-
68+
7169
init(rawValue: UInt8) {
7270
self.rawValue = rawValue
7371
}
74-
75-
72+
7673
public func typeClass() -> Class {
7774
for tc in [Class.application, Class.contextSpecific, Class.private] {
7875
if (rawValue & tc.rawValue) == tc.rawValue {
@@ -81,18 +78,18 @@ public class ASN1Identifier : CustomStringConvertible {
8178
}
8279
return .universal
8380
}
84-
81+
8582
public func isPrimitive() -> Bool {
8683
return (rawValue & 0x20) == 0
8784
}
8885
public func isConstructed() -> Bool {
8986
return (rawValue & 0x20) != 0
9087
}
91-
88+
9289
public func tagNumber() -> TagNumber {
9390
return TagNumber(rawValue: rawValue & 0x1F) ?? .endOfContent
9491
}
95-
92+
9693
public var description: String {
9794
if typeClass() == .universal {
9895
return String(describing: tagNumber())
@@ -102,4 +99,3 @@ public class ASN1Identifier : CustomStringConvertible {
10299
}
103100
}
104101
}
105-

ASN1Decoder/ASN1Object.swift

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,39 +21,32 @@
2121
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2222
// SOFTWARE.
2323

24-
2524
import Foundation
2625

27-
2826
public class ASN1Object : CustomStringConvertible {
29-
30-
init() {
31-
}
32-
3327
/// This property contains the DER encoded object
3428
public var rawValue: Data?
35-
29+
3630
/// This property contains the decoded Swift object whenever is possible
3731
public var value: Any?
38-
39-
32+
4033
public var identifier: ASN1Identifier?
41-
34+
4235
var sub: [ASN1Object]?
43-
36+
4437
weak var parent: ASN1Object?
45-
38+
4639
public func sub(_ index: Int) -> ASN1Object? {
4740
if let sub = self.sub, index >= 0 && index < sub.count {
4841
return sub[index]
4942
}
5043
return nil
5144
}
52-
45+
5346
public func subCount() -> Int {
5447
return sub?.count ?? 0
5548
}
56-
49+
5750
public func findOid(_ oid: String) -> ASN1Object? {
5851
for child in sub ?? [] {
5952
if child.identifier?.tagNumber() == .objectIdentifier {
@@ -68,11 +61,11 @@ public class ASN1Object : CustomStringConvertible {
6861
}
6962
return nil
7063
}
71-
64+
7265
public var description: String {
7366
return printAsn1()
7467
}
75-
68+
7669
fileprivate func printAsn1(insets: String = "") -> String {
7770
var output = insets
7871
output.append(identifier?.description.uppercased() ?? "")
@@ -90,8 +83,8 @@ public class ASN1Object : CustomStringConvertible {
9083
output.append(sub != nil && sub!.count > 0 ? insets + "}\n" : "")
9184
return output
9285
}
93-
94-
86+
87+
9588
static let oidDecodeMap:[String:String] = [
9689
"0.4.0.1862.1.1" : "etsiQcsCompliance",
9790
"0.4.0.1862.1.3" : "etsiQcsRetentionPeriod",
@@ -152,8 +145,4 @@ public class ASN1Object : CustomStringConvertible {
152145
"2.5.4.8" : "stateOrProvinceName",
153146
"2.5.4.9" : "streetAddress"
154147
]
155-
156-
157148
}
158-
159-

ASN1Decoder/Asn1Decoder.swift

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -222,18 +222,18 @@ public class ASN1DERDecoder {
222222
}
223223
return Data(bytes: byteArray)
224224
}
225-
225+
226226
// Decode DER OID bytes to String with dot notation
227227
private static func decodeOid(contentData: inout Data) -> String {
228228
if contentData.isEmpty {
229229
return ""
230230
}
231-
231+
232232
var oid: String = ""
233-
233+
234234
let first = Int(contentData.remove(at: 0))
235235
oid.append("\(first / 40).\(first % 40)")
236-
236+
237237
var t = 0
238238
while contentData.count > 0 {
239239
let n = Int(contentData.remove(at: 0))
@@ -246,7 +246,6 @@ public class ASN1DERDecoder {
246246
return oid
247247
}
248248

249-
250249
private static func dateFormatter(contentData: inout Data, formats: [String]) -> Date? {
251250
if let str = String(data: contentData, encoding: .utf8) {
252251
for format in formats {
@@ -262,31 +261,22 @@ public class ASN1DERDecoder {
262261
}
263262
}
264263

265-
266-
267264
enum ASN1Error: Error {
268265
case parseError
269266
case outOfBuffer
270267
}
271268

272-
273-
274269
extension Data {
275-
276270
func toIntValue() -> UInt64? {
277-
278271
if self.count > 8 { // check if suitable for UInt64
279272
return nil
280273
}
281-
274+
282275
var value: UInt64 = 0
283-
284276
for (i,b) in self.enumerated() {
285277
let v = UInt64(b) << UInt64(8*(count-i-1))
286278
value += v
287279
}
288-
289280
return value
290281
}
291-
292282
}

0 commit comments

Comments
 (0)