瀏覽代碼

Don't use deprecated Data(bytes:

Marcin Krzyzanowski 6 年之前
父節點
當前提交
a6ab2d09e0

+ 2 - 2
CryptoSwift.playground/Contents.swift

@@ -8,7 +8,7 @@ import Foundation
 /*:
  # Data types conversinn
  */
-let data = Data(bytes: [0x01, 0x02, 0x03])
+let data = Data([0x01, 0x02, 0x03])
 let bytes = data.bytes
 let bytesHex = Array<UInt8>(hex: "0x010203")
 let hexString = bytesHex.toHexString()
@@ -138,7 +138,7 @@ do {
     var encryptor = try! aes.makeEncryptor()
 
     // prepare streams
-    let data = Data(bytes: (0 ..< 100).map { $0 })
+    let data = Data( (0 ..< 100).map { $0 })
     let inputStream = InputStream(data: data)
     let outputStream = OutputStream(toMemory: ())
     inputStream.open()

+ 3 - 3
README.md

@@ -222,7 +222,7 @@ For you convenience **CryptoSwift** provides two functions to easily convert arr
 Data from bytes:
 
 ```swift
-let data = Data(bytes: [0x01, 0x02, 0x03])
+let data = Data( [0x01, 0x02, 0x03])
 ```
 
 `Data` to `Array<UInt8>`
@@ -261,7 +261,7 @@ let digest = Digest.md5(bytes)
 ```
 
 ```swift
-let data = Data(bytes: [0x01, 0x02, 0x03])
+let data = Data( [0x01, 0x02, 0x03])
 
 let hash = data.md5()
 let hash = data.sha1()
@@ -434,7 +434,7 @@ let encrypted: Array<UInt8> = try! AES(key: Array("secret0key000000".utf8), bloc
 Using convenience extensions
     
 ```swift
-let plain = Data(bytes: [0x01, 0x02, 0x03])
+let plain = Data( [0x01, 0x02, 0x03])
 let encrypted = try! plain.encrypt(ChaCha20(key: key, iv: iv))
 let decrypted = try! encrypted.decrypt(ChaCha20(key: key, iv: iv))
 ```

+ 1 - 1
Sources/CryptoSwift/Foundation/Array+Foundation.swift

@@ -17,7 +17,7 @@ import Foundation
 
 public extension Array where Element == UInt8 {
     func toBase64() -> String? {
-        return Data(bytes: self).base64EncodedString()
+        return Data( self).base64EncodedString()
     }
 
     init(base64: String) {

+ 13 - 13
Sources/CryptoSwift/Foundation/Data+Extension.swift

@@ -28,55 +28,55 @@ extension Data {
     }
 
     public func md5() -> Data {
-        return Data(bytes: Digest.md5(bytes))
+        return Data( Digest.md5(bytes))
     }
 
     public func sha1() -> Data {
-        return Data(bytes: Digest.sha1(bytes))
+        return Data( Digest.sha1(bytes))
     }
 
     public func sha224() -> Data {
-        return Data(bytes: Digest.sha224(bytes))
+        return Data( Digest.sha224(bytes))
     }
 
     public func sha256() -> Data {
-        return Data(bytes: Digest.sha256(bytes))
+        return Data( Digest.sha256(bytes))
     }
 
     public func sha384() -> Data {
-        return Data(bytes: Digest.sha384(bytes))
+        return Data( Digest.sha384(bytes))
     }
 
     public func sha512() -> Data {
-        return Data(bytes: Digest.sha512(bytes))
+        return Data( Digest.sha512(bytes))
     }
 
     public func sha3(_ variant: SHA3.Variant) -> Data {
-        return Data(bytes: Digest.sha3(bytes, variant: variant))
+        return Data( Digest.sha3(bytes, variant: variant))
     }
 
     public func crc32(seed: UInt32? = nil, reflect: Bool = true) -> Data {
-        return Data(bytes: Checksum.crc32(bytes, seed: seed, reflect: reflect).bytes())
+        return Data( Checksum.crc32(bytes, seed: seed, reflect: reflect).bytes())
     }
 
     public func crc32c(seed: UInt32? = nil, reflect: Bool = true) -> Data {
-        return Data(bytes: Checksum.crc32c(bytes, seed: seed, reflect: reflect).bytes())
+        return Data( Checksum.crc32c(bytes, seed: seed, reflect: reflect).bytes())
     }
 
     public func crc16(seed: UInt16? = nil) -> Data {
-        return Data(bytes: Checksum.crc16(bytes, seed: seed).bytes())
+        return Data( Checksum.crc16(bytes, seed: seed).bytes())
     }
 
     public func encrypt(cipher: Cipher) throws -> Data {
-        return Data(bytes: try cipher.encrypt(bytes.slice))
+        return Data( try cipher.encrypt(bytes.slice))
     }
 
     public func decrypt(cipher: Cipher) throws -> Data {
-        return Data(bytes: try cipher.decrypt(bytes.slice))
+        return Data( try cipher.decrypt(bytes.slice))
     }
 
     public func authenticate(with authenticator: Authenticator) throws -> Data {
-        return Data(bytes: try authenticator.authenticate(bytes))
+        return Data( try authenticator.authenticate(bytes))
     }
 }
 

+ 1 - 1
Tests/Tests/Access.swift

@@ -129,7 +129,7 @@ class Access: XCTestCase {
     }
 
     func testDataExtension() {
-        let data = Data(bytes: [1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8])
+        let data = Data( [1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8])
         _ = data.checksum()
         _ = data.md5()
         _ = data.sha1()

+ 1 - 1
Tests/Tests/ExtensionsTest.swift

@@ -41,7 +41,7 @@ final class ExtensionsTest: XCTestCase {
     }
 
     func testDataInit() {
-        let data = Data(bytes: [0x01, 0x02, 0x03])
+        let data = Data( [0x01, 0x02, 0x03])
         XCTAssert(data.count == 3, "Invalid data")
     }
 

+ 2 - 2
Tests/Tests/Poly1305Tests.swift

@@ -26,8 +26,8 @@ final class Poly1305Tests: XCTestCase {
         XCTAssertEqual(try Poly1305(key: key).authenticate(msg), expectedMac)
 
         // extensions
-        let msgData = Data(bytes: msg)
-        XCTAssertEqual(try msgData.authenticate(with: Poly1305(key: key)), Data(bytes: expectedMac), "Invalid authentication result")
+        let msgData = Data( msg)
+        XCTAssertEqual(try msgData.authenticate(with: Poly1305(key: key)), Data( expectedMac), "Invalid authentication result")
     }
 
     // https://github.com/krzyzanowskim/CryptoSwift/issues/183