Refactor api (#6)
* Refactor library, remove duplicates * Rebuild structure to use Messages and Signature models * Use PGPSplitMessage * Remove signature model * Various fixes * Add helpers with tests * Fixes, add some docs, add tests * Add attachment helpers * Add helpers Symmetric encryption * Edit docs + examples * Rename kr to keyRing * Various fixes for documentation * Edit JSON handling functions, add decrypt keyring via token * Add proposal changes doc * Fix CI * Drop *Message functions, join CleartextMessage and BinaryMessage * Change canonicalization and trimming only to text signatures * Add cleartextsignature, detach signature from message model, move helpers * Documentation, remove optional parameters * Move verification to separate model * Don't return message in VerifyDetached * Update table of contents in readme * Appease golint * Run go fmt * Rename Encrypt/DecryptMessageWithPassword to ..WithToken These functions shouldn't be used with user-provided passwords, as they don't do any key-stretching. * Change key generation usernames
This commit is contained in:
parent
82d49bf235
commit
e65ed17b41
34 changed files with 2573 additions and 1478 deletions
45
helper/cleartext_test.go
Normal file
45
helper/cleartext_test.go
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
package helper
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
const signedPlainText = "Signed message\n"
|
||||
const testTime = 1557754627 // 2019-05-13T13:37:07+00:00
|
||||
var signedMessageTest = regexp.MustCompile(
|
||||
"(?s)^-----BEGIN PGP SIGNED MESSAGE-----.*-----BEGIN PGP SIGNATURE-----.*-----END PGP SIGNATURE-----$")
|
||||
|
||||
func TestSignClearText(t *testing.T) {
|
||||
// Password defined in base_test
|
||||
armored, err := SignCleartextMessageArmored(
|
||||
readTestFile("keyring_privateKey", false),
|
||||
testMailboxPassword,
|
||||
signedPlainText,
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
t.Fatal("Cannot armor message:", err)
|
||||
}
|
||||
|
||||
assert.Regexp(t, signedMessageTest, armored)
|
||||
|
||||
verified, err := VerifyCleartextMessageArmored(
|
||||
readTestFile("keyring_publicKey", false),
|
||||
armored,
|
||||
pgp.GetUnixTime(),
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatal("Cannot verify message:", err)
|
||||
}
|
||||
|
||||
assert.Exactly(t, canonicalizeAndTrim(signedPlainText), verified)
|
||||
}
|
||||
|
||||
func TestMessageCanonicalizeAndTrim(t *testing.T) {
|
||||
text := "Hi \ntest!\r\n\n"
|
||||
canon := canonicalizeAndTrim(text)
|
||||
assert.Exactly(t, "Hi\r\ntest!\r\n\r\n", canon)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue