stripPadding removes XML Encryption padding (section 5.2): the last byte holds the number of padding bytes, between 1 and the block size, and the other padding bytes are arbitrary. They are not checked: unlike PKCS#7, XML Encryption lets them take any value, and common senders (Apache Santuario, .NE
(buf []byte, blockSize int)
| 200 | // Santuario, .NET's EncryptedXml) use ISO 10126 padding, whose other bytes |
| 201 | // are random. Every failure returns ErrDecryptionFailed. |
| 202 | func stripPadding(buf []byte, blockSize int) ([]byte, error) { |
| 203 | if len(buf) < 1 { |
| 204 | return nil, ErrDecryptionFailed |
| 205 | } |
| 206 | paddingBytes := int(buf[len(buf)-1]) |
| 207 | if paddingBytes < 1 || paddingBytes > len(buf) || paddingBytes > blockSize { |
| 208 | return nil, ErrDecryptionFailed |
| 209 | } |
| 210 | return buf[:len(buf)-paddingBytes], nil |
| 211 | } |
no outgoing calls