MCPcopy
hub / github.com/syncthing/syncthing / TestEnDecryptBytes

Function TestEnDecryptBytes

lib/protocol/encryption_test.go:119–145  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

117}
118
119func TestEnDecryptBytes(t *testing.T) {
120 var key [32]byte
121 cases := [][]byte{
122 {},
123 {1, 2, 3, 4, 5},
124 }
125 for _, tc := range cases {
126 var prev []byte
127 for i := 0; i < 5; i++ {
128 enc := encryptBytes(tc, &key)
129 if bytes.Equal(enc, prev) {
130 t.Error("encryption should not repeat")
131 }
132 prev = enc
133 if len(tc) > 0 && bytes.Contains(enc, tc) {
134 t.Error("shouldn't contain plaintext")
135 }
136 dec, err := DecryptBytes(enc, &key)
137 if err != nil {
138 t.Error(err)
139 }
140 if !bytes.Equal(dec, tc) {
141 t.Error("mismatch after decryption")
142 }
143 }
144 }
145}
146
147func encFileInfo() FileInfo {
148 return FileInfo{

Callers

nothing calls this directly

Calls 5

encryptBytesFunction · 0.85
DecryptBytesFunction · 0.85
ContainsMethod · 0.80
ErrorMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected