Would you like to suggest some code for the implementation of this check?
Just looked again and saw that this padding handling is declared as private, and this makes things weird to begin with, PKCS7 padding scheme might be its own class as auxiliary.
Looking more.. i can't find more direct and correct way to add this class except in DECFormat, but all classes there are TFormat_XXX so it might be TFormat_PKCS7Padder ( had to check for padder as word, and it does exist), well it is not up to me to decide naming.
The checker is exactly as you did it, the last byte value is repeated "value" times, it should not be 0 and obviously can't be more than 255, so implementing it is trivial, but with an important thing in mind:
There is no scheme or standard in my recollection that demand a limitation, meaning PKCS7 padding when used for symmetric encryption then the target padded size must be satisfy
n*blocksize; n > 0
and this in contrary to the most usual usage of pad to one block size, so for AES the minimum padding is 1 byte to satisfy the full length to a multiply of 16 bytes, but it could be 32, 48... and will still correct and valid,(many stick to pad AES encryption to one block), the scheme by its design when de-padding (removing the padding) will remove all the residue, although not PKCS7 but in TOR as example padding done up to 512 or a multiple of 512 byte for obfuscation, same can be used with PKCS7 you can choose to pad to 128 bytes so all entries in
db no matter how long names or addresses are encrypted as the same size.
back to suggested class, in case you decided to add it as separate class, it should accept block_size as optional input (parameter) along the data, so
block_size =0 then the checking or the loop will only make sure the
all last trailing k bytes have the value k and
k >0
block_size >0 then the checking will be the same as above with extra check that length of the
data length is equal to block_size * m, because in this case the size must be padded (aligned)
that is it, removing the padding by truncating the data length by k, padding is the same, so for padding, it could have the block size parameter along with requested length, the actual padding must be more or equal to than the requested length and equal to multiple block size, padding length can't be more than 255 bytes.