Skip to content

Commit

Permalink
Merge pull request #1021 from matthiasgeihs/fix/pkcs7
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanfallet committed Nov 2, 2023
2 parents db51c40 + fe41a8f commit 23bc51a
Showing 1 changed file with 2 additions and 9 deletions.
11 changes: 2 additions & 9 deletions Sources/CryptoSwift/PKCS/PKCS7Padding.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,8 @@ struct PKCS7Padding: PaddingProtocol {
@inlinable
func add(to bytes: Array<UInt8>, blockSize: Int) -> Array<UInt8> {
let padding = UInt8(blockSize - (bytes.count % blockSize))
var withPadding = bytes
if padding == 0 {
// If the original data is a multiple of N bytes, then an extra block of bytes with value N is added.
withPadding += Array<UInt8>(repeating: UInt8(blockSize), count: Int(blockSize))
} else {
// The value of each added byte is the number of bytes that are added
withPadding += Array<UInt8>(repeating: padding, count: Int(padding))
}
return withPadding
// The value of each added byte is the number of bytes that are added
return bytes + Array<UInt8>(repeating: padding, count: Int(padding))
}

@inlinable
Expand Down

0 comments on commit 23bc51a

Please sign in to comment.