Add getEntity and getEcryptionKeyIDs functions to key and message types respectively (#55)

* add getEntity function to key struct

* add getEncryptionKeyIDs

* add chengelog + bool return in getEncryptionKeyIDs

* fix description
This commit is contained in:
Ilya Chesnokov 2020-07-02 15:55:11 +07:00 committed by GitHub
parent d1f6f7d718
commit 8d42a53775
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 64 additions and 0 deletions

View file

@ -223,6 +223,27 @@ func (msg *PGPMessage) GetArmoredWithCustomHeaders(comment, version string) (str
return armor.ArmorWithTypeAndCustomHeaders(msg.Data, constants.PGPMessageHeader, version, comment)
}
// getEncryptionKeyIds Returns the key IDs of the keys to which the session key is encrypted.
func (msg *PGPMessage) getEncryptionKeyIDs() ([]uint64, bool) {
packets := packet.NewReader(bytes.NewReader(msg.Data))
var err error
var ids []uint64
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)
}
}
if len(ids) > 0 {
return ids, true
}
return ids, false
}
// GetBinaryDataPacket returns the unarmored binary datapacket as a []byte.
func (msg *PGPSplitMessage) GetBinaryDataPacket() []byte {
return msg.DataPacket