@protontech/openpgp 4.10.5 → 5.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +311 -239
- package/dist/lightweight/bn.interface.min.mjs +3 -0
- package/dist/lightweight/bn.interface.min.mjs.map +1 -0
- package/dist/lightweight/bn.interface.mjs +340 -0
- package/dist/lightweight/bn.min.mjs +3 -0
- package/dist/lightweight/bn.min.mjs.map +1 -0
- package/dist/lightweight/bn.mjs +3434 -0
- package/dist/lightweight/elliptic.min.mjs +3 -0
- package/dist/lightweight/elliptic.min.mjs.map +1 -0
- package/dist/lightweight/elliptic.mjs +4313 -0
- package/dist/lightweight/openpgp.min.mjs +3 -0
- package/dist/lightweight/openpgp.min.mjs.map +1 -0
- package/dist/lightweight/openpgp.mjs +31375 -0
- package/dist/lightweight/ponyfill.es6.min.mjs +3 -0
- package/dist/lightweight/ponyfill.es6.min.mjs.map +1 -0
- package/dist/lightweight/ponyfill.es6.mjs +3831 -0
- package/dist/lightweight/web-streams-adapter.min.mjs +17 -0
- package/dist/lightweight/web-streams-adapter.min.mjs.map +1 -0
- package/dist/lightweight/web-streams-adapter.mjs +561 -0
- package/dist/node/openpgp.js +43943 -0
- package/dist/node/openpgp.min.js +17 -0
- package/dist/node/openpgp.min.js.map +1 -0
- package/dist/node/openpgp.min.mjs +17 -0
- package/dist/node/openpgp.min.mjs.map +1 -0
- package/dist/node/openpgp.mjs +43880 -0
- package/dist/openpgp.js +41080 -41565
- package/dist/openpgp.min.js +17 -2
- package/dist/openpgp.min.js.map +1 -0
- package/dist/openpgp.min.mjs +17 -0
- package/dist/openpgp.min.mjs.map +1 -0
- package/dist/openpgp.mjs +43868 -0
- package/lightweight/package.json +5 -0
- package/openpgp.d.ts +889 -0
- package/package.json +63 -57
- package/dist/compat/openpgp.js +0 -61067
- package/dist/compat/openpgp.min.js +0 -2
- package/dist/compat/openpgp.worker.js +0 -173
- package/dist/compat/openpgp.worker.min.js +0 -2
- package/dist/lightweight/elliptic.min.js +0 -5
- package/dist/lightweight/openpgp.js +0 -40024
- package/dist/lightweight/openpgp.min.js +0 -2
- package/dist/lightweight/openpgp.worker.js +0 -173
- package/dist/lightweight/openpgp.worker.min.js +0 -2
- package/dist/openpgp.worker.js +0 -173
- package/dist/openpgp.worker.min.js +0 -2
- package/src/cleartext.js +0 -220
- package/src/config/config.js +0 -224
- package/src/config/index.js +0 -7
- package/src/config/localStorage.js +0 -35
- package/src/crypto/aes_kw.js +0 -153
- package/src/crypto/cfb.js +0 -169
- package/src/crypto/cipher/aes.js +0 -27
- package/src/crypto/cipher/blowfish.js +0 -398
- package/src/crypto/cipher/cast5.js +0 -610
- package/src/crypto/cipher/des.js +0 -476
- package/src/crypto/cipher/index.js +0 -91
- package/src/crypto/cipher/twofish.js +0 -346
- package/src/crypto/cmac.js +0 -98
- package/src/crypto/crypto.js +0 -394
- package/src/crypto/eax.js +0 -172
- package/src/crypto/gcm.js +0 -141
- package/src/crypto/hash/index.js +0 -163
- package/src/crypto/hash/md5.js +0 -205
- package/src/crypto/index.js +0 -57
- package/src/crypto/ocb.js +0 -274
- package/src/crypto/pkcs1.js +0 -170
- package/src/crypto/pkcs5.js +0 -55
- package/src/crypto/public_key/dsa.js +0 -188
- package/src/crypto/public_key/elgamal.js +0 -137
- package/src/crypto/public_key/elliptic/curves.js +0 -385
- package/src/crypto/public_key/elliptic/ecdh.js +0 -414
- package/src/crypto/public_key/elliptic/ecdsa.js +0 -348
- package/src/crypto/public_key/elliptic/eddsa.js +0 -119
- package/src/crypto/public_key/elliptic/index.js +0 -34
- package/src/crypto/public_key/elliptic/indutnyKey.js +0 -85
- package/src/crypto/public_key/index.js +0 -28
- package/src/crypto/public_key/prime.js +0 -275
- package/src/crypto/public_key/rsa.js +0 -597
- package/src/crypto/random.js +0 -145
- package/src/crypto/signature.js +0 -137
- package/src/encoding/armor.js +0 -433
- package/src/encoding/base64.js +0 -96
- package/src/enums.js +0 -493
- package/src/hkp.js +0 -89
- package/src/index.js +0 -161
- package/src/key/factory.js +0 -326
- package/src/key/helper.js +0 -363
- package/src/key/index.js +0 -32
- package/src/key/key.js +0 -890
- package/src/key/subkey.js +0 -187
- package/src/key/user.js +0 -230
- package/src/keyring/index.js +0 -12
- package/src/keyring/keyring.js +0 -229
- package/src/keyring/localstore.js +0 -119
- package/src/lightweight_helper.js +0 -26
- package/src/message.js +0 -825
- package/src/openpgp.js +0 -717
- package/src/packet/all_packets.js +0 -116
- package/src/packet/clone.js +0 -189
- package/src/packet/compressed.js +0 -194
- package/src/packet/index.js +0 -20
- package/src/packet/literal.js +0 -168
- package/src/packet/marker.js +0 -62
- package/src/packet/one_pass_signature.js +0 -156
- package/src/packet/packet.js +0 -300
- package/src/packet/packetlist.js +0 -232
- package/src/packet/public_key.js +0 -280
- package/src/packet/public_key_encrypted_session_key.js +0 -156
- package/src/packet/public_subkey.js +0 -44
- package/src/packet/secret_key.js +0 -448
- package/src/packet/secret_subkey.js +0 -41
- package/src/packet/signature.js +0 -782
- package/src/packet/sym_encrypted_aead_protected.js +0 -189
- package/src/packet/sym_encrypted_integrity_protected.js +0 -139
- package/src/packet/sym_encrypted_session_key.js +0 -204
- package/src/packet/symmetrically_encrypted.js +0 -118
- package/src/packet/trust.js +0 -35
- package/src/packet/user_attribute.js +0 -94
- package/src/packet/userid.js +0 -87
- package/src/polyfills.js +0 -64
- package/src/signature.js +0 -73
- package/src/type/ecdh_symkey.js +0 -69
- package/src/type/kdf_params.js +0 -114
- package/src/type/keyid.js +0 -110
- package/src/type/mpi.js +0 -138
- package/src/type/oid.js +0 -110
- package/src/type/s2k.js +0 -203
- package/src/util.js +0 -836
- package/src/wkd.js +0 -88
- package/src/worker/async_proxy.js +0 -190
- package/src/worker/worker.js +0 -167
- package/test/crypto/aes_kw.js +0 -57
- package/test/crypto/cipher/aes.js +0 -86
- package/test/crypto/cipher/blowfish.js +0 -58
- package/test/crypto/cipher/cast5.js +0 -25
- package/test/crypto/cipher/des.js +0 -143
- package/test/crypto/cipher/index.js +0 -7
- package/test/crypto/cipher/twofish.js +0 -71
- package/test/crypto/crypto.js +0 -383
- package/test/crypto/eax.js +0 -150
- package/test/crypto/ecdh.js +0 -359
- package/test/crypto/elliptic.js +0 -251
- package/test/crypto/elliptic_data.js +0 -102
- package/test/crypto/hash/index.js +0 -5
- package/test/crypto/hash/md5.js +0 -16
- package/test/crypto/hash/ripemd.js +0 -14
- package/test/crypto/hash/sha.js +0 -20
- package/test/crypto/index.js +0 -14
- package/test/crypto/ocb.js +0 -183
- package/test/crypto/pkcs5.js +0 -39
- package/test/crypto/random.js +0 -79
- package/test/crypto/rsa.js +0 -180
- package/test/crypto/validate.js +0 -387
- package/test/general/armor.js +0 -408
- package/test/general/brainpool.js +0 -360
- package/test/general/decompression.js +0 -60
- package/test/general/ecc_nist.js +0 -115
- package/test/general/ecc_secp256k1.js +0 -242
- package/test/general/forwarding.js +0 -43
- package/test/general/hkp.js +0 -165
- package/test/general/index.js +0 -20
- package/test/general/key.js +0 -3402
- package/test/general/keyring.js +0 -336
- package/test/general/oid.js +0 -39
- package/test/general/openpgp.js +0 -2542
- package/test/general/packet.js +0 -937
- package/test/general/signature.js +0 -1665
- package/test/general/streaming.js +0 -944
- package/test/general/testInputs.js +0 -18
- package/test/general/util.js +0 -183
- package/test/general/wkd.js +0 -48
- package/test/general/x25519.js +0 -556
- package/test/unittests.js +0 -64
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Exports all OpenPGP packet types
|
|
3
|
-
* @requires enums
|
|
4
|
-
* @module packet/all_packets
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import enums from '../enums.js';
|
|
8
|
-
import * as packets from './all_packets.js'; // re-import module to parse packets from tag
|
|
9
|
-
|
|
10
|
-
export {
|
|
11
|
-
/** @see module:packet.Compressed */
|
|
12
|
-
default as Compressed
|
|
13
|
-
} from './compressed.js';
|
|
14
|
-
export {
|
|
15
|
-
/** @see module:packet.SymEncryptedIntegrityProtected */
|
|
16
|
-
default as SymEncryptedIntegrityProtected
|
|
17
|
-
} from './sym_encrypted_integrity_protected.js';
|
|
18
|
-
export {
|
|
19
|
-
/** @see module:packet.SymEncryptedAEADProtected */
|
|
20
|
-
default as SymEncryptedAEADProtected
|
|
21
|
-
} from './sym_encrypted_aead_protected.js';
|
|
22
|
-
export {
|
|
23
|
-
/** @see module:packet.PublicKeyEncryptedSessionKey */
|
|
24
|
-
default as PublicKeyEncryptedSessionKey
|
|
25
|
-
} from './public_key_encrypted_session_key.js';
|
|
26
|
-
export {
|
|
27
|
-
/** @see module:packet.SymEncryptedSessionKey */
|
|
28
|
-
default as SymEncryptedSessionKey
|
|
29
|
-
} from './sym_encrypted_session_key.js';
|
|
30
|
-
export {
|
|
31
|
-
/** @see module:packet.Literal */
|
|
32
|
-
default as Literal
|
|
33
|
-
} from './literal.js';
|
|
34
|
-
export {
|
|
35
|
-
/** @see module:packet.PublicKey */
|
|
36
|
-
default as PublicKey
|
|
37
|
-
} from './public_key.js';
|
|
38
|
-
export {
|
|
39
|
-
/** @see module:packet.SymmetricallyEncrypted */
|
|
40
|
-
default as SymmetricallyEncrypted
|
|
41
|
-
} from './symmetrically_encrypted.js';
|
|
42
|
-
export {
|
|
43
|
-
/** @see module:packet.Marker */
|
|
44
|
-
default as Marker
|
|
45
|
-
} from './marker.js';
|
|
46
|
-
export {
|
|
47
|
-
/** @see module:packet.PublicSubkey */
|
|
48
|
-
default as PublicSubkey
|
|
49
|
-
} from './public_subkey.js';
|
|
50
|
-
export {
|
|
51
|
-
/** @see module:packet.UserAttribute */
|
|
52
|
-
default as UserAttribute
|
|
53
|
-
} from './user_attribute.js';
|
|
54
|
-
export {
|
|
55
|
-
/** @see module:packet.OnePassSignature */
|
|
56
|
-
default as OnePassSignature
|
|
57
|
-
} from './one_pass_signature.js';
|
|
58
|
-
export {
|
|
59
|
-
/** @see module:packet.SecretKey */
|
|
60
|
-
default as SecretKey
|
|
61
|
-
} from './secret_key.js';
|
|
62
|
-
export {
|
|
63
|
-
/** @see module:packet.Userid */
|
|
64
|
-
default as Userid
|
|
65
|
-
} from './userid.js';
|
|
66
|
-
export {
|
|
67
|
-
/** @see module:packet.SecretSubkey */
|
|
68
|
-
default as SecretSubkey
|
|
69
|
-
} from './secret_subkey.js';
|
|
70
|
-
export {
|
|
71
|
-
/** @see module:packet.Signature */
|
|
72
|
-
default as Signature
|
|
73
|
-
} from './signature.js';
|
|
74
|
-
export {
|
|
75
|
-
/** @see module:packet.Trust */
|
|
76
|
-
default as Trust
|
|
77
|
-
} from './trust.js';
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Allocate a new packet
|
|
81
|
-
* @function newPacketFromTag
|
|
82
|
-
* @memberof module:packet
|
|
83
|
-
* @param {String} tag property name from {@link module:enums.packet}
|
|
84
|
-
* @returns {Object} new packet object with type based on tag
|
|
85
|
-
*/
|
|
86
|
-
export function newPacketFromTag(tag) {
|
|
87
|
-
return new packets[packetClassFromTagName(tag)]();
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Allocate a new packet from structured packet clone
|
|
92
|
-
* @see {@link https://w3c.github.io/html/infrastructure.html#safe-passing-of-structured-data}
|
|
93
|
-
* @function fromStructuredClone
|
|
94
|
-
* @memberof module:packet
|
|
95
|
-
* @param {Object} packetClone packet clone
|
|
96
|
-
* @returns {Object} new packet object with data from packet clone
|
|
97
|
-
*/
|
|
98
|
-
export function fromStructuredClone(packetClone) {
|
|
99
|
-
const tagName = enums.read(enums.packet, packetClone.tag);
|
|
100
|
-
const packet = newPacketFromTag(tagName);
|
|
101
|
-
Object.assign(packet, packetClone);
|
|
102
|
-
if (packet.postCloneTypeFix) {
|
|
103
|
-
packet.postCloneTypeFix();
|
|
104
|
-
}
|
|
105
|
-
return packet;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* Convert tag name to class name
|
|
110
|
-
* @param {String} tag property name from {@link module:enums.packet}
|
|
111
|
-
* @returns {String}
|
|
112
|
-
* @private
|
|
113
|
-
*/
|
|
114
|
-
function packetClassFromTagName(tag) {
|
|
115
|
-
return tag.substr(0, 1).toUpperCase() + tag.substr(1);
|
|
116
|
-
}
|
package/src/packet/clone.js
DELETED
|
@@ -1,189 +0,0 @@
|
|
|
1
|
-
// OpenPGP.js - An OpenPGP implementation in javascript
|
|
2
|
-
// Copyright (C) 2015 Tankred Hase
|
|
3
|
-
//
|
|
4
|
-
// This library is free software; you can redistribute it and/or
|
|
5
|
-
// modify it under the terms of the GNU Lesser General Public
|
|
6
|
-
// License as published by the Free Software Foundation; either
|
|
7
|
-
// version 3.0 of the License, or (at your option) any later version.
|
|
8
|
-
//
|
|
9
|
-
// This library is distributed in the hope that it will be useful,
|
|
10
|
-
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
-
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
12
|
-
// Lesser General Public License for more details.
|
|
13
|
-
//
|
|
14
|
-
// You should have received a copy of the GNU Lesser General Public
|
|
15
|
-
// License along with this library; if not, write to the Free Software
|
|
16
|
-
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* @fileoverview This module implements packet list cloning required to
|
|
20
|
-
* pass certain object types between the web worker and main thread using
|
|
21
|
-
* the structured cloning algorithm.
|
|
22
|
-
* @module packet/clone
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
import stream from 'web-stream-tools';
|
|
26
|
-
import { Key } from '../key';
|
|
27
|
-
import { Message } from '../message';
|
|
28
|
-
import { CleartextMessage } from '../cleartext';
|
|
29
|
-
import { Signature } from '../signature';
|
|
30
|
-
import List from './packetlist';
|
|
31
|
-
import type_keyid from '../type/keyid';
|
|
32
|
-
import util from '../util';
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
//////////////////////////////
|
|
36
|
-
// //
|
|
37
|
-
// List --> Clone //
|
|
38
|
-
// //
|
|
39
|
-
//////////////////////////////
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Create a packetlist from the correspoding object types.
|
|
44
|
-
* @param {Object} options the object passed to and from the web worker
|
|
45
|
-
* @returns {Object} a mutated version of the options optject
|
|
46
|
-
*/
|
|
47
|
-
export function clonePackets(options) {
|
|
48
|
-
if (options.publicKeys) {
|
|
49
|
-
options.publicKeys = options.publicKeys.map(key => key.toPacketlist());
|
|
50
|
-
}
|
|
51
|
-
if (options.privateKeys) {
|
|
52
|
-
options.privateKeys = options.privateKeys.map(key => key.toPacketlist());
|
|
53
|
-
}
|
|
54
|
-
if (options.publicKey) {
|
|
55
|
-
options.publicKey = options.publicKey.toPacketlist();
|
|
56
|
-
}
|
|
57
|
-
if (options.privateKey) {
|
|
58
|
-
options.privateKey = options.privateKey.toPacketlist();
|
|
59
|
-
}
|
|
60
|
-
if (options.key) {
|
|
61
|
-
options.key = options.key.toPacketlist();
|
|
62
|
-
}
|
|
63
|
-
if (options.message) {
|
|
64
|
-
//could be either a Message or CleartextMessage object
|
|
65
|
-
if (options.message instanceof Message) {
|
|
66
|
-
options.message = { packets: options.message.packets, fromStream: options.message.fromStream };
|
|
67
|
-
} else if (options.message instanceof CleartextMessage) {
|
|
68
|
-
options.message = { text: options.message.text, signature: options.message.signature.packets };
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
if (options.signature && (options.signature instanceof Signature)) {
|
|
72
|
-
options.signature = options.signature.packets;
|
|
73
|
-
}
|
|
74
|
-
if (options.signatures) {
|
|
75
|
-
options.signatures.forEach(verificationObjectToClone);
|
|
76
|
-
}
|
|
77
|
-
return options;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
function verificationObjectToClone(verObject) {
|
|
81
|
-
const verified = verObject.verified;
|
|
82
|
-
verObject.verified = stream.fromAsync(() => verified);
|
|
83
|
-
if (verObject.signature instanceof Promise) {
|
|
84
|
-
const signature = verObject.signature;
|
|
85
|
-
verObject.signature = stream.fromAsync(async () => {
|
|
86
|
-
const packets = (await signature).packets;
|
|
87
|
-
try {
|
|
88
|
-
await verified;
|
|
89
|
-
} catch (e) {}
|
|
90
|
-
if (packets && packets[0]) {
|
|
91
|
-
delete packets[0].signature;
|
|
92
|
-
delete packets[0].hashed;
|
|
93
|
-
}
|
|
94
|
-
return packets;
|
|
95
|
-
});
|
|
96
|
-
} else {
|
|
97
|
-
verObject.signature = verObject.signature.packets;
|
|
98
|
-
}
|
|
99
|
-
if (verObject.error) {
|
|
100
|
-
verObject.error = verObject.error.message;
|
|
101
|
-
}
|
|
102
|
-
return verObject;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
//////////////////////////////
|
|
106
|
-
// //
|
|
107
|
-
// Clone --> List //
|
|
108
|
-
// //
|
|
109
|
-
//////////////////////////////
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Creates an object with the correct prototype from a corresponding packetlist.
|
|
114
|
-
* @param {Object} options the object passed to and from the web worker
|
|
115
|
-
* @param {String} method the public api function name to be delegated to the worker
|
|
116
|
-
* @returns {Object} a mutated version of the options optject
|
|
117
|
-
*/
|
|
118
|
-
export function parseClonedPackets(options) {
|
|
119
|
-
if (options.publicKeys) {
|
|
120
|
-
options.publicKeys = options.publicKeys.map(packetlistCloneToKey);
|
|
121
|
-
}
|
|
122
|
-
if (options.privateKeys) {
|
|
123
|
-
options.privateKeys = options.privateKeys.map(packetlistCloneToKey);
|
|
124
|
-
}
|
|
125
|
-
if (options.publicKey) {
|
|
126
|
-
options.publicKey = packetlistCloneToKey(options.publicKey);
|
|
127
|
-
}
|
|
128
|
-
if (options.privateKey) {
|
|
129
|
-
options.privateKey = packetlistCloneToKey(options.privateKey);
|
|
130
|
-
}
|
|
131
|
-
if (options.key) {
|
|
132
|
-
options.key = packetlistCloneToKey(options.key);
|
|
133
|
-
}
|
|
134
|
-
if (options.message && options.message.signature) {
|
|
135
|
-
options.message = packetlistCloneToCleartextMessage(options.message);
|
|
136
|
-
} else if (options.message) {
|
|
137
|
-
options.message = packetlistCloneToMessage(options.message);
|
|
138
|
-
}
|
|
139
|
-
if (options.signatures) {
|
|
140
|
-
options.signatures = options.signatures.map(packetlistCloneToSignatures);
|
|
141
|
-
}
|
|
142
|
-
if (options.signature) {
|
|
143
|
-
options.signature = packetlistCloneToSignature(options.signature);
|
|
144
|
-
}
|
|
145
|
-
return options;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
function packetlistCloneToKey(clone) {
|
|
149
|
-
const packetlist = List.fromStructuredClone(clone);
|
|
150
|
-
return new Key(packetlist);
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
function packetlistCloneToMessage(clone) {
|
|
154
|
-
const packetlist = List.fromStructuredClone(clone.packets);
|
|
155
|
-
const message = new Message(packetlist);
|
|
156
|
-
message.fromStream = clone.fromStream;
|
|
157
|
-
return message;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
function packetlistCloneToCleartextMessage(clone) {
|
|
161
|
-
const packetlist = List.fromStructuredClone(clone.signature);
|
|
162
|
-
return new CleartextMessage(clone.text, new Signature(packetlist));
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
//verification objects
|
|
166
|
-
function packetlistCloneToSignatures(clone) {
|
|
167
|
-
clone.keyid = type_keyid.fromClone(clone.keyid);
|
|
168
|
-
if (util.isStream(clone.signature)) {
|
|
169
|
-
clone.signature = stream.readToEnd(clone.signature, ([signature]) => new Signature(List.fromStructuredClone(signature)));
|
|
170
|
-
clone.signature.catch(() => {});
|
|
171
|
-
} else {
|
|
172
|
-
clone.signature = new Signature(List.fromStructuredClone(clone.signature));
|
|
173
|
-
}
|
|
174
|
-
clone.verified = stream.readToEnd(clone.verified, ([verified]) => verified);
|
|
175
|
-
clone.verified.catch(() => {});
|
|
176
|
-
if (clone.error) {
|
|
177
|
-
clone.error = new Error(clone.error);
|
|
178
|
-
}
|
|
179
|
-
return clone;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
function packetlistCloneToSignature(clone) {
|
|
183
|
-
if (util.isString(clone) || util.isStream(clone)) {
|
|
184
|
-
//signature is armored
|
|
185
|
-
return clone;
|
|
186
|
-
}
|
|
187
|
-
const packetlist = List.fromStructuredClone(clone);
|
|
188
|
-
return new Signature(packetlist);
|
|
189
|
-
}
|
package/src/packet/compressed.js
DELETED
|
@@ -1,194 +0,0 @@
|
|
|
1
|
-
// GPG4Browsers - An OpenPGP implementation in javascript
|
|
2
|
-
// Copyright (C) 2011 Recurity Labs GmbH
|
|
3
|
-
//
|
|
4
|
-
// This library is free software; you can redistribute it and/or
|
|
5
|
-
// modify it under the terms of the GNU Lesser General Public
|
|
6
|
-
// License as published by the Free Software Foundation; either
|
|
7
|
-
// version 3.0 of the License, or (at your option) any later version.
|
|
8
|
-
//
|
|
9
|
-
// This library is distributed in the hope that it will be useful,
|
|
10
|
-
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
-
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
12
|
-
// Lesser General Public License for more details.
|
|
13
|
-
//
|
|
14
|
-
// You should have received a copy of the GNU Lesser General Public
|
|
15
|
-
// License along with this library; if not, write to the Free Software
|
|
16
|
-
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* @requires web-stream-tools
|
|
20
|
-
* @requires pako
|
|
21
|
-
* @requires config
|
|
22
|
-
* @requires enums
|
|
23
|
-
* @requires util
|
|
24
|
-
* @requires compression/bzip2
|
|
25
|
-
*/
|
|
26
|
-
|
|
27
|
-
import pako from 'pako';
|
|
28
|
-
import Bunzip from 'seek-bzip';
|
|
29
|
-
import stream from 'web-stream-tools';
|
|
30
|
-
import config from '../config';
|
|
31
|
-
import enums from '../enums';
|
|
32
|
-
import util from '../util';
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Implementation of the Compressed Data Packet (Tag 8)
|
|
36
|
-
*
|
|
37
|
-
* {@link https://tools.ietf.org/html/rfc4880#section-5.6|RFC4880 5.6}:
|
|
38
|
-
* The Compressed Data packet contains compressed data. Typically,
|
|
39
|
-
* this packet is found as the contents of an encrypted packet, or following
|
|
40
|
-
* a Signature or One-Pass Signature packet, and contains a literal data packet.
|
|
41
|
-
* @memberof module:packet
|
|
42
|
-
* @constructor
|
|
43
|
-
*/
|
|
44
|
-
function Compressed() {
|
|
45
|
-
/**
|
|
46
|
-
* Packet type
|
|
47
|
-
* @type {module:enums.packet}
|
|
48
|
-
*/
|
|
49
|
-
this.tag = enums.packet.compressed;
|
|
50
|
-
/**
|
|
51
|
-
* List of packets
|
|
52
|
-
* @type {module:packet.List}
|
|
53
|
-
*/
|
|
54
|
-
this.packets = null;
|
|
55
|
-
/**
|
|
56
|
-
* Compression algorithm
|
|
57
|
-
* @type {compression}
|
|
58
|
-
*/
|
|
59
|
-
this.algorithm = 'zip';
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Compressed packet data
|
|
63
|
-
* @type {Uint8Array | ReadableStream<Uint8Array>}
|
|
64
|
-
*/
|
|
65
|
-
this.compressed = null;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Parsing function for the packet.
|
|
70
|
-
* @param {Uint8Array | ReadableStream<Uint8Array>} bytes Payload of a tag 8 packet
|
|
71
|
-
*/
|
|
72
|
-
Compressed.prototype.read = async function (bytes, streaming) {
|
|
73
|
-
await stream.parse(bytes, async reader => {
|
|
74
|
-
|
|
75
|
-
// One octet that gives the algorithm used to compress the packet.
|
|
76
|
-
this.algorithm = enums.read(enums.compression, await reader.readByte());
|
|
77
|
-
|
|
78
|
-
// Compressed data, which makes up the remainder of the packet.
|
|
79
|
-
this.compressed = reader.remainder();
|
|
80
|
-
|
|
81
|
-
await this.decompress(streaming);
|
|
82
|
-
});
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Return the compressed packet.
|
|
88
|
-
* @returns {Uint8Array | ReadableStream<Uint8Array>} binary compressed packet
|
|
89
|
-
*/
|
|
90
|
-
Compressed.prototype.write = function () {
|
|
91
|
-
if (this.compressed === null) {
|
|
92
|
-
this.compress();
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
return util.concat([new Uint8Array([enums.write(enums.compression, this.algorithm)]), this.compressed]);
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* Decompression method for decompressing the compressed data
|
|
101
|
-
* read by read_packet
|
|
102
|
-
*/
|
|
103
|
-
Compressed.prototype.decompress = async function (streaming) {
|
|
104
|
-
|
|
105
|
-
if (!decompress_fns[this.algorithm]) {
|
|
106
|
-
throw new Error(this.algorithm + ' decompression not supported');
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
await this.packets.read(decompress_fns[this.algorithm](this.compressed), streaming);
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Compress the packet data (member decompressedData)
|
|
114
|
-
*/
|
|
115
|
-
Compressed.prototype.compress = function () {
|
|
116
|
-
|
|
117
|
-
if (!compress_fns[this.algorithm]) {
|
|
118
|
-
throw new Error(this.algorithm + ' compression not supported');
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
this.compressed = compress_fns[this.algorithm](this.packets.write());
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
export default Compressed;
|
|
125
|
-
|
|
126
|
-
//////////////////////////
|
|
127
|
-
// //
|
|
128
|
-
// Helper functions //
|
|
129
|
-
// //
|
|
130
|
-
//////////////////////////
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
const nodeZlib = util.getNodeZlib();
|
|
134
|
-
|
|
135
|
-
function uncompressed(data) {
|
|
136
|
-
return data;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
function node_zlib(func, options = {}) {
|
|
140
|
-
return function (data) {
|
|
141
|
-
return stream.nodeToWeb(stream.webToNode(data).pipe(func(options)));
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
function pako_zlib(constructor, options = {}) {
|
|
146
|
-
return function(data) {
|
|
147
|
-
const obj = new constructor(options);
|
|
148
|
-
return stream.transform(data, value => {
|
|
149
|
-
if (value.length) {
|
|
150
|
-
obj.push(value, pako.Z_SYNC_FLUSH);
|
|
151
|
-
return obj.result;
|
|
152
|
-
}
|
|
153
|
-
}, () => {
|
|
154
|
-
if (constructor === pako.Deflate) {
|
|
155
|
-
obj.push([], pako.Z_FINISH);
|
|
156
|
-
return obj.result;
|
|
157
|
-
}
|
|
158
|
-
});
|
|
159
|
-
};
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
function bzip2(func) {
|
|
163
|
-
return function(data) {
|
|
164
|
-
return stream.fromAsync(async () => func(await stream.readToEnd(data)));
|
|
165
|
-
};
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
let compress_fns;
|
|
169
|
-
let decompress_fns;
|
|
170
|
-
if (nodeZlib) { // Use Node native zlib for DEFLATE compression/decompression
|
|
171
|
-
compress_fns = {
|
|
172
|
-
zip: node_zlib(nodeZlib.createDeflateRaw, { level: config.deflate_level }),
|
|
173
|
-
zlib: node_zlib(nodeZlib.createDeflate, { level: config.deflate_level })
|
|
174
|
-
};
|
|
175
|
-
|
|
176
|
-
decompress_fns = {
|
|
177
|
-
uncompressed: uncompressed,
|
|
178
|
-
zip: node_zlib(nodeZlib.createInflateRaw),
|
|
179
|
-
zlib: node_zlib(nodeZlib.createInflate),
|
|
180
|
-
bzip2: bzip2(Bunzip.decode)
|
|
181
|
-
};
|
|
182
|
-
} else { // Use JS fallbacks
|
|
183
|
-
compress_fns = {
|
|
184
|
-
zip: pako_zlib(pako.Deflate, { raw: true, level: config.deflate_level }),
|
|
185
|
-
zlib: pako_zlib(pako.Deflate, { level: config.deflate_level })
|
|
186
|
-
};
|
|
187
|
-
|
|
188
|
-
decompress_fns = {
|
|
189
|
-
uncompressed: uncompressed,
|
|
190
|
-
zip: pako_zlib(pako.Inflate, { raw: true }),
|
|
191
|
-
zlib: pako_zlib(pako.Inflate),
|
|
192
|
-
bzip2: bzip2(Bunzip.decode)
|
|
193
|
-
};
|
|
194
|
-
}
|
package/src/packet/index.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview OpenPGP packet types
|
|
3
|
-
* @see module:packet/all_packets
|
|
4
|
-
* @see module:packet/clone
|
|
5
|
-
* @see module:packet.List
|
|
6
|
-
* @module packet
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import * as packets from './all_packets';
|
|
10
|
-
import * as clone from './clone';
|
|
11
|
-
import List from './packetlist';
|
|
12
|
-
|
|
13
|
-
const mod = {
|
|
14
|
-
List,
|
|
15
|
-
clone
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
Object.assign(mod, packets);
|
|
19
|
-
|
|
20
|
-
export default mod;
|
package/src/packet/literal.js
DELETED
|
@@ -1,168 +0,0 @@
|
|
|
1
|
-
// GPG4Browsers - An OpenPGP implementation in javascript
|
|
2
|
-
// Copyright (C) 2011 Recurity Labs GmbH
|
|
3
|
-
//
|
|
4
|
-
// This library is free software; you can redistribute it and/or
|
|
5
|
-
// modify it under the terms of the GNU Lesser General Public
|
|
6
|
-
// License as published by the Free Software Foundation; either
|
|
7
|
-
// version 3.0 of the License, or (at your option) any later version.
|
|
8
|
-
//
|
|
9
|
-
// This library is distributed in the hope that it will be useful,
|
|
10
|
-
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
-
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
12
|
-
// Lesser General Public License for more details.
|
|
13
|
-
//
|
|
14
|
-
// You should have received a copy of the GNU Lesser General Public
|
|
15
|
-
// License along with this library; if not, write to the Free Software
|
|
16
|
-
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* @requires web-stream-tools
|
|
20
|
-
* @requires enums
|
|
21
|
-
* @requires util
|
|
22
|
-
*/
|
|
23
|
-
|
|
24
|
-
import stream from 'web-stream-tools';
|
|
25
|
-
import enums from '../enums';
|
|
26
|
-
import util from '../util';
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Implementation of the Literal Data Packet (Tag 11)
|
|
30
|
-
*
|
|
31
|
-
* {@link https://tools.ietf.org/html/rfc4880#section-5.9|RFC4880 5.9}:
|
|
32
|
-
* A Literal Data packet contains the body of a message; data that is not to be
|
|
33
|
-
* further interpreted.
|
|
34
|
-
* @param {Date} date the creation date of the literal package
|
|
35
|
-
* @memberof module:packet
|
|
36
|
-
* @constructor
|
|
37
|
-
*/
|
|
38
|
-
function Literal(date = new Date()) {
|
|
39
|
-
this.tag = enums.packet.literal;
|
|
40
|
-
this.format = 'utf8'; // default format for literal data packets
|
|
41
|
-
this.date = util.normalizeDate(date);
|
|
42
|
-
this.text = null; // textual data representation
|
|
43
|
-
this.data = null; // literal data representation
|
|
44
|
-
this.filename = 'msg.txt';
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Set the packet data to a javascript native string, end of line
|
|
49
|
-
* will be normalized to \r\n and by default text is converted to UTF8
|
|
50
|
-
* @param {String | ReadableStream<String>} text Any native javascript string
|
|
51
|
-
* @param {utf8|binary|text|mime} format (optional) The format of the string of bytes
|
|
52
|
-
*/
|
|
53
|
-
Literal.prototype.setText = function(text, format = 'utf8') {
|
|
54
|
-
this.format = format;
|
|
55
|
-
this.text = text;
|
|
56
|
-
this.data = null;
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Returns literal data packets as native JavaScript string
|
|
61
|
-
* with normalized end of line to \n
|
|
62
|
-
* @param {Boolean} clone (optional) Whether to return a clone so that getBytes/getText can be called again
|
|
63
|
-
* @returns {String | ReadableStream<String>} literal data as text
|
|
64
|
-
*/
|
|
65
|
-
Literal.prototype.getText = function(clone = false) {
|
|
66
|
-
if (this.text === null || util.isStream(this.text)) { // Assume that this.text has been read
|
|
67
|
-
this.text = util.decode_utf8(util.nativeEOL(this.getBytes(clone)));
|
|
68
|
-
}
|
|
69
|
-
return this.text;
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Set the packet data to value represented by the provided string of bytes.
|
|
74
|
-
* @param {Uint8Array | ReadableStream<Uint8Array>} bytes The string of bytes
|
|
75
|
-
* @param {utf8|binary|text|mime} format The format of the string of bytes
|
|
76
|
-
*/
|
|
77
|
-
Literal.prototype.setBytes = function(bytes, format) {
|
|
78
|
-
this.format = format;
|
|
79
|
-
this.data = bytes;
|
|
80
|
-
this.text = null;
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Get the byte sequence representing the literal packet data
|
|
86
|
-
* @param {Boolean} clone (optional) Whether to return a clone so that getBytes/getText can be called again
|
|
87
|
-
* @returns {Uint8Array | ReadableStream<Uint8Array>} A sequence of bytes
|
|
88
|
-
*/
|
|
89
|
-
Literal.prototype.getBytes = function(clone = false) {
|
|
90
|
-
if (this.data === null) {
|
|
91
|
-
// encode UTF8 and normalize EOL to \r\n
|
|
92
|
-
this.data = util.canonicalizeEOL(util.encode_utf8(this.text));
|
|
93
|
-
}
|
|
94
|
-
if (clone) {
|
|
95
|
-
return stream.passiveClone(this.data);
|
|
96
|
-
}
|
|
97
|
-
return this.data;
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Sets the filename of the literal packet data
|
|
103
|
-
* @param {String} filename Any native javascript string
|
|
104
|
-
*/
|
|
105
|
-
Literal.prototype.setFilename = function(filename) {
|
|
106
|
-
this.filename = filename;
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* Get the filename of the literal packet data
|
|
112
|
-
* @returns {String} filename
|
|
113
|
-
*/
|
|
114
|
-
Literal.prototype.getFilename = function() {
|
|
115
|
-
return this.filename;
|
|
116
|
-
};
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Parsing function for a literal data packet (tag 11).
|
|
121
|
-
*
|
|
122
|
-
* @param {Uint8Array | ReadableStream<Uint8Array>} input Payload of a tag 11 packet
|
|
123
|
-
* @returns {module:packet.Literal} object representation
|
|
124
|
-
*/
|
|
125
|
-
Literal.prototype.read = async function(bytes) {
|
|
126
|
-
await stream.parse(bytes, async reader => {
|
|
127
|
-
// - A one-octet field that describes how the data is formatted.
|
|
128
|
-
const format = enums.read(enums.literal, await reader.readByte());
|
|
129
|
-
|
|
130
|
-
const filename_len = await reader.readByte();
|
|
131
|
-
this.filename = util.decode_utf8(await reader.readBytes(filename_len));
|
|
132
|
-
|
|
133
|
-
this.date = util.readDate(await reader.readBytes(4));
|
|
134
|
-
|
|
135
|
-
const data = reader.remainder();
|
|
136
|
-
|
|
137
|
-
this.setBytes(data, format);
|
|
138
|
-
});
|
|
139
|
-
};
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* Creates a Uint8Array representation of the packet, excluding the data
|
|
143
|
-
*
|
|
144
|
-
* @returns {Uint8Array} Uint8Array representation of the packet
|
|
145
|
-
*/
|
|
146
|
-
Literal.prototype.writeHeader = function() {
|
|
147
|
-
const filename = util.encode_utf8(this.filename);
|
|
148
|
-
const filename_length = new Uint8Array([filename.length]);
|
|
149
|
-
|
|
150
|
-
const format = new Uint8Array([enums.write(enums.literal, this.format)]);
|
|
151
|
-
const date = util.writeDate(this.date);
|
|
152
|
-
|
|
153
|
-
return util.concatUint8Array([format, filename_length, filename, date]);
|
|
154
|
-
};
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
* Creates a Uint8Array representation of the packet
|
|
158
|
-
*
|
|
159
|
-
* @returns {Uint8Array | ReadableStream<Uint8Array>} Uint8Array representation of the packet
|
|
160
|
-
*/
|
|
161
|
-
Literal.prototype.write = function() {
|
|
162
|
-
const header = this.writeHeader();
|
|
163
|
-
const data = this.getBytes();
|
|
164
|
-
|
|
165
|
-
return util.concat([header, data]);
|
|
166
|
-
};
|
|
167
|
-
|
|
168
|
-
export default Literal;
|