mirror of
https://github.com/simplex-chat/simplexmq.git
synced 2026-04-27 08:35:15 +00:00
2a89394174
* separate skipped messages from ratchet * return diff for skipped messages instead of the whole state (tests fail) * fix ratchet tests * JSON encoding/decoding for ratchet state * schema for ratchets * split MonadUnliftIO instance for ExceptT to a separate file * update StrEncoding instance for Str * ratchet store methods * updateRatchet store method * move E2E ratchet params to Ratchet module * x3dh key agreement for double ratchet * test/fix x3dh, use x3dh for ratchets initialization * store/get x3dh keys, save ratchet of fixed X448 type * double-ratchet encryption integration (tests fail) * fix double ratchet * fix padding and message length * remove unused code for "activations" * remove comment * add version checks for forward/backward compatibility * split loading ratchet and skipped message keys * remove unused encoding instances for Algorithm types * update ratchet initialization params
31 lines
1.1 KiB
Haskell
31 lines
1.1 KiB
Haskell
module Simplex.Messaging.Agent.QueryString where
|
|
|
|
import Data.Attoparsec.ByteString.Char8 (Parser)
|
|
import qualified Data.Attoparsec.ByteString.Char8 as A
|
|
import Data.ByteString.Char8 (ByteString)
|
|
import qualified Data.ByteString.Char8 as B
|
|
import Data.List (find)
|
|
import qualified Network.HTTP.Types as Q
|
|
import Simplex.Messaging.Encoding.String
|
|
import Simplex.Messaging.Parsers (parseAll)
|
|
|
|
data QueryStringParams = QSP QSPEscaping Q.SimpleQuery
|
|
deriving (Show)
|
|
|
|
data QSPEscaping = QEscape | QNoEscaping
|
|
deriving (Show)
|
|
|
|
instance StrEncoding QueryStringParams where
|
|
strEncode (QSP esc q) = case esc of
|
|
QEscape -> Q.renderSimpleQuery False q
|
|
QNoEscaping ->
|
|
Q.renderQueryPartialEscape False $
|
|
map (\(n, v) -> (n, [Q.QN v])) q
|
|
strP = QSP QEscape . Q.parseSimpleQuery <$> A.takeTill (\c -> c == ' ' || c == '\n')
|
|
|
|
queryParam :: StrEncoding a => ByteString -> QueryStringParams -> Parser a
|
|
queryParam name (QSP _ q) =
|
|
case find ((== name) . fst) q of
|
|
Just (_, p) -> either fail pure $ parseAll strP p
|
|
_ -> fail $ "no qs param " <> B.unpack name
|