mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-06-28 22:30:01 +00:00
fixes openpgp type compatibility with api (#31555)
* fixes openpgp type compatibility with api * Update index.d.ts
This commit is contained in:
committed by
Nathan Shively-Sanders
parent
bb560329b9
commit
f680ffc4f0
10
types/openpgp/index.d.ts
vendored
10
types/openpgp/index.d.ts
vendored
@@ -37,8 +37,8 @@ export interface EncryptOptions {
|
||||
}
|
||||
|
||||
export interface EncryptedMessage {
|
||||
data: string,
|
||||
message: string,
|
||||
data?: string,
|
||||
message?: message.Message,
|
||||
}
|
||||
|
||||
export interface DecryptOptions {
|
||||
@@ -571,6 +571,10 @@ export namespace message {
|
||||
@param keys array of keys to verify signatures
|
||||
*/
|
||||
verify(keys: Array<key.Key>): Array<Object>,
|
||||
|
||||
packets: {
|
||||
write(): Uint8Array,
|
||||
},
|
||||
}
|
||||
|
||||
/** creates new message object from binary data
|
||||
@@ -595,7 +599,7 @@ export namespace message {
|
||||
* @returns {Message} new message object
|
||||
* @static
|
||||
*/
|
||||
function read(data: Uint8Array): Message;
|
||||
function read(data: Uint8Array): Promise<Message>;
|
||||
}
|
||||
|
||||
export namespace packet {
|
||||
|
||||
@@ -70,6 +70,45 @@ Promise.all(promises).then(function (values) {
|
||||
// failure
|
||||
});
|
||||
|
||||
openpgp.initWorker({ path:'openpgp.worker.js' });
|
||||
|
||||
(async () => {
|
||||
let msgOptions: openpgp.EncryptOptions;
|
||||
|
||||
msgOptions = {
|
||||
message: openpgp.message.fromBinary(new Uint8Array([0x01, 0x01, 0x01])),
|
||||
passwords: ['secret stuff'],
|
||||
armor: false,
|
||||
};
|
||||
|
||||
let cipher = await openpgp.encrypt(msgOptions);
|
||||
let encrypted = cipher.message.packets.write(); // get raw encrypted packets as Uint8Array
|
||||
|
||||
let plain = await openpgp.decrypt({
|
||||
message: await openpgp.message.read(encrypted),
|
||||
passwords: ['secret stuff'],
|
||||
format: 'binary'
|
||||
});
|
||||
|
||||
return plain.data;
|
||||
})();
|
||||
|
||||
(async () => {
|
||||
let cipher = await openpgp.encrypt({
|
||||
message: openpgp.message.fromText('hello world'),
|
||||
passwords: 'super secure',
|
||||
armor: true,
|
||||
});
|
||||
let encrypted = cipher.data;
|
||||
|
||||
let plain = await openpgp.decrypt({
|
||||
message: await openpgp.message.readArmored(encrypted),
|
||||
passwords: 'super secure',
|
||||
});
|
||||
|
||||
return plain.data;
|
||||
})();
|
||||
|
||||
|
||||
// Open PGP Tests
|
||||
|
||||
|
||||
10
types/openpgp/ts3.2/index.d.ts
vendored
10
types/openpgp/ts3.2/index.d.ts
vendored
@@ -36,8 +36,8 @@ export interface EncryptOptions {
|
||||
}
|
||||
|
||||
export interface EncryptedMessage {
|
||||
data: string,
|
||||
message: string,
|
||||
data?: string,
|
||||
message?: message.Message,
|
||||
}
|
||||
|
||||
export interface DecryptOptions {
|
||||
@@ -570,6 +570,10 @@ export namespace message {
|
||||
@param keys array of keys to verify signatures
|
||||
*/
|
||||
verify(keys: Array<key.Key>): Array<Object>,
|
||||
|
||||
packets: {
|
||||
write(): Uint8Array,
|
||||
},
|
||||
}
|
||||
|
||||
/** creates new message object from binary data
|
||||
@@ -594,7 +598,7 @@ export namespace message {
|
||||
* @returns {Message} new message object
|
||||
* @static
|
||||
*/
|
||||
function read(data: Uint8Array): Message;
|
||||
function read(data: Uint8Array): Promise<Message>;
|
||||
}
|
||||
|
||||
export namespace packet {
|
||||
|
||||
@@ -70,6 +70,45 @@ Promise.all(promises).then(function (values) {
|
||||
// failure
|
||||
});
|
||||
|
||||
openpgp.initWorker({ path:'openpgp.worker.js' });
|
||||
|
||||
(async () => {
|
||||
let msgOptions: openpgp.EncryptOptions;
|
||||
|
||||
msgOptions = {
|
||||
message: openpgp.message.fromBinary(new Uint8Array([0x01, 0x01, 0x01])),
|
||||
passwords: ['secret stuff'],
|
||||
armor: false,
|
||||
};
|
||||
|
||||
let cipher = await openpgp.encrypt(msgOptions);
|
||||
let encrypted = cipher.message.packets.write(); // get raw encrypted packets as Uint8Array
|
||||
|
||||
let plain = await openpgp.decrypt({
|
||||
message: await openpgp.message.read(encrypted),
|
||||
passwords: ['secret stuff'],
|
||||
format: 'binary'
|
||||
});
|
||||
|
||||
return plain.data;
|
||||
})();
|
||||
|
||||
(async () => {
|
||||
let cipher = await openpgp.encrypt({
|
||||
message: openpgp.message.fromText('hello world'),
|
||||
passwords: 'super secure',
|
||||
armor: true,
|
||||
});
|
||||
let encrypted = cipher.data;
|
||||
|
||||
let plain = await openpgp.decrypt({
|
||||
message: await openpgp.message.readArmored(encrypted),
|
||||
passwords: 'super secure',
|
||||
});
|
||||
|
||||
return plain.data;
|
||||
})();
|
||||
|
||||
|
||||
// Open PGP Tests
|
||||
|
||||
|
||||
Reference in New Issue
Block a user