Browse Source

Dont remove padding when padding is not expected

Marcin Krzyżanowski 11 years ago
parent
commit
903cfee236
1 changed files with 4 additions and 1 deletions
  1. 4 1
      CryptoSwift/PKCS7.swift

+ 4 - 1
CryptoSwift/PKCS7.swift

@@ -34,7 +34,10 @@ public struct PKCS7 {
     
     public func removePadding() -> NSData {
         if let padding = data.bytes().last {
-            return data.subdataWithRange(NSRange(location: 0, length: data.length - Int(padding)))
+            if (padding <= 8) {
+                return data.subdataWithRange(NSRange(location: 0, length: data.length - Int(padding)))
+            }
+            return data;
         }
         return data
     }