PKCS8.writeKeyFileToMemory PKCS8.PKCS8Format
. singleton
. X509.PrivKeyRSA
extract
. PKCS8.readKeyFileFromMemory
where
extract ((PKCS8.Unprotected (X509.PrivKeyRSA x)):_) = Just x
extract (_ : rest) = extract rest
extract _ = Nothing
X509.writePubKeyFileToMemory
. singleton
. X509.PubKeyRSA
extract
. X509.readPubKeyFileFromMemory
where
extract ((X509.PubKeyRSA x):_) = Just x
extract (_ : rest) = extract rest
extract _ = Nothing
liftIO (decodePrivateKey <$> BS.readFile path) >>= \case
Just x -> return x
Nothing -> fail "Bad key file"