Browse Source

Make convenienc method for Cipher

Marcin Krzyżanowski 8 years ago
parent
commit
1511b8a891

+ 1 - 0
Sources/CryptoSwift/Blowfish.swift

@@ -474,6 +474,7 @@ public final class Blowfish {
 }
 
 extension Blowfish: Cipher {
+
     /// Encrypt the 8-byte padded buffer, block by block. Note that for amounts of data larger than a block, it is not safe to just call encrypt() on successive blocks.
     ///
     /// - Parameter bytes: Plaintext data

+ 2 - 2
Sources/CryptoSwift/ChaCha20.swift

@@ -244,11 +244,11 @@ public final class ChaCha20: BlockCipher {
 // MARK: Cipher
 extension ChaCha20: Cipher {
 
-    public func encrypt<C: Collection>(_ bytes: C) throws -> Array<UInt8> where C.Element == UInt8, C.IndexDistance == Int, C.Index == Int {
+    public func encrypt(_ bytes: ArraySlice<UInt8>) throws -> Array<UInt8> {
         return process(bytes: Array(bytes), counter: &self.counter, key: Array(self.key))
     }
 
-    public func decrypt<C: Collection>(_ bytes: C) throws -> Array<UInt8> where C.Element == UInt8, C.IndexDistance == Int, C.Index == Int {
+    public func decrypt(_ bytes: ArraySlice<UInt8>) throws -> Array<UInt8> {
         return try encrypt(bytes)
     }
 }

+ 12 - 0
Sources/CryptoSwift/Cipher.swift

@@ -25,10 +25,22 @@ public protocol Cipher: class {
     /// - parameter bytes: Plaintext data
     /// - returns: Encrypted data
     func encrypt(_ bytes: ArraySlice<UInt8>) throws -> Array<UInt8>
+    func encrypt(_ bytes: Array<UInt8>) throws -> Array<UInt8>
 
     /// Decrypt given bytes at once
     ///
     /// - parameter bytes: Ciphertext data
     /// - returns: Plaintext data
     func decrypt(_ bytes: ArraySlice<UInt8>) throws -> Array<UInt8>
+    func decrypt(_ bytes: Array<UInt8>) throws -> Array<UInt8>
+}
+
+extension Cipher {
+    public func encrypt(_ bytes: Array<UInt8>) throws -> Array<UInt8> {
+        return try encrypt(bytes.slice)
+    }
+
+    public func decrypt(_ bytes: Array<UInt8>) throws -> Array<UInt8> {
+        return try decrypt(bytes.slice)
+    }
 }