crypto: use application/vnd namespace instead of binary/

This commit is contained in:
Peter Cai 2020-12-31 14:27:57 +08:00
parent cb41215ec9
commit 324903108b
2 changed files with 4 additions and 4 deletions

View File

@ -44,7 +44,7 @@ encryptFile = (file) ->
# Encrypt
encrypted = await crypto.subtle.encrypt algoParams, key, await file.arrayBuffer()
name = hex await crypto.subtle.encrypt algoParams, key, utf8Bytes file.name
mime = 'binary/' + hex await crypto.subtle.encrypt algoParams, key, utf8Bytes file.type
mime = 'application/vnd.angry.paste+' + hex await crypto.subtle.encrypt algoParams, key, utf8Bytes file.type
exportedKey = hex await crypto.subtle.exportKey 'raw', key
[exportedKey, hex(iv), name, mime, encrypted]
@ -63,7 +63,7 @@ importKeyAndIv = (key, iv) ->
decryptMetadata = (key, iv, name, mime) ->
[key, algoParams] = await importKeyAndIv key, iv
name = fromUtf8Bytes await crypto.subtle.decrypt algoParams, key, fromHex name
mime = fromHex mime.replace /^binary\//, ""
mime = fromHex mime.replace /^application\/vnd\.angry\.paste\+/, ""
mime = fromUtf8Bytes await crypto.subtle.decrypt algoParams, key, mime
[name, mime]
@ -80,4 +80,4 @@ export {
encryptFile,
decryptMetadata,
decryptFile
}
}

View File

@ -231,4 +231,4 @@ handleRemoteFetch = (req) ->
new Response "/paste/" + id,
status: 200
export default main
export default main