Support unicode surrogate code points

This commit is contained in:
Daniel Huigens
2018-07-30 17:02:13 +02:00
parent a2f53b2ce2
commit 00a2c0c0c2
11 changed files with 59 additions and 67 deletions

View File

@@ -707,7 +707,7 @@ yYDnCgA=
await privKey.decrypt('hello world');
return openpgp.sign({ privateKeys:[privKey], message: openpgp.message.fromText(plaintext), detached: true}).then(async function(signed) {
const signature = await openpgp.signature.readArmored(signed.signature);
return openpgp.verify({ publicKeys:[pubKey], message: openpgp.message.fromBinary(openpgp.util.str_to_Uint8Array(openpgp.util.encode_utf8(plaintext))), signature: signature });
return openpgp.verify({ publicKeys:[pubKey], message: openpgp.message.fromBinary(openpgp.util.encode_utf8(plaintext)), signature: signature });
}).then(function(cleartextSig) {
expect(cleartextSig).to.exist;
expect(cleartextSig.signatures).to.have.length(1);
@@ -740,7 +740,7 @@ yYDnCgA=
await Promise.all([privKey.primaryKey.decrypt('hello world'), privKey.subKeys[0].keyPacket.decrypt('hello world')]);
return openpgp.sign({ privateKeys:[privKey], message: openpgp.message.fromText(plaintext), detached: true}).then(async function(signed) {
const signature = await openpgp.signature.readArmored(signed.signature);
return openpgp.encrypt({ message: openpgp.message.fromBinary(openpgp.util.str_to_Uint8Array(openpgp.util.encode_utf8(plaintext))), publicKeys: [pubKey], signature })
return openpgp.encrypt({ message: openpgp.message.fromBinary(openpgp.util.encode_utf8(plaintext)), publicKeys: [pubKey], signature })
}).then(async ({ data }) => {
const csMsg = await openpgp.message.readArmored(data);
return openpgp.decrypt({ message: csMsg, privateKeys: [ privKey ], publicKeys: [ pubKey ] });

View File

@@ -431,7 +431,7 @@ function tests() {
});
expect(util.isStream(decrypted.data)).to.equal(expectedType);
const reader = openpgp.stream.getReader(decrypted.data);
expect((await reader.peekBytes(256)).toString('utf8').substr(0, 64)).to.equal(plaintext[0]);
expect((await reader.peekBytes(plaintext[0].length * 4)).toString('utf8').substr(0, plaintext[0].length)).to.equal(plaintext[0]);
if (i > 10) throw new Error('Data did not arrive early.');
expect((await reader.readToEnd()).toString('utf8')).to.equal(util.concat(plaintext));
} finally {

View File

@@ -3,15 +3,16 @@
* Generates a 64 character long javascript string out of the whole utf-8 range.
*/
function createSomeMessage(){
const length = 50;
let arr = [];
for (let i= 0; i < length; i++){
arr.push(String.fromCharCode(
Math.floor(Math.random() * 10174) + 1));
for (let i = 0; i < 30; i++) {
arr.push(Math.floor(Math.random() * 10174) + 1);
}
return ' \t' + arr.join('').replace(/\r/g, '\n') + ' \t\n한국어/조선말';
for (let i = 0; i < 10; i++) {
arr.push(0x1F600 + Math.floor(Math.random() * (0x1F64F - 0x1F600)) + 1);
}
return ' \t' + String.fromCodePoint(...arr).replace(/\r/g, '\n') + ' \t\n한국어/조선말';
}
module.exports = {
createSomeMessage: createSomeMessage
};
module.exports = {
createSomeMessage: createSomeMessage
};

View File

@@ -153,10 +153,6 @@ describe('Util unit tests', function() {
});
describe("Misc.", function() {
it('util.decode_utf8 throws error if invalid parameter type', function () {
const test = openpgp.util.decode_utf8.bind(null, {chameleon: true});
expect(test).to.throw(Error, /Parameter "utf8" is not of type string/);
});
it('util.readNumber should not overflow until full range of uint32', function () {
const ints = [Math.pow(2, 20), Math.pow(2, 25), Math.pow(2, 30), Math.pow(2, 32) - 1];
for(let i = 0; i < ints.length; i++) {