MCPcopy Create free account
hub / github.com/crewjam/saml / stripPadding

Function stripPadding

xmlenc/cbc.go:202–211  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

200// Santuario, .NET's EncryptedXml) use ISO 10126 padding, whose other bytes
201// are random. Every failure returns ErrDecryptionFailed.
202func 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}

Callers 2

TestCovStripPaddingFunction · 0.85
DecryptMethod · 0.85

Calls

no outgoing calls

Tested by 1

TestCovStripPaddingFunction · 0.68