From 27e600673bad56c6f3524c08ebdbab5ccd1b7f45 Mon Sep 17 00:00:00 2001 From: Stefan Friese Date: Sat, 20 Apr 2024 01:20:53 +0200 Subject: [PATCH] changed functions from last commit, because these were pretty much bullshit. decode base64 has erro handlin now --- .Main.hs.swp | Bin 0 -> 20480 bytes Main.hs | 69 ++++++++++++++++++++++++++------------------------- based.cabal | 12 ++++++--- 3 files changed, 43 insertions(+), 38 deletions(-) create mode 100644 .Main.hs.swp diff --git a/.Main.hs.swp b/.Main.hs.swp new file mode 100644 index 0000000000000000000000000000000000000000..21d2f5224bf0b03d0ca1f97e4155146c62bd45fc GIT binary patch literal 20480 zcmeHOZHy#E8E(ErK@OAzL?M=YD6_EBd;2xao$lez?%nO;F88rJu$O~K&rI)bdo$g$ z{c$_Pa*#+wNsKXp81M%PAxI)d5dEPE@qkDqXo4C@M52iyL4WWO6B9`!#^UyhcYrAeNEvpSxm z+mzMs;B}3*;8aEs$Fvw?J-z+yc1;atq`Z z$SsgtAh$qnfe*m~T0>D7%6*>#b)5hE@&B6_E6Vf0bHJ0pcY$r-7%&N34*X|_qWlQx z0yhFz1OL8AQCBVD9->702Xiqa0T$^3l!xi zz*E3Oz+FHcm#Th zRNzwJz4K8f@I3H1@NHldxEc5&z<~3Bw?CpN&jP1_Cx9OUCa?mOfUAJNoCjUN!@xHH z3pfOP8n^=Z6!1DWRDKQo7-#|&UChlKYb$7*DFkM#Yusy8f46|w0Vb`%TyOsrc z9jC`Tb{iPGdcXJVVaFhU8!PT*_*RsfVWw&vhsGce8iQx4G5DR($mmlnvLnX&hRYgy z-D>C!Dld|t__RfR&1Jf66N5ir&4%`CMiVlwCB@mAZMC>DN|Sro5WDU=k`OAm9{fRx zcQVV}(CsY)MhnU-RFWgnlqMHdp>9z(4cxL}HHTSiOc9Cu(bNivrAbPkPNu@(vudU5>as~_={|$n&16D2 z7oHLRq&8GHc^3($`~h3~4fRv}{s}cyWXX<+wo&!-sBMb)v0{ZA7E3$BX32KlgdV4U zO{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>q;{5#-@F1`W+z9Lh-p5({tH6^0oyXUKY2Y&8UD)$Q;1Pgq+XbSZ)Se7? z5V{c^luGlwNI!aBj3&D~OoO&8+GabVZL=NIHphqVc9;fj37RalHXhM7o~|s+g0eWv z*Hw<_Dre{lv7jr?@^y{vlFInl$G^d+nigxGfCgm=TA-~I&~&qo{p}2GJsN3?(|m0c zzR`Hyumhg1EkuL11kKkre!8|04cb7%i-bP3-s{pkWmXlt(TK8+`Zp@@OjlZHts*wd>6H~{ zi+pk8hGapZ_gq301tEZn6tuePmy}>bOPn1o2(o=jLi`mesaow^BLreM&<3 z7AfiQp?)RB+0iyZwoges+zWM6v}<7S=s5=xutXI%u2fdADI!NCj>i^`bEr@GeU8xY ziaekh9v-HSj+ciHM90#J29${75j^R6lBreZ3-B|lGE5aaPNExPb9!4h8*~(8(E*L-vaaQ^EzQLF7dBF84abWj`=KJ# zCpe`fyN8pbCgtAB7y97}j+Oe2xHvsJ;&2?>Z^-e0JY3eqc)zmZ^jKLC?lZi3G#|`C zILwtLQ3#5>v>AengsK-B)Fdwo3*_mnja!g!1cbz*j)a2f>>U^R7B$x}#fV1n1(8f; z&=U^nv@Rvnak8u`!VDyEHxy@~_?a9X(!F>sWbcP74sD|1W8>87Sg}EMqLm&dZ^PRT zbJ2W7#lt@CtTdd$sdHj(CNh8DMW-&@7wkJtrijFPm=uW0qvp{X@=XL=cRkx=SJRC@ z+102DW|fA5caeN#UngfxrGwu$sGJttx)5V*FcFNEYqM$i^u&mmiYEis7=Hiw1rTEF&Ao~NEoPvf*N^u zrCb 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,