(no title)
ryandv | 1 month ago
I may want to communicate further information about the inhabitants or values of a particular type, without introducing extraneous or superfluous types:
-- given a path to a PEM encoded PKCS#8 formatted RSA private key and a
-- JWT Claims Set (RFC 7519) represented as a strict ByteString,
-- return a strict ByteString representing a base64 encoded RSA256-signed JWS.
generateJWT :: FilePath -> B.ByteString -> IO (Maybe B.ByteString)
generateJWT fp claims = (fmap unJwt <$>) . (maybe (return Nothing) (fmap eitherToMaybe . encodeClaims) =<<)
$ fromPKCS8 fp
where eitherToMaybe = preview _Right
encodeClaims = (flip $ rsaEncode RS256) claims
Arguably newtype wrappers could (or even should) be introduced in place of the more primitive FilePaths and ByteStrings - but even if they were, the type names would either be prohibitively long, or fail to communicate the full depth of information of the comment.
No comments yet.