<commit_before>module Scurry.Crypto (
    getRSAKey
) where

import System.Directory
import OpenSSL.RSA
import OpenSSL.PEM
import OpenSSL.EVP.PKey

import Scurry.Config

getRSAKey :: IO RSAKeyPair
getRSAKey = do
    dd <- userDataDir
    
    let pub = dd ++ "/pubKey"
        prv = dd ++ "/prvKey"

    pube <- doesFileExist pub
    prve <- doesFileExist prv

    case pube && prve of
         True  -> do
                (Just k) <- openRSAKey pub prv
                return k

         False -> do
                k <- generateRSAKey' 2048 65537
                writeRSAKey k pub prv
                return k<commit_msg>Expanded key opening and added cipher stuff i'll remove later<commit_after>module Scurry.Crypto (
    getRSAKey
) where

import Control.Monad
import Data.Maybe
import System.Directory

import OpenSSL.RSA
import OpenSSL.PEM
import OpenSSL.EVP.PKey
import OpenSSL.EVP.Cipher

import Scurry.Config

getRSAKey :: IO RSAKeyPair
getRSAKey = do
    dd <- userDataDir
    
    let pub = dd ++ "/pubKey"
        prv = dd ++ "/prvKey"

    pube <- doesFileExist pub
    prve <- doesFileExist prv

    c <- liftM fromJust $ getCipherByName "AES256-SHA"

    case pube && prve of
         True  -> do
                k <- openRSAKey pub prv
                case k of
                    Nothing   -> error $ "Not a private RSA key: " ++ prv
                    (Just k') -> return k'

         False -> do
                k <- generateRSAKey' 2048 65537
                writeRSAKey k pub prv
                return k
{'fraction_non_alphanumeric': 0.07531106745252128, 'fraction_numerical': 0.0137524557956778, 'mean_word_length': 1.7285714285714286, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4399783', 'n_tokens_mistral': 526, 'n_tokens_neox': 459, 'n_words': 149}