Make newlines in armored objects consistent

- Don't add an extraneous newline at the end of base64-encoded data
  if it is a multiple of 60 characters long.
- Generate \r\n instead of \n in base64-encoded data.
- Generate one newline instead of two after END PGP PUBLIC KEY BLOCK
  for consistency with the other footers.
This commit is contained in:
Daniel Huigens
2018-09-12 14:41:14 +02:00
parent 585ee3ff44
commit d8840294cf
4 changed files with 83 additions and 12 deletions

View File

@@ -391,7 +391,7 @@ function armor(messagetype, body, partindex, parttotal, customComment) {
result.push(addheader(customComment));
result.push(base64.encode(body));
result.push("\r\n=", getCheckSum(bodyClone), "\r\n");
result.push("-----END PGP PUBLIC KEY BLOCK-----\r\n\r\n");
result.push("-----END PGP PUBLIC KEY BLOCK-----\r\n");
break;
case enums.armor.private_key:
result.push("-----BEGIN PGP PRIVATE KEY BLOCK-----\r\n");

View File

@@ -41,6 +41,9 @@ function s2r(t, u = false) {
const r = [];
const tl = value.length;
for (let n = 0; n < tl; n++) {
if (l && (l % 60) === 0 && !u) {
r.push("\r\n");
}
c = value[n];
if (s === 0) {
r.push(b64.charAt((c >> 2) & 63));
@@ -52,15 +55,11 @@ function s2r(t, u = false) {
r.push(b64.charAt(a | ((c >> 6) & 3)));
l += 1;
if ((l % 60) === 0 && !u) {
r.push("\n");
r.push("\r\n");
}
r.push(b64.charAt(c & 63));
}
l += 1;
if ((l % 60) === 0 && !u) {
r.push("\n");
}
s += 1;
if (s === 3) {
s = 0;
@@ -73,7 +72,7 @@ function s2r(t, u = false) {
r.push(b64.charAt(a));
l += 1;
if ((l % 60) === 0 && !u) {
r.push("\n");
r.push("\r\n");
}
if (!u) {
r.push('=');
@@ -82,7 +81,7 @@ function s2r(t, u = false) {
}
if (s === 1 && !u) {
if ((l % 60) === 0 && !u) {
r.push("\n");
r.push("\r\n");
}
r.push('=');
}