Replace Key with PrivateKey and PublicKey classes (#1300)

- Add `PrivateKey` and `PublicKey` classes. A `PrivateKey` can always
  be passed where a `PublicKey` key is expected, but not vice versa.
- Unexport `Key`, and export `PrivateKey` and `PublicKey`. 
- Rename `Key.packetlist2structure` to `Key.packetListToStructure`.
- Change `Key.update` to return a new updated key, rather than
  modifying the destination one in place.
- Add `openpgp.readPrivateKey` and `openpgp.readPrivateKeys` to avoid
  having to downcast the result of `readKey(s)` in TypeScript.
This commit is contained in:
larabr
2021-05-25 19:18:47 +02:00
committed by GitHub
parent 3349fab89e
commit f028026217
18 changed files with 815 additions and 487 deletions

View File

@@ -1,6 +1,6 @@
const openpgp = typeof window !== 'undefined' && window.openpgp ? window.openpgp : require('../..');
const { readKey, Key, createMessage, enums, PacketList, SignaturePacket } = openpgp;
const { readKey, PrivateKey, createMessage, enums, PacketList, SignaturePacket } = openpgp;
const chai = require('chai');
chai.use(require('chai-as-promised'));
@@ -82,7 +82,7 @@ async function makeKeyValid() {
// reconstruct the modified key
const newlist = new PacketList();
newlist.push(pubkey, puser, pusersig);
let modifiedkey = new Key(newlist);
let modifiedkey = new PrivateKey(newlist);
// re-read the message to eliminate any
// behaviour due to cached values.
modifiedkey = await readKey({ armoredKey: await modifiedkey.armor() });