Skip to content

Commit

Permalink
Merge pull request #142 from ProtonMail/new-key-entity
Browse files Browse the repository at this point in the history
Add NewKeyFromEntity
  • Loading branch information
wussler authored Aug 4, 2021
2 parents f929560 + e0531b7 commit 2329c36
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
13 changes: 8 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,21 @@ 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

### 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`.
Expand Down
9 changes: 8 additions & 1 deletion crypto/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 2329c36

Please sign in to comment.