{-# OPTIONS_HADDOCK show-extensions #-}
{-# LANGUAGE DerivingStrategies #-}
module Libjwt.Keys
( Secret(..)
, RsaKeyPair(..)
, RsaPubKey(..)
, EcKeyPair(..)
, EcPubKey(..)
, SigningKey(..)
, DecodingKey(..)
)
where
import Data.ByteString ( ByteString )
import qualified Data.ByteString as ByteString
import qualified Data.ByteString.UTF8 as UTF8
import Data.String
newtype Secret = MkSecret { Secret -> ByteString
reveal :: ByteString }
deriving stock (Int -> Secret -> ShowS
[Secret] -> ShowS
Secret -> String
(Int -> Secret -> ShowS)
-> (Secret -> String) -> ([Secret] -> ShowS) -> Show Secret
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Secret] -> ShowS
$cshowList :: [Secret] -> ShowS
show :: Secret -> String
$cshow :: Secret -> String
showsPrec :: Int -> Secret -> ShowS
$cshowsPrec :: Int -> Secret -> ShowS
Show, Secret -> Secret -> Bool
(Secret -> Secret -> Bool)
-> (Secret -> Secret -> Bool) -> Eq Secret
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Secret -> Secret -> Bool
$c/= :: Secret -> Secret -> Bool
== :: Secret -> Secret -> Bool
$c== :: Secret -> Secret -> Bool
Eq)
instance IsString Secret where
fromString :: String -> Secret
fromString = ByteString -> Secret
MkSecret (ByteString -> Secret)
-> (String -> ByteString) -> String -> Secret
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ByteString
UTF8.fromString
data RsaKeyPair = FromRsaPem { RsaKeyPair -> ByteString
privKey :: ByteString, RsaKeyPair -> ByteString
pubKey :: ByteString }
deriving stock (Int -> RsaKeyPair -> ShowS
[RsaKeyPair] -> ShowS
RsaKeyPair -> String
(Int -> RsaKeyPair -> ShowS)
-> (RsaKeyPair -> String)
-> ([RsaKeyPair] -> ShowS)
-> Show RsaKeyPair
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RsaKeyPair] -> ShowS
$cshowList :: [RsaKeyPair] -> ShowS
show :: RsaKeyPair -> String
$cshow :: RsaKeyPair -> String
showsPrec :: Int -> RsaKeyPair -> ShowS
$cshowsPrec :: Int -> RsaKeyPair -> ShowS
Show, RsaKeyPair -> RsaKeyPair -> Bool
(RsaKeyPair -> RsaKeyPair -> Bool)
-> (RsaKeyPair -> RsaKeyPair -> Bool) -> Eq RsaKeyPair
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RsaKeyPair -> RsaKeyPair -> Bool
$c/= :: RsaKeyPair -> RsaKeyPair -> Bool
== :: RsaKeyPair -> RsaKeyPair -> Bool
$c== :: RsaKeyPair -> RsaKeyPair -> Bool
Eq)
newtype RsaPubKey = FromRsaPub { RsaPubKey -> ByteString
rsaPublicKey :: ByteString }
deriving stock (Int -> RsaPubKey -> ShowS
[RsaPubKey] -> ShowS
RsaPubKey -> String
(Int -> RsaPubKey -> ShowS)
-> (RsaPubKey -> String)
-> ([RsaPubKey] -> ShowS)
-> Show RsaPubKey
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RsaPubKey] -> ShowS
$cshowList :: [RsaPubKey] -> ShowS
show :: RsaPubKey -> String
$cshow :: RsaPubKey -> String
showsPrec :: Int -> RsaPubKey -> ShowS
$cshowsPrec :: Int -> RsaPubKey -> ShowS
Show, RsaPubKey -> RsaPubKey -> Bool
(RsaPubKey -> RsaPubKey -> Bool)
-> (RsaPubKey -> RsaPubKey -> Bool) -> Eq RsaPubKey
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RsaPubKey -> RsaPubKey -> Bool
$c/= :: RsaPubKey -> RsaPubKey -> Bool
== :: RsaPubKey -> RsaPubKey -> Bool
$c== :: RsaPubKey -> RsaPubKey -> Bool
Eq)
data EcKeyPair = FromEcPem { EcKeyPair -> ByteString
ecPrivKey :: ByteString, EcKeyPair -> ByteString
ecPubKey :: ByteString }
deriving stock (Int -> EcKeyPair -> ShowS
[EcKeyPair] -> ShowS
EcKeyPair -> String
(Int -> EcKeyPair -> ShowS)
-> (EcKeyPair -> String)
-> ([EcKeyPair] -> ShowS)
-> Show EcKeyPair
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [EcKeyPair] -> ShowS
$cshowList :: [EcKeyPair] -> ShowS
show :: EcKeyPair -> String
$cshow :: EcKeyPair -> String
showsPrec :: Int -> EcKeyPair -> ShowS
$cshowsPrec :: Int -> EcKeyPair -> ShowS
Show, EcKeyPair -> EcKeyPair -> Bool
(EcKeyPair -> EcKeyPair -> Bool)
-> (EcKeyPair -> EcKeyPair -> Bool) -> Eq EcKeyPair
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: EcKeyPair -> EcKeyPair -> Bool
$c/= :: EcKeyPair -> EcKeyPair -> Bool
== :: EcKeyPair -> EcKeyPair -> Bool
$c== :: EcKeyPair -> EcKeyPair -> Bool
Eq)
newtype EcPubKey = FromEcPub { EcPubKey -> ByteString
ecPublicKey :: ByteString }
deriving stock (Int -> EcPubKey -> ShowS
[EcPubKey] -> ShowS
EcPubKey -> String
(Int -> EcPubKey -> ShowS)
-> (EcPubKey -> String) -> ([EcPubKey] -> ShowS) -> Show EcPubKey
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [EcPubKey] -> ShowS
$cshowList :: [EcPubKey] -> ShowS
show :: EcPubKey -> String
$cshow :: EcPubKey -> String
showsPrec :: Int -> EcPubKey -> ShowS
$cshowsPrec :: Int -> EcPubKey -> ShowS
Show, EcPubKey -> EcPubKey -> Bool
(EcPubKey -> EcPubKey -> Bool)
-> (EcPubKey -> EcPubKey -> Bool) -> Eq EcPubKey
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: EcPubKey -> EcPubKey -> Bool
$c/= :: EcPubKey -> EcPubKey -> Bool
== :: EcPubKey -> EcPubKey -> Bool
$c== :: EcPubKey -> EcPubKey -> Bool
Eq)
class DecodingKey k where
getDecodingKey :: k -> ByteString
instance DecodingKey Secret where
getDecodingKey :: Secret -> ByteString
getDecodingKey = Secret -> ByteString
reveal
instance DecodingKey RsaKeyPair where
getDecodingKey :: RsaKeyPair -> ByteString
getDecodingKey = RsaKeyPair -> ByteString
pubKey
instance DecodingKey RsaPubKey where
getDecodingKey :: RsaPubKey -> ByteString
getDecodingKey = RsaPubKey -> ByteString
rsaPublicKey
instance DecodingKey EcKeyPair where
getDecodingKey :: EcKeyPair -> ByteString
getDecodingKey = EcKeyPair -> ByteString
ecPubKey
instance DecodingKey EcPubKey where
getDecodingKey :: EcPubKey -> ByteString
getDecodingKey = EcPubKey -> ByteString
ecPublicKey
instance DecodingKey () where
getDecodingKey :: () -> ByteString
getDecodingKey ()
_ = ByteString
ByteString.empty
class DecodingKey k => SigningKey k where
getSigningKey :: k -> ByteString
instance SigningKey Secret where
getSigningKey :: Secret -> ByteString
getSigningKey = Secret -> ByteString
reveal
instance SigningKey RsaKeyPair where
getSigningKey :: RsaKeyPair -> ByteString
getSigningKey = RsaKeyPair -> ByteString
privKey
instance SigningKey EcKeyPair where
getSigningKey :: EcKeyPair -> ByteString
getSigningKey = EcKeyPair -> ByteString
ecPrivKey
instance SigningKey () where
getSigningKey :: () -> ByteString
getSigningKey ()
_ = ByteString
ByteString.empty