Skip to content

Commit fab0d54

Browse files
author
Bill Abt
committed
Formatting changes for consistency. No functional changes.
1 parent 23a88ce commit fab0d54

File tree

5 files changed

+179
-171
lines changed

5 files changed

+179
-171
lines changed

Sources/Crypto.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,11 @@ extension String: CryptoDigest {
116116
/// - Returns: A hex string of the calculated digest
117117
///
118118
public func digest(using algorithm: Digest.Algorithm) -> String {
119+
119120
// This force unwrap may look scary but for CommonCrypto this cannot fail.
120121
// The API allows for optionals to support the OpenSSL implementation which can.
121122
let result = (Digest(using: algorithm).update(string: self as String)?.final())!
122123
return CryptoUtils.hexString(from: result)
124+
123125
}
124126
}

Sources/HMAC.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ public class HMAC : Updateable {
105105
return EVP_sha512()
106106
}
107107
}
108+
108109
#endif
109110

110111
///
@@ -147,16 +148,21 @@ public class HMAC : Updateable {
147148
case .sha512:
148149
return Int(SHA512_DIGEST_LENGTH)
149150
}
151+
150152
#endif
151153

152154
}
153155
}
154156

155157
/// Context
156158
#if os(OSX)
159+
157160
typealias Context = UnsafeMutablePointer<CCHmacContext>
161+
158162
#elseif os(Linux)
163+
159164
typealias Context = UnsafeMutablePointer<HMAC_CTX>
165+
160166
#endif
161167

162168
/// Status of the calculation

Sources/Status.swift

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -63,23 +63,23 @@ public enum Status: CCCryptorStatus, ErrorProtocol, CustomStringConvertible {
6363

6464
switch self {
6565

66-
case success:
66+
case .success:
6767
return CCCryptorStatus(kCCSuccess)
68-
case paramError:
68+
case .paramError:
6969
return CCCryptorStatus(kCCParamError)
70-
case bufferTooSmall:
70+
case .bufferTooSmall:
7171
return CCCryptorStatus(kCCBufferTooSmall)
72-
case memoryFailure:
72+
case .memoryFailure:
7373
return CCCryptorStatus(kCCMemoryFailure)
74-
case alignmentError:
74+
case .alignmentError:
7575
return CCCryptorStatus(kCCAlignmentError)
76-
case decodeError:
76+
case .decodeError:
7777
return CCCryptorStatus(kCCDecodeError)
78-
case unimplemented:
78+
case .unimplemented:
7979
return CCCryptorStatus(kCCUnimplemented)
80-
case overflow:
80+
case .overflow:
8181
return CCCryptorStatus(kCCOverflow)
82-
case rngFailure:
82+
case .rngFailure:
8383
return CCCryptorStatus(kCCRNGFailure)
8484
}
8585
}
@@ -212,14 +212,14 @@ public enum Status: ErrorProtocol, CustomStringConvertible {
212212

213213
// MARK: Operators
214214

215-
func == (left: Status, right: Status) -> Bool {
215+
func == (lhs: Status, rhs: Status) -> Bool {
216216

217-
return left.code == right.code
217+
return lhs.code == rhs.code
218218
}
219219

220-
func != (left: Status, right: Status) -> Bool {
220+
func != (lhs: Status, rhs: Status) -> Bool {
221221

222-
return left.code != right.code
222+
return lhs.code != rhs.code
223223
}
224224

225225
#endif

Sources/StreamCryptor.swift

Lines changed: 110 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -213,46 +213,46 @@ public class StreamCryptor {
213213

214214
#if os(OSX)
215215

216-
/// Advanced Encryption Standard
217-
/// - Note: aes and aes128 are equivalent.
218-
case aes, aes128, aes192, aes256
219-
220-
/// Data Encryption Standard
221-
case des
222-
223-
/// Triple des
224-
case tripleDes
225-
226-
/// cast
227-
case cast
228-
229-
/// rc2
230-
case rc2
231-
232-
/// blowfish
233-
case blowfish
216+
/// Advanced Encryption Standard
217+
/// - Note: aes and aes128 are equivalent.
218+
case aes, aes128, aes192, aes256
219+
220+
/// Data Encryption Standard
221+
case des
222+
223+
/// Triple des
224+
case tripleDes
225+
226+
/// cast
227+
case cast
228+
229+
/// rc2
230+
case rc2
231+
232+
/// blowfish
233+
case blowfish
234234

235235
#elseif os(Linux)
236236

237-
/// Advanced Encryption Standard
238-
/// - Note: aes and aes128 are equivalent.
239-
case aes, aes128, aes192, aes256
240-
241-
/// Data Encryption Standard
242-
case des
243-
244-
/// Triple des
245-
case tripleDes
246-
247-
/// cast
248-
case cast
249-
250-
/// rc2
251-
case rc2
252-
253-
/// blowfish
254-
case blowfish
255-
237+
/// Advanced Encryption Standard
238+
/// - Note: aes and aes128 are equivalent.
239+
case aes, aes128, aes192, aes256
240+
241+
/// Data Encryption Standard
242+
case des
243+
244+
/// Triple des
245+
case tripleDes
246+
247+
/// cast
248+
case cast
249+
250+
/// rc2
251+
case rc2
252+
253+
/// blowfish
254+
case blowfish
255+
256256
#endif
257257

258258
/// Blocksize, in bytes, of algorithm.
@@ -312,99 +312,99 @@ public class StreamCryptor {
312312

313313
#if os(OSX)
314314

315-
/// Native, CommonCrypto constant for algorithm.
316-
func nativeValue() -> CCAlgorithm {
317-
318-
switch self {
319-
320-
case .aes, .aes128, .aes192, .aes256:
321-
return CCAlgorithm(kCCAlgorithmAES)
322-
323-
case .des:
324-
return CCAlgorithm(kCCAlgorithmDES)
325-
326-
case .tripleDes:
327-
return CCAlgorithm(kCCAlgorithm3DES)
328-
329-
case .cast:
330-
return CCAlgorithm(kCCAlgorithmCAST)
331-
332-
case .rc2:
333-
return CCAlgorithm(kCCAlgorithmRC2)
315+
/// Native, CommonCrypto constant for algorithm.
316+
func nativeValue() -> CCAlgorithm {
334317

335-
case .blowfish:
336-
return CCAlgorithm(kCCAlgorithmBlowfish)
337-
}
338-
}
339-
340-
#elseif os(Linux)
341-
342-
/// Native, OpenSSL function for algorithm.
343-
func nativeValue(options: Options) -> UnsafePointer<EVP_CIPHER> {
344-
345-
if options == .pkcs7Padding || options == .none {
346-
347318
switch self {
348319

349-
case .aes, .aes128:
350-
return EVP_aes_128_cbc()
351-
352-
case .aes192:
353-
return EVP_aes_192_cbc()
354-
355-
case .aes256:
356-
return EVP_aes_256_cbc()
320+
case .aes, .aes128, .aes192, .aes256:
321+
return CCAlgorithm(kCCAlgorithmAES)
357322

358323
case .des:
359-
return EVP_des_cbc()
324+
return CCAlgorithm(kCCAlgorithmDES)
360325

361326
case .tripleDes:
362-
return EVP_des_ede3_cbc()
327+
return CCAlgorithm(kCCAlgorithm3DES)
363328

364329
case .cast:
365-
return EVP_cast5_cbc()
330+
return CCAlgorithm(kCCAlgorithmCAST)
366331

367332
case .rc2:
368-
return EVP_rc2_cbc()
333+
return CCAlgorithm(kCCAlgorithmRC2)
369334

370335
case .blowfish:
371-
return EVP_bf_cbc()
336+
return CCAlgorithm(kCCAlgorithmBlowfish)
372337
}
373338
}
374339

375-
if options == .ecbMode {
376-
377-
switch self {
378-
379-
case .aes, .aes128:
380-
return EVP_aes_128_ecb()
381-
382-
case .aes192:
383-
return EVP_aes_192_ecb()
340+
#elseif os(Linux)
384341

385-
case .aes256:
386-
return EVP_aes_256_ecb()
387-
388-
case .des:
389-
return EVP_des_ecb()
390-
391-
case .tripleDes:
392-
return EVP_des_ede3_ecb()
393-
394-
case .cast:
395-
return EVP_cast5_ecb()
396-
397-
case .rc2:
398-
return EVP_rc2_ecb()
342+
/// Native, OpenSSL function for algorithm.
343+
func nativeValue(options: Options) -> UnsafePointer<EVP_CIPHER> {
344+
345+
if options == .pkcs7Padding || options == .none {
346+
347+
switch self {
348+
349+
case .aes, .aes128:
350+
return EVP_aes_128_cbc()
351+
352+
case .aes192:
353+
return EVP_aes_192_cbc()
354+
355+
case .aes256:
356+
return EVP_aes_256_cbc()
357+
358+
case .des:
359+
return EVP_des_cbc()
360+
361+
case .tripleDes:
362+
return EVP_des_ede3_cbc()
363+
364+
case .cast:
365+
return EVP_cast5_cbc()
366+
367+
case .rc2:
368+
return EVP_rc2_cbc()
369+
370+
case .blowfish:
371+
return EVP_bf_cbc()
372+
}
373+
}
374+
375+
if options == .ecbMode {
399376

400-
case .blowfish:
401-
return EVP_bf_ecb()
377+
switch self {
378+
379+
case .aes, .aes128:
380+
return EVP_aes_128_ecb()
381+
382+
case .aes192:
383+
return EVP_aes_192_ecb()
384+
385+
case .aes256:
386+
return EVP_aes_256_ecb()
387+
388+
case .des:
389+
return EVP_des_ecb()
390+
391+
case .tripleDes:
392+
return EVP_des_ede3_ecb()
393+
394+
case .cast:
395+
return EVP_cast5_ecb()
396+
397+
case .rc2:
398+
return EVP_rc2_ecb()
399+
400+
case .blowfish:
401+
return EVP_bf_ecb()
402+
}
402403
}
404+
405+
fatalError("Unsupported options and/or algorithm.")
403406
}
404-
405-
fatalError("Unsupported options and/or algorithm.")
406-
}
407-
407+
408408
#endif
409409

410410
///

0 commit comments

Comments
 (0)