Explorar o código

A more correct implementation of zero prepended block formatting

Brandon Toms %!s(int64=3) %!d(string=hai) anos
pai
achega
c95b9db830
Modificáronse 1 ficheiros con 12 adicións e 7 borrados
  1. 12 7
      Sources/CryptoSwift/RSA/RSA+Cipher.swift

+ 12 - 7
Sources/CryptoSwift/RSA/RSA+Cipher.swift

@@ -109,15 +109,20 @@ extension RSA {
           return bytes
           return bytes
         case .raw, .pksc1v15:
         case .raw, .pksc1v15:
           // Format the encrypted bytes before returning
           // Format the encrypted bytes before returning
+          //var bytes = bytes
+//          if bytes.isEmpty {
+//            // Instead of returning an empty byte array, we return an array of zero's of length keySize bytes
+//            // This functionality matches that of Apple's `Security` framework
+//            return Array<UInt8>(repeating: 0, count: blockSize)
+//          } else {
+//            while bytes.count % 4 != 0 { bytes.insert(0x00, at: 0) }
+//            return bytes
+//          }
           var bytes = bytes
           var bytes = bytes
-          if bytes.isEmpty {
-            // Instead of returning an empty byte array, we return an array of zero's of length keySize bytes
-            // This functionality matches that of Apple's `Security` framework
-            return Array<UInt8>(repeating: 0, count: blockSize)
-          } else {
-            while bytes.count % 4 != 0 { bytes.insert(0x00, at: 0) }
-            return bytes
+          while bytes.count != blockSize {
+            bytes.insert(0x00, at: 0)
           }
           }
+          return bytes
       }
       }
     }
     }