Преглед на файлове

Fix updatable condition

Marcin Krzyżanowski преди 9 години
родител
ревизия
24d0997922
променени са 3 файла, в които са добавени 3 реда и са изтрити 3 реда
  1. 1 1
      Sources/CryptoSwift/MD5.swift
  2. 1 1
      Sources/CryptoSwift/SHA2.swift
  3. 1 1
      Sources/CryptoSwift/SHA3.swift

+ 1 - 1
Sources/CryptoSwift/MD5.swift

@@ -122,7 +122,7 @@ extension MD5: Updatable {
 
         var processedBytes = 0
         for chunk in BytesSequence(chunkSize: MD5.blockSize, data: self.accumulated) {
-            if (isLast || self.accumulated.count >= MD5.blockSize) {
+            if (isLast || (self.accumulated.count - processedBytes) >= MD5.blockSize) {
                 self.process(block: chunk, currentHash: &self.accumulatedHash)
                 processedBytes += chunk.count
             }

+ 1 - 1
Sources/CryptoSwift/SHA2.swift

@@ -274,7 +274,7 @@ extension SHA2: Updatable {
 
         var processedBytes = 0
         for chunk in BytesSequence(chunkSize: self.blockSize, data: self.accumulated) {
-            if (isLast || self.accumulated.count >= self.blockSize) {
+            if (isLast || (self.accumulated.count - processedBytes) >= self.blockSize) {
                 switch self.variant {
                     case .sha224, .sha256:
                         self.process32(block: chunk, currentHash: &self.accumulatedHash32)

+ 1 - 1
Sources/CryptoSwift/SHA3.swift

@@ -256,7 +256,7 @@ extension SHA3: Updatable {
 
         var processedBytes = 0
         for chunk in BytesSequence(chunkSize: self.variant.blockSize, data: self.accumulated) {
-            if (isLast || self.accumulated.count >= self.variant.blockSize) {
+            if (isLast || (self.accumulated.count - processedBytes) >= self.variant.blockSize) {
                 self.process(block: chunk.toUInt64Array(), currentHash: &self.accumulatedHash)
                 processedBytes += chunk.count
             }