Merge pull request #639 from openpgpjs/alg_info
Add getAlgorithmInfo function for public key
This commit is contained in:
commit
790799f2e7
|
@ -35,6 +35,7 @@ import crypto from '../crypto';
|
||||||
import enums from '../enums';
|
import enums from '../enums';
|
||||||
import util from '../util';
|
import util from '../util';
|
||||||
import type_keyid from '../type/keyid';
|
import type_keyid from '../type/keyid';
|
||||||
|
import type_mpi from '../type/mpi';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constructor
|
* @constructor
|
||||||
|
@ -194,11 +195,18 @@ PublicKey.prototype.getFingerprint = function () {
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns bit size of key
|
* Returns algorithm information
|
||||||
* @return {int} Number of bits
|
* @return {Promise<Object} An object of the form {algorithm: String, bits:int, curve:String}
|
||||||
*/
|
*/
|
||||||
PublicKey.prototype.getBitSize = function () {
|
PublicKey.prototype.getAlgorithmInfo = function () {
|
||||||
return this.params[0].byteLength() * 8;
|
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;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue
Block a user