From 96ae3efa6419ce272dc216da4f38469efaaf611d Mon Sep 17 00:00:00 2001 From: Lucas Clemente Date: Sun, 10 Apr 2016 20:33:24 +0200 Subject: [PATCH] simplify AEAD.Seal --- crypto/AEAD.go | 2 +- crypto/NullAEAD.go | 4 +--- crypto/NullAEAD_test.go | 2 +- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/crypto/AEAD.go b/crypto/AEAD.go index 8dff1545a..a6275705d 100644 --- a/crypto/AEAD.go +++ b/crypto/AEAD.go @@ -8,5 +8,5 @@ import ( // An AEAD implements QUIC's authenticated encryption and associated data type AEAD interface { Open(associatedData []byte, ciphertext io.Reader) (*bytes.Reader, error) - Seal(b *bytes.Buffer, associatedData []byte, r *bytes.Reader) + Seal(b *bytes.Buffer, associatedData []byte, plaintext []byte) } diff --git a/crypto/NullAEAD.go b/crypto/NullAEAD.go index d3ebf8f7c..b03d8bd5b 100644 --- a/crypto/NullAEAD.go +++ b/crypto/NullAEAD.go @@ -40,9 +40,7 @@ func (*NullAEAD) Open(associatedData []byte, r io.Reader) (*bytes.Reader, error) } // Seal writes hash and ciphertext to the buffer -func (*NullAEAD) Seal(b *bytes.Buffer, associatedData []byte, r *bytes.Reader) { - plaintext, _ := ioutil.ReadAll(r) - +func (*NullAEAD) Seal(b *bytes.Buffer, associatedData []byte, plaintext []byte) { hash := New128a() hash.Write(associatedData) hash.Write(plaintext) diff --git a/crypto/NullAEAD_test.go b/crypto/NullAEAD_test.go index fe74bfb8e..ca92775dc 100644 --- a/crypto/NullAEAD_test.go +++ b/crypto/NullAEAD_test.go @@ -38,7 +38,7 @@ var _ = Describe("Crypto/NullAEAD", func() { plainText := []byte("They are endowed with reason and conscience and should act towards one another in a spirit of brotherhood.") b := &bytes.Buffer{} aead := &crypto.NullAEAD{} - aead.Seal(b, aad, bytes.NewReader(plainText)) + aead.Seal(b, aad, plainText) Expect(b.Bytes()).To(Equal(append([]byte{0x98, 0x9b, 0x33, 0x3f, 0xe8, 0xde, 0x32, 0x5c, 0xa6, 0x7f, 0x9c, 0xf7}, []byte("They are endowed with reason and conscience and should act towards one another in a spirit of brotherhood.")...))) }) })