parseTlsConfig :: (Key, Cert) -> Maybe TlsConfig
parseTlsConfig (PEM key, PEM certs) = do
  let (cerByt, keyByt) = (wainBytes certs, wainBytes key)
  pems <- pemParseBS cerByt & either (const Nothing) Just
  (cert, chain) <- case pems of
    []     -> Nothing
    p : ps -> pure (pemWriteBS p, pemWriteBS <$> ps)
  pure $ TlsConfig keyByt cert chain
 where
  wainBytes :: Wain -> ByteString
  wainBytes = encodeUtf8 . unWain
parseTlsConfig :: (Key, Cert) -> Maybe TlsConfig
parseTlsConfig (PEM key, PEM certs) = do
  let (cerByt, keyByt) = (wainBytes certs, wainBytes key)
  pems <- pemParseBS cerByt & either (const Nothing) Just
  (cert, chain) <- case pems of
    []     -> Nothing
    p : ps -> pure (pemWriteBS p, pemWriteBS <$> ps)
  pure $ TlsConfig keyByt cert chain
 where
  wainBytes :: Wain -> ByteString
  wainBytes = encodeUtf8 . unWain
parseTlsConfig (PEM key, PEM certs) = do
  let (cerByt, keyByt) = (wainBytes certs, wainBytes key)
  pems <- pemParseBS cerByt & either (const Nothing) Just
  (cert, chain) <- case pems of
    []     -> Nothing
    p : ps -> pure (pemWriteBS p, pemWriteBS <$> ps)
  pure $ TlsConfig keyByt cert chain
 where
  wainBytes :: Wain -> ByteString
  wainBytes = encodeUtf8 . unWain