package service_test import ( "bytes" "crypto/rand" "crypto/rsa" "git.cijber.net/zer.ooo/service" "testing" ) func TestPadding(t *testing.T) { x := []byte{0, 0, 0} x = append(x, service.Pad(x)...) padLen := service.GetPad(x) if padLen != 5 { t.Errorf("Failed adding/measuring padding, Pad(%v, len=%d)", x, padLen) } y := service.Unpad(x) if len(y) != 3 { t.Errorf("Failed padding and unpadding, Pad(%v), Unpad(%v)", x, y) } } func TestSingleRound(t *testing.T) { keyA, _ := rsa.GenerateKey(rand.Reader, 4096) keyB, _ := rsa.GenerateKey(rand.Reader, 4096) signature := []byte("Hello world!") v := &service.BaseMessage{} x := make([]byte, 0) b := bytes.NewBuffer(x) err := service.EncryptAndSign(v, keyA, &keyB.PublicKey, signature, b) if err != nil { t.Errorf("Failed encrypting: %s", err) } err = service.DecryptAndVerify(b.Bytes(), keyB, &keyA.PublicKey, signature, &service.BaseMessage{}) if err != nil { t.Errorf("Failed decrypting: %s", err) } }