break for cycle in getEncryptionKeyIDs (#74)

break cycle on literal/aead/encrypted/compressed packets
This commit is contained in:
Ilya Chesnokov 2020-08-26 19:05:06 +03:00 committed by GitHub
parent 475db8b1cb
commit af371097e0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -228,14 +228,22 @@ func (msg *PGPMessage) getEncryptionKeyIDs() ([]uint64, bool) {
packets := packet.NewReader(bytes.NewReader(msg.Data))
var err error
var ids []uint64
var encryptedKey *packet.EncryptedKey
Loop:
for {
var p packet.Packet
if p, err = packets.Next(); err == io.EOF {
break
}
enc, ok := p.(*packet.EncryptedKey)
if ok {
ids = append(ids, enc.KeyId)
switch p := p.(type) {
case *packet.EncryptedKey:
encryptedKey = p
ids = append(ids, encryptedKey.KeyId)
case *packet.SymmetricallyEncrypted,
*packet.AEADEncrypted,
*packet.Compressed,
*packet.LiteralData:
break Loop
}
}
if len(ids) > 0 {