Skip to content

Make JSON de/serializing of CipherText roundtrip#10

Merged
wraithm merged 1 commit intobitnomial:masterfrom
LaurentRDC:master
Apr 29, 2025
Merged

Make JSON de/serializing of CipherText roundtrip#10
wraithm merged 1 commit intobitnomial:masterfrom
LaurentRDC:master

Conversation

@LaurentRDC
Copy link

This is a small update to ensure that CipherText JSON de/serialization roundtrips.

This was tested using a script like so:

{-# LANGUAGE OverloadedStrings #-}

import qualified Data.ByteString.Base64 as B64
import Data.Text (Text)
import qualified Data.Text.Encoding as TE
import Network.VaultTool
import Network.VaultTool.Transit

main = do
    let vaultAddress = VaultAddress "..."
        vaultAuthToken = VaultAuthToken "..."
        vaultMountedPath = VaultMountedPath "transit"

        sensitiveInfo = "12345678" :: Text

        keyname = "..."

    manager <- defaultManager

    let conn = authenticatedVaultConnection manager vaultAddress vaultAuthToken

    CipherText b64 <-
        encryptBase64
            conn
            vaultMountedPath
            keyname
            (encodeBase64 $ TE.encodeUtf8 sensitiveInfo)

    xs <-
        either error TE.decodeUtf8Lenient
            . decodeBase64
            <$> decryptBase64
                conn
                vaultMountedPath
                keyname
                (CipherText b64)

    print xs

@LaurentRDC LaurentRDC requested a review from wraithm April 29, 2025 18:33
@wraithm wraithm merged commit 1f8a031 into bitnomial:master Apr 29, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants