github.com/kaisenlinux/docker.io@v0.0.0-20230510090727-ea55db55fac7/swarmkit/manager/state/raft/storage/common_test.go (about) 1 package storage 2 3 import ( 4 "bytes" 5 "fmt" 6 7 "github.com/docker/swarmkit/api" 8 "github.com/docker/swarmkit/manager/encryption" 9 ) 10 11 // Common test utilities 12 13 type meowCrypter struct { 14 // only take encryption failures - decrypt failures can happen if the bytes 15 // do not have a cat 16 encryptFailures map[string]struct{} 17 } 18 19 func (m meowCrypter) Encrypt(orig []byte) (*api.MaybeEncryptedRecord, error) { 20 if _, ok := m.encryptFailures[string(orig)]; ok { 21 return nil, fmt.Errorf("refusing to encrypt") 22 } 23 return &api.MaybeEncryptedRecord{ 24 Algorithm: m.Algorithm(), 25 Data: append(orig, []byte("🐱")...), 26 }, nil 27 } 28 29 func (m meowCrypter) Decrypt(orig api.MaybeEncryptedRecord) ([]byte, error) { 30 if orig.Algorithm != m.Algorithm() || !bytes.HasSuffix(orig.Data, []byte("🐱")) { 31 return nil, fmt.Errorf("not meowcoded") 32 } 33 return bytes.TrimSuffix(orig.Data, []byte("🐱")), nil 34 } 35 36 func (m meowCrypter) Algorithm() api.MaybeEncryptedRecord_Algorithm { 37 return api.MaybeEncryptedRecord_Algorithm(-1) 38 } 39 40 var _ encryption.Encrypter = meowCrypter{} 41 var _ encryption.Decrypter = meowCrypter{}