cipher_test.go 754 B

1234567891011121314151617181920212223242526272829303132
  1. package osscrypto
  2. import (
  3. "io"
  4. "strings"
  5. . "gopkg.in/check.v1"
  6. )
  7. func (s *OssCryptoBucketSuite) TestAesCtr(c *C) {
  8. var cipherData CipherData
  9. cipherData.RandomKeyIv(32, 16)
  10. cipher, _ := newAesCtr(cipherData)
  11. byteReader := strings.NewReader(RandLowStr(100))
  12. enReader := cipher.Encrypt(byteReader)
  13. encrypter := &CryptoEncrypter{Body: byteReader, Encrypter: enReader}
  14. encrypter.Close()
  15. buff := make([]byte, 10)
  16. n, err := encrypter.Read(buff)
  17. c.Assert(n, Equals, 0)
  18. c.Assert(err, Equals, io.EOF)
  19. deReader := cipher.Encrypt(byteReader)
  20. Decrypter := &CryptoDecrypter{Body: byteReader, Decrypter: deReader}
  21. Decrypter.Close()
  22. buff = make([]byte, 10)
  23. n, err = Decrypter.Read(buff)
  24. c.Assert(n, Equals, 0)
  25. c.Assert(err, Equals, io.EOF)
  26. }