Add BodyLen, rename EncryptedLen to BoxLen

This commit is contained in:
Jonathan Rudenberg 2014-07-10 22:14:51 -07:00
parent 0ab5aed0b2
commit 84d73f6f89

View File

@ -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)
}