Skip to content

Commit c2dcc5c

Browse files
rameshrvzeebo
authored andcommitted
avoid panic while encrypting empty data (#109)
1 parent a66df3e commit c2dcc5c

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

ciphers.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,9 @@ func NewDecryptionCipherCtx(c *Cipher, e *Engine, key, iv []byte) (
287287
}
288288

289289
func (ctx *encryptionCipherCtx) EncryptUpdate(input []byte) ([]byte, error) {
290+
if len(input) == 0 {
291+
return nil, nil
292+
}
290293
outbuf := make([]byte, len(input)+ctx.BlockSize())
291294
outlen := C.int(len(outbuf))
292295
res := C.EVP_EncryptUpdate(ctx.ctx, (*C.uchar)(&outbuf[0]), &outlen,
@@ -298,6 +301,9 @@ func (ctx *encryptionCipherCtx) EncryptUpdate(input []byte) ([]byte, error) {
298301
}
299302

300303
func (ctx *decryptionCipherCtx) DecryptUpdate(input []byte) ([]byte, error) {
304+
if len(input) == 0 {
305+
return nil, nil
306+
}
301307
outbuf := make([]byte, len(input)+ctx.BlockSize())
302308
outlen := C.int(len(outbuf))
303309
res := C.EVP_DecryptUpdate(ctx.ctx, (*C.uchar)(&outbuf[0]), &outlen,

0 commit comments

Comments
 (0)