John starr rocks!
This commit is contained in:
1 parent
d2cd50b2e3
commit
0095eb7159
12 files changed
+343
-9
No files matched your search
@@ -0,0 +1,9 @@
|
||||
package integration
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestEnvelop(t *testing.T) {
|
||||
|
||||
}
|
||||
@@ -3,8 +3,11 @@ package integration
|
||||
import (
|
||||
"archive/zip"
|
||||
"bytes"
|
||||
"crypto"
|
||||
"crypto/rsa"
|
||||
"testing"
|
||||
|
||||
"github.com/didiercrunch/filou/asymetric"
|
||||
"github.com/didiercrunch/filou/envelop"
|
||||
"github.com/didiercrunch/filou/helper"
|
||||
"github.com/didiercrunch/filou/payload"
|
||||
@@ -23,6 +26,22 @@ func (this *mockEncryptor) Encrypt(data []byte) ([]byte, error) {
|
||||
|
||||
type mockSigner struct{}
|
||||
|
||||
var random = helper.NewMockRandomReader()
|
||||
|
||||
func generateRSAKeyPair() (*rsa.PrivateKey, *rsa.PublicKey) {
|
||||
if key, err := rsa.GenerateKey(random, 2048); err != nil {
|
||||
panic(err)
|
||||
} else {
|
||||
return key, &key.PublicKey
|
||||
}
|
||||
}
|
||||
|
||||
func getEncryterAndSigner() *asymetric.RsaOaepPss {
|
||||
alicePrivateKey, _ := generateRSAKeyPair()
|
||||
_, bobPubKey := generateRSAKeyPair()
|
||||
return &asymetric.RsaOaepPss{alicePrivateKey, bobPubKey, crypto.SHA512, random}
|
||||
}
|
||||
|
||||
func (this *mockSigner) Sign(data []byte) ([]byte, error) {
|
||||
// a slice with the sum of the data plus a "secret" value
|
||||
var sum byte = 36
|
||||
@@ -33,11 +52,13 @@ func (this *mockSigner) Sign(data []byte) ([]byte, error) {
|
||||
}
|
||||
|
||||
func TestPayloadCanBeUseInEnvelop(t *testing.T) {
|
||||
encryterAndSigner := getEncryterAndSigner()
|
||||
payload_ := payload.GetDefaultPayload(bytes.NewBufferString("some data to encrypt"))
|
||||
envelop := envelop.NewEnveloper(&mockEncryptor{}, payload_, &mockSigner{})
|
||||
envelop := envelop.NewEnveloper(encryterAndSigner, payload_, encryterAndSigner)
|
||||
w := helper.NewMockIoWriter()
|
||||
if err := envelop.WriteToWriter(w); err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
r, err := zip.NewReader(w.ReaderAt(), int64(w.Length()))
|
||||
if err != nil {
|
||||
|
||||
Reference in new issue
Block a user