-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathencrypt_test.go
45 lines (42 loc) · 1.76 KB
/
encrypt_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package minilock
import (
"bytes"
"testing"
)
func Test_RoundTripMinilock(t *testing.T) {
// EncryptFile(filename string, fileContents []byte, sender *taber.Keys, recipients... *taber.Keys) (miniLockContents []byte, err error)
// DecryptFileContents(file_contents []byte, recipientKey *taber.Keys) (senderID, filename string, contents []byte, err error)
// Set Up
testcase, err := Asset("binary_samples/mye.go")
if err != nil {
t.Fatal("Couldn't load test binary asset.")
}
sender := testKey1
recipient := testKey2
// Encryption
gen_crypted, err := EncryptFileContents("mye.go", testcase, sender, recipient.PublicOnly(), sender.PublicOnly())
if err != nil {
t.Fatal("Couldn't create encrypted test case: ", err.Error())
}
// Decryption
senderID, filename, contents, err := DecryptFileContents(gen_crypted, recipient)
if err != nil {
t.Fatal("Failed to decrypt with recipient key: " + err.Error())
}
realSenderID, err := sender.EncodeID()
if err != nil {
t.Error(err.Error())
}
if senderID != realSenderID {
t.Error("Received SenderID [1] did not match sending key's ID [2]: ", senderID, realSenderID)
}
if filename != "mye.go" {
t.Error("Received filename [1] didn't match encrypted filename [2]: ", filename, "mye.go")
}
if !bytes.Equal(testcase, contents) {
t.Error("Received plaintext [1] didn't match encrypted plaintext [2]: \n", string(contents), "\n", string(testcase))
}
}
// func (self *miniLockv1Header) ExtractDecryptInfo(recipientKey *taber.Keys) (nonce []byte, DI *DecryptInfoEntry, err error) {
// func (self *miniLockv1Header) ExtractFileInfo(recipientKey *taber.Keys) (*FileInfo, error) {
// func (self *miniLockv1Header) DecryptContents(ciphertext []byte, recipientKey *taber.Keys) (senderID, filename string, contents []byte, err error) {