Skip to content

Commit d8014ca

Browse files
author
Fernando Fernandes
committed
Upgrade Swift Tools version (5.1)
- Migrate Package files to Xcode 11. - Remove images from project (in favor of Imgur).
1 parent ef2a30f commit d8014ca

File tree

10 files changed

+53
-32
lines changed

10 files changed

+53
-32
lines changed

.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>IDEDidComputeMac32BitWarning</key>
6+
<true/>
7+
</dict>
8+
</plist>

AESCryptable.XcodeSPM.gif

-658 KB
Binary file not shown.

AESCryptable.playground.gif

-260 KB
Binary file not shown.

Package.swift

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
1-
// swift-tools-version:5.0
1+
// swift-tools-version:5.1
22

33
import PackageDescription
44

55
let package = Package(
66
name: "AESCryptable",
77
products: [
8-
.library(name: "AESCryptable", targets: ["AESCryptable"]),
8+
.library(
9+
name: "AESCryptable",
10+
targets: ["AESCryptable"]),
911
],
1012
dependencies: [],
1113
targets: [
12-
.target(name: "AESCryptable", dependencies: []),
13-
.testTarget(name: "AESCryptableTests",dependencies: ["AESCryptable"]),
14+
.target(
15+
name: "AESCryptable",
16+
dependencies: []),
17+
.testTarget(
18+
name: "AESCryptableTests",
19+
dependencies: ["AESCryptable"]),
1420
]
1521
)

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Provides [`Advanced Encryption Standard (AES)`](https://en.wikipedia.org/wiki/Ad
1313

1414
## Integration
1515
### Xcode 11+
16-
![AESCryptable Xcode 11 SPM](https://github.com/backslash-f/aescryptable/blob/master/AESCryptable.XcodeSPM.gif)
16+
![AESCryptable Xcode 11 SPM](https://i.imgur.com/JKciz5T.gif)
1717

1818
More from WWDC 2019:
1919
[Adopting Swift Packages in Xcode](https://developer.apple.com/videos/play/wwdc2019/408/)
@@ -59,4 +59,4 @@ do {
5959
## Demo
6060
Clone the repo and use `AESCryptable.playground` to see the code in action:
6161

62-
![AESCryptable Demo](https://github.com/backslash-f/aescryptable/blob/master/AESCryptable.playground.gif)
62+
![AESCryptable Demo](https://i.imgur.com/6cI5Knu.gif)

Sources/AESCryptable/AES.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ import CommonCrypto
1919
///
2020
/// Interesting reading: [Differences between DES and AES](http://bit.ly/desVSaes)
2121
public struct AES {
22-
22+
2323
// MARK: - Internal Properties
2424

2525
// MARK: Key Related
26-
26+
2727
public let key: Data
2828

2929
// MARK: CCCrypt Related
@@ -41,7 +41,7 @@ public struct AES {
4141
/// - Parameter keyString: 256 bit AES key size.
4242
/// - Throws: `AESError`
4343
public init(keyString: String) throws {
44-
44+
4545
guard keyString.count == kCCKeySizeAES256 else {
4646
throw AES.Error.invalidKeySize
4747
}

Sources/AESCryptable/AESCryptable.swift

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,26 @@ extension AES: Cryptable {
1616
// MARK: - Encrypt
1717

1818
public func encrypt(_ string: String) throws -> Data {
19-
19+
2020
let dataToEncrypt: Data = Data(string.utf8)
21-
21+
2222
let bufferSize: Int = ivSize + dataToEncrypt.count + kCCBlockSizeAES128
2323
var buffer = Data(count: bufferSize)
2424
try generateRandomIV(for: &buffer)
25-
25+
2626
var numberBytesEncrypted: Int = 0
27-
27+
2828
do {
2929
try key.withUnsafeBytes { keyBytes in
3030
try dataToEncrypt.withUnsafeBytes { dataToEncryptBytes in
3131
try buffer.withUnsafeMutableBytes { bufferBytes in
32-
32+
3333
guard let keyBytesBaseAddress = keyBytes.baseAddress,
3434
let dataToEncryptBytesBaseAddress = dataToEncryptBytes.baseAddress,
3535
let bufferBytesBaseAddress = bufferBytes.baseAddress else {
3636
throw Error.encryptionFailed
3737
}
38-
38+
3939
let cryptStatus: CCCryptorStatus = CCCrypt( // Stateless, one-shot encrypt operation
4040
CCOperation(kCCEncrypt), // op: CCOperation
4141
CCAlgorithm(kCCAlgorithmAES), // alg: CCAlgorithm
@@ -49,7 +49,7 @@ extension AES: Cryptable {
4949
bufferSize, // dataOutAvailable: encrypted Data buffer size
5050
&numberBytesEncrypted // dataOutMoved: the number of bytes written
5151
)
52-
52+
5353
guard cryptStatus == CCCryptorStatus(kCCSuccess) else {
5454
throw Error.encryptionFailed
5555
}
@@ -59,31 +59,31 @@ extension AES: Cryptable {
5959
} catch {
6060
throw Error.encryptionFailed
6161
}
62-
62+
6363
let encryptedData: Data = buffer[..<(numberBytesEncrypted + ivSize)]
6464
return encryptedData
6565
}
6666

6767
// MARK: - Decrypt
6868

6969
public func decrypt(_ data: Data) throws -> String {
70-
70+
7171
let bufferSize: Int = data.count - ivSize
7272
var buffer = Data(count: bufferSize)
73-
73+
7474
var numberBytesDecrypted: Int = 0
75-
75+
7676
do {
7777
try key.withUnsafeBytes { keyBytes in
7878
try data.withUnsafeBytes { dataToDecryptBytes in
7979
try buffer.withUnsafeMutableBytes { bufferBytes in
80-
80+
8181
guard let keyBytesBaseAddress = keyBytes.baseAddress,
8282
let dataToDecryptBytesBaseAddress = dataToDecryptBytes.baseAddress,
8383
let bufferBytesBaseAddress = bufferBytes.baseAddress else {
8484
throw Error.encryptionFailed
8585
}
86-
86+
8787
let cryptStatus: CCCryptorStatus = CCCrypt( // Stateless, one-shot encrypt operation
8888
CCOperation(kCCDecrypt), // op: CCOperation
8989
CCAlgorithm(kCCAlgorithmAES128), // alg: CCAlgorithm
@@ -97,7 +97,7 @@ extension AES: Cryptable {
9797
bufferSize, // dataOutAvailable: decrypted Data buffer size
9898
&numberBytesDecrypted // dataOutMoved: the number of bytes written
9999
)
100-
100+
101101
guard cryptStatus == CCCryptorStatus(kCCSuccess) else {
102102
throw Error.decryptionFailed
103103
}
@@ -107,13 +107,13 @@ extension AES: Cryptable {
107107
} catch {
108108
throw Error.encryptionFailed
109109
}
110-
110+
111111
let decryptedData: Data = buffer[..<numberBytesDecrypted]
112-
112+
113113
guard let decryptedString = String(data: decryptedData, encoding: .utf8) else {
114114
throw Error.dataToStringFailed
115115
}
116-
116+
117117
return decryptedString
118118
}
119119
}

Sources/AESCryptable/AESExtension.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,26 +35,26 @@ public extension AES {
3535
// MARK: - Internal Extension
3636

3737
internal extension AES {
38-
38+
3939
/// Generates an `Initialization Vector` with random data for the `Cipher Block Chaining (CBC)` mode with
4040
/// block size `kCCBlockSizeAES128` and append it to the give `Data`.
4141
///
4242
/// - Parameter data: The `Data` in which the generated `iv` will be attached into.
4343
/// - Throws: `AESError`
4444
func generateRandomIV(for data: inout Data) throws {
45-
45+
4646
try data.withUnsafeMutableBytes { dataBytes in
47-
47+
4848
guard let dataBytesBaseAddress = dataBytes.baseAddress else {
4949
throw Error.generateRandomIVFailed
5050
}
51-
51+
5252
let status: Int32 = SecRandomCopyBytes(
5353
kSecRandomDefault,
5454
kCCBlockSizeAES128,
5555
dataBytesBaseAddress
5656
)
57-
57+
5858
guard status == 0 else {
5959
throw Error.generateRandomIVFailed
6060
}

Sources/AESCryptable/CryptableProtocol.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import Foundation
1010

1111
/// Conform to this protocol to implement and provide encryption / decryption capabilities.
1212
protocol Cryptable {
13-
13+
1414
/// Encrypts the given `String` and returns it as `Data`.
1515
///
1616
/// - Parameter string: The information to be encrypted.

0 commit comments

Comments
 (0)