mirror of
https://github.com/openpgpjs/openpgpjs.git
synced 2025-06-17 11:46:38 +00:00
Internal: improve tree-shaking in armor module
This commit is contained in:
parent
8e5da78971
commit
6db98f1e47
@ -16,7 +16,7 @@
|
|||||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
|
||||||
import { transform as streamTransform, transformPair as streamTransformPair, getReader as streamGetReader, getWriter as streamGetWriter, isArrayStream, readToEnd as streamReadToEnd, passiveClone as streamPassiveClone } from '@openpgp/web-stream-tools';
|
import { transform as streamTransform, transformPair as streamTransformPair, getReader as streamGetReader, getWriter as streamGetWriter, isArrayStream, readToEnd as streamReadToEnd, passiveClone as streamPassiveClone } from '@openpgp/web-stream-tools';
|
||||||
import * as base64 from './base64';
|
import { encode as encodeBase64, decode as decodeBase64 } from './base64';
|
||||||
import enums from '../enums';
|
import enums from '../enums';
|
||||||
import util from '../util';
|
import util from '../util';
|
||||||
import defaultConfig from '../config';
|
import defaultConfig from '../config';
|
||||||
@ -115,7 +115,7 @@ function addheader(customComment, config) {
|
|||||||
*/
|
*/
|
||||||
function getCheckSum(data) {
|
function getCheckSum(data) {
|
||||||
const crc = createcrc24(data);
|
const crc = createcrc24(data);
|
||||||
return base64.encode(crc);
|
return encodeBase64(crc);
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://create.stephan-brumme.com/crc32/#slicing-by-8-overview
|
// https://create.stephan-brumme.com/crc32/#slicing-by-8-overview
|
||||||
@ -239,7 +239,7 @@ export function unarmor(input) {
|
|||||||
let headersDone;
|
let headersDone;
|
||||||
let text = [];
|
let text = [];
|
||||||
let textDone;
|
let textDone;
|
||||||
const data = base64.decode(streamTransformPair(input, async (readable, writable) => {
|
const data = decodeBase64(streamTransformPair(input, async (readable, writable) => {
|
||||||
const reader = streamGetReader(readable);
|
const reader = streamGetReader(readable);
|
||||||
try {
|
try {
|
||||||
while (true) {
|
while (true) {
|
||||||
@ -357,14 +357,14 @@ export function armor(messageType, body, partIndex, partTotal, customComment, em
|
|||||||
case enums.armor.multipartSection:
|
case enums.armor.multipartSection:
|
||||||
result.push('-----BEGIN PGP MESSAGE, PART ' + partIndex + '/' + partTotal + '-----\n');
|
result.push('-----BEGIN PGP MESSAGE, PART ' + partIndex + '/' + partTotal + '-----\n');
|
||||||
result.push(addheader(customComment, config));
|
result.push(addheader(customComment, config));
|
||||||
result.push(base64.encode(body));
|
result.push(encodeBase64(body));
|
||||||
maybeBodyClone && result.push('=', getCheckSum(maybeBodyClone));
|
maybeBodyClone && result.push('=', getCheckSum(maybeBodyClone));
|
||||||
result.push('-----END PGP MESSAGE, PART ' + partIndex + '/' + partTotal + '-----\n');
|
result.push('-----END PGP MESSAGE, PART ' + partIndex + '/' + partTotal + '-----\n');
|
||||||
break;
|
break;
|
||||||
case enums.armor.multipartLast:
|
case enums.armor.multipartLast:
|
||||||
result.push('-----BEGIN PGP MESSAGE, PART ' + partIndex + '-----\n');
|
result.push('-----BEGIN PGP MESSAGE, PART ' + partIndex + '-----\n');
|
||||||
result.push(addheader(customComment, config));
|
result.push(addheader(customComment, config));
|
||||||
result.push(base64.encode(body));
|
result.push(encodeBase64(body));
|
||||||
maybeBodyClone && result.push('=', getCheckSum(maybeBodyClone));
|
maybeBodyClone && result.push('=', getCheckSum(maybeBodyClone));
|
||||||
result.push('-----END PGP MESSAGE, PART ' + partIndex + '-----\n');
|
result.push('-----END PGP MESSAGE, PART ' + partIndex + '-----\n');
|
||||||
break;
|
break;
|
||||||
@ -374,35 +374,35 @@ export function armor(messageType, body, partIndex, partTotal, customComment, em
|
|||||||
result.push(text.replace(/^-/mg, '- -'));
|
result.push(text.replace(/^-/mg, '- -'));
|
||||||
result.push('\n-----BEGIN PGP SIGNATURE-----\n');
|
result.push('\n-----BEGIN PGP SIGNATURE-----\n');
|
||||||
result.push(addheader(customComment, config));
|
result.push(addheader(customComment, config));
|
||||||
result.push(base64.encode(body));
|
result.push(encodeBase64(body));
|
||||||
maybeBodyClone && result.push('=', getCheckSum(maybeBodyClone));
|
maybeBodyClone && result.push('=', getCheckSum(maybeBodyClone));
|
||||||
result.push('-----END PGP SIGNATURE-----\n');
|
result.push('-----END PGP SIGNATURE-----\n');
|
||||||
break;
|
break;
|
||||||
case enums.armor.message:
|
case enums.armor.message:
|
||||||
result.push('-----BEGIN PGP MESSAGE-----\n');
|
result.push('-----BEGIN PGP MESSAGE-----\n');
|
||||||
result.push(addheader(customComment, config));
|
result.push(addheader(customComment, config));
|
||||||
result.push(base64.encode(body));
|
result.push(encodeBase64(body));
|
||||||
maybeBodyClone && result.push('=', getCheckSum(maybeBodyClone));
|
maybeBodyClone && result.push('=', getCheckSum(maybeBodyClone));
|
||||||
result.push('-----END PGP MESSAGE-----\n');
|
result.push('-----END PGP MESSAGE-----\n');
|
||||||
break;
|
break;
|
||||||
case enums.armor.publicKey:
|
case enums.armor.publicKey:
|
||||||
result.push('-----BEGIN PGP PUBLIC KEY BLOCK-----\n');
|
result.push('-----BEGIN PGP PUBLIC KEY BLOCK-----\n');
|
||||||
result.push(addheader(customComment, config));
|
result.push(addheader(customComment, config));
|
||||||
result.push(base64.encode(body));
|
result.push(encodeBase64(body));
|
||||||
maybeBodyClone && result.push('=', getCheckSum(maybeBodyClone));
|
maybeBodyClone && result.push('=', getCheckSum(maybeBodyClone));
|
||||||
result.push('-----END PGP PUBLIC KEY BLOCK-----\n');
|
result.push('-----END PGP PUBLIC KEY BLOCK-----\n');
|
||||||
break;
|
break;
|
||||||
case enums.armor.privateKey:
|
case enums.armor.privateKey:
|
||||||
result.push('-----BEGIN PGP PRIVATE KEY BLOCK-----\n');
|
result.push('-----BEGIN PGP PRIVATE KEY BLOCK-----\n');
|
||||||
result.push(addheader(customComment, config));
|
result.push(addheader(customComment, config));
|
||||||
result.push(base64.encode(body));
|
result.push(encodeBase64(body));
|
||||||
maybeBodyClone && result.push('=', getCheckSum(maybeBodyClone));
|
maybeBodyClone && result.push('=', getCheckSum(maybeBodyClone));
|
||||||
result.push('-----END PGP PRIVATE KEY BLOCK-----\n');
|
result.push('-----END PGP PRIVATE KEY BLOCK-----\n');
|
||||||
break;
|
break;
|
||||||
case enums.armor.signature:
|
case enums.armor.signature:
|
||||||
result.push('-----BEGIN PGP SIGNATURE-----\n');
|
result.push('-----BEGIN PGP SIGNATURE-----\n');
|
||||||
result.push(addheader(customComment, config));
|
result.push(addheader(customComment, config));
|
||||||
result.push(base64.encode(body));
|
result.push(encodeBase64(body));
|
||||||
maybeBodyClone && result.push('=', getCheckSum(maybeBodyClone));
|
maybeBodyClone && result.push('=', getCheckSum(maybeBodyClone));
|
||||||
result.push('-----END PGP SIGNATURE-----\n');
|
result.push('-----END PGP SIGNATURE-----\n');
|
||||||
break;
|
break;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user