Use seperate nonces for thumbnails and full images
Corresponds to dd2748c in aviary-cli
This commit is contained in:
parent
0895108c07
commit
3802543623
|
@ -2,7 +2,7 @@ module Aviary.Logic where
|
|||
|
||||
import Prelude
|
||||
import AviaryFormat.Format (Format(..), Image, Index, parseIndex) as Format
|
||||
import Aviary.FFI (arrayBufferToBlob, nonce, decodeBlurhash32)
|
||||
import Aviary.FFI (arrayBufferToBlob, nonce_a, nonce_b, decodeBlurhash32)
|
||||
import Aviary.Model (formatToMime, GalleryError(..), Image, ImageData(..), ImageError(..), Model(..))
|
||||
|
||||
import Control.Monad.Error.Class (try)
|
||||
|
@ -106,8 +106,8 @@ fetchImageAsBlobUrl nonce format key fileID = do
|
|||
else UnknownStatusCodeForImage status
|
||||
Left e -> pure $ IError $ NetworkError $ message e
|
||||
|
||||
_fetchImg :: ImageData -> Format.Format -> Aff (Maybe CryptoKey) -> Aff ImageData
|
||||
_fetchImg imgdata format cryptokey = case imgdata of
|
||||
_fetchImg :: ArrayBuffer -> ImageData -> Format.Format -> Aff (Maybe CryptoKey) -> Aff ImageData
|
||||
_fetchImg nonce imgdata format cryptokey = case imgdata of
|
||||
Unloaded fileID -> do
|
||||
key' <- cryptokey
|
||||
case key' of
|
||||
|
@ -116,10 +116,10 @@ _fetchImg imgdata format cryptokey = case imgdata of
|
|||
loadedOrError -> pure loadedOrError
|
||||
|
||||
fetchThumb :: Image -> Aff ImageData
|
||||
fetchThumb image = _fetchImg image.thumb Format.Format_WEBP image.key
|
||||
fetchThumb image = _fetchImg nonce_b image.thumb Format.Format_WEBP image.key
|
||||
|
||||
fetchFull :: Image -> Aff ImageData
|
||||
fetchFull image = _fetchImg image.full image.format image.key
|
||||
fetchFull image = _fetchImg nonce_a image.full image.format image.key
|
||||
|
||||
type Parameters =
|
||||
{ fileId :: String
|
||||
|
@ -148,7 +148,7 @@ fetch_and_decrypt_gallery params = do
|
|||
case result of
|
||||
Right {status: 200, arrayBuffer} -> do
|
||||
encryptedIndex <- arrayBuffer
|
||||
serializedIndex <- try $ decryptBlob params.key encryptedIndex nonce
|
||||
serializedIndex <- try $ decryptBlob params.key encryptedIndex nonce_a
|
||||
case serializedIndex of
|
||||
Left _ -> pure $ GError DecryptFailed
|
||||
Right serializedIndex' -> do
|
||||
|
|
|
@ -4,7 +4,8 @@ export function arrayBufferToBlob(mime) {
|
|||
}
|
||||
}
|
||||
|
||||
export const nonce = new Uint8Array([0xd0, 0xc3, 0x75, 0x56, 0x58, 0xc1, 0x7e, 0x5f, 0xd6, 0xcc, 0xb6, 0x76]).buffer
|
||||
export const nonce_a = new Uint8Array([0xd0, 0xc3, 0x75, 0x56, 0x58, 0xc1, 0x7e, 0x5f, 0xd6, 0xcc, 0xb6, 0x76]).buffer
|
||||
export const nonce_b = new Uint8Array([0x77, 0xe7, 0xf7, 0x64, 0x33, 0x80, 0x25, 0x49, 0xec, 0xef, 0x57, 0x3f]).buffer
|
||||
|
||||
export function decodeBlurhashImpl(just) {
|
||||
return function(nothing) {
|
||||
|
|
|
@ -11,7 +11,8 @@ import Web.File.Blob (Blob)
|
|||
-- blobData :: ArrayBuffer
|
||||
foreign import arrayBufferToBlob :: String -> ArrayBuffer -> Blob
|
||||
|
||||
foreign import nonce :: ArrayBuffer
|
||||
foreign import nonce_a :: ArrayBuffer
|
||||
foreign import nonce_b :: ArrayBuffer
|
||||
|
||||
foreign import decodeBlurhashImpl :: (forall x. x -> Maybe x) -> (forall x. Maybe x) -> Int -> Int -> String -> Maybe String
|
||||
decodeBlurhash :: Int -> Int -> String -> Maybe String
|
||||
|
|
Loading…
Reference in New Issue