Parcourir la source

update(withBytes:), finish(withBytes:)

Marcin Krzyżanowski il y a 9 ans
Parent
commit
2ec762a849

+ 1 - 1
CryptoSwiftTests/AESTests.swift

@@ -86,7 +86,7 @@ final class AESTests: XCTestCase {
 
         var partialEncrypted = [UInt8]()
         var encryptor = aes.makeEncryptor()
-        partialEncrypted.appendContentsOf(try! encryptor.updateWith(bytes: Array(plaintext[0..<16])))
+        partialEncrypted.appendContentsOf(try! encryptor.update(withBytes: Array(plaintext[0..<16])))
         partialEncrypted.appendContentsOf(try! encryptor.finish(withBytes: Array(plaintext[16..<32])))
         //partialEncrypted.appendContentsOf(try! encryptor.finish())
         XCTAssertEqual(encrypted, partialEncrypted, "encryption failed")

+ 4 - 4
Sources/CryptoSwift/AES.swift

@@ -400,7 +400,7 @@ extension AES {
             self.worker = aes.blockMode.worker(aes.iv, cipherOperation: aes.encryptBlock)
         }
 
-        mutating public func updateWith(bytes bytes:[UInt8], isLast: Bool = false) throws -> [UInt8] {
+        mutating public func update(withBytes bytes:[UInt8], isLast: Bool = false) throws -> [UInt8] {
             if isLast {
                 let paddedBytes = padding.add(bytes, blockSize: AES.blockSize)
                 var result = [UInt8]()
@@ -435,7 +435,7 @@ extension AES {
             }
         }
 
-        mutating public func updateWith(bytes bytes:[UInt8], isLast: Bool = false) throws -> [UInt8] {
+        mutating public func update(withBytes bytes:[UInt8], isLast: Bool = false) throws -> [UInt8] {
             if bytes.count == 0 {
                 return bytes;
             }
@@ -470,7 +470,7 @@ extension AES: Cipher {
         var out = [UInt8]()
         out.reserveCapacity(bytes.count)
         for (idx, block) in chunks.enumerate() {
-            out.appendContentsOf(try oneTimeCryptor.updateWith(bytes: block, isLast: idx == max(0,chunks.count - 1)))
+            out.appendContentsOf(try oneTimeCryptor.update(withBytes: block, isLast: idx == max(0,chunks.count - 1)))
         }
 
         if blockMode.options.contains(.PaddingRequired) && (out.count % AES.blockSize != 0) {
@@ -490,7 +490,7 @@ extension AES: Cipher {
         var out = [UInt8]()
         out.reserveCapacity(bytes.count)
         for (idx,chunk) in chunks.enumerate() {
-            out.appendContentsOf(try oneTimeCryptor.updateWith(bytes: chunk, isLast: idx == max(0,chunks.count - 1)))
+            out.appendContentsOf(try oneTimeCryptor.update(withBytes: chunk, isLast: idx == max(0,chunks.count - 1)))
         }
         return out
     }

+ 2 - 2
Sources/CryptoSwift/ChaCha20.swift

@@ -170,7 +170,7 @@ extension ChaCha20 {
             self.chacha20 = chacha20
         }
 
-        public func updateWith(bytes bytes: [UInt8], isLast: Bool = false) throws -> [UInt8] {
+        public func update(withBytes bytes: [UInt8], isLast: Bool = false) throws -> [UInt8] {
             return try chacha20.encrypt(bytes)
         }
     }
@@ -184,7 +184,7 @@ extension ChaCha20 {
             self.chacha20 = chacha20
         }
 
-        public func updateWith(bytes bytes: [UInt8], isLast: Bool = false) throws -> [UInt8] {
+        public func update(withBytes bytes: [UInt8], isLast: Bool = false) throws -> [UInt8] {
             return try chacha20.decrypt(bytes)
         }
     }

+ 2 - 2
Sources/CryptoSwift/Cryptor.swift

@@ -12,12 +12,12 @@ public protocol Cryptor {
     /// - parameter bytes: Ciphertext data
     /// - parameter isLast: Given chunk is the last one. No more updates after this call.
     /// - returns: Plaintext data
-    mutating func updateWith(bytes bytes:[UInt8], isLast: Bool) throws -> [UInt8]
+    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.updateWith(bytes: bytes, isLast: true)
+        return try self.update(withBytes: bytes, isLast: true)
     }
 }

+ 2 - 2
Sources/CryptoSwift/Rabbit.swift

@@ -181,7 +181,7 @@ extension Rabbit {
             self.rabbit = rabbit
         }
 
-        public func updateWith(bytes bytes: [UInt8], isLast: Bool = false) throws -> [UInt8] {
+        public func update(withBytes bytes: [UInt8], isLast: Bool = false) throws -> [UInt8] {
             return rabbit.encrypt(bytes)
         }
     }
@@ -195,7 +195,7 @@ extension Rabbit {
             self.rabbit = rabbit
         }
 
-        public func updateWith(bytes bytes: [UInt8], isLast: Bool = false) throws -> [UInt8] {
+        public func update(withBytes bytes: [UInt8], isLast: Bool = false) throws -> [UInt8] {
             return rabbit.decrypt(bytes)
         }
     }