Fix test encryption test (#37)
* Fix TestMultipleKeyMessageEncryption * Fix TestMultipleKeyMessageEncryption - simplify code * Add diffs to changelog * Simplify test code further
This commit is contained in:
parent
3f33c71496
commit
c8b7e87135
2 changed files with 19 additions and 9 deletions
|
|
@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
|
|||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [Unreleased]
|
||||
### Fixed
|
||||
- Fixed test `TestMultipleKeyMessageEncryption`
|
||||
|
||||
## [2.0.0] - 2020-01-06
|
||||
Since the open-sourcing of the library in May the API has been updated, listening to internal and
|
||||
external feedback, in order to have a flexible library, that can be used in a simple settings,
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ package crypto
|
|||
import (
|
||||
"bytes"
|
||||
"encoding/base64"
|
||||
"io"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
|
@ -153,19 +152,26 @@ func TestMultipleKeyMessageEncryption(t *testing.T) {
|
|||
t.Fatal("Expected no error when encrypting, got:", err)
|
||||
}
|
||||
|
||||
numKeyPackets := 0
|
||||
packets := packet.NewReader(bytes.NewReader(ciphertext.Data))
|
||||
for {
|
||||
// Test that ciphertext data contains three Encrypted Key Packets (tag 1)
|
||||
// followed by a single symmetrically encrypted data packet (tag 18)
|
||||
var p packet.Packet
|
||||
if p, err = packets.Next(); err == io.EOF {
|
||||
break
|
||||
packets := packet.NewReader(bytes.NewReader(ciphertext.Data))
|
||||
for i := 0; i < 3; i++ {
|
||||
if p, err = packets.Next(); err != nil {
|
||||
t.Fatal(err.Error())
|
||||
}
|
||||
if _, ok := p.(*packet.EncryptedKey); ok {
|
||||
numKeyPackets++
|
||||
if _, ok := p.(*packet.EncryptedKey); !ok {
|
||||
t.Fatalf("Expected Encrypted Key packet, got %T", p)
|
||||
}
|
||||
}
|
||||
assert.Exactly(t, 3, numKeyPackets)
|
||||
if p, err = packets.Next(); err != nil {
|
||||
t.Fatal(err.Error())
|
||||
}
|
||||
if _, ok := p.(*packet.SymmetricallyEncrypted); !ok {
|
||||
t.Fatalf("Expected Symmetrically Encrypted Data packet, got %T", p)
|
||||
}
|
||||
|
||||
// Decrypt message and verify correctness
|
||||
decrypted, err := keyRingTestPrivate.Decrypt(ciphertext, keyRingTestPublic, GetUnixTime())
|
||||
if err != nil {
|
||||
t.Fatal("Expected no error when decrypting, got:", err)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue