@protontech/openpgp 4.10.8 → 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.
Files changed (173) hide show
  1. package/README.md +311 -239
  2. package/dist/lightweight/bn.interface.min.mjs +3 -0
  3. package/dist/lightweight/bn.interface.min.mjs.map +1 -0
  4. package/dist/lightweight/bn.interface.mjs +340 -0
  5. package/dist/lightweight/bn.min.mjs +3 -0
  6. package/dist/lightweight/bn.min.mjs.map +1 -0
  7. package/dist/lightweight/bn.mjs +3434 -0
  8. package/dist/lightweight/elliptic.min.mjs +3 -0
  9. package/dist/lightweight/elliptic.min.mjs.map +1 -0
  10. package/dist/lightweight/elliptic.mjs +4313 -0
  11. package/dist/lightweight/openpgp.min.mjs +3 -0
  12. package/dist/lightweight/openpgp.min.mjs.map +1 -0
  13. package/dist/lightweight/openpgp.mjs +31375 -0
  14. package/dist/lightweight/ponyfill.es6.min.mjs +3 -0
  15. package/dist/lightweight/ponyfill.es6.min.mjs.map +1 -0
  16. package/dist/lightweight/ponyfill.es6.mjs +3831 -0
  17. package/dist/lightweight/web-streams-adapter.min.mjs +17 -0
  18. package/dist/lightweight/web-streams-adapter.min.mjs.map +1 -0
  19. package/dist/lightweight/web-streams-adapter.mjs +561 -0
  20. package/dist/node/openpgp.js +43943 -0
  21. package/dist/node/openpgp.min.js +17 -0
  22. package/dist/node/openpgp.min.js.map +1 -0
  23. package/dist/node/openpgp.min.mjs +17 -0
  24. package/dist/node/openpgp.min.mjs.map +1 -0
  25. package/dist/node/openpgp.mjs +43880 -0
  26. package/dist/openpgp.js +41077 -41609
  27. package/dist/openpgp.min.js +17 -2
  28. package/dist/openpgp.min.js.map +1 -0
  29. package/dist/openpgp.min.mjs +17 -0
  30. package/dist/openpgp.min.mjs.map +1 -0
  31. package/dist/openpgp.mjs +43868 -0
  32. package/lightweight/package.json +5 -0
  33. package/openpgp.d.ts +889 -0
  34. package/package.json +63 -57
  35. package/dist/compat/openpgp.js +0 -61152
  36. package/dist/compat/openpgp.min.js +0 -2
  37. package/dist/compat/openpgp.worker.js +0 -173
  38. package/dist/compat/openpgp.worker.min.js +0 -2
  39. package/dist/lightweight/elliptic.min.js +0 -5
  40. package/dist/lightweight/openpgp.js +0 -40071
  41. package/dist/lightweight/openpgp.min.js +0 -2
  42. package/dist/lightweight/openpgp.worker.js +0 -173
  43. package/dist/lightweight/openpgp.worker.min.js +0 -2
  44. package/dist/openpgp.worker.js +0 -173
  45. package/dist/openpgp.worker.min.js +0 -2
  46. package/src/cleartext.js +0 -220
  47. package/src/config/config.js +0 -232
  48. package/src/config/index.js +0 -7
  49. package/src/config/localStorage.js +0 -35
  50. package/src/crypto/aes_kw.js +0 -153
  51. package/src/crypto/cfb.js +0 -169
  52. package/src/crypto/cipher/aes.js +0 -27
  53. package/src/crypto/cipher/blowfish.js +0 -398
  54. package/src/crypto/cipher/cast5.js +0 -610
  55. package/src/crypto/cipher/des.js +0 -476
  56. package/src/crypto/cipher/index.js +0 -91
  57. package/src/crypto/cipher/twofish.js +0 -346
  58. package/src/crypto/cmac.js +0 -98
  59. package/src/crypto/crypto.js +0 -394
  60. package/src/crypto/eax.js +0 -172
  61. package/src/crypto/gcm.js +0 -141
  62. package/src/crypto/hash/index.js +0 -163
  63. package/src/crypto/hash/md5.js +0 -205
  64. package/src/crypto/index.js +0 -57
  65. package/src/crypto/ocb.js +0 -274
  66. package/src/crypto/pkcs1.js +0 -170
  67. package/src/crypto/pkcs5.js +0 -55
  68. package/src/crypto/public_key/dsa.js +0 -188
  69. package/src/crypto/public_key/elgamal.js +0 -137
  70. package/src/crypto/public_key/elliptic/curves.js +0 -385
  71. package/src/crypto/public_key/elliptic/ecdh.js +0 -414
  72. package/src/crypto/public_key/elliptic/ecdsa.js +0 -348
  73. package/src/crypto/public_key/elliptic/eddsa.js +0 -119
  74. package/src/crypto/public_key/elliptic/index.js +0 -34
  75. package/src/crypto/public_key/elliptic/indutnyKey.js +0 -85
  76. package/src/crypto/public_key/index.js +0 -28
  77. package/src/crypto/public_key/prime.js +0 -275
  78. package/src/crypto/public_key/rsa.js +0 -597
  79. package/src/crypto/random.js +0 -145
  80. package/src/crypto/signature.js +0 -137
  81. package/src/encoding/armor.js +0 -433
  82. package/src/encoding/base64.js +0 -96
  83. package/src/enums.js +0 -493
  84. package/src/hkp.js +0 -89
  85. package/src/index.js +0 -161
  86. package/src/key/factory.js +0 -326
  87. package/src/key/helper.js +0 -378
  88. package/src/key/index.js +0 -32
  89. package/src/key/key.js +0 -888
  90. package/src/key/subkey.js +0 -187
  91. package/src/key/user.js +0 -230
  92. package/src/keyring/index.js +0 -12
  93. package/src/keyring/keyring.js +0 -229
  94. package/src/keyring/localstore.js +0 -119
  95. package/src/lightweight_helper.js +0 -26
  96. package/src/message.js +0 -825
  97. package/src/openpgp.js +0 -717
  98. package/src/packet/all_packets.js +0 -116
  99. package/src/packet/clone.js +0 -189
  100. package/src/packet/compressed.js +0 -194
  101. package/src/packet/index.js +0 -20
  102. package/src/packet/literal.js +0 -168
  103. package/src/packet/marker.js +0 -62
  104. package/src/packet/one_pass_signature.js +0 -156
  105. package/src/packet/packet.js +0 -300
  106. package/src/packet/packetlist.js +0 -232
  107. package/src/packet/public_key.js +0 -280
  108. package/src/packet/public_key_encrypted_session_key.js +0 -161
  109. package/src/packet/public_subkey.js +0 -44
  110. package/src/packet/secret_key.js +0 -468
  111. package/src/packet/secret_subkey.js +0 -41
  112. package/src/packet/signature.js +0 -786
  113. package/src/packet/sym_encrypted_aead_protected.js +0 -189
  114. package/src/packet/sym_encrypted_integrity_protected.js +0 -139
  115. package/src/packet/sym_encrypted_session_key.js +0 -204
  116. package/src/packet/symmetrically_encrypted.js +0 -118
  117. package/src/packet/trust.js +0 -35
  118. package/src/packet/user_attribute.js +0 -94
  119. package/src/packet/userid.js +0 -87
  120. package/src/polyfills.js +0 -64
  121. package/src/signature.js +0 -73
  122. package/src/type/ecdh_symkey.js +0 -69
  123. package/src/type/kdf_params.js +0 -114
  124. package/src/type/keyid.js +0 -110
  125. package/src/type/mpi.js +0 -138
  126. package/src/type/oid.js +0 -110
  127. package/src/type/s2k.js +0 -203
  128. package/src/util.js +0 -836
  129. package/src/wkd.js +0 -84
  130. package/src/worker/async_proxy.js +0 -190
  131. package/src/worker/worker.js +0 -167
  132. package/test/crypto/aes_kw.js +0 -57
  133. package/test/crypto/cipher/aes.js +0 -86
  134. package/test/crypto/cipher/blowfish.js +0 -58
  135. package/test/crypto/cipher/cast5.js +0 -25
  136. package/test/crypto/cipher/des.js +0 -143
  137. package/test/crypto/cipher/index.js +0 -7
  138. package/test/crypto/cipher/twofish.js +0 -71
  139. package/test/crypto/crypto.js +0 -383
  140. package/test/crypto/eax.js +0 -150
  141. package/test/crypto/ecdh.js +0 -359
  142. package/test/crypto/elliptic.js +0 -251
  143. package/test/crypto/elliptic_data.js +0 -102
  144. package/test/crypto/hash/index.js +0 -5
  145. package/test/crypto/hash/md5.js +0 -16
  146. package/test/crypto/hash/ripemd.js +0 -14
  147. package/test/crypto/hash/sha.js +0 -20
  148. package/test/crypto/index.js +0 -14
  149. package/test/crypto/ocb.js +0 -183
  150. package/test/crypto/pkcs5.js +0 -39
  151. package/test/crypto/random.js +0 -79
  152. package/test/crypto/rsa.js +0 -180
  153. package/test/crypto/validate.js +0 -387
  154. package/test/general/armor.js +0 -408
  155. package/test/general/brainpool.js +0 -360
  156. package/test/general/decompression.js +0 -60
  157. package/test/general/ecc_nist.js +0 -115
  158. package/test/general/ecc_secp256k1.js +0 -242
  159. package/test/general/forwarding.js +0 -43
  160. package/test/general/hkp.js +0 -165
  161. package/test/general/index.js +0 -20
  162. package/test/general/key.js +0 -3491
  163. package/test/general/keyring.js +0 -336
  164. package/test/general/oid.js +0 -39
  165. package/test/general/openpgp.js +0 -2577
  166. package/test/general/packet.js +0 -950
  167. package/test/general/signature.js +0 -1715
  168. package/test/general/streaming.js +0 -944
  169. package/test/general/testInputs.js +0 -18
  170. package/test/general/util.js +0 -183
  171. package/test/general/wkd.js +0 -48
  172. package/test/general/x25519.js +0 -556
  173. package/test/unittests.js +0 -64
@@ -1,94 +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 packet
20
- * @requires enums
21
- * @requires util
22
- */
23
-
24
- import packet from './packet';
25
- import enums from '../enums';
26
- import util from '../util';
27
-
28
- /**
29
- * Implementation of the User Attribute Packet (Tag 17)
30
- *
31
- * The User Attribute packet is a variation of the User ID packet. It
32
- * is capable of storing more types of data than the User ID packet,
33
- * which is limited to text. Like the User ID packet, a User Attribute
34
- * packet may be certified by the key owner ("self-signed") or any other
35
- * key owner who cares to certify it. Except as noted, a User Attribute
36
- * packet may be used anywhere that a User ID packet may be used.
37
- *
38
- * While User Attribute packets are not a required part of the OpenPGP
39
- * standard, implementations SHOULD provide at least enough
40
- * compatibility to properly handle a certification signature on the
41
- * User Attribute packet. A simple way to do this is by treating the
42
- * User Attribute packet as a User ID packet with opaque contents, but
43
- * an implementation may use any method desired.
44
- * @memberof module:packet
45
- * @constructor
46
- */
47
- function UserAttribute() {
48
- this.tag = enums.packet.userAttribute;
49
- this.attributes = [];
50
- }
51
-
52
- /**
53
- * parsing function for a user attribute packet (tag 17).
54
- * @param {Uint8Array} input payload of a tag 17 packet
55
- */
56
- UserAttribute.prototype.read = function(bytes) {
57
- let i = 0;
58
- while (i < bytes.length) {
59
- const len = packet.readSimpleLength(bytes.subarray(i, bytes.length));
60
- i += len.offset;
61
-
62
- this.attributes.push(util.Uint8Array_to_str(bytes.subarray(i, i + len.len)));
63
- i += len.len;
64
- }
65
- };
66
-
67
- /**
68
- * Creates a binary representation of the user attribute packet
69
- * @returns {Uint8Array} string representation
70
- */
71
- UserAttribute.prototype.write = function() {
72
- const arr = [];
73
- for (let i = 0; i < this.attributes.length; i++) {
74
- arr.push(packet.writeSimpleLength(this.attributes[i].length));
75
- arr.push(util.str_to_Uint8Array(this.attributes[i]));
76
- }
77
- return util.concatUint8Array(arr);
78
- };
79
-
80
- /**
81
- * Compare for equality
82
- * @param {module:packet.UserAttribute} usrAttr
83
- * @returns {Boolean} true if equal
84
- */
85
- UserAttribute.prototype.equals = function(usrAttr) {
86
- if (!usrAttr || !(usrAttr instanceof UserAttribute)) {
87
- return false;
88
- }
89
- return this.attributes.every(function(attr, index) {
90
- return attr === usrAttr.attributes[index];
91
- });
92
- };
93
-
94
- export default UserAttribute;
@@ -1,87 +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 enums
20
- * @requires util
21
- */
22
-
23
- import enums from '../enums';
24
- import util from '../util';
25
-
26
- /**
27
- * Implementation of the User ID Packet (Tag 13)
28
- *
29
- * A User ID packet consists of UTF-8 text that is intended to represent
30
- * the name and email address of the key holder. By convention, it
31
- * includes an RFC 2822 [RFC2822] mail name-addr, but there are no
32
- * restrictions on its content. The packet length in the header
33
- * specifies the length of the User ID.
34
- * @memberof module:packet
35
- * @constructor
36
- */
37
- function Userid() {
38
- this.tag = enums.packet.userid;
39
- /** A string containing the user id. Usually in the form
40
- * John Doe <john@example.com>
41
- * @type {String}
42
- */
43
- this.userid = '';
44
-
45
- this.name = '';
46
- this.email = '';
47
- this.comment = '';
48
- }
49
-
50
- /**
51
- * Parsing function for a user id packet (tag 13).
52
- * @param {Uint8Array} input payload of a tag 13 packet
53
- */
54
- Userid.prototype.read = function (bytes) {
55
- this.parse(util.decode_utf8(bytes));
56
- };
57
-
58
- /**
59
- * Parse userid string, e.g. 'John Doe <john@example.com>'
60
- */
61
- Userid.prototype.parse = function (userid) {
62
- try {
63
- Object.assign(this, util.parseUserId(userid));
64
- } catch (e) {}
65
- this.userid = userid;
66
- };
67
-
68
- /**
69
- * Creates a binary representation of the user id packet
70
- * @returns {Uint8Array} binary representation
71
- */
72
- Userid.prototype.write = function () {
73
- return util.encode_utf8(this.userid);
74
- };
75
-
76
- /**
77
- * Set userid string from object, e.g. { name:'Phil Zimmermann', email:'phil@openpgp.org' }
78
- */
79
- Userid.prototype.format = function (userid) {
80
- if (util.isString(userid)) {
81
- userid = util.parseUserId(userid);
82
- }
83
- Object.assign(this, userid);
84
- this.userid = util.formatUserId(userid);
85
- };
86
-
87
- export default Userid;
package/src/polyfills.js DELETED
@@ -1,64 +0,0 @@
1
- /**
2
- * @fileoverview Old browser polyfills
3
- * All are listed as dev dependencies because Node does not need them
4
- * and for browser babel will take care of it
5
- * @requires util
6
- * @module polyfills
7
- */
8
-
9
- import util from './util';
10
-
11
- if (typeof global !== 'undefined') {
12
- /********************************************************************
13
- * NOTE: This list is duplicated in Gruntfile.js, *
14
- * so that these polyfills are only included in the compat bundle. *
15
- ********************************************************************/
16
-
17
- try {
18
- if (typeof global.fetch === 'undefined') {
19
- require('whatwg-fetch');
20
- }
21
- if (typeof Array.prototype.fill === 'undefined') {
22
- require('core-js/fn/array/fill');
23
- }
24
- if (typeof Array.prototype.find === 'undefined') {
25
- require('core-js/fn/array/find');
26
- }
27
- if (typeof Array.prototype.includes === 'undefined') {
28
- require('core-js/fn/array/includes');
29
- }
30
- if (typeof Array.from === 'undefined') {
31
- require('core-js/fn/array/from');
32
- }
33
-
34
- // No if-statement on Promise because of IE11. Otherwise Promise is undefined in the service worker.
35
- require('core-js/fn/promise');
36
-
37
- if (typeof Uint8Array.from === 'undefined') {
38
- require('core-js/fn/typed/uint8-array');
39
- }
40
- if (typeof String.prototype.repeat === 'undefined') {
41
- require('core-js/fn/string/repeat');
42
- }
43
- if (typeof Symbol === 'undefined') {
44
- require('core-js/fn/symbol');
45
- }
46
- if (typeof Object.assign === 'undefined') {
47
- require('core-js/fn/object/assign');
48
- }
49
- } catch (e) {}
50
- }
51
-
52
- if (typeof TransformStream === 'undefined') {
53
- require('@mattiasbuelens/web-streams-polyfill/es6');
54
- }
55
- if (typeof TextEncoder === 'undefined') {
56
- const nodeUtil = util.nodeRequire('util') || {};
57
- global.TextEncoder = nodeUtil.TextEncoder;
58
- global.TextDecoder = nodeUtil.TextDecoder;
59
- }
60
- if (typeof TextEncoder === 'undefined') {
61
- const textEncoding = require('text-encoding-utf-8');
62
- global.TextEncoder = textEncoding.TextEncoder;
63
- global.TextDecoder = textEncoding.TextDecoder;
64
- }
package/src/signature.js DELETED
@@ -1,73 +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 encoding/armor
20
- * @requires packet
21
- * @requires enums
22
- * @module signature
23
- */
24
-
25
- import armor from './encoding/armor';
26
- import packet from './packet';
27
- import enums from './enums';
28
-
29
- /**
30
- * @class
31
- * @classdesc Class that represents an OpenPGP signature.
32
- * @param {module:packet.List} packetlist The signature packets
33
- */
34
- export function Signature(packetlist) {
35
- if (!(this instanceof Signature)) {
36
- return new Signature(packetlist);
37
- }
38
- this.packets = packetlist || new packet.List();
39
- }
40
-
41
-
42
- /**
43
- * Returns ASCII armored text of signature
44
- * @returns {ReadableStream<String>} ASCII armor
45
- */
46
- Signature.prototype.armor = function() {
47
- return armor.encode(enums.armor.signature, this.packets.write());
48
- };
49
-
50
- /**
51
- * reads an OpenPGP armored signature and returns a signature object
52
- * @param {String | ReadableStream<String>} armoredText text to be parsed
53
- * @returns {Signature} new signature object
54
- * @async
55
- * @static
56
- */
57
- export async function readArmored(armoredText) {
58
- const input = await armor.decode(armoredText);
59
- return read(input.data);
60
- }
61
-
62
- /**
63
- * reads an OpenPGP signature as byte array and returns a signature object
64
- * @param {Uint8Array | ReadableStream<Uint8Array>} input binary signature
65
- * @returns {Signature} new signature object
66
- * @async
67
- * @static
68
- */
69
- export async function read(input) {
70
- const packetlist = new packet.List();
71
- await packetlist.read(input);
72
- return new Signature(packetlist);
73
- }
@@ -1,69 +0,0 @@
1
- // OpenPGP.js - An OpenPGP implementation in javascript
2
- // Copyright (C) 2015-2016 Decentral
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
- * Encoded symmetric key for ECDH
20
- *
21
- * @requires util
22
- * @module type/ecdh_symkey
23
- */
24
-
25
- import util from '../util';
26
-
27
- /**
28
- * @constructor
29
- */
30
- function ECDHSymmetricKey(data) {
31
- if (typeof data === 'undefined') {
32
- data = new Uint8Array([]);
33
- } else if (util.isString(data)) {
34
- data = util.str_to_Uint8Array(data);
35
- } else {
36
- data = new Uint8Array(data);
37
- }
38
- this.data = data;
39
- }
40
-
41
- /**
42
- * Read an ECDHSymmetricKey from an Uint8Array
43
- * @param {Uint8Array} input Where to read the encoded symmetric key from
44
- * @returns {Number} Number of read bytes
45
- */
46
- ECDHSymmetricKey.prototype.read = function (input) {
47
- if (input.length >= 1) {
48
- const length = input[0];
49
- if (input.length >= 1 + length) {
50
- this.data = input.subarray(1, 1 + length);
51
- return 1 + this.data.length;
52
- }
53
- }
54
- throw new Error('Invalid symmetric key');
55
- };
56
-
57
- /**
58
- * Write an ECDHSymmetricKey as an Uint8Array
59
- * @returns {Uint8Array} An array containing the value
60
- */
61
- ECDHSymmetricKey.prototype.write = function () {
62
- return util.concatUint8Array([new Uint8Array([this.data.length]), this.data]);
63
- };
64
-
65
- ECDHSymmetricKey.fromClone = function (clone) {
66
- return new ECDHSymmetricKey(clone.data);
67
- };
68
-
69
- export default ECDHSymmetricKey;
@@ -1,114 +0,0 @@
1
- // OpenPGP.js - An OpenPGP implementation in javascript
2
- // Copyright (C) 2015-2016 Decentral
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
- * Implementation of type KDF parameters
20
- *
21
- * {@link https://tools.ietf.org/html/rfc6637#section-7|RFC 6637 7}:
22
- * A key derivation function (KDF) is necessary to implement the EC
23
- * encryption. The Concatenation Key Derivation Function (Approved
24
- * Alternative 1) [NIST-SP800-56A] with the KDF hash function that is
25
- * SHA2-256 [FIPS-180-3] or stronger is REQUIRED.
26
- * @requires enums
27
- * @module type/kdf_params
28
- */
29
-
30
- import enums from '../enums';
31
- import utils from '../util';
32
-
33
- /**
34
- * @constructor
35
- * @param {Integer} version Version, defaults to 1
36
- * @param {enums.hash} hash Hash algorithm
37
- * @param {enums.symmetric} cipher Symmetric algorithm
38
- * @param {enums.kdfFlags} flags (v2 only) flags
39
- * @param {Uint8Array} replacementFingerprint (v2 only) fingerprint to use instead of recipient one (v5 keys, the 20 leftmost bytes of the fingerprint)
40
- * @param {Uint8Array} replacementKDFParams (v2 only) serialized KDF params to use in KDF digest computation
41
-
42
- */
43
- function KDFParams(data) {
44
- if (data) {
45
- const { version, hash, cipher, flags, replacementFingerprint, replacementKDFParams } = data;
46
- this.version = version || 1;
47
- this.hash = hash;
48
- this.cipher = cipher;
49
-
50
- this.flags = flags;
51
- this.replacementFingerprint = replacementFingerprint;
52
- this.replacementKDFParams = replacementKDFParams;
53
- } else {
54
- this.version = null;
55
- this.hash = null;
56
- this.cipher = null;
57
- this.flags = null;
58
- this.replacementFingerprint = null;
59
- this.replacementKDFParams = null;
60
- }
61
- }
62
-
63
- /**
64
- * Read KDFParams from an Uint8Array
65
- * @param {Uint8Array} input Where to read the KDFParams from
66
- * @returns {Number} Number of read bytes
67
- */
68
- KDFParams.prototype.read = function (input) {
69
- this.version = input[1];
70
- this.hash = input[2];
71
- this.cipher = input[3];
72
- let readBytes = 4;
73
-
74
- if (this.version === 2) {
75
- this.flags = input[readBytes++];
76
- if (this.flags & enums.kdfFlags.replace_fingerprint) {
77
- this.replacementFingerprint = input.slice(readBytes, readBytes + 20);
78
- readBytes += 20;
79
- }
80
- if (this.flags & enums.kdfFlags.replace_kdf_params) {
81
- const fieldLength = input[readBytes] + 1; // account for length
82
- this.replacementKDFParams = input.slice(readBytes, readBytes + fieldLength);
83
- readBytes += fieldLength;
84
- }
85
- }
86
- return readBytes;
87
- };
88
-
89
- /**
90
- * Write KDFParams to an Uint8Array
91
- * @returns {Uint8Array} Array with the KDFParams value
92
- */
93
- KDFParams.prototype.write = function () {
94
- if (!this.version || this.version === 1) {
95
- return new Uint8Array([3, 1, this.hash, this.cipher]);
96
- }
97
-
98
- const v2Fields = utils.concatUint8Array([
99
- new Uint8Array([4, 2, this.hash, this.cipher, this.flags]),
100
- this.replacementFingerprint || new Uint8Array(),
101
- this.replacementKDFParams || new Uint8Array()
102
- ]);
103
-
104
- // update length field
105
- v2Fields[0] = v2Fields.length - 1;
106
- return new Uint8Array(v2Fields);
107
- };
108
-
109
- KDFParams.fromClone = function (clone) {
110
- const { hash, cipher, flags, replacementFingerprint, replacementKDFParams } = clone;
111
- return new KDFParams({ hash, cipher, flags, replacementFingerprint, replacementKDFParams });
112
- };
113
-
114
- export default KDFParams;
package/src/type/keyid.js DELETED
@@ -1,110 +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
- * Implementation of type key id
20
- *
21
- * {@link https://tools.ietf.org/html/rfc4880#section-3.3|RFC4880 3.3}:
22
- * A Key ID is an eight-octet scalar that identifies a key.
23
- * Implementations SHOULD NOT assume that Key IDs are unique. The
24
- * section "Enhanced Key Formats" below describes how Key IDs are
25
- * formed.
26
- * @requires util
27
- * @module type/keyid
28
- */
29
-
30
- import util from '../util.js';
31
-
32
- /**
33
- * @constructor
34
- */
35
- function Keyid() {
36
- this.bytes = '';
37
- }
38
-
39
- /**
40
- * Parsing method for a key id
41
- * @param {Uint8Array} input Input to read the key id from
42
- */
43
- Keyid.prototype.read = function(bytes) {
44
- this.bytes = util.Uint8Array_to_str(bytes.subarray(0, 8));
45
- };
46
-
47
- /**
48
- * Serializes the Key ID
49
- * @returns {Uint8Array} Key ID as a Uint8Array
50
- */
51
- Keyid.prototype.write = function() {
52
- return util.str_to_Uint8Array(this.bytes);
53
- };
54
-
55
- /**
56
- * Returns the Key ID represented as a hexadecimal string
57
- * @returns {String} Key ID as a hexadecimal string
58
- */
59
- Keyid.prototype.toHex = function() {
60
- return util.str_to_hex(this.bytes);
61
- };
62
-
63
- /**
64
- * Checks equality of Key ID's
65
- * @param {Keyid} keyid
66
- * @param {Boolean} matchWildcard Indicates whether to check if either keyid is a wildcard
67
- */
68
- Keyid.prototype.equals = function(keyid, matchWildcard = false) {
69
- return (matchWildcard && (keyid.isWildcard() || this.isWildcard())) || this.bytes === keyid.bytes;
70
- };
71
-
72
- /**
73
- * Checks to see if the Key ID is unset
74
- * @returns {Boolean} true if the Key ID is null
75
- */
76
- Keyid.prototype.isNull = function() {
77
- return this.bytes === '';
78
- };
79
-
80
- /**
81
- * Checks to see if the Key ID is a "wildcard" Key ID (all zeros)
82
- * @returns {Boolean} true if this is a wildcard Key ID
83
- */
84
- Keyid.prototype.isWildcard = function() {
85
- return /^0+$/.test(this.toHex());
86
- };
87
-
88
- Keyid.mapToHex = function (keyId) {
89
- return keyId.toHex();
90
- };
91
-
92
- Keyid.fromClone = function (clone) {
93
- const keyid = new Keyid();
94
- keyid.bytes = clone.bytes;
95
- return keyid;
96
- };
97
-
98
- Keyid.fromId = function (hex) {
99
- const keyid = new Keyid();
100
- keyid.read(util.hex_to_Uint8Array(hex));
101
- return keyid;
102
- };
103
-
104
- Keyid.wildcard = function () {
105
- const keyid = new Keyid();
106
- keyid.read(new Uint8Array(8));
107
- return keyid;
108
- };
109
-
110
- export default Keyid;