mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-10-11 02:38:07 +00:00
core: fix encoding for name proof (#7672)
Co-authored-by: Evgeny @ SimpleX Chat <259188159+evgeny-simplex@users.noreply.github.com>
This commit is contained in:
co-authored by
Evgeny @ SimpleX Chat
parent
f2b3fe385c
commit
f924d233e4
@@ -295,7 +295,13 @@ data ProofPresHeader
|
||||
| PHFileDescr {chatBinding :: ByteString, fileSize :: Int64, descrHash :: ByteString, fileExpires :: Maybe UTCTime}
|
||||
| PHUnknown Char ByteString
|
||||
deriving (Eq, Show)
|
||||
deriving (ToJSON, FromJSON) via (StrJSON "ProofPresHeader" ProofPresHeader)
|
||||
|
||||
instance ToJSON ProofPresHeader where
|
||||
toJSON = toJSON . BBSPresHeader . strEncode
|
||||
toEncoding = toEncoding . BBSPresHeader . strEncode
|
||||
|
||||
instance FromJSON ProofPresHeader where
|
||||
parseJSON v = parseJSON v >>= \(BBSPresHeader ph) -> either fail pure $ strDecode ph
|
||||
|
||||
instance StrEncoding ProofPresHeader where
|
||||
strEncode = \case
|
||||
|
||||
@@ -51,6 +51,7 @@ badgeTests = do
|
||||
it "should accept unknown badge types" testUnknownBadgeType
|
||||
it "credential serializes to a paste-able token and back" testCredentialSerialization
|
||||
it "presentation headers encode and decode" testPresHeaderEncoding
|
||||
it "presentation headers with binary bytes round-trip through JSON" testPresHeaderJSON
|
||||
it "should reject a proof presented under another chat binding" testOtherChatBinding
|
||||
describe "redemption codes" $ do
|
||||
it "a generated code reads back" testCodeRoundTrip
|
||||
@@ -209,6 +210,21 @@ testPresHeaderEncoding =
|
||||
PHUnknown 'Z' "payload"
|
||||
]
|
||||
|
||||
testPresHeaderJSON :: IO ()
|
||||
testPresHeaderJSON =
|
||||
mapM_
|
||||
( \ph -> do
|
||||
J.eitherDecode (J.encode ph) `shouldBe` Right ph
|
||||
J.toJSON ph `shouldBe` J.toJSON (BBSPresHeader $ strEncode ph)
|
||||
)
|
||||
[ PHChat binaryBytes,
|
||||
PHFileInv {chatBinding = binaryBytes, fileSize = 139737},
|
||||
PHFileDescr {chatBinding = binaryBytes, fileSize = 139737, descrHash = binaryBytes, fileExpires = Just futureTime},
|
||||
PHUnknown 'Z' binaryBytes
|
||||
]
|
||||
where
|
||||
binaryBytes = "\0\1\31\34\92\127\128\195\255"
|
||||
|
||||
testOtherChatBinding :: IO ()
|
||||
testOtherChatBinding = do
|
||||
let ph = PHFileInv {chatBinding = aliceBinding, fileSize = 139737}
|
||||
|
||||
Reference in New Issue
Block a user