Преглед на файлове

Get rid of CSArrayType hack

Marcin Krzyżanowski преди 8 години
родител
ревизия
47eefd0f62

+ 11 - 8
CryptoSwift.xcodeproj/project.pbxproj

@@ -45,13 +45,13 @@
 		75EC528F1EE8B81A0048EB3B /* Cipher.swift in Sources */ = {isa = PBXBuildFile; fileRef = 75EC524C1EE8B6CA0048EB3B /* Cipher.swift */; };
 		75EC52901EE8B81A0048EB3B /* Collection+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 75EC524D1EE8B6CA0048EB3B /* Collection+Extension.swift */; };
 		75EC52911EE8B81A0048EB3B /* Cryptors.swift in Sources */ = {isa = PBXBuildFile; fileRef = 75EC524E1EE8B6CA0048EB3B /* Cryptors.swift */; };
-		75EC52921EE8B81A0048EB3B /* CSArrayType+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 75EC524F1EE8B6CA0048EB3B /* CSArrayType+Extensions.swift */; };
+		75EC52921EE8B81A0048EB3B /* Array+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 75EC524F1EE8B6CA0048EB3B /* Array+Extensions.swift */; };
 		75EC52931EE8B81A0048EB3B /* Digest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 75EC52501EE8B6CA0048EB3B /* Digest.swift */; };
 		75EC52941EE8B81A0048EB3B /* DigestType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 75EC52511EE8B6CA0048EB3B /* DigestType.swift */; };
 		75EC52951EE8B8200048EB3B /* AES+Foundation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 75EC52531EE8B6CA0048EB3B /* AES+Foundation.swift */; };
 		75EC52961EE8B8200048EB3B /* Blowfish+Foundation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 75EC52541EE8B6CA0048EB3B /* Blowfish+Foundation.swift */; };
 		75EC52971EE8B8200048EB3B /* ChaCha20+Foundation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 75EC52551EE8B6CA0048EB3B /* ChaCha20+Foundation.swift */; };
-		75EC52981EE8B8200048EB3B /* CSArrayType+Foundation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 75EC52561EE8B6CA0048EB3B /* CSArrayType+Foundation.swift */; };
+		75EC52981EE8B8200048EB3B /* Array+Foundation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 75EC52561EE8B6CA0048EB3B /* Array+Foundation.swift */; };
 		75EC52991EE8B8200048EB3B /* Data+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 75EC52571EE8B6CA0048EB3B /* Data+Extension.swift */; };
 		75EC529A1EE8B8200048EB3B /* HMAC+Foundation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 75EC52581EE8B6CA0048EB3B /* HMAC+Foundation.swift */; };
 		75EC529B1EE8B8200048EB3B /* Rabbit+Foundation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 75EC52591EE8B6CA0048EB3B /* Rabbit+Foundation.swift */; };
@@ -192,13 +192,13 @@
 		75EC524C1EE8B6CA0048EB3B /* Cipher.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Cipher.swift; sourceTree = "<group>"; };
 		75EC524D1EE8B6CA0048EB3B /* Collection+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Collection+Extension.swift"; sourceTree = "<group>"; };
 		75EC524E1EE8B6CA0048EB3B /* Cryptors.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Cryptors.swift; sourceTree = "<group>"; };
-		75EC524F1EE8B6CA0048EB3B /* CSArrayType+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CSArrayType+Extensions.swift"; sourceTree = "<group>"; };
+		75EC524F1EE8B6CA0048EB3B /* Array+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Array+Extensions.swift"; sourceTree = "<group>"; };
 		75EC52501EE8B6CA0048EB3B /* Digest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Digest.swift; sourceTree = "<group>"; };
 		75EC52511EE8B6CA0048EB3B /* DigestType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DigestType.swift; sourceTree = "<group>"; };
 		75EC52531EE8B6CA0048EB3B /* AES+Foundation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AES+Foundation.swift"; sourceTree = "<group>"; };
 		75EC52541EE8B6CA0048EB3B /* Blowfish+Foundation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Blowfish+Foundation.swift"; sourceTree = "<group>"; };
 		75EC52551EE8B6CA0048EB3B /* ChaCha20+Foundation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ChaCha20+Foundation.swift"; sourceTree = "<group>"; };
-		75EC52561EE8B6CA0048EB3B /* CSArrayType+Foundation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CSArrayType+Foundation.swift"; sourceTree = "<group>"; };
+		75EC52561EE8B6CA0048EB3B /* Array+Foundation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Array+Foundation.swift"; sourceTree = "<group>"; };
 		75EC52571EE8B6CA0048EB3B /* Data+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Data+Extension.swift"; sourceTree = "<group>"; };
 		75EC52581EE8B6CA0048EB3B /* HMAC+Foundation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "HMAC+Foundation.swift"; sourceTree = "<group>"; };
 		75EC52591EE8B6CA0048EB3B /* Rabbit+Foundation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Rabbit+Foundation.swift"; sourceTree = "<group>"; };
@@ -339,7 +339,7 @@
 				75EC524C1EE8B6CA0048EB3B /* Cipher.swift */,
 				75EC524D1EE8B6CA0048EB3B /* Collection+Extension.swift */,
 				75EC524E1EE8B6CA0048EB3B /* Cryptors.swift */,
-				75EC524F1EE8B6CA0048EB3B /* CSArrayType+Extensions.swift */,
+				75EC524F1EE8B6CA0048EB3B /* Array+Extensions.swift */,
 				75EC52501EE8B6CA0048EB3B /* Digest.swift */,
 				75EC52511EE8B6CA0048EB3B /* DigestType.swift */,
 				75EC52521EE8B6CA0048EB3B /* Foundation */,
@@ -394,7 +394,7 @@
 				75EC52531EE8B6CA0048EB3B /* AES+Foundation.swift */,
 				75EC52541EE8B6CA0048EB3B /* Blowfish+Foundation.swift */,
 				75EC52551EE8B6CA0048EB3B /* ChaCha20+Foundation.swift */,
-				75EC52561EE8B6CA0048EB3B /* CSArrayType+Foundation.swift */,
+				75EC52561EE8B6CA0048EB3B /* Array+Foundation.swift */,
 				75EC52571EE8B6CA0048EB3B /* Data+Extension.swift */,
 				75EC52581EE8B6CA0048EB3B /* HMAC+Foundation.swift */,
 				75EC52591EE8B6CA0048EB3B /* Rabbit+Foundation.swift */,
@@ -572,7 +572,7 @@
 				75EC52A91EE8B83D0048EB3B /* PKCS7Padding.swift in Sources */,
 				75EC52A51EE8B8290048EB3B /* Padding.swift in Sources */,
 				75EC527F1EE8B8130048EB3B /* BatchedCollection.swift in Sources */,
-				75EC52921EE8B81A0048EB3B /* CSArrayType+Extensions.swift in Sources */,
+				75EC52921EE8B81A0048EB3B /* Array+Extensions.swift in Sources */,
 				75EC52991EE8B8200048EB3B /* Data+Extension.swift in Sources */,
 				75EC52B61EE8B83D0048EB3B /* UInt8+Extension.swift in Sources */,
 				75EC52891EE8B8170048EB3B /* OFB.swift in Sources */,
@@ -592,7 +592,7 @@
 				75EC52AB1EE8B83D0048EB3B /* Rabbit.swift in Sources */,
 				75EC529C1EE8B8200048EB3B /* String+FoundationExtension.swift in Sources */,
 				75EC52B81EE8B83D0048EB3B /* Utils.swift in Sources */,
-				75EC52981EE8B8200048EB3B /* CSArrayType+Foundation.swift in Sources */,
+				75EC52981EE8B8200048EB3B /* Array+Foundation.swift in Sources */,
 				75EC52B11EE8B83D0048EB3B /* SHA3.swift in Sources */,
 				75EC52A31EE8B8290048EB3B /* NoPadding.swift in Sources */,
 				75EC52931EE8B81A0048EB3B /* Digest.swift in Sources */,
@@ -797,6 +797,7 @@
 				PRODUCT_NAME = CryptoSwift;
 				SKIP_INSTALL = YES;
 				SWIFT_OPTIMIZATION_LEVEL = "-Onone";
+				SWIFT_VERSION = 4.0;
 				TVOS_DEPLOYMENT_TARGET = 9.0;
 				WATCHOS_DEPLOYMENT_TARGET = 2.0;
 			};
@@ -824,6 +825,7 @@
 				SKIP_INSTALL = YES;
 				SWIFT_DISABLE_SAFETY_CHECKS = YES;
 				SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
+				SWIFT_VERSION = 4.0;
 				TVOS_DEPLOYMENT_TARGET = 9.0;
 				WATCHOS_DEPLOYMENT_TARGET = 2.0;
 			};
@@ -957,6 +959,7 @@
 				SKIP_INSTALL = YES;
 				SWIFT_DISABLE_SAFETY_CHECKS = YES;
 				SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
+				SWIFT_VERSION = 4.0;
 				TVOS_DEPLOYMENT_TARGET = 9.0;
 				WATCHOS_DEPLOYMENT_TARGET = 2.0;
 			};

+ 83 - 0
Sources/CryptoSwift/Array+Extensions.swift

@@ -0,0 +1,83 @@
+//
+//  Array+Extensions.swift
+//  CryptoSwift
+//
+//  Copyright (C) 2014-2017 Marcin Krzyżanowski <marcin@krzyzanowskim.com>
+//  This software is provided 'as-is', without any express or implied warranty.
+//
+//  In no event will the authors be held liable for any damages arising from the use of this software.
+//
+//  Permission is granted to anyone to use this software for any purpose,including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions:
+//
+//  - The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation is required.
+//  - Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
+//  - This notice may not be removed or altered from any source or binary distribution.
+//
+
+public extension Array where Element == UInt8 {
+
+    public func toHexString() -> String {
+        return `lazy`.reduce("") {
+            var s = String($1, radix: 16)
+            if s.characters.count == 1 {
+                s = "0" + s
+            }
+            return $0 + s
+        }
+    }
+}
+
+public extension Array where Element == UInt8 {
+
+    public func md5() -> [Element] {
+        return Digest.md5(self)
+    }
+
+    public func sha1() -> [Element] {
+        return Digest.sha1(self)
+    }
+
+    public func sha224() -> [Element] {
+        return Digest.sha224(self)
+    }
+
+    public func sha256() -> [Element] {
+        return Digest.sha256(self)
+    }
+
+    public func sha384() -> [Element] {
+        return Digest.sha384(self)
+    }
+
+    public func sha512() -> [Element] {
+        return Digest.sha512(self)
+    }
+
+    public func sha2(_ variant: SHA2.Variant) -> [Element] {
+        return Digest.sha2(self, variant: variant)
+    }
+
+    public func sha3(_ variant: SHA3.Variant) -> [Element] {
+        return Digest.sha3(self, variant: variant)
+    }
+
+    public func crc32(seed: UInt32? = nil, reflect: Bool = true) -> UInt32 {
+        return Checksum.crc32(self, seed: seed, reflect: reflect)
+    }
+
+    public func crc16(seed: UInt16? = nil) -> UInt16 {
+        return Checksum.crc16(self, seed: seed)
+    }
+
+    public func encrypt(cipher: Cipher) throws -> [Element] {
+        return try cipher.encrypt(self.slice)
+    }
+
+    public func decrypt(cipher: Cipher) throws -> [Element] {
+        return try cipher.decrypt(self.slice)
+    }
+
+    public func authenticate<A: Authenticator>(with authenticator: A) throws -> [Element] {
+        return try authenticator.authenticate(self)
+    }
+}

+ 0 - 94
Sources/CryptoSwift/CSArrayType+Extensions.swift

@@ -1,94 +0,0 @@
-//
-//  _ArrayType+Extensions.swift
-//  CryptoSwift
-//
-//  Copyright (C) 2014-2017 Marcin Krzyżanowski <marcin@krzyzanowskim.com>
-//  This software is provided 'as-is', without any express or implied warranty.
-//
-//  In no event will the authors be held liable for any damages arising from the use of this software.
-//
-//  Permission is granted to anyone to use this software for any purpose,including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions:
-//
-//  - The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation is required.
-//  - Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
-//  - This notice may not be removed or altered from any source or binary distribution.
-//
-
-public protocol CSArrayType: RangeReplaceableCollection {
-    func cs_arrayValue() -> [Iterator.Element]
-}
-
-extension Array: CSArrayType {
-
-    public func cs_arrayValue() -> [Iterator.Element] {
-        return self
-    }
-}
-
-public extension CSArrayType where Iterator.Element == UInt8 {
-
-    public func toHexString() -> String {
-        return `lazy`.reduce("") {
-            var s = String($1, radix: 16)
-            if s.characters.count == 1 {
-                s = "0" + s
-            }
-            return $0 + s
-        }
-    }
-}
-
-public extension CSArrayType where Iterator.Element == UInt8 {
-
-    public func md5() -> [Iterator.Element] {
-        return Digest.md5(cs_arrayValue())
-    }
-
-    public func sha1() -> [Iterator.Element] {
-        return Digest.sha1(cs_arrayValue())
-    }
-
-    public func sha224() -> [Iterator.Element] {
-        return Digest.sha224(cs_arrayValue())
-    }
-
-    public func sha256() -> [Iterator.Element] {
-        return Digest.sha256(cs_arrayValue())
-    }
-
-    public func sha384() -> [Iterator.Element] {
-        return Digest.sha384(cs_arrayValue())
-    }
-
-    public func sha512() -> [Iterator.Element] {
-        return Digest.sha512(cs_arrayValue())
-    }
-
-    public func sha2(_ variant: SHA2.Variant) -> [Iterator.Element] {
-        return Digest.sha2(cs_arrayValue(), variant: variant)
-    }
-
-    public func sha3(_ variant: SHA3.Variant) -> [Iterator.Element] {
-        return Digest.sha3(cs_arrayValue(), variant: variant)
-    }
-
-    public func crc32(seed: UInt32? = nil, reflect: Bool = true) -> UInt32 {
-        return Checksum.crc32(cs_arrayValue(), seed: seed, reflect: reflect)
-    }
-
-    public func crc16(seed: UInt16? = nil) -> UInt16 {
-        return Checksum.crc16(cs_arrayValue(), seed: seed)
-    }
-
-    public func encrypt(cipher: Cipher) throws -> [Iterator.Element] {
-        return try cipher.encrypt(cs_arrayValue().slice)
-    }
-
-    public func decrypt(cipher: Cipher) throws -> [Iterator.Element] {
-        return try cipher.decrypt(cs_arrayValue().slice)
-    }
-
-    public func authenticate<A: Authenticator>(with authenticator: A) throws -> [Iterator.Element] {
-        return try authenticator.authenticate(cs_arrayValue())
-    }
-}

+ 3 - 7
Sources/CryptoSwift/Foundation/CSArrayType+Foundation.swift → Sources/CryptoSwift/Foundation/Array+Foundation.swift

@@ -1,5 +1,5 @@
 //
-//  CSArrayType+Foundation.swift
+//  Array+Foundation.swift
 //  CryptoSwift
 //
 //  Copyright (C) 2014-2017 Marcin Krzyżanowski <marcin@krzyzanowskim.com>
@@ -16,14 +16,10 @@
 
 import Foundation
 
-public extension CSArrayType where Iterator.Element == UInt8 {
+public extension Array where Element == UInt8 {
 
     public func toBase64() -> String? {
-        guard let bytesArray = self as? Array<UInt8> else {
-            return nil
-        }
-
-        return Data(bytes: bytesArray).base64EncodedString()
+        return Data(bytes: self).base64EncodedString()
     }
 
     public init(base64: String) {