Skip to content

Commit a6ab2d0

Browse files
committed
Don't use deprecated Data(bytes:
1 parent bf9acad commit a6ab2d0

File tree

7 files changed

+23
-23
lines changed

7 files changed

+23
-23
lines changed

CryptoSwift.playground/Contents.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import Foundation
88
/*:
99
# Data types conversinn
1010
*/
11-
let data = Data(bytes: [0x01, 0x02, 0x03])
11+
let data = Data([0x01, 0x02, 0x03])
1212
let bytes = data.bytes
1313
let bytesHex = Array<UInt8>(hex: "0x010203")
1414
let hexString = bytesHex.toHexString()
@@ -138,7 +138,7 @@ do {
138138
var encryptor = try! aes.makeEncryptor()
139139

140140
// prepare streams
141-
let data = Data(bytes: (0 ..< 100).map { $0 })
141+
let data = Data( (0 ..< 100).map { $0 })
142142
let inputStream = InputStream(data: data)
143143
let outputStream = OutputStream(toMemory: ())
144144
inputStream.open()

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ For you convenience **CryptoSwift** provides two functions to easily convert arr
222222
Data from bytes:
223223

224224
```swift
225-
let data = Data(bytes: [0x01, 0x02, 0x03])
225+
let data = Data( [0x01, 0x02, 0x03])
226226
```
227227

228228
`Data` to `Array<UInt8>`
@@ -261,7 +261,7 @@ let digest = Digest.md5(bytes)
261261
```
262262

263263
```swift
264-
let data = Data(bytes: [0x01, 0x02, 0x03])
264+
let data = Data( [0x01, 0x02, 0x03])
265265

266266
let hash = data.md5()
267267
let hash = data.sha1()
@@ -434,7 +434,7 @@ let encrypted: Array<UInt8> = try! AES(key: Array("secret0key000000".utf8), bloc
434434
Using convenience extensions
435435

436436
```swift
437-
let plain = Data(bytes: [0x01, 0x02, 0x03])
437+
let plain = Data( [0x01, 0x02, 0x03])
438438
let encrypted = try! plain.encrypt(ChaCha20(key: key, iv: iv))
439439
let decrypted = try! encrypted.decrypt(ChaCha20(key: key, iv: iv))
440440
```

Sources/CryptoSwift/Foundation/Array+Foundation.swift

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

1818
public extension Array where Element == UInt8 {
1919
func toBase64() -> String? {
20-
return Data(bytes: self).base64EncodedString()
20+
return Data( self).base64EncodedString()
2121
}
2222

2323
init(base64: String) {

Sources/CryptoSwift/Foundation/Data+Extension.swift

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,55 +28,55 @@ extension Data {
2828
}
2929

3030
public func md5() -> Data {
31-
return Data(bytes: Digest.md5(bytes))
31+
return Data( Digest.md5(bytes))
3232
}
3333

3434
public func sha1() -> Data {
35-
return Data(bytes: Digest.sha1(bytes))
35+
return Data( Digest.sha1(bytes))
3636
}
3737

3838
public func sha224() -> Data {
39-
return Data(bytes: Digest.sha224(bytes))
39+
return Data( Digest.sha224(bytes))
4040
}
4141

4242
public func sha256() -> Data {
43-
return Data(bytes: Digest.sha256(bytes))
43+
return Data( Digest.sha256(bytes))
4444
}
4545

4646
public func sha384() -> Data {
47-
return Data(bytes: Digest.sha384(bytes))
47+
return Data( Digest.sha384(bytes))
4848
}
4949

5050
public func sha512() -> Data {
51-
return Data(bytes: Digest.sha512(bytes))
51+
return Data( Digest.sha512(bytes))
5252
}
5353

5454
public func sha3(_ variant: SHA3.Variant) -> Data {
55-
return Data(bytes: Digest.sha3(bytes, variant: variant))
55+
return Data( Digest.sha3(bytes, variant: variant))
5656
}
5757

5858
public func crc32(seed: UInt32? = nil, reflect: Bool = true) -> Data {
59-
return Data(bytes: Checksum.crc32(bytes, seed: seed, reflect: reflect).bytes())
59+
return Data( Checksum.crc32(bytes, seed: seed, reflect: reflect).bytes())
6060
}
6161

6262
public func crc32c(seed: UInt32? = nil, reflect: Bool = true) -> Data {
63-
return Data(bytes: Checksum.crc32c(bytes, seed: seed, reflect: reflect).bytes())
63+
return Data( Checksum.crc32c(bytes, seed: seed, reflect: reflect).bytes())
6464
}
6565

6666
public func crc16(seed: UInt16? = nil) -> Data {
67-
return Data(bytes: Checksum.crc16(bytes, seed: seed).bytes())
67+
return Data( Checksum.crc16(bytes, seed: seed).bytes())
6868
}
6969

7070
public func encrypt(cipher: Cipher) throws -> Data {
71-
return Data(bytes: try cipher.encrypt(bytes.slice))
71+
return Data( try cipher.encrypt(bytes.slice))
7272
}
7373

7474
public func decrypt(cipher: Cipher) throws -> Data {
75-
return Data(bytes: try cipher.decrypt(bytes.slice))
75+
return Data( try cipher.decrypt(bytes.slice))
7676
}
7777

7878
public func authenticate(with authenticator: Authenticator) throws -> Data {
79-
return Data(bytes: try authenticator.authenticate(bytes))
79+
return Data( try authenticator.authenticate(bytes))
8080
}
8181
}
8282

Tests/Tests/Access.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ class Access: XCTestCase {
129129
}
130130

131131
func testDataExtension() {
132-
let data = Data(bytes: [1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8])
132+
let data = Data( [1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8])
133133
_ = data.checksum()
134134
_ = data.md5()
135135
_ = data.sha1()

Tests/Tests/ExtensionsTest.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ final class ExtensionsTest: XCTestCase {
4141
}
4242

4343
func testDataInit() {
44-
let data = Data(bytes: [0x01, 0x02, 0x03])
44+
let data = Data( [0x01, 0x02, 0x03])
4545
XCTAssert(data.count == 3, "Invalid data")
4646
}
4747

Tests/Tests/Poly1305Tests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ final class Poly1305Tests: XCTestCase {
2626
XCTAssertEqual(try Poly1305(key: key).authenticate(msg), expectedMac)
2727

2828
// extensions
29-
let msgData = Data(bytes: msg)
30-
XCTAssertEqual(try msgData.authenticate(with: Poly1305(key: key)), Data(bytes: expectedMac), "Invalid authentication result")
29+
let msgData = Data( msg)
30+
XCTAssertEqual(try msgData.authenticate(with: Poly1305(key: key)), Data( expectedMac), "Invalid authentication result")
3131
}
3232

3333
// https://github.com/krzyzanowskim/CryptoSwift/issues/183

0 commit comments

Comments
 (0)