Made a whole bunch of changes
Really not in the mood for git hygine right now
This commit is contained in:
parent
6885935089
commit
a3fbcea843
|
@ -100,29 +100,16 @@ in upstream
|
|||
-}
|
||||
|
||||
https://github.com/purescript/package-sets/releases/download/psc-0.15.4-20220901/packages.dhall sha256:f1531b29c21ac437ffe5666c1b6cc76f0a9c29d3c9d107ff047aa2567744994f
|
||||
with base64 =
|
||||
with base64-codec =
|
||||
{ dependencies =
|
||||
[ "arraybuffer-types"
|
||||
, "arrays"
|
||||
, "assert"
|
||||
, "console"
|
||||
, "effect"
|
||||
, "either"
|
||||
, "encoding"
|
||||
, "enums"
|
||||
, "exceptions"
|
||||
, "functions"
|
||||
, "partial"
|
||||
, "newtype"
|
||||
, "prelude"
|
||||
, "quickcheck"
|
||||
, "strings"
|
||||
, "stringutils"
|
||||
, "unicode"
|
||||
]
|
||||
, repo =
|
||||
"https://github.com/menelaos/purescript-b64"
|
||||
"https://github.com/gardspirito/purescript-base64-codec.git"
|
||||
, version =
|
||||
"v0.0.8" -- branch, tag, or commit hash
|
||||
"master" -- branch, tag, or commit hash
|
||||
}
|
||||
with subtlecrypto =
|
||||
{ dependencies =
|
||||
|
|
|
@ -14,11 +14,13 @@ to generate this file without the comments in this block.
|
|||
, dependencies =
|
||||
[ "aff"
|
||||
, "arraybuffer-types"
|
||||
, "b64"
|
||||
, "arraybuffer-builder"
|
||||
, "base64-codec"
|
||||
, "console"
|
||||
, "effect"
|
||||
, "either"
|
||||
, "fetch"
|
||||
, "foldable-traversable"
|
||||
, "maybe"
|
||||
, "prelude"
|
||||
, "strings"
|
||||
|
|
|
@ -7,25 +7,33 @@ import Effect.Aff (Aff, launchAff)
|
|||
import Effect.Class (liftEffect)
|
||||
import Effect.Console (log)
|
||||
import Fetch (fetch)
|
||||
import Data.Binary.Base64 (decode)
|
||||
import Data.Either (Either, hush, note)
|
||||
import Data.Base64 (decodeBase64, fromString)
|
||||
import Data.Either (Either, note)
|
||||
import Data.Maybe (Maybe(..))
|
||||
import Data.ArrayBuffer.Types (ArrayBuffer, Uint8Array)
|
||||
import Data.ArrayBuffer.Builder (execPut, putInt32be)
|
||||
import Data.ArrayBuffer.Types (ArrayBuffer)
|
||||
import Data.Foldable (traverse_)
|
||||
import Data.String (drop, indexOf', indexOf, splitAt)
|
||||
import Data.String.Pattern (Pattern(..))
|
||||
|
||||
import Crypto.Subtle.Constants.AES (aesGCM)
|
||||
import Crypto.Subtle.Constants.AES (aesGCM, t128)
|
||||
import Crypto.Subtle.Encrypt (aesGCM, decrypt) as Alg
|
||||
import Crypto.Subtle.Key.Import (aes)
|
||||
import Crypto.Subtle.Key.Import (importKey) as SC
|
||||
import Crypto.Subtle.Key.Types (CryptoKey, decrypt, raw)
|
||||
|
||||
nonceE :: Effect ArrayBuffer
|
||||
nonceE = execPut $ traverse_ putInt32be [0xd0, 0xc3, 0x75, 0x56, 0x58, 0xc1, 0x7e, 0x5f, 0xd6, 0xcc, 0xb6, 0x76]
|
||||
|
||||
data AviaryError
|
||||
= MalformedKey
|
||||
| MalformedUrl
|
||||
| DecryptFailed
|
||||
|
||||
instance showAviaryError :: Show AviaryError where
|
||||
show MalformedKey = "Malformed key!!"
|
||||
show MalformedUrl = "Malformed url!!"
|
||||
show DecryptFailed = "Either the data provided by the server was bad, or valid but incorrect key. Expiration likely."
|
||||
|
||||
type UrlInfo =
|
||||
{ server :: String
|
||||
|
@ -41,13 +49,18 @@ parseUrl url = note MalformedUrl do
|
|||
let { after: key, before: fileId } = splitAt poundIndex after
|
||||
Just { server, fileId, key: drop 1 key }
|
||||
|
||||
decodeKey :: String -> Either AviaryError Uint8Array
|
||||
decodeKey key = note MalformedKey $ hush $ decode key
|
||||
decodeKey :: String -> Either AviaryError ArrayBuffer
|
||||
decodeKey key = note MalformedKey $ decodeBase64 <$> fromString key
|
||||
|
||||
importKey :: ArrayBuffer -> Aff CryptoKey
|
||||
importKey key =
|
||||
SC.importKey raw key (aes aesGCM) false [decrypt]
|
||||
|
||||
decryptBlob :: CryptoKey -> ArrayBuffer -> ArrayBuffer -> Aff ArrayBuffer
|
||||
decryptBlob key cyphertext nonce =
|
||||
-- nonce <- makeAff (\_ -> nonceE)
|
||||
Alg.decrypt (Alg.aesGCM nonce Nothing (Just t128)) key cyphertext
|
||||
|
||||
main_aff :: Aff Unit
|
||||
main_aff = do
|
||||
{ status, text } <- fetch "https://envs.sh/Q_V.txt" {}
|
||||
|
|
Loading…
Reference in a new issue