From e0531b779cb6c7a9de73e1aac69c5d3d0c3c5509 Mon Sep 17 00:00:00 2001 From: Aron Wussler Date: Wed, 4 Aug 2021 12:00:27 +0200 Subject: [PATCH] Add NewKeyFromEntity --- CHANGELOG.md | 13 ++++++++----- crypto/key.go | 9 ++++++++- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9dbe220..95f9626 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,11 +5,8 @@ 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 -### Security -- All keys are now checked on parsing from the underlying library - -### Fixed -- Dummy keys now show the correct locked/unlocked status +### Added +- `NewKeyFromEntity` to create a key from an openpgp entity ### Changed - Improved documentation for differences between text and binary messages @@ -17,6 +14,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Deprecated - `(key *Key) Check() (bool, error)` is now deprecated, all keys are now checked upon import from x/crypto +### Fixed +- Dummy keys now show the correct locked/unlocked status + +### Security +- All keys are now checked on parsing from the underlying library + ## [2.2.1] 2021-07-27 ### Changed - Changed the returned `SignatureVerificationError.Status` when trying to verify a message with no embedded signature. It used to return `constants.SIGNATURE_NO_VERIFIER` and now returns `constants.SIGNATURE_NOT_SIGNED`. diff --git a/crypto/key.go b/crypto/key.go index ced0fc3..f73a910 100644 --- a/crypto/key.go +++ b/crypto/key.go @@ -59,6 +59,13 @@ func NewKeyFromArmored(armored string) (key *Key, err error) { return NewKeyFromArmoredReader(strings.NewReader(armored)) } +func NewKeyFromEntity(entity *openpgp.Entity) (*Key, error) { + if entity == nil { + return nil, errors.New("gopenpgp: nil entity provided") + } + return &Key{entity: entity}, nil +} + // GenerateRSAKeyWithPrimes generates a RSA key using the given primes. func GenerateRSAKeyWithPrimes( name, email string, @@ -466,7 +473,7 @@ func generateKey( return nil, errors.New("gopenpgp: error in generating private key") } - return &Key{newEntity}, nil + return NewKeyFromEntity(newEntity) } // keyIDToHex casts a keyID to hex with the correct padding.