From 84d73f6f891244d211610012b51e6214a9ca7120 Mon Sep 17 00:00:00 2001 From: Jonathan Rudenberg Date: Thu, 10 Jul 2014 22:14:51 -0700 Subject: [PATCH] Add BodyLen, rename EncryptedLen to BoxLen --- box/box.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/box/box.go b/box/box.go index b68860d..ae5dbbf 100644 --- a/box/box.go +++ b/box/box.go @@ -78,7 +78,7 @@ func (c *Crypter) EncryptBox(dst []byte, ephKey *Key, plaintext []byte, padLen i } dstPrefixLen := len(dst) // Allocate a new slice that can fit the full encrypted box if the current dst doesn't fit - if encLen := c.EncryptedLen(len(plaintext) + padLen); cap(dst)-len(dst) < encLen { + if encLen := c.BoxLen(len(plaintext) + padLen); cap(dst)-len(dst) < encLen { newDst := make([]byte, len(dst), len(dst)+encLen) copy(newDst, dst) dst = newDst @@ -97,10 +97,14 @@ func (c *Crypter) EncryptBox(dst []byte, ephKey *Key, plaintext []byte, padLen i return c.EncryptBody(dst, plaintext, dst[dstPrefixLen:], padLen), nil } -func (c *Crypter) EncryptedLen(n int) int { +func (c *Crypter) BoxLen(n int) int { return n + (2 * c.Cipher.DHLen()) + (2 * c.Cipher.MACLen()) + 4 } +func (c *Crypter) BodyLen(n int) int { + return n + c.Cipher.MACLen() + 4 +} + func (c *Crypter) SetContext(cc []byte) { c.cipher(cc) }