Implement GetArmoredWithCustomHeaders (#48)
* Implement GetArmoredWithCustomHeaders ArmorWithTypeAndCustomHeaders can be reused by other PGP armoured objects. * Update linting, and lint accordingly `godot` has been improved and `goerr113` has been added (and ignored here). * Add custom headers for keys * Minor comment changes Co-authored-by: Aron Wussler <aron@wussler.it>
This commit is contained in:
parent
b1e005fec3
commit
dcc82c9fc3
10 changed files with 176 additions and 31 deletions
|
|
@ -178,3 +178,39 @@ func TestMultipleKeyMessageEncryption(t *testing.T) {
|
|||
}
|
||||
assert.Exactly(t, message.GetString(), decrypted.GetString())
|
||||
}
|
||||
|
||||
func TestMessageGetArmoredWithCustomHeaders(t *testing.T) {
|
||||
var message = NewPlainMessageFromString("plain text")
|
||||
|
||||
ciphertext, err := keyRingTestPublic.Encrypt(message, keyRingTestPrivate)
|
||||
if err != nil {
|
||||
t.Fatal("Expected no error when encrypting, got:", err)
|
||||
}
|
||||
comment := "User-defined comment"
|
||||
version := "User-defined version"
|
||||
armored, err := ciphertext.GetArmoredWithCustomHeaders(comment, version)
|
||||
if err != nil {
|
||||
t.Fatal("Could not armor the ciphertext:", err)
|
||||
}
|
||||
|
||||
assert.Contains(t, armored, "Comment: "+comment)
|
||||
assert.Contains(t, armored, "Version: "+version)
|
||||
}
|
||||
|
||||
func TestMessageGetArmoredWithEmptyHeaders(t *testing.T) {
|
||||
var message = NewPlainMessageFromString("plain text")
|
||||
|
||||
ciphertext, err := keyRingTestPublic.Encrypt(message, keyRingTestPrivate)
|
||||
if err != nil {
|
||||
t.Fatal("Expected no error when encrypting, got:", err)
|
||||
}
|
||||
comment := ""
|
||||
version := ""
|
||||
armored, err := ciphertext.GetArmoredWithCustomHeaders(comment, version)
|
||||
if err != nil {
|
||||
t.Fatal("Could not armor the ciphertext:", err)
|
||||
}
|
||||
|
||||
assert.NotContains(t, armored, "Version")
|
||||
assert.NotContains(t, armored, "Comment")
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue