Skip to content

Commit

Permalink
fromX509PubKey: support Edwards EdDSA and ECDSA keys
Browse files Browse the repository at this point in the history
  • Loading branch information
frasertweedale committed Dec 14, 2023
1 parent d918a2e commit aad40cc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
## Version NEXT

- Added `Crypto.JOSE.JWK.fromX509PubKey`, which supports conversion
from the `Data.X509.PubKey` type, such as can be read via the
*crypton-x509-store* package. It supports RSA, NIST ECC, and
Edwards curve key types (Ed25519, Ed448, X25519, X448).

- Updated `Crypto.JOSE.JWK.fromX509Certificate` to support Edwards
curve key types (Ed25519, Ed448, X25519, X448).


## Version 0.11 (2023-10-31)

- Migrate to the *crypton* library ecosystem. *crypton* was a hard
Expand Down
12 changes: 9 additions & 3 deletions src/Crypto/JOSE/JWK.hs
Original file line number Diff line number Diff line change
Expand Up @@ -255,15 +255,21 @@ fromOctets =


-- | Convert from a 'X509.PubKey' (such as can be read via the
-- /crypton-x509-store/ package).
-- /crypton-x509-store/ package). Supports RSA, ECDSA, Ed25519,
-- Ed448, X25519 and X448 keys.
--
fromX509PubKey :: (AsError e, MonadError e m) => X509.PubKey -> m JWK
fromX509PubKey = \case
X509.PubKeyRSA k -> pure (fromRSAPublic k)
X509.PubKeyEC k -> fromECPublic k
X509.PubKeyRSA k -> pure (fromRSAPublic k)
X509.PubKeyEC k -> fromECPublic k
X509.PubKeyX25519 k -> fromOKP $ X25519Key k Nothing
X509.PubKeyX448 k -> fromOKP $ X448Key k Nothing
X509.PubKeyEd25519 k -> fromOKP $ Ed25519Key k Nothing
X509.PubKeyEd448 k -> fromOKP $ Ed448Key k Nothing
_ -> throwing _KeyMismatch "X.509 key type not supported"
where
fromECPublic = fmap (fromKeyMaterial . ECKeyMaterial) . ecParametersFromX509
fromOKP = pure . fromKeyMaterial . OKPKeyMaterial


-- | Convert an X.509 certificate into a JWK.
Expand Down

0 comments on commit aad40cc

Please sign in to comment.