MCPcopy
hub / github.com/syncthing/syncthing / TestKeyDerivation

Function TestKeyDerivation

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

Source from the content-addressed store, hash-verified

83}
84
85func TestKeyDerivation(t *testing.T) {
86 folderKey := testKeyGen.KeyFromPassword("my folder", "my password")
87 encryptedName := encryptDeterministic([]byte("filename.txt"), folderKey, nil)
88 if base32Hex.EncodeToString(encryptedName) != "3T5957I4IOA20VEIEER6JSQG0PEPIRV862II3K7LOF75Q" {
89 t.Error("encrypted name mismatch")
90 }
91
92 fileKey := testKeyGen.FileKey("filename.txt", folderKey)
93 // fmt.Println(base32Hex.EncodeToString(encryptBytes([]byte("hello world"), fileKey))) => A1IPD...
94 const encrypted = `A1IPD28ISL7VNPRSSSQM2L31L3IJPC08283RO89J5UG0TI9P38DO9RFGK12DK0KD7PKQP6U51UL2B6H96O`
95 bs, _ := base32Hex.DecodeString(encrypted)
96 dec, err := DecryptBytes(bs, fileKey)
97 if err != nil {
98 t.Error(err)
99 }
100 if string(dec) != "hello world" {
101 t.Error("decryption mismatch")
102 }
103}
104
105func TestDecryptNameInvalid(t *testing.T) {
106 key := new([32]byte)

Callers

nothing calls this directly

Calls 5

encryptDeterministicFunction · 0.85
DecryptBytesFunction · 0.85
KeyFromPasswordMethod · 0.80
FileKeyMethod · 0.80
ErrorMethod · 0.65

Tested by

no test coverage detected