Bladeren bron

Move documentation to protocols

Marcin Krzyżanowski 9 jaren geleden
bovenliggende
commit
158361c79f

+ 0 - 8
Sources/CryptoSwift/AES.swift

@@ -453,10 +453,6 @@ extension AES: CipherProtocol {
         return Decryptor(aes: self)
     }
 
-    /// Encrypt given bytes at once
-    ///
-    /// - parameter bytes: Plaintext data
-    /// - returns: Encrypted data
     public func encrypt(bytes:[UInt8]) throws -> [UInt8] {
         let chunks = bytes.chunks(AES.blockSize)
 
@@ -474,10 +470,6 @@ extension AES: CipherProtocol {
         return out
     }
 
-    /// Decrypt given bytes at once
-    ///
-    /// - parameter bytes: Ciphertext data
-    /// - returns: Plaintext data
     public func decrypt(bytes:[UInt8]) throws -> [UInt8] {
         if blockMode.options.contains(.PaddingRequired) && (bytes.count % AES.blockSize != 0) {
             throw Error.DataPaddingRequired

+ 2 - 2
Sources/CryptoSwift/ChaCha20.swift

@@ -163,7 +163,7 @@ final public class ChaCha20: BlockCipher {
 }
 
 extension ChaCha20 {
-    public class Encryptor: Cryptor {
+    public struct Encryptor: Cryptor {
         let chacha20: ChaCha20
 
         init(chacha20: ChaCha20) {
@@ -177,7 +177,7 @@ extension ChaCha20 {
 }
 
 extension ChaCha20 {
-    public class Decryptor: Cryptor {
+    public struct Decryptor: Cryptor {
         let chacha20: ChaCha20
 
         init(chacha20: ChaCha20) {

+ 12 - 0
Sources/CryptoSwift/CipherProtocol.swift

@@ -19,10 +19,22 @@ public enum CipherError: ErrorType {
 
 public protocol CipherProtocol {
 
+    /// Cryptor suitable for encryption
     func encryptor() -> Cryptor;
+
+    /// Cryptor suitable for decryption
     func decryptor() -> Cryptor;
 
+    /// Encrypt given bytes at once
+    ///
+    /// - parameter bytes: Plaintext data
+    /// - returns: Encrypted data
     func encrypt(bytes: [UInt8]) throws -> [UInt8]
+
+    /// Decrypt given bytes at once
+    ///
+    /// - parameter bytes: Ciphertext data
+    /// - returns: Plaintext data
     func decrypt(bytes: [UInt8]) throws -> [UInt8]
     
     static func randomIV(blockSize:Int) -> [UInt8]

+ 5 - 0
Sources/CryptoSwift/Cryptor.swift

@@ -7,5 +7,10 @@
 //
 
 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(bytes:[UInt8], isLast: Bool) throws -> [UInt8]
 }

+ 2 - 2
Sources/CryptoSwift/Rabbit.swift

@@ -174,7 +174,7 @@ final public class Rabbit: BlockCipher {
 }
 
 extension Rabbit {
-    public class Encryptor: Cryptor {
+    public struct Encryptor: Cryptor {
         let rabbit: Rabbit
 
         init(rabbit: Rabbit) {
@@ -188,7 +188,7 @@ extension Rabbit {
 }
 
 extension Rabbit {
-    public class Decryptor: Cryptor {
+    public struct Decryptor: Cryptor {
         let rabbit: Rabbit
 
         init(rabbit: Rabbit) {