فهرست منبع

Rename protocols

Marcin Krzyżanowski 9 سال پیش
والد
کامیت
e79918cc24

+ 3 - 3
Sources/CryptoSwift/AES.swift

@@ -391,7 +391,7 @@ extension AES {
 
 // MARK: Encryptor
 extension AES {
-    public struct Encryptor: Cryptor {
+    public struct Encryptor: UpdatableCryptor {
         private var worker: BlockModeWorker
         private let padding: Padding
         private var accumulated = [UInt8]()
@@ -428,7 +428,7 @@ extension AES {
 
 // MARK: Decryptor
 extension AES {
-    public struct Decryptor: Cryptor {
+    public struct Decryptor: UpdatableCryptor {
         private var worker: BlockModeWorker
         private let padding: Padding
 
@@ -459,7 +459,7 @@ extension AES {
 }
 
 // MARK: UpdatableCryptor
-extension AES: UpdatableCryptor {
+extension AES: Cryptors {
     
     public func makeEncryptor() -> AES.Encryptor {
         return Encryptor(aes: self)

+ 0 - 23
Sources/CryptoSwift/Cryptor.swift

@@ -1,23 +0,0 @@
-//
-//  Cryptor.swift
-//  CryptoSwift
-//
-//  Created by Marcin Krzyzanowski on 06/05/16.
-//  Copyright © 2016 Marcin Krzyzanowski. All rights reserved.
-//
-
-public protocol Cryptor {
-    /// Decrypt given bytes in chunks.
-    ///
-    /// - parameter bytes: Ciphertext data
-    /// - parameter isLast: Given chunk is the last one. No more updates after this call.
-    /// - returns: Plaintext data
-    mutating func update(withBytes bytes:[UInt8], isLast: Bool) throws -> [UInt8]
-    mutating func finish(withBytes bytes:[UInt8]) throws  -> [UInt8]
-}
-
-extension Cryptor {
-    mutating public func finish(withBytes bytes:[UInt8] = []) throws  -> [UInt8] {
-        return try self.update(withBytes: bytes, isLast: true)
-    }
-}

+ 37 - 0
Sources/CryptoSwift/Cryptors.swift

@@ -0,0 +1,37 @@
+//
+//  Cryptors.swift
+//  CryptoSwift
+//
+//  Created by Marcin Krzyzanowski on 30/08/14.
+//  Copyright (c) 2014 Marcin Krzyzanowski. All rights reserved.
+//
+
+#if os(Linux)
+    import Glibc
+#else
+    import Darwin
+#endif
+
+
+public protocol Cryptors {
+    associatedtype EncryptorType: UpdatableCryptor
+    associatedtype DecryptorType: UpdatableCryptor
+
+    /// Cryptor suitable for encryption
+    func makeEncryptor() -> EncryptorType
+
+    /// Cryptor suitable for decryption
+    func makeDecryptor() -> DecryptorType
+
+    static func randomIV(blockSize:Int) -> [UInt8]
+}
+
+extension Cryptors {
+    static public func randomIV(blockSize:Int) -> [UInt8] {
+        var randomIV:[UInt8] = [UInt8]();
+        for _ in 0..<blockSize {
+            randomIV.append(UInt8(truncatingBitPattern: cs_arc4random_uniform(256)));
+        }
+        return randomIV
+    }
+}

+ 14 - 24
Sources/CryptoSwift/UpdatableCryptor.swift

@@ -2,36 +2,26 @@
 //  UpdatableCryptor.swift
 //  CryptoSwift
 //
-//  Created by Marcin Krzyzanowski on 30/08/14.
-//  Copyright (c) 2014 Marcin Krzyzanowski. All rights reserved.
+//  Created by Marcin Krzyzanowski on 06/05/16.
+//  Copyright © 2016 Marcin Krzyzanowski. All rights reserved.
 //
 
-#if os(Linux)
-    import Glibc
-#else
-    import Darwin
-#endif
-
-
 public protocol UpdatableCryptor {
-    associatedtype EncryptorType: Cryptor
-    associatedtype DecryptorType: Cryptor
-
-    /// Cryptor suitable for encryption
-    func makeEncryptor() -> EncryptorType
-
-    /// Cryptor suitable for decryption
-    func makeDecryptor() -> DecryptorType
+    /// Encrypt/Decrypt given bytes in chunks.
+    ///
+    /// - parameter bytes: Bytes to process
+    /// - parameter isLast: (Optional) Given chunk is the last one. No more updates after this call.
+    /// - returns: Processed data or empty array.
+    mutating func update(withBytes bytes:[UInt8], isLast: Bool) throws -> [UInt8]
 
-    static func randomIV(blockSize:Int) -> [UInt8]
+    /// Finish encryption/decryption. This may apply padding.
+    /// - parameter bytes: Bytes to process
+    /// - returns: Processed data.
+    mutating func finish(withBytes bytes:[UInt8]) throws  -> [UInt8]
 }
 
 extension UpdatableCryptor {
-    static public func randomIV(blockSize:Int) -> [UInt8] {
-        var randomIV:[UInt8] = [UInt8]();
-        for _ in 0..<blockSize {
-            randomIV.append(UInt8(truncatingBitPattern: cs_arc4random_uniform(256)));
-        }
-        return randomIV
+    mutating public func finish(withBytes bytes:[UInt8] = []) throws  -> [UInt8] {
+        return try self.update(withBytes: bytes, isLast: true)
     }
 }