Add signature context for embedded signatures

This commit is contained in:
M. Thiercelin 2023-04-06 11:38:15 +02:00
parent 49211b24ff
commit 97323a4c2b
No known key found for this signature in database
GPG key ID: 29581E7E24EBEC0A
11 changed files with 931 additions and 169 deletions

View file

@ -36,3 +36,45 @@ func TestAEADKeyRingDecryption(t *testing.T) {
assert.Exactly(t, "hello world\n", decrypted.GetString())
}
func TestTextMessageEncryptionWithSignatureAndContext(t *testing.T) {
var message = NewPlainMessageFromString("plain text")
var testContext = "test-context"
ciphertext, err := keyRingTestPublic.EncryptWithContext(message, keyRingTestPrivate, NewSigningContext(testContext, true))
if err != nil {
t.Fatal("Expected no error when encrypting, got:", err)
}
decrypted, err := keyRingTestPrivate.DecryptWithContext(
ciphertext,
keyRingTestPublic,
GetUnixTime(),
NewVerificationContext(testContext, true, 0),
)
if err != nil {
t.Fatal("Expected no error when decrypting, got:", err)
}
assert.Exactly(t, message.GetString(), decrypted.GetString())
}
func TestTextMessageEncryptionWithSignatureAndContextAndCompression(t *testing.T) {
var message = NewPlainMessageFromString("plain text")
var testContext = "test-context"
ciphertext, err := keyRingTestPublic.EncryptWithContextAndCompression(message, keyRingTestPrivate, NewSigningContext(testContext, true))
if err != nil {
t.Fatal("Expected no error when encrypting, got:", err)
}
decrypted, err := keyRingTestPrivate.DecryptWithContext(
ciphertext,
keyRingTestPublic,
GetUnixTime(),
NewVerificationContext(testContext, true, 0),
)
if err != nil {
t.Fatal("Expected no error when decrypting, got:", err)
}
assert.Exactly(t, message.GetString(), decrypted.GetString())
}