Marcin Krzyżanowski 10 anni fa
parent
commit
d594ae0ec6

+ 4 - 0
CryptoSwift.xcodeproj/project.pbxproj

@@ -59,6 +59,7 @@
 		75BC3AE31A4E412000ADF343 /* CipherBlockMode.swift in Sources */ = {isa = PBXBuildFile; fileRef = 75BC3AE21A4E412000ADF343 /* CipherBlockMode.swift */; };
 		75BE4EB11B1E4A9F007A2B57 /* IntegerConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 75BE4EB01B1E4A9F007A2B57 /* IntegerConvertible.swift */; };
 		75D2D1A01B5689EB000A2615 /* NSDataSequence.swift in Sources */ = {isa = PBXBuildFile; fileRef = 75D2D19F1B5689EB000A2615 /* NSDataSequence.swift */; };
+		75D63F751BB711270041579B /* BytesSequence.swift in Sources */ = {isa = PBXBuildFile; fileRef = 75D63F741BB711270041579B /* BytesSequence.swift */; settings = {ASSET_TAGS = (); }; };
 		75D94E2419B60C08007CB2A4 /* Operators.swift in Sources */ = {isa = PBXBuildFile; fileRef = 75D94E2319B60C08007CB2A4 /* Operators.swift */; };
 		75D94E2619B60C4F007CB2A4 /* UInt32Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 75D94E2519B60C4F007CB2A4 /* UInt32Extension.swift */; };
 		75D94E2819B60DDE007CB2A4 /* UInt64Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 75D94E2719B60DDE007CB2A4 /* UInt64Extension.swift */; };
@@ -171,6 +172,7 @@
 		75BC3AE21A4E412000ADF343 /* CipherBlockMode.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CipherBlockMode.swift; sourceTree = "<group>"; };
 		75BE4EB01B1E4A9F007A2B57 /* IntegerConvertible.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IntegerConvertible.swift; sourceTree = "<group>"; };
 		75D2D19F1B5689EB000A2615 /* NSDataSequence.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NSDataSequence.swift; sourceTree = "<group>"; };
+		75D63F741BB711270041579B /* BytesSequence.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BytesSequence.swift; sourceTree = "<group>"; };
 		75D94E2319B60C08007CB2A4 /* Operators.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Operators.swift; sourceTree = "<group>"; };
 		75D94E2519B60C4F007CB2A4 /* UInt32Extension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UInt32Extension.swift; sourceTree = "<group>"; };
 		75D94E2719B60DDE007CB2A4 /* UInt64Extension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UInt64Extension.swift; sourceTree = "<group>"; };
@@ -258,6 +260,7 @@
 				758C764019B61AE500653BC6 /* Generics.swift */,
 				75BE4EB01B1E4A9F007A2B57 /* IntegerConvertible.swift */,
 				75D2D19F1B5689EB000A2615 /* NSDataSequence.swift */,
+				75D63F741BB711270041579B /* BytesSequence.swift */,
 				754BE45819693E190098E6F3 /* Supporting Files */,
 			);
 			path = CryptoSwift;
@@ -447,6 +450,7 @@
 				75EB380119ABDD710002375A /* ChaCha20.swift in Sources */,
 				75A663A61AA0CAD00052110B /* Padding.swift in Sources */,
 				75164E4919AD30AC00737F30 /* Utils.swift in Sources */,
+				75D63F751BB711270041579B /* BytesSequence.swift in Sources */,
 				759D481119B517BC005FF7FC /* BitExtension.swift in Sources */,
 				754C8FED19979F94005AD904 /* ArrayExtension.swift in Sources */,
 				7539E3291B3B4A530037F4E1 /* MD5.swift in Sources */,

+ 24 - 0
CryptoSwift/BytesSequence.swift

@@ -0,0 +1,24 @@
+//
+//  BytesSequence.swift
+//  CryptoSwift
+//
+//  Created by Marcin Krzyzanowski on 26/09/15.
+//  Copyright © 2015 Marcin Krzyzanowski. All rights reserved.
+//
+
+struct BytesSequence: SequenceType {
+    let chunkSize: Int
+    let data: [UInt8]
+    
+    func generate() -> AnyGenerator<ArraySlice<UInt8>> {
+        
+        var offset:Int = 0
+        
+        return anyGenerator {
+            let end = min(self.chunkSize, self.data.count - offset)
+            let result = self.data[offset...offset + end]
+            offset += result.count
+            return result.count > 0 ? result : nil
+        }
+    }
+}

+ 0 - 2
CryptoSwift/NSDataSequence.swift

@@ -6,8 +6,6 @@
 //  Copyright © 2015 Marcin Krzyzanowski. All rights reserved.
 //
 
-import Foundation
-
 struct NSDataSequence: SequenceType {
     
     let chunkSize: Int