diff --git a/.Main.hs.swp b/.Main.hs.swp new file mode 100644 index 0000000..21d2f52 Binary files /dev/null and b/.Main.hs.swp differ diff --git a/Main.hs b/Main.hs index 262d25e..b6a0ea2 100644 --- a/Main.hs +++ b/Main.hs @@ -73,28 +73,29 @@ data Based = Decode { -- helper functions -convertToByteString :: String -> Either String BS.ByteString -convertToByteString str = - case BSU.fromString str of - Just bs -> Right bs - Nothing -> Left "Failed to convert string to ByteString." +-- convertToByteString :: String -> Either String C.ByteString +-- convertToByteString str = +-- case BSU.fromString str of +-- Just bs -> Right bs + -- Nothing -> Left "Failed to convert string to ByteString." -decodeFromBase91 :: C.ByteString -> Either String BS.ByteString - case B91.decode bs = - Just bs -> Right decoded - Nothing -> Left "Failed to decode from Base91." +-- decodeFromBase91 :: C.ByteString -> Either String BS.ByteString +-- decodeToBase91 decoded = +-- case B91.decode of +-- Just bs -> Right decoded +-- Nothing -> Left "Failed to decode from Base91." -encodeToBase64 :: C.ByteString -> Either String BS.ByteString -encodeToBase64 bs = - case B64.encode bs of - encoded | BS.null encoded -> Left "Failed to encode base64." - | otherwise -> Right encoded +-- encodeToBase64 :: C.ByteString -> Either String BS.ByteString +-- encodeToBase64 bs = +-- case B64.encode bs of +-- encoded | BS.null encoded -> Left "Failed to encode base64." +-- | otherwise -> Right encoded -decodeFromBase64 :: C.ByteString -> Either String BS.ByteString +decodeFromBase64 :: C.ByteString -> Either String C.ByteString decodeFromBase64 bs = case B64L.decodeLenient bs of - decoded | BS.null decoded -> Left "Failed to decode from base64." + decoded | C.null decoded -> Left "Failed to decode from base64." | otherwise -> Right decoded -- | otherwise -> Right (BSU.toString decoded) -- Left err -> Left $ "Failed to decode from base64: " ++ err @@ -111,31 +112,31 @@ octToInt (x : xs) = x + 8 * octToInt xs -- base functions -- without the show func, sequences like \n will not be shown as characters but will be executed as newline --- dec91 = C.unpack . B91.decode -dec91 :: C.ByteString -> Either String String -dec91 input = do - decoded <- decodeFromBase91 input - -- return $ C.unpack decoded - -- is the same as - return (C.unpack decoded) +dec91 = C.unpack . B91.decode +-- dec91 :: C.ByteString -> Either String String +-- dec91 input = do +-- decoded <- decodeFromBase91 input +-- -- return $ C.unpack decoded +-- -- is the same as +-- return (C.unpack decoded) enc91 = B91.encode . BSU.fromString dec85 = C.unpack . U.fromRight . B85.decode . BSU.fromString enc85 = C.unpack . B85.encode . BSU.fromString -- dec64 = C.unpack . B64L.decodeLenient . BSU.fromString -dec64 :: String -> Either String String -dec64 input = do - byteString <- convertToByteString input - decoded <- decodeFromBase64 byteString - return $ BSU.toString decoded +dec64 :: String -> String +dec64 input = + case decodeFromBase64 (BSU.fromString input) of + Right byteString -> C.unpack byteString + Left errMsg -> "Error: " ++ errMsg --- enc64 = C.unpack . B64.encode . BSU.fromString -enc64 :: String -> Either String String -enc64 input = do - byteString <- convertToByteString input - encoded <- encodeToBase64 byteString - return $ BS.unpack encoded +enc64 = C.unpack . B64.encode . BSU.fromString +-- enc64 :: String -> Either String String +-- enc64 input = do +-- byteString <- convertToByteString input +-- encoded <- encodeToBase64 byteString +-- return $ BS.unpack encoded dec64url = C.unpack . U.fromRight . B64U.decode . BSU.fromString enc64url = C.unpack . B64U.encode . BSU.fromString diff --git a/based.cabal b/based.cabal index bc4c7f0..3a2659d 100644 --- a/based.cabal +++ b/based.cabal @@ -11,8 +11,10 @@ library other-modules: -- Data.Bytes.Text.Ascii build-depends: - base ^>= 4.13.0.0, - byteslice == 0.2.6.0, + -- base ^>= 4.13.0.0, + base, + -- byteslice == 0.2.6.0, + byteslice, -- hs-source-dirs: default-language: Haskell2010 @@ -20,14 +22,16 @@ executable based main-is: Main.hs other-modules: MyLib build-depends: - base ^>= 4.13.0.0, + -- base ^>= 4.13.0.0, + base, cmdargs, sandi, base62, base91, utf8-string, bytestring, - byteslice == 0.2.6.0, + -- byteslice == 0.2.6.0, + byteslice, either-unwrap, text-show, hxt,