Merge pull request #19650 from Snuffleupagus/shorten-crypto
Shorten the `src/core/crypto.js` file a little bit
This commit is contained in:
commit
78b310afb1
@ -916,23 +916,15 @@ class CipherTransformFactory {
|
|||||||
cipher = new ARCFourCipher(derivedKey);
|
cipher = new ARCFourCipher(derivedKey);
|
||||||
checkData = cipher.encryptBlock(checkData);
|
checkData = cipher.encryptBlock(checkData);
|
||||||
}
|
}
|
||||||
for (j = 0, n = checkData.length; j < n; ++j) {
|
|
||||||
if (userPassword[j] !== checkData[j]) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
cipher = new ARCFourCipher(encryptionKey);
|
cipher = new ARCFourCipher(encryptionKey);
|
||||||
checkData = cipher.encryptBlock(
|
checkData = cipher.encryptBlock(
|
||||||
CipherTransformFactory._defaultPasswordBytes
|
CipherTransformFactory._defaultPasswordBytes
|
||||||
);
|
);
|
||||||
for (j = 0, n = checkData.length; j < n; ++j) {
|
|
||||||
if (userPassword[j] !== checkData[j]) {
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
return checkData.every((data, k) => userPassword[k] === data)
|
||||||
}
|
? encryptionKey
|
||||||
return encryptionKey;
|
: null;
|
||||||
}
|
}
|
||||||
|
|
||||||
#decodeUserPassword(password, ownerPassword, revision, keyLength) {
|
#decodeUserPassword(password, ownerPassword, revision, keyLength) {
|
||||||
@ -1133,12 +1125,13 @@ class CipherTransformFactory {
|
|||||||
perms
|
perms
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (!encryptionKey && !password) {
|
if (!encryptionKey) {
|
||||||
|
if (!password) {
|
||||||
throw new PasswordException(
|
throw new PasswordException(
|
||||||
"No password given",
|
"No password given",
|
||||||
PasswordResponses.NEED_PASSWORD
|
PasswordResponses.NEED_PASSWORD
|
||||||
);
|
);
|
||||||
} else if (!encryptionKey && password) {
|
}
|
||||||
// Attempting use the password as an owner password
|
// Attempting use the password as an owner password
|
||||||
const decodedPassword = this.#decodeUserPassword(
|
const decodedPassword = this.#decodeUserPassword(
|
||||||
passwordBytes,
|
passwordBytes,
|
||||||
|
|||||||
@ -992,7 +992,7 @@
|
|||||||
"password": "ELXRTQWS",
|
"password": "ELXRTQWS",
|
||||||
"md5": "db2fedbd36d6fa27d4e52f9bd2d96b8c",
|
"md5": "db2fedbd36d6fa27d4e52f9bd2d96b8c",
|
||||||
"rounds": 1,
|
"rounds": 1,
|
||||||
"type": "load"
|
"type": "eq"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": "issue5334",
|
"id": "issue5334",
|
||||||
@ -5961,7 +5961,7 @@
|
|||||||
"md5": "b58adce5dbb08936ddb0d904f0da8716",
|
"md5": "b58adce5dbb08936ddb0d904f0da8716",
|
||||||
"rounds": 1,
|
"rounds": 1,
|
||||||
"link": false,
|
"link": false,
|
||||||
"type": "load",
|
"type": "eq",
|
||||||
"password": "abc"
|
"password": "abc"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -5970,7 +5970,7 @@
|
|||||||
"md5": "73a8091d0ab2a47af5ca45047f04da99",
|
"md5": "73a8091d0ab2a47af5ca45047f04da99",
|
||||||
"rounds": 1,
|
"rounds": 1,
|
||||||
"link": false,
|
"link": false,
|
||||||
"type": "load",
|
"type": "eq",
|
||||||
"password": "\u00E6\u00F8\u00E5",
|
"password": "\u00E6\u00F8\u00E5",
|
||||||
"about": "The password (æøå) is UTF8 encoded."
|
"about": "The password (æøå) is UTF8 encoded."
|
||||||
},
|
},
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user