forked from quic-go/quic-go
simplify AEAD.Seal
This commit is contained in:
@@ -8,5 +8,5 @@ import (
|
|||||||
// An AEAD implements QUIC's authenticated encryption and associated data
|
// An AEAD implements QUIC's authenticated encryption and associated data
|
||||||
type AEAD interface {
|
type AEAD interface {
|
||||||
Open(associatedData []byte, ciphertext io.Reader) (*bytes.Reader, error)
|
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)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,9 +40,7 @@ func (*NullAEAD) Open(associatedData []byte, r io.Reader) (*bytes.Reader, error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Seal writes hash and ciphertext to the buffer
|
// Seal writes hash and ciphertext to the buffer
|
||||||
func (*NullAEAD) Seal(b *bytes.Buffer, associatedData []byte, r *bytes.Reader) {
|
func (*NullAEAD) Seal(b *bytes.Buffer, associatedData []byte, plaintext []byte) {
|
||||||
plaintext, _ := ioutil.ReadAll(r)
|
|
||||||
|
|
||||||
hash := New128a()
|
hash := New128a()
|
||||||
hash.Write(associatedData)
|
hash.Write(associatedData)
|
||||||
hash.Write(plaintext)
|
hash.Write(plaintext)
|
||||||
|
|||||||
@@ -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.")
|
plainText := []byte("They are endowed with reason and conscience and should act towards one another in a spirit of brotherhood.")
|
||||||
b := &bytes.Buffer{}
|
b := &bytes.Buffer{}
|
||||||
aead := &crypto.NullAEAD{}
|
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.")...)))
|
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.")...)))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user