Merge pull request #639 from openpgpjs/alg_info

Add getAlgorithmInfo function for public key
This commit is contained in:
Bart Butler 2018-02-13 12:35:40 -08:00 committed by GitHub
commit 790799f2e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -35,6 +35,7 @@ import crypto from '../crypto';
import enums from '../enums';
import util from '../util';
import type_keyid from '../type/keyid';
import type_mpi from '../type/mpi';
/**
* @constructor
@ -194,11 +195,18 @@ PublicKey.prototype.getFingerprint = function () {
};
/**
* Returns bit size of key
* @return {int} Number of bits
* Returns algorithm information
* @return {Promise<Object} An object of the form {algorithm: String, bits:int, curve:String}
*/
PublicKey.prototype.getBitSize = function () {
return this.params[0].byteLength() * 8;
PublicKey.prototype.getAlgorithmInfo = function () {
var result = {};
result.algorithm = this.algorithm;
if (this.params[0] instanceof type_mpi) {
result.bits = this.params[0].byteLength() * 8;
} else {
result.curve = crypto.publicKey.elliptic.get(this.params[0]).name;
}
return result;
};
/**