moduleStorage.Hashed.Hash(Hash(..),encodeBase64u,decodeBase64u,encodeBase16,decodeBase16,sha256,rawHash,match)whereimportqualifiedBundled.SHA256asSHAimportqualifiedData.ByteStringasBSimportqualifiedData.ByteString.InternalasBSIimportqualifiedData.ByteString.LazyasBLimportqualifiedCodec.Binary.Base64UrlasB64UimportqualifiedCodec.Binary.Base16asB16importData.Maybe(isJust,fromJust)importData.Char(toLower,toUpper)dataHash=SHA256!BS.ByteString|SHA1!BS.ByteString|NoHashderiving(Show,Eq,Ord,Read)base16::BS.ByteString->BS.ByteStringdebase16::BS.ByteString->MaybeBS.ByteStringbase64u::BS.ByteString->BS.ByteStringdebase64u::BS.ByteString->MaybeBS.ByteStringbase16=BS.pack.map(BSI.c2w.toLower).B16.encode.BS.unpackbase64u=BS.pack.mapBSI.c2w.B64U.encode.BS.unpackdebase64ubs=caseB64U.decode$mapBSI.w2c$BS.unpackbsofJusts->Just$BS.packsNothing->Nothingdebase16bs=caseB16.decode$map(toUpper.BSI.w2c)$BS.unpackbsofJusts->Just$BS.packsNothing->NothingencodeBase64u::Hash->BS.ByteStringencodeBase64u(SHA256bs)=base64ubsencodeBase64u(SHA1bs)=base64ubsencodeBase64uNoHash=BS.empty-- | Produce a base16 (ascii-hex) encoded string from a hash. This can be-- turned back into a Hash (see "decodeBase16". This is a loss-less process.encodeBase16::Hash->BS.ByteStringencodeBase16(SHA256bs)=base16bsencodeBase16(SHA1bs)=base16bsencodeBase16NoHash=BS.empty-- | Take a base64/url-encoded string and decode it as a "Hash". If the string-- is malformed, yields NoHash.decodeBase64u::BS.ByteString->HashdecodeBase64ubs|BS.lengthbs==44&&isJust(debase64ubs)=SHA256(fromJust$debase64ubs)|BS.lengthbs==28&&isJust(debase64ubs)=SHA1(fromJust$debase64ubs)|otherwise=NoHash-- | Take a base16-encoded string and decode it as a "Hash". If the string is-- malformed, yields NoHash.decodeBase16::BS.ByteString->HashdecodeBase16bs|BS.lengthbs==64&&isJust(debase16bs)=SHA256(fromJust$debase16bs)|BS.lengthbs==40&&isJust(debase16bs)=SHA1(fromJust$debase16bs)|otherwise=NoHash-- | Compute a sha256 of a (lazy) ByteString. However, although this works-- correctly for any bytestring, it is only efficient if the bytestring only-- has a sigle chunk.sha256::BL.ByteString->Hashsha256bits=SHA256(SHA.sha256$BS.concat$BL.toChunksbits)rawHash::Hash->BS.ByteStringrawHashNoHash=error"Cannot obtain raw hash from NoHash."rawHash(SHA1s)=srawHash(SHA256s)=smatch::Hash->Hash->BoolNoHash`match`_=False_`match`NoHash=Falsex`match`y=x==y