소스 검색

Merge branch 'release-type' of https://github.com/xlc/CryptoSwift into xlc-release-type

Marcin Krzyżanowski 9 년 전
부모
커밋
586d273682
2개의 변경된 파일17개의 추가작업 그리고 9개의 파일을 삭제
  1. 2 2
      Sources/CryptoSwift/AES.swift
  2. 15 7
      Sources/CryptoSwift/UpdatableCryptor.swift

+ 2 - 2
Sources/CryptoSwift/AES.swift

@@ -403,7 +403,7 @@ extension AES {
             self.paddingRequired = aes.blockMode.options.contains(.PaddingRequired)
             self.paddingRequired = aes.blockMode.options.contains(.PaddingRequired)
         }
         }
 
 
-        mutating public func update(withBytes bytes:Array<UInt8>, isLast: Bool = false) throws -> Array<UInt8> {
+        mutating public func update<T: SequenceType where T.Generator.Element == UInt8>(withBytes bytes:T, isLast: Bool = false) throws -> Array<UInt8> {
             self.accumulated += bytes
             self.accumulated += bytes
 
 
             if isLast {
             if isLast {
@@ -445,7 +445,7 @@ extension AES {
             self.paddingRequired = aes.blockMode.options.contains(.PaddingRequired);
             self.paddingRequired = aes.blockMode.options.contains(.PaddingRequired);
         }
         }
 
 
-        mutating public func update(withBytes bytes:Array<UInt8>, isLast: Bool = false) throws -> Array<UInt8> {
+        mutating public func update<T: SequenceType where T.Generator.Element == UInt8>(withBytes bytes:T, isLast: Bool = false) throws -> Array<UInt8> {
             self.accumulated += bytes
             self.accumulated += bytes
 
 
             var plaintext = Array<UInt8>()
             var plaintext = Array<UInt8>()

+ 15 - 7
Sources/CryptoSwift/UpdatableCryptor.swift

@@ -12,7 +12,7 @@ public protocol UpdatableCryptor {
     /// - parameter bytes: Bytes to process
     /// - parameter bytes: Bytes to process
     /// - parameter isLast: (Optional) Given chunk is the last one. No more updates after this call.
     /// - parameter isLast: (Optional) Given chunk is the last one. No more updates after this call.
     /// - returns: Processed data or empty array.
     /// - returns: Processed data or empty array.
-    mutating func update(withBytes bytes:Array<UInt8>, isLast: Bool) throws -> Array<UInt8>
+    mutating func update<T: SequenceType where T.Generator.Element == UInt8>(withBytes bytes:T, isLast: Bool) throws -> Array<UInt8>
 
 
     /// Encrypt/Decrypt given bytes in chunks.
     /// Encrypt/Decrypt given bytes in chunks.
     ///
     ///
@@ -20,36 +20,44 @@ public protocol UpdatableCryptor {
     /// - parameter isLast: (Optional) Given chunk is the last one. No more updates after this call.
     /// - parameter isLast: (Optional) Given chunk is the last one. No more updates after this call.
     /// - parameter output: Resulting data
     /// - parameter output: Resulting data
     /// - returns: Processed data or empty array.
     /// - returns: Processed data or empty array.
-    mutating func update(withBytes bytes:Array<UInt8>, isLast: Bool, output: (Array<UInt8>) -> Void) throws
+    mutating func update<T: SequenceType where T.Generator.Element == UInt8>(withBytes bytes:T, isLast: Bool, output: (Array<UInt8>) -> Void) throws
 
 
     /// Finish encryption/decryption. This may apply padding.
     /// Finish encryption/decryption. This may apply padding.
     /// - parameter bytes: Bytes to process
     /// - parameter bytes: Bytes to process
     /// - returns: Processed data.
     /// - returns: Processed data.
-    mutating func finish(withBytes bytes:Array<UInt8>) throws -> Array<UInt8>
+    mutating func finish<T: SequenceType where T.Generator.Element == UInt8>(withBytes bytes:T) throws -> Array<UInt8>
 
 
     /// Finish encryption/decryption. This may apply padding.
     /// Finish encryption/decryption. This may apply padding.
     /// - parameter bytes: Bytes to process
     /// - parameter bytes: Bytes to process
     /// - parameter output: Resulting data
     /// - parameter output: Resulting data
     /// - returns: Processed data.
     /// - returns: Processed data.
-    mutating func finish(withBytes bytes:Array<UInt8>, output: (Array<UInt8>) -> Void) throws
+    mutating func finish<T: SequenceType where T.Generator.Element == UInt8>(withBytes bytes:T, output: (Array<UInt8>) -> Void) throws
 }
 }
 
 
 extension UpdatableCryptor {
 extension UpdatableCryptor {
-    mutating public func update(withBytes bytes:Array<UInt8>, isLast: Bool = false, output: (Array<UInt8>) -> Void) throws {
+    mutating public func update<T: SequenceType where T.Generator.Element == UInt8>(withBytes bytes:T, isLast: Bool = false, output: (Array<UInt8>) -> Void) throws {
         let processed = try self.update(withBytes: bytes, isLast: isLast)
         let processed = try self.update(withBytes: bytes, isLast: isLast)
         if (!processed.isEmpty) {
         if (!processed.isEmpty) {
             output(processed)
             output(processed)
         }
         }
     }
     }
 
 
-    mutating public func finish(withBytes bytes:Array<UInt8> = []) throws  -> Array<UInt8> {
+    mutating public func finish<T: SequenceType where T.Generator.Element == UInt8>(withBytes bytes:T) throws -> Array<UInt8> {
         return try self.update(withBytes: bytes, isLast: true)
         return try self.update(withBytes: bytes, isLast: true)
     }
     }
+    
+    mutating public func finish() throws  -> Array<UInt8> {
+        return try self.update(withBytes: [], isLast: true)
+    }
 
 
-    mutating public func finish(withBytes bytes:Array<UInt8> = [], output: (Array<UInt8>) -> Void) throws {
+    mutating public func finish<T: SequenceType where T.Generator.Element == UInt8>(withBytes bytes:T, output: (Array<UInt8>) -> Void) throws {
         let processed = try self.update(withBytes: bytes, isLast: true)
         let processed = try self.update(withBytes: bytes, isLast: true)
         if (!processed.isEmpty) {
         if (!processed.isEmpty) {
             output(processed)
             output(processed)
         }
         }
     }
     }
+    
+    mutating public func finish(output: (Array<UInt8>) -> Void) throws {
+        try self.finish(withBytes: [], output: output)
+    }
 }
 }