From eacf839182d1efcd45991eedf227d365458d9c03 Mon Sep 17 00:00:00 2001 From: Mikkel Krautz Date: Sat, 8 Dec 2012 23:39:19 +0100 Subject: [PATCH] pkg/cryptstate: add Overhead(); use it internally. --- pkg/cryptstate/cryptstate.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pkg/cryptstate/cryptstate.go b/pkg/cryptstate/cryptstate.go index 03afd80..43493bf 100644 --- a/pkg/cryptstate/cryptstate.go +++ b/pkg/cryptstate/cryptstate.go @@ -97,12 +97,18 @@ func (cs *CryptState) SetKey(key []byte, eiv []byte, div []byte) error { return nil } +// Overhead returns the length, in bytes, that a ciphertext +// is longer than a plaintext. +func (cs *CryptState) Overhead() int { + return 1 + cs.mode.Overhead() +} + func (cs *CryptState) Decrypt(dst, src []byte) error { - if len(src) < 4 { + if len(src) < cs.Overhead() { return errors.New("cryptstate: crypted length too short to decrypt") } - plain_len := len(src) - 4 + plain_len := len(src) - cs.Overhead() if len(dst) != plain_len { return errors.New("cryptstate: plain_len and src len mismatch") }